Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Updates #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,40 @@ cordova.plugins.playGamesServices.showAchievements(function () {
// On error
});
```
#### Reveal achievement

Reveals a hidden achievement inmediately and waits for response:

```js
var data = {
achievementId: "achievementId1"
};

cordova.plugins.playGamesServices.revealAchievement(data, function () {
// On success
}, function() {
// On error
});
```

### Events

#### Increment Event

Increments the specified incremental event by the provided numSteps and waits for response

```js
var data = {
eventId: "eventId1",
numSteps: 1
};

cordova.plugins.playGamesServices.incrementEvent(data, function () {
// On success
}, function() {
// On error
});
```

### Other

Expand Down
48 changes: 48 additions & 0 deletions plugin/src/com/berriart/cordova/plugins/PlayGamesServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class PlayGamesServices extends CordovaPlugin implements GameHelperListen

private static final String ACTION_UNLOCK_ACHIEVEMENT = "unlockAchievement";
private static final String ACTION_UNLOCK_ACHIEVEMENT_NOW = "unlockAchievementNow";

private static final String ACTION_REVEAL_ACHIEVEMENT = "revealAchievement";
private static final String ACTION_INCREMENT_EVENT = "incrementEvent";

private static final String ACTION_INCREMENT_ACHIEVEMENT = "incrementAchievement";
private static final String ACTION_INCREMENT_ACHIEVEMENT_NOW = "incrementAchievementNow";
private static final String ACTION_SHOW_ACHIEVEMENTS = "showAchievements";
Expand Down Expand Up @@ -138,6 +142,10 @@ public boolean execute(String action, JSONArray inputs, CallbackContext callback
executeUnlockAchievement(options, callbackContext);
} else if (ACTION_UNLOCK_ACHIEVEMENT_NOW.equals(action)) {
executeUnlockAchievementNow(options, callbackContext);
} else if (ACTION_REVEAL_ACHIEVEMENT.equals(action)) {
executeRevealAchievement(options, callbackContext);
} else if (ACTION_INCREMENT_EVENT.equals(action)) {
executeIncrementEvent(options, callbackContext);
} else if (ACTION_INCREMENT_ACHIEVEMENT.equals(action)) {
executeIncrementAchievement(options, callbackContext);
} else if (ACTION_INCREMENT_ACHIEVEMENT_NOW.equals(action)) {
Expand Down Expand Up @@ -404,7 +412,44 @@ public void onResult(Achievements.UpdateAchievementResult achievementResult) {
}
});
}

private void executeRevealAchievement(final JSONObject options,final CallbackContext callbackContext) {
Log.d(LOGTAG, "executeRevealAchievement");

final PlayGamesServices plugin = this;

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {

if (gameHelper.isSignedIn()) {
Games.Achievements.reveal(gameHelper.getApiClient(),options.optString("achievementId"));
callbackContext.success();
} else {
Log.w(LOGTAG, "executeRevealAchievement: not yet signed in");
callbackContext.error("executeRevealAchievement: not yet signed in");
}
}
});
}

private void executeIncrementEvent(final JSONObject options, final CallbackContext callbackContext) {
Log.d(LOGTAG, "executeIncrementEvent");

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (gameHelper.isSignedIn()) {
Games.Events.increment(gameHelper.getApiClient(), options.optString("eventId"), options.optInt("numSteps"));
callbackContext.success();
} else {
Log.w(LOGTAG, "executeIncrementEvent: not yet signed in");
callbackContext.error("executeIncrementEvent: not yet signed in");
}
}
});
}

private void executeIncrementAchievement(final JSONObject options, final CallbackContext callbackContext) {
Log.d(LOGTAG, "executeIncrementAchievement");

Expand Down Expand Up @@ -455,7 +500,10 @@ public void onResult(Achievements.UpdateAchievementResult achievementResult) {
}
});
}




private void executeShowAchievements(final CallbackContext callbackContext) {
Log.d(LOGTAG, "executeShowAchievements");

Expand Down
2 changes: 1 addition & 1 deletion plugin/www/play-games-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var PlayGamesServices = function () {
var actions = ['auth', 'signOut', 'isSignedIn',
'submitScore', 'submitScoreNow', 'getPlayerScore', 'showAllLeaderboards', 'showLeaderboard',
'unlockAchievement', 'unlockAchievementNow', 'incrementAchievement', 'incrementAchievementNow',
'showAchievements', 'showPlayer'];
'showAchievements', 'showPlayer', 'revealAchievement', 'incrementEvent'];

actions.forEach(function (action) {
PlayGamesServices.prototype[action] = function (data, success, failure) {
Expand Down