From 54a708638f757ea86032ad265d739d1ffcc7393d Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 15 Jan 2015 13:03:37 -0800 Subject: [PATCH] Initial Commit --- .gitignore | 1 + LICENSE | 176 ++++++++++++++++++ README.md | 4 + bower.json | 22 +++ config-form.html | 52 ++++++ config-form.js | 454 +++++++++++++++++++++++++++++++++++++++++++++++ index.css | 67 +++++++ index.html | 121 +++++++++++++ index.js | 145 +++++++++++++++ info.js | 77 ++++++++ 10 files changed, 1119 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 bower.json create mode 100644 config-form.html create mode 100644 config-form.js create mode 100644 index.css create mode 100644 index.html create mode 100644 index.js create mode 100644 info.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d4ae25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bower_components diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d0381d6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/README.md b/README.md new file mode 100644 index 0000000..4744a1b --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Play Game Services Magic Configuration +A tool that uses the [Play Game Services Publishing API](https://developers.google.com/games/services/publishing/) to automatically configure achievements and leaderboards for pre-configured samples. + +For an example of how to use the Publshing API, visit the [management-tools sample](https://github.com/playgameservices/management-tools). diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..e9915a7 --- /dev/null +++ b/bower.json @@ -0,0 +1,22 @@ +{ + "name": "games-magic-button", + "version": "0.1.0", + "authors": [ + "Sam Stern " + ], + "description": "Automatically configure Play Game services samples", + "main": "index.html", + "moduleType": [ + "globals", + "node" + ], + "license": "Apache-2.0", + "ignore": [ + "**/.*", + "node_modules", + "bower_components" + ], + "dependencies": { + "paper-elements": "Polymer/paper-elements#^0.5.0" + } +} diff --git a/config-form.html b/config-form.html new file mode 100644 index 0000000..ed37bc0 --- /dev/null +++ b/config-form.html @@ -0,0 +1,52 @@ + + + + + + + + + diff --git a/config-form.js b/config-form.js new file mode 100644 index 0000000..af08191 --- /dev/null +++ b/config-form.js @@ -0,0 +1,454 @@ +/* + * Copyright (C) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function() { + var app = app || {}; + var util = util || {}; + var config = config || {}; + + var elm = undefined; + + // Initialize Polymer + Polymer('config-form', { + publish: { + appid: { + reflect: true + }, + infofile: { + reflect: true + }, + sample: { + reflect: true + } + }, + ready: function() { + this.reset = app.reset; + this.list = app.list; + this.configure = app.configure; + + this.hasAppId = function() { + return (this.appid != undefined && this.appid.length > 0); + }; + + elm = this; + console.log('Config Form Ready'); + } + }); + + /** + * Skeleton objects for achievementConfiguration and leaderboardConfiguration. + * Populated by info objects to create resources. + */ + var SKELETONS = { + achievement: { + achievementType: 'STANDARD', + initialState: 'REVEALED', + draft: { + name: { + translations: [ + { + locale: 'en-US', + value: undefined + } + ] + }, + description: { + translations: [ + { + locale: 'en-US', + value: undefined + } + ] + }, + pointValue: undefined + } + }, + leaderboard: { + scoreOrder: undefined, + draft: { + name: { + translations: [ + { + locale: 'en-US', + value: undefined + } + ] + }, + scoreFormat: { + numberFormatType: 'NUMERIC', + numDecimalPlaces: 0 + } + } + } + }; + + /** + * Run the full configuration process. Adds all missing achievements and + * leaderboards, then creates and displays a sample ids.xml file. + */ + app.configure = function() { + console.log('Setting Configuration'); + if (!elm.hasAppId()) { + alert('Please enter your App ID'); + return; + } + + // Insert all achievements and leaderboards + elm.fire('action-start'); + var ach = config.insertAllConfigs(app.getAchievementInfo(), + config.listAchievements, config.insertAchievement, + util.createAchievementResource); + var ldr = config.insertAllConfigs(app.getLeaderboardInfo(), + config.listLeaderboards, config.insertLeaderboard, + util.createLeaderboardResource); + + // Once all inserted, print ids.xml + ach.then(ldr).then(function() { + console.log('Configuration complete.'); + elm.fire('action-end'); + app.makeIdsXml(); + }); + }; + + /** + * List the current configuration of the application. Prints the results + * as a sample ids.xml file. + */ + app.list = function() { + console.log('Listing Configuration'); + if (!elm.hasAppId()) { + alert('Please enter your App ID'); + return; + } + + elm.fire('action-start'); + app.makeIdsXml(); + }; + + /** + * Delete all of the applications existing leaderboards and achievements. + * Print an ids.xml file when completed that shows only the App ID. + */ + app.reset = function() { + console.log('Resetting Configuration'); + if (!elm.hasAppId()) { + alert('Please enter your App ID'); + return; + } + + elm.fire('action-start'); + var ldr = config.deleteAllLeaderboards(); + var ach = config.deleteAllAchievements(); + + // TODO(samstern): Make sure both are executing + ach.then(ldr).then(function() { + console.log('All configuration deleted.'); + elm.fire('action-end'); + app.makeIdsXml(); + }); + }; + + /** + * List all of the applications configured leaderboards and achievements + * and convert the response into a single Android XML file. Display result + * in the UI. + */ + app.makeIdsXml = function() { + elm.fire('action-start'); + + var batch = gapi.client.newBatch(); + batch.add(config.listAchievements(), {id: 'ach'}); + batch.add(config.listLeaderboards(), {id: 'ldr'}); + + batch.then(function(results) { + var achItems = results.result['ach'].result.items; + var ldrItems = results.result['ldr'].result.items; + + var achXml = util.resourcesToXml(achItems, 'achievement'); + var ldrXml = util.resourcesToXml(ldrItems, 'leaderboard'); + + var appIdXml = document.createElement('string'); + appIdXml.setAttribute('name', 'app_id'); + appIdXml.innerHTML = elm.appid; + + // AppId + Achievements + Leaderboards + var allXML = appIdXml.outerHTML + '\n\n' + achXml + '\n' + ldrXml; + + elm.result = allXML; + elm.fire('action-end'); + elm.fire('action-result'); + }); + }; + + /** + * Get the information needed to configure achievements for this sample. + * @return {object} the achievement information from the 'config' object. + */ + app.getAchievementInfo = function() { + return configs[elm.sample].achievements; + }; + + /** + * Get the information needed to configure leaderboards for this sample. + * @return {object} the leaderboard information from the 'config' object. + */ + app.getLeaderboardInfo = function() { + return configs[elm.sample].leaderboards; + }; + + /** + * List all achievement configurations for the current application. + * @return {promise} a promise from the achievementConfigurations.list + * method. + */ + config.listAchievements = function() { + return gapi.client.gamesConfiguration.achievementConfigurations.list({ + applicationId: elm.appid + }); + }; + + /** + * Insert a draft achievement into the current application. + * @param {object} resource - an achievementConfiguration resource object, + * @return {promise} a promise from the achievementConfigurations.insert + * method. + */ + config.insertAchievement = function(resource) { + return gapi.client.gamesConfiguration.achievementConfigurations.insert({ + applicationId: elm.appid, + resource: resource + }); + }; + + /** + * Delete an achievement from the current application. + * @param {object} achievementId - the id of the achievement to delete. + * @return {promise} a promise from the achievementConfigurations.delete + * method. + */ + config.deleteAchievement = function(achievementId) { + return gapi.client.gamesConfiguration.achievementConfigurations.delete({ + achievementId: achievementId + }); + }; + + /** + * List all leaderboard configurations for the current application. + * @return {promise} a promise from the leaderboardConfigurations.list + * method. + */ + config.listLeaderboards = function() { + return gapi.client.gamesConfiguration.leaderboardConfigurations.list({ + applicationId: elm.appid + }); + }; + + /** + * Insert a draft leaderboard into the current application. + * @param {object} resource - an leaderboardConfiguration resource object, + * @return {promise} a promise from the leaderboardConfigurations.insert + * method. + */ + config.insertLeaderboard = function(resource) { + return gapi.client.gamesConfiguration.leaderboardConfigurations.insert({ + applicationId: elm.appid, + resource: resource + }); + }; + + /** + * Delete a leaderboard from the current application. + * @param {object} leaderboardId - the id of the leaderboard to delete. + * @return {promise} a promise from the leaderboardConfigurations.delete + * method. + */ + config.deleteLeaderboard = function(leaderboardId) { + return gapi.client.gamesConfiguration.leaderboardConfigurations.delete({ + leaderboardId: leaderboardId + }); + }; + + /** + * Delete all leaderboards from the current application. + * @return {promise} the aggregate promise of the delete requests for each + * leaderboard + */ + config.deleteAllLeaderboards = function() { + return config.listLeaderboards().then(function(resp) { + var items = resp.result.items; + var batch = gapi.client.newBatch(); + for (var i in items) { + console.log('Deleting Leaderboard: ', items[i].id); + batch.add(config.deleteLeaderboard(items[i].id)); + } + + return batch; + }); + }; + + /** + * Delete all achievements from the current application. + * @return {promise} the aggregate promise of the delete requests for each + * achievement + */ + config.deleteAllAchievements = function() { + return config.listAchievements().then(function(resp) { + var items = resp.result.items; + var batch = gapi.client.newBatch(); + for (var i in items) { + console.log('Deleting Achievement: ', items[i].id); + batch.add(config.deleteAchievement(items[i].id)); + } + + return batch; + }); + }; + + /** + * Insert a series of configuration objects for the current application. + * @param {array} infoObjs - an array of info objects that will be converted + * to configuration resources. + * @param {function} listFn - the function to list all existing configurations + * of the type to be inserted. This should return a promise. + * @param {function} insertFn - the function to insert a configuration + * resource of the desired type. This should take a resource object as its + * only argument and return a promise. + * @param {function} resourceFn - the function to convert a single info object + * into a resource of the desired type. + * @return {promise} the aggregate promise of all the insertFn requests. + */ + config.insertAllConfigs = function(infoObjs, listFn, insertFn, resourceFn) { + var inserted = 0; + var toInsert = infoObjs.length; + + return listFn().then(function(resp) { + var items = resp.result.items; + + var batch = gapi.client.newBatch(); + batch.add(listFn()); + + for (var i in infoObjs) { + // Create new leaderboard + var infoObj = infoObjs[i]; + var newResource = resourceFn(infoObj); + + // Check if it exists + var exists = false; + for (var j in items) { + if (items[j].draft.name.translations[0].value === infoObj.name) { + exists = true; + } + } + + // Insert if necessary + if (!exists) { + console.log('Inserting: ', infoObj.name); + batch.add(insertFn(newResource)); + } else { + console.log('Skipping (duplicate name): ', infoObj.name); + } + } + + // Wait until all inserts have resolved + return batch; + }); + }; + + /** + * Make a clone of a simple JSON object. Uses serialization. + * @param {object} obj - the JSON object to clone. + * @return {object} a value-for-value clone of the argument object. + */ + util.cloneObject = function(obj) { + // Clone object by going through JSON + return JSON.parse(JSON.stringify(obj)); + }; + + /** + * Create an achievement resource from a simple info object. Properly + * populates a skeleton with any provided fields. + * @param {object} infoObj - the info object representing the achievement. + * @return {object} a properly-formed achievementConfiguration resource + * object. + */ + util.createAchievementResource = function(infoObj) { + // Make a copy of the skeleton object + var newResource = util.cloneObject(SKELETONS.achievement); + + // Set name, desc, and pointValue + newResource.draft.name.translations[0].value = infoObj.name; + newResource.draft.description.translations[0].value = infoObj.description; + newResource.draft.pointValue = infoObj.pointValue; + + // Check if achievement should be incremental, otherwise standard + if (infoObj.stepsToUnlock) { + newResource.achievementType = 'INCREMENTAL'; + newResource.stepsToUnlock = infoObj.stepsToUnlock; + } + + // Check if achievement should be hidden, otherwise revealed + if (infoObj.hidden) { + newResource.initialState = 'HIDDEN'; + } + + return newResource; + }; + + /** + * Create an leaderboard resource from a simple info object. Properly + * populates a skeleton with any provided fields. + * @param {object} infoObj - the info object representing the leaderboard. + * @return {object} a properly-formed leaderboardConfiguration resource object. + */ + util.createLeaderboardResource = function(infoObj) { + // Make a clone of the skeleton object + var newResource = util.cloneObject(SKELETONS.leaderboard); + + // Set name and score order + newResource.draft.name.translations[0].value = infoObj.name; + newResource.scoreOrder = infoObj.scoreOrder; + + return newResource; + }; + + /** + * Convert a series of resource objects to an Android XML file. + * @param {array} items - an array of resource objects. + * @param {string} prefix - a prefix to be used for the string key names in + * the XML file. + * @return {string} a string representing the contents of an Android resources + * XML file. + */ + util.resourcesToXml = function(items, prefix) { + var root = document.createElement('xml'); + + for (var i in items) { + var item = items[i]; + var itemElm = document.createElement('string'); + var itemName = item.draft.name.translations[0].value; + var name = prefix + '_' + itemName.toLowerCase().replace(/\s/g, '_'); + + itemElm.setAttribute('name', name); + itemElm.innerHTML = item.id; + + root.appendChild(itemElm); + root.innerHTML += '\n'; + } + + return root.innerHTML; + }; + +})(); + diff --git a/index.css b/index.css new file mode 100644 index 0000000..a26416f --- /dev/null +++ b/index.css @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +html, body { + height: 100%; + margin: 0; + background-color: #E5E5E5; + font-family: 'RobotoDraft', sans-serif; +} + +.card { + background: white; + padding: 20px; + max-width: 960px; + margin-left: auto; + margin-right: auto; + margin-top: 20px; +} + +core-header-panel { + height: 100%; + overflow: auto; + -webkit-overflow-scrolling: touch; +} + +core-toolbar { + background: #2196F3; + color: white; +} + +paper-button { + margin: 0; + color: #2196F3; + background: white; +} + +paper-progress { + margin-top: 10px; + margin-bottom: 10px; + width: 100%; +} + +paper-progress.blue::shadow #activeProgress { + background-color: #2196F3; +} + +.label { + color: gray; + margin-top: 0; + margin-bottom: 0; +} + +.shadow { + box-shadow: 2px 2px 4px 2px #B6B6B6; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..717d3d6 --- /dev/null +++ b/index.html @@ -0,0 +1,121 @@ + + + + Config Magic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Play Games Sample Configuration + + + + + + + +
+

Instructions

+

+ Welcome to the Play Game Services sample configuration tool. + + This tool uses the Management API to automatically configure Achievements and Leaderboards for Play Game Services sample applications for Android. +

+

+ Before using this tool, you will need to create a Play Game Services project in the Google Play Developer's Console. Follow the instructions here but skip steps 5 and 6 where you would normally configure Achievements and Leaderboards. This tool will automate those steps for you. +

+

+ To get started, sign-in and then paste your App ID into the input field below. Click 'Configure' to add all of the required Achievements and Leaderboards to your project and then copy the output at the bottom of the page into your res/ids.xml file. +

+
+ +
+

Actions

+
+ + Sign In + +
+ + +
+ +
+

res/ids.xml

+ +
+      
+
+ + diff --git a/index.js b/index.js new file mode 100644 index 0000000..e9f614c --- /dev/null +++ b/index.js @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var CLIENT_ID = + '845336616957-pa9ouhagvc7hvv4i0sb46ngd2ldqkerr.apps.googleusercontent.com'; +var SCOPES = [ + 'https://www.googleapis.com/auth/androidpublisher', +]; + +var auth = auth || {}; +var ui = ui || {}; + +$(document).ready(function() { + // Put the sample name in the menu bar title + $('#sample').text('(' + ui.getSample() + ')'); + + // Tell the config-form which sample + $('config-form').attr('sample', ui.getSample()); + + // Start of configuration event + $('config-form').on('action-start', function() { + ui.showProgressBar(); + ui.clearResults(); + }); + + // End of configuration event + $('config-form').on('action-end', function() { + ui.hideProgressBar(); + }); + + // Configuration event produced useful result + $('config-form').on('action-result', function(e) { + ui.setResults(e.target.result); + }); +}); + +function onClientLoad() { + // Get the Games Configuration API + gapi.client.load('gamesConfiguration', 'v1configuration', function() { + console.log('Games Configuration API Loaded'); + + // Try silent login + console.log('Attempting silent authorization...'); + auth.signIn(true); + }); +} + + +/** + * Initiate the sign-in process. + * @param {boolean} immediate - true if the immediate, silent sign-in flow + * should be used, false if the user should be prompted for consent. + */ +auth.signIn = function(immediate) { + gapi.auth.authorize({ + client_id: CLIENT_ID, + immediate: immediate, + scope: SCOPES.join(' ') + }, auth.authCallback); +}; + + +/** + * Initiate the sign-out process. + */ +auth.signOut = function() { + console.log('Signing Out'); + gapi.auth.signOut(auth.authCallback); + auth.authCallback({}); +}; + + +/** + * Callback to parse the result of sign-in or sign-out. Displays the correct UI + * for the sign-in state. + * @param {object} authResult - the JSON object returned to a signIn or signOut + * call. + */ +auth.authCallback = function(authResult) { + console.log('Auth Result: ', authResult); + if (authResult.access_token) { + $('.signed-in').show(); + $('.signed-out').hide(); + } else { + $('.signed-in').hide(); + $('.signed-out').show(); + } +}; + + +/** + * Parse the name of the sample to be configured from the 'sample' URL + * query parameter. + * @return {string} the name of the sample to be configured. + */ +ui.getSample = function() { + var url = window.location.href; + var matches = url.match(/sample=([a-zA-z0-9]*)/); + return matches[1]; +}; + + +/** + * Show an indeterminate progress bar. + */ +ui.showProgressBar = function() { + $('#progress').show(); +}; + + +/** + * Hide the indeterminate progress bar. + */ +ui.hideProgressBar = function() { + $('#progress').hide(); +}; + + +/** + * Set the text in the results area. + * @param {string} result - the text to put in the result area. + */ +ui.setResults = function(result) { + $('#ids').text(result); +}; + + +/** + * Clear the results from any previous action. + */ +ui.clearResults = function() { + $('#ids').empty(); +}; diff --git a/info.js b/info.js new file mode 100644 index 0000000..548a334 --- /dev/null +++ b/info.js @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var configs = { + /** TRIVIAL QUEST **/ + trivialquest: { + achievements: [ + { + name: 'Trivial Victory', + description: 'Complete the Trivial Quest', + pointValue: 50 + } + ], + leaderboards: [] + }, + + /** TYPE A NUMBER **/ + typeanumber: { + achievements: [ + { + name: 'Prime', + description: 'Type a prime number', + pointValue: 50 + }, + { + name: 'Really Bored', + description: 'You are so bored!', + pointValue: 50, + stepsToUnlock: 100 + }, + { + name: 'Bored', + description: 'You must be bored.', + pointValue: 50, + stepsToUnlock: 100 + }, + { + name: 'Humble', + description: 'You are a humble fellow', + pointValue: 50 + }, + { + name: 'Arrogant', + description: 'Wow, you are arrogant.', + pointValue: 50 + }, + { + name: 'Leet', + description: 'You are the most 1337 H4X0R', + pointValue: 50, + hidden: true + } + ], + leaderboards: [ + { + name: 'Easy', + scoreOrder: 'LARGER_IS_BETTER' + }, + { + name: 'Hard', + scoreOrder: 'LARGER_IS_BETTER' + } + ] + } +};