package com.rubenvandeven.emotionhero; import android.support.annotation.NonNull; import android.util.Log; import android.util.SparseArray; import com.google.gson.Gson; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * Created by ruben on 20/08/16. */ public class PlayerInfo { public Map levelScores = new HashMap<>(); public int reachedLevelId = -1; public ScoreList getScoresForLevel(int lvl_id) { ScoreList scoreList; if(!levelScores.containsKey(lvl_id)) { scoreList = new ScoreList(); levelScores.put(lvl_id, scoreList); } else { scoreList = levelScores.get(lvl_id); } return scoreList; } /** * The individual score object contains the level id, so we can fetch the corresponding * scorelist to add this score * @param score */ public void addScore(Score score) { ScoreList scoreList = getScoresForLevel(score.lvl_id); scoreList.add(score); } public static PlayerInfo fromJson(String json) { Gson gson = new Gson(); return gson.fromJson(json, PlayerInfo.class); } public String toJson() { Gson gson = new Gson(); String json = gson.toJson(this); Log.i("PlayerInfo", "Generated: "+json); return json; } /** * Whether the reachedLevelId is higher than the first level * used to show 'continue' button in menu * @return */ public boolean canContinueLevel() { if(reachedLevelId < 0) return false; if(Scenario.SCENARIOS.indexOf(reachedLevelId) > 0) { return true; } return false; } }