The goal of this project is to provide a web UI for the Google Play Games API loosely based on the Android UI.
Follow the client only setup instructions.
Include the following at the end of your body element:
<script src="{PATH_TO_JS}/underscore.js"></script>
<script src="{PATH_TO_JS}/api.js"></script>
<!-- This is dumb, but the callback function must be directly attached to window. -->;
<script>YOUR_JS_CALLBACK_FUNCTION = GoogleGamesApi.authCallback;</script>
<script src="https://apis.google.com/js/client:platform.js"></script>
Start using the API.
Fetch a list of leaderboards for the game.
GoogleGamesApi.runWhenAuthenticated(function(oApi) {
oApi.leaderboards.list(function(oResponse) {
// Do something with the response.
});
});
Load achievement definitions and instances in sequence.
GoogleGamesApi.runWhenAuthenticated(function(oApi) {
var oAchievementInstanceMap = {};
GoogleGamesApi.achievements.definitions(function(oResponse) {
_.each(oResponse.items, function(oAchievementDefinition) {
oAchievementInstanceMap[oAchievementDefinition.id] = oAchievementDefinition;
});
}).achievements.instances(function(oResponse) {
_.each(oResponse.items, function(oAchievementInstance) {
var oAchievementDefinition = oAchievementInstanceMap[oAchievementInstance.id];
console.log('You have ' + oAchievementInstance.achievementState
+ ' the achievement ' + oAchievementDefinition.name);
});
}, {playerId: 'me'});
});
UnderscoreJs is currently the only required third party library, but as the code base grows, I will probably use RequireJs as well to modularize dependencies.
The existing Google Play Games API requires unnecessary boilerplate and lots of nested callback functions to order operations. Instead I wanted to wrap the authentication boilerplate and create chainable methods so dependent data can be loaded in sequence (ex. definitions & instances).
All methods have been namespaced on the GoogleGamesApi object and the returned object from any method will have the same namespaces. Only chained calls will wait on each other, calling GoogleGamesApi directly will execute all methods asynchronously.
All methods will assert that the Google Play Games Services are available or will raise an exception.
The signature for all API calls is a callback function followed by an object that should contain any required or optional keys. The required/optional keys can be found on the Google Play Games developer website.
Here is a list of the available API endpoints linked to their documentation:
Achievements
- GoogleGamesApi.achievements.definitions
- GoogleGamesApi.achievements.increment
- GoogleGamesApi.achievements.instances
- GoogleGamesApi.achievements.reveal
- GoogleGamesApi.achievements.setStepsAtLeast
- GoogleGamesApi.achievements.unlock
- GoogleGamesApi.achievements.updateMultiple
Applications
Events
Leaderboards
MetaGame
Players
Push Tokens
Quests
Rooms
- GoogleGamesApi.rooms.create
- GoogleGamesApi.rooms.decline
- GoogleGamesApi.rooms.dismiss
- GoogleGamesApi.rooms.get
- GoogleGamesApi.rooms.join
- GoogleGamesApi.rooms.leave
- GoogleGamesApi.rooms.list
- GoogleGamesApi.rooms.reportStatus
Scores
- GoogleGamesApi.scores.get
- GoogleGamesApi.scores.list
- GoogleGamesApi.scores.listWindow
- GoogleGamesApi.scores.submit
- GoogleGamesApi.scores.submitMultiple
Snapshots
Turn-based Multiplayer (TMBP)
- GoogleGamesApi.tbmp.cancel
- GoogleGamesApi.tbmp.create
- GoogleGamesApi.tbmp.decline
- GoogleGamesApi.tbmp.dismiss
- GoogleGamesApi.tbmp.finish
- GoogleGamesApi.tbmp.get
- GoogleGamesApi.tbmp.join
- GoogleGamesApi.tbmp.leave
- GoogleGamesApi.tbmp.leaveTurn
- GoogleGamesApi.tbmp.list
- GoogleGamesApi.tbmp.rematch
- GoogleGamesApi.tbmp.sync
- GoogleGamesApi.tbmp.takeTurn
Roadmap
- 0.1 - API wrapper written
- 0.2 - UI for achievements
- 0.3 - UI for leaderboards
- 0.4 - UI for players
- 0.5 - UI for quests
- 0.6 - modularize UI
- 1.0 - usable product