Skip to content

Commit 162e910

Browse files
committed
Added intent methods and leaderboard score class
1 parent b30e418 commit 162e910

2 files changed

Lines changed: 97 additions & 6 deletions

File tree

src/fbinstant/FacebookInstantGamesPlugin.js

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Class = require('../utils/Class');
88
var DataManager = require('../data/DataManager');
99
var EventEmitter = require('eventemitter3');
1010
var GetValue = require('../utils/object/GetValue');
11+
var LeaderboardScore = require('./LeaderboardScore');
1112

1213
/**
1314
* @classdesc
@@ -126,14 +127,12 @@ var FacebookInstantGamesPlugin = new Class({
126127

127128
}, this);
128129

129-
scene.load.start();
130-
131130
return this;
132131
},
133132

134133
gameStarted: function ()
135134
{
136-
console.log('gameStarted');
135+
console.log('FBP gameStarted');
137136

138137
this.apis = FBInstant.getSupportedAPIs();
139138

@@ -149,14 +148,19 @@ var FacebookInstantGamesPlugin = new Class({
149148

150149
var _this = this;
151150

151+
FBInstant.onPause(function() {
152+
_this.emit('pause');
153+
});
154+
152155
FBInstant.getEntryPointAsync().then(function (entrypoint) {
153156

154157
_this.entryPoint = entrypoint;
155158
_this.entryPointData = FBInstant.getEntryPointData();
159+
_this.emit('startgame');
156160

157161
});
158162

159-
this.emit('startgame');
163+
// this.emit('startgame');
160164
},
161165

162166
loadPlayerPhoto: function (scene, key)
@@ -294,6 +298,44 @@ var FacebookInstantGamesPlugin = new Class({
294298
},
295299

296300
openShare: function (text, key, frame, sessionData)
301+
{
302+
return this._share('SHARE', text, key, frame, sessionData);
303+
},
304+
305+
openInvite: function (text, key, frame, sessionData)
306+
{
307+
return this._share('INVITE', text, key, frame, sessionData);
308+
},
309+
310+
openRequest: function (text, key, frame, sessionData)
311+
{
312+
return this._share('REQUEST', text, key, frame, sessionData);
313+
},
314+
315+
openChallenge: function (text, key, frame, sessionData)
316+
{
317+
return this._share('CHALLENGE', text, key, frame, sessionData);
318+
},
319+
320+
createShortcut: function ()
321+
{
322+
var _this = this;
323+
324+
FBInstant.canCreateShortcutAsync().then(function(canCreateShortcut) {
325+
326+
if (canCreateShortcut)
327+
{
328+
FBInstant.createShortcutAsync().then(function() {
329+
_this.emit('shortcutcreated');
330+
}).catch(function() {
331+
_this.emit('shortcutfailed');
332+
});
333+
}
334+
335+
});
336+
},
337+
338+
_share: function (intent, text, key, frame, sessionData)
297339
{
298340
if (sessionData === undefined) { sessionData = {}; }
299341

@@ -303,13 +345,13 @@ var FacebookInstantGamesPlugin = new Class({
303345
}
304346

305347
var payload = {
306-
intent: 'SHARE',
348+
intent: intent,
307349
image: imageData,
308350
text: text,
309351
data: sessionData
310352
};
311353

312-
console.log(payload);
354+
// console.log(payload);
313355

314356
// intent ("INVITE" | "REQUEST" | "CHALLENGE" | "SHARE") Indicates the intent of the share.
315357
// image string A base64 encoded image to be shared.
@@ -321,6 +363,20 @@ var FacebookInstantGamesPlugin = new Class({
321363
FBInstant.shareAsync(payload).then(function() {
322364
_this.emit('resume');
323365
});
366+
367+
return this;
368+
},
369+
370+
log: function (name, value, params)
371+
{
372+
if (params === undefined) { params = {}; }
373+
374+
if (name.length >= 2 && name.length <= 40)
375+
{
376+
FBInstant.logEvent(name, parseFloat(value), params);
377+
}
378+
379+
return this;
324380
},
325381

326382
/**
@@ -331,6 +387,8 @@ var FacebookInstantGamesPlugin = new Class({
331387
*/
332388
destroy: function ()
333389
{
390+
FBInstant.quit();
391+
334392
this.game = null;
335393
}
336394

src/fbinstant/LeaderboardScore.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Class = require('../utils/Class');
8+
9+
/**
10+
* @classdesc
11+
* [description]
12+
*
13+
* @class FacebookInstantGamesPlugin
14+
* @memberOf Phaser
15+
* @constructor
16+
* @since 3.12.0
17+
*/
18+
var LeaderboardScore = new Class({
19+
20+
initialize:
21+
22+
function LeaderboardScore ()
23+
{
24+
this.value;
25+
this.valueFormatted;
26+
this.timestamp;
27+
this.rank;
28+
this.data;
29+
}
30+
31+
});
32+
33+
module.exports = LeaderboardScore;

0 commit comments

Comments
 (0)