@@ -8,6 +8,7 @@ var Class = require('../utils/Class');
88var DataManager = require ( '../data/DataManager' ) ;
99var EventEmitter = require ( 'eventemitter3' ) ;
1010var 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
0 commit comments