Achievements and leaderboards improved interface in libGDX

Hi everybody!
I want to share with you my own approach of making an achievements and leaderboards interface.
It’s important to read this first:

1.- Why do I need this?
You will need this if you are planning to implement Game Center on iOS and Google Play on android

Ok, so here’s the interface with everything explained:

public interface ActionResolver {
	
	public static enum ACHIEVEMENTS_LIST{
		/**LEADERBOARDS**/
		LEADERBOARD_EASY,
		LEADERBOARD_MEDIUM,
		LEADERBOARD_HARD,
		
		/**ACHIEVEMENTS**/
		ACHIEVEMENT_1,
		ACHIEVEMENT_2,
		ACHIEVEMENT_3,
		...
	}	
	public ObjectMap<ACHIEVEMENTS_LIST,String> generateAchievementsMap();	

        /**Make this method return true when you finished implementing the interface and it's functional**/
	public boolean isEnabled();
        /**Check if you are logged in**/
	public boolean getSignedIn();
	public void login();
	public void submitScore(String leaderboardId,long score);
	public void unlockAchievement(String achievementId);
	public void revealAchievement(String achievementId);
	public void incrementAchievement(String achievementId,int steps);
	public void getLeaderboard();
	public void getAchievements();

}

The most important thing here is the ACHIEVEMENTS_LIST and the generateAchievementsMap() Method.
With the generateAchievementsMap() method, you will create a hashmap that has an unique equivalence of the achievement on the ACHIEVEMENTS_LIST with the achievement Id on each of the specific platform (Game Center, Google Play)

Once you have this interface, we will implement it on each of the platforms where we have achievements/leaderboards.
Here’s an example of how to code the achievements map on android launcher:


	@Override
	public ObjectMap<ACHIEVEMENTS_LIST, String> generateAchievementsMap() {
		ObjectMap<ACHIEVEMENTS_LIST,String> map = new ObjectMap<ACHIEVEMENTS_LIST,String>();

		map.put(ACHIEVEMENTS_LIST.LEADERBOARD_EASY, getString(R.string.leaderboard_alpha));
		map.put(ACHIEVEMENTS_LIST.LEADERBOARD_MEDIUM, getString(R.string.leaderboard_beta));
		map.put(ACHIEVEMENTS_LIST.LEADERBOARD_HARD, getString(R.string.leaderboard_omega));

		map.put(ACHIEVEMENTS_LIST.ACHIEVEMENT_1, getString(R.string.achievement_achievement_1));
		map.put(ACHIEVEMENTS_LIST.ACHIEVEMENT_2, getString(R.string.achievement_achievement_2));
		map.put(ACHIEVEMENTS_LIST.ACHIEVEMENT_3, getString(R.string.achievement_achievement_3));
                ....

		return map;
	}

Once you have filled every method of the interface, in your core project you can call the methods like this:


	private ActionResolver resolver;
	private ObjectMap<ACHIEVEMENTS_LIST,String> idMap;

	public Game(ActionResolver resolver){
		this.resolver = resolver;
		if (this.resolver.isEnabled()){
			this.idMap = resolver.generateAchievementsMap();

			/**Unlock achievement 1**/
			resolver.unlockAchievement(idMap.get(ACHIEVEMENTS_LIST.ACHIEVEMENT_1));       
		}
	}

I hope this will be helpful!

PS: If you don’t understand how to implement the interface for an android/ios project and would like to know more, just let me know!