1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var platform = require("./platform");
|
7 |
|
8 | if (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 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | "reportAchievement": function(id, percent) {
|
33 | authFirst(function() {
|
34 | gameCenter.reportAchievement(id, percent);
|
35 | });
|
36 | },
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | "reportScore": function(leaderboard, score) {
|
44 | authFirst(function() {
|
45 | gameCenter.reportScore(leaderboard, score);
|
46 | });
|
47 | },
|
48 | |
49 |
|
50 |
|
51 |
|
52 | "showAchievements": function() {
|
53 | authFirst(function() {
|
54 | gameCenter.showAchievements();
|
55 | });
|
56 | },
|
57 | |
58 |
|
59 |
|
60 |
|
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 |
|