Added intent methods and leaderboard score class

This commit is contained in:
Richard Davey 2018-07-27 11:19:41 +01:00
parent b30e4185b9
commit 162e910d18
2 changed files with 97 additions and 6 deletions

View file

@ -8,6 +8,7 @@ var Class = require('../utils/Class');
var DataManager = require('../data/DataManager');
var EventEmitter = require('eventemitter3');
var GetValue = require('../utils/object/GetValue');
var LeaderboardScore = require('./LeaderboardScore');
/**
* @classdesc
@ -126,14 +127,12 @@ var FacebookInstantGamesPlugin = new Class({
}, this);
scene.load.start();
return this;
},
gameStarted: function ()
{
console.log('gameStarted');
console.log('FBP gameStarted');
this.apis = FBInstant.getSupportedAPIs();
@ -149,14 +148,19 @@ var FacebookInstantGamesPlugin = new Class({
var _this = this;
FBInstant.onPause(function() {
_this.emit('pause');
});
FBInstant.getEntryPointAsync().then(function (entrypoint) {
_this.entryPoint = entrypoint;
_this.entryPointData = FBInstant.getEntryPointData();
_this.emit('startgame');
});
this.emit('startgame');
// this.emit('startgame');
},
loadPlayerPhoto: function (scene, key)
@ -294,6 +298,44 @@ var FacebookInstantGamesPlugin = new Class({
},
openShare: function (text, key, frame, sessionData)
{
return this._share('SHARE', text, key, frame, sessionData);
},
openInvite: function (text, key, frame, sessionData)
{
return this._share('INVITE', text, key, frame, sessionData);
},
openRequest: function (text, key, frame, sessionData)
{
return this._share('REQUEST', text, key, frame, sessionData);
},
openChallenge: function (text, key, frame, sessionData)
{
return this._share('CHALLENGE', text, key, frame, sessionData);
},
createShortcut: function ()
{
var _this = this;
FBInstant.canCreateShortcutAsync().then(function(canCreateShortcut) {
if (canCreateShortcut)
{
FBInstant.createShortcutAsync().then(function() {
_this.emit('shortcutcreated');
}).catch(function() {
_this.emit('shortcutfailed');
});
}
});
},
_share: function (intent, text, key, frame, sessionData)
{
if (sessionData === undefined) { sessionData = {}; }
@ -303,13 +345,13 @@ var FacebookInstantGamesPlugin = new Class({
}
var payload = {
intent: 'SHARE',
intent: intent,
image: imageData,
text: text,
data: sessionData
};
console.log(payload);
// console.log(payload);
// intent ("INVITE" | "REQUEST" | "CHALLENGE" | "SHARE") Indicates the intent of the share.
// image string A base64 encoded image to be shared.
@ -321,6 +363,20 @@ var FacebookInstantGamesPlugin = new Class({
FBInstant.shareAsync(payload).then(function() {
_this.emit('resume');
});
return this;
},
log: function (name, value, params)
{
if (params === undefined) { params = {}; }
if (name.length >= 2 && name.length <= 40)
{
FBInstant.logEvent(name, parseFloat(value), params);
}
return this;
},
/**
@ -331,6 +387,8 @@ var FacebookInstantGamesPlugin = new Class({
*/
destroy: function ()
{
FBInstant.quit();
this.game = null;
}

View file

@ -0,0 +1,33 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
/**
* @classdesc
* [description]
*
* @class FacebookInstantGamesPlugin
* @memberOf Phaser
* @constructor
* @since 3.12.0
*/
var LeaderboardScore = new Class({
initialize:
function LeaderboardScore ()
{
this.value;
this.valueFormatted;
this.timestamp;
this.rank;
this.data;
}
});
module.exports = LeaderboardScore;