UNPKG

1.84 kBJavaScriptView Raw
1"use strict";
2/**
3 * @namespace Splat.leaderboards
4 */
5
6var platform = require("./platform");
7
8if (platform.isEjecta()) {
9 var gameCenter = new window.Ejecta.GameCenter();
10 gameCenter.softAuthenticate();
11
12 var authFirst = function(action) {
13 if (gameCenter.authed) {
14 action();
15 } else {
16 gameCenter.authenticate(function(err) {
17 if (err) {
18 return;
19 }
20 action();
21 });
22 }
23 };
24
25 module.exports = {
26 /**
27 * Report that an achievement was achieved.
28 * @alias Splat.leaderboards.reportAchievement
29 * @param {string} id The name of the achievement.
30 * @param {int} percent The percentage of the achievement that is completed in the range of 0-100.
31 */
32 "reportAchievement": function(id, percent) {
33 authFirst(function() {
34 gameCenter.reportAchievement(id, percent);
35 });
36 },
37 /**
38 * Report that a score was achieved on a leaderboard.
39 * @alias Splat.leaderboards.reportScore
40 * @param {string} leaderboard The name of the leaderboard the score is on.
41 * @param {int} score The score that was achieved.
42 */
43 "reportScore": function(leaderboard, score) {
44 authFirst(function() {
45 gameCenter.reportScore(leaderboard, score);
46 });
47 },
48 /**
49 * Show the achievements screen.
50 * @alias Splat.leaderboards.showAchievements
51 */
52 "showAchievements": function() {
53 authFirst(function() {
54 gameCenter.showAchievements();
55 });
56 },
57 /**
58 * Show a leaderboard screen.
59 * @alias Splat.leaderboards.showLeaderboard
60 * @param {string} name The name of the leaderboard to show.
61 */
62 "showLeaderboard": function(name) {
63 authFirst(function() {
64 gameCenter.showLeaderboard(name);
65 });
66 }
67 };
68} else {
69 module.exports = {
70 "reportAchievement": function() {},
71 "reportScore": function() {},
72 "showAchievements": function() {},
73 "showLeaderboard": function() {}
74 };
75}
76