Skip to content

Commit

Permalink
Pass Leaderboard Id to score JSON objects (#30)
Browse files Browse the repository at this point in the history
* Pass LeaderboardId to LeaderboardScore JSON

* leaderboardId needs to be final
  • Loading branch information
SkaterDad committed Nov 12, 2020
1 parent b4f070c commit 323402c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions gpgs/src/java/com/defold/gpgs/GpgsJNI.java
Expand Up @@ -617,8 +617,9 @@ public void submitScore(String leaderboardId, double score) {
}
}

private static JSONObject scoreToJSON(LeaderboardScore score) throws JSONException {
private static JSONObject scoreToJSON(LeaderboardScore score, String leaderboardId) throws JSONException {
JSONObject json = new JSONObject();
json.put("leaderboard_id", leaderboardId);
json.put("display_rank", score.getDisplayRank());
json.put("display_score", score.getDisplayScore());
json.put("rank", score.getRank());
Expand All @@ -631,7 +632,7 @@ private static JSONObject scoreToJSON(LeaderboardScore score) throws JSONExcepti
return json;
}

public void loadTopScores(String leaderboardId, int span, int collection, int maxResults) {
public void loadTopScores(final String leaderboardId, int span, int collection, int maxResults) {
if(initLeaderboards()) {
Task<AnnotatedData<LeaderboardsClient.LeaderboardScores>> task = mLeaderboardsClient.loadTopScores(leaderboardId, span, collection, maxResults);
task.addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardsClient.LeaderboardScores>>() {
Expand All @@ -643,7 +644,7 @@ public void onSuccess(AnnotatedData<LeaderboardsClient.LeaderboardScores> data)
try {
JSONArray result = new JSONArray();
for (LeaderboardScore score : buffer) {
JSONObject json = scoreToJSON(score);
JSONObject json = scoreToJSON(score, leaderboardId);
result.put(json.toString());
}
message = result.toString();
Expand All @@ -658,7 +659,7 @@ public void onSuccess(AnnotatedData<LeaderboardsClient.LeaderboardScores> data)
}
}

public void loadPlayerCenteredScores(String leaderboardId, int span, int collection, int maxResults) {
public void loadPlayerCenteredScores(final String leaderboardId, int span, int collection, int maxResults) {
if(initLeaderboards()) {
Task<AnnotatedData<LeaderboardsClient.LeaderboardScores>> task = mLeaderboardsClient.loadPlayerCenteredScores(leaderboardId, span, collection, maxResults);
task.addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardsClient.LeaderboardScores>>() {
Expand All @@ -670,7 +671,7 @@ public void onSuccess(AnnotatedData<LeaderboardsClient.LeaderboardScores> data)
try {
JSONArray result = new JSONArray();
for (LeaderboardScore score : buffer) {
JSONObject json = scoreToJSON(score);
JSONObject json = scoreToJSON(score, leaderboardId);
result.put(json.toString());
}
message = result.toString();
Expand All @@ -685,7 +686,7 @@ public void onSuccess(AnnotatedData<LeaderboardsClient.LeaderboardScores> data)
}
}

public void loadCurrentPlayerLeaderboardScore(String leaderboardId, int span, int collection) {
public void loadCurrentPlayerLeaderboardScore(final String leaderboardId, int span, int collection) {
if(initLeaderboards()) {
Task<AnnotatedData<LeaderboardScore>> task = mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(leaderboardId, span, collection);
task.addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
Expand All @@ -699,7 +700,7 @@ public void onSuccess(AnnotatedData<LeaderboardScore> data) {
}
else {
try {
JSONObject result = scoreToJSON(score);
JSONObject result = scoreToJSON(score, leaderboardId);
message = result.toString();
} catch (JSONException e) {
message = "{ \"error\": \"Error while converting leaderboard score to JSON: " + e.getMessage() + "\", \"status\": " + STATUS_FAILED + " }";
Expand Down

0 comments on commit 323402c

Please sign in to comment.