Skip to content

Commit

Permalink
Merge pull request #26 from openforge/fix/user-score-resolve
Browse files Browse the repository at this point in the history
fix/user-score-resolve
  • Loading branch information
Ricardo385 authored Dec 4, 2023
2 parents a55a64a + 1065823 commit 7f6d12c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ public void getUserTotalScore(PluginCall call) {
@Override
public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
if (leaderboardScore != null) {
long totalScore = leaderboardScore.getResult().get().getRawScore();
long userTotalScore = 0;
if (leaderboardScore.getResult().get() != null) {
userTotalScore = leaderboardScore.getResult().get().getRawScore();
}
JSObject result = new JSObject();
result.put("player_score", totalScore);
result.put("player_score", userTotalScore);
call.resolve(result);
}
}
Expand Down
16 changes: 7 additions & 9 deletions ios/Plugin/CapacitorGameConnect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import Capacitor

let leaderboardID = String(call.getString("leaderboardID") ?? "") // * Property to get the leaderboard ID
let leaderboard = GKLeaderboard() // * LeaderBoard functions
var userTotalScore = 0 // * Property to store user total score
leaderboard.identifier = leaderboardID // * LeaderBoard we are going to use for
leaderboard.playerScope = .global // * Section to use
leaderboard.timeScope = .allTime // * Time to search for
Expand All @@ -149,20 +150,17 @@ import Capacitor
} else if let scores = scores {
for score in scores {
if score.player.gamePlayerID == GKLocalPlayer.local.gamePlayerID {
let result = [
"player_score": score.value
]
call.resolve(result)
break
userTotalScore = Int(score.value)
}
}
}
} else {
let result = [
"player_score": 0
]
call.resolve(result as PluginCallResultData)
userTotalScore = 0
}
let result = [
"player_score": userTotalScore
]
call.resolve(result as PluginCallResultData)
}
}
}
1 change: 0 additions & 1 deletion ios/Plugin/CapacitorGameConnectPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ public class CapacitorGameConnectPlugin: CAPPlugin {

@objc func getUserTotalScore(_ call: CAPPluginCall) {
implementation.getUserTotalScore(call)
call.resolve()
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openforge/capacitor-game-connect",
"version": "5.0.1",
"version": "5.0.2",
"description": "Use Game Services and Game Connect",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down

0 comments on commit 7f6d12c

Please sign in to comment.