51 lines
1.2 KiB
Java
51 lines
1.2 KiB
Java
package com.rubenvandeven.emotionhero;
|
|
|
|
import android.support.annotation.NonNull;
|
|
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<Integer, ScoreList> levelScores = new HashMap<>();
|
|
|
|
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();
|
|
return gson.toJson(this);
|
|
}
|
|
}
|