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