Git Product home page Git Product logo

google-play-games-web-ui's Introduction

Introduction

The goal of this project is to provide a web UI for the Google Play Games API loosely based on the Android UI.

Getting started

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'});
});

Dependencies

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.

API

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

Applications

Events

Leaderboards

MetaGame

Players

Push Tokens

Quests

Rooms

Scores

Snapshots

Turn-based Multiplayer (TMBP)

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

google-play-games-web-ui's People

Contributors

mattsnider avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.