Skip to content

Commit 939fc24

Browse files
committed
Added lots of new API calls
1 parent c111175 commit 939fc24

1 file changed

Lines changed: 131 additions & 1 deletion

File tree

src/fbinstant/FacebookInstantGamesPlugin.js

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ var FacebookInstantGamesPlugin = new Class({
5050
this.hasLoaded = false;
5151
this.dataLocked = false;
5252

53+
this.apis = [];
54+
this.entryPoint = '';
55+
this.entryPointData = null;
56+
this.contextID = 0;
57+
this.contextType = '';
58+
this.locale = '';
59+
this.platform = '';
60+
this.version = '';
61+
5362
this.playerID = '';
5463
this.playerName = '';
5564
this.playerPhotoURL = '';
@@ -125,11 +134,28 @@ var FacebookInstantGamesPlugin = new Class({
125134
gameStarted: function ()
126135
{
127136
console.log('gameStarted');
137+
138+
this.apis = FBInstant.getSupportedAPIs();
139+
140+
this.contextID = FBInstant.context.getID();
141+
this.contextType = FBInstant.context.getType();
142+
this.locale = FBInstant.getLocale();
143+
this.platform = FBInstant.getPlatform();
144+
this.version = FBInstant.getSDKVersion();
128145

129146
this.playerID = FBInstant.player.getID();
130147
this.playerName = FBInstant.player.getName();
131148
this.playerPhotoURL = FBInstant.player.getPhoto();
132149

150+
var _this = this;
151+
152+
FBInstant.getEntryPointAsync().then(function (entrypoint) {
153+
154+
_this.entryPoint = entrypoint;
155+
_this.entryPointData = FBInstant.getEntryPointData();
156+
157+
});
158+
133159
this.emit('startgame');
134160
},
135161

@@ -185,14 +211,118 @@ var FacebookInstantGamesPlugin = new Class({
185211

186212
saveData: function (data)
187213
{
214+
var _this = this;
215+
188216
FBInstant.player.setDataAsync(data).then(function() {
189217
console.log('data saved to fb');
190-
this.emit('savedata', data);
218+
_this.emit('savedata', data);
219+
});
220+
221+
return this;
222+
},
223+
224+
getStats: function (keys)
225+
{
226+
var _this = this;
227+
228+
FBInstant.player.getStatsAsync(keys).then(function(data) {
229+
console.log('stats got from fb');
230+
_this.emit('getstats', data);
231+
});
232+
233+
return this;
234+
},
235+
236+
saveStats: function (data)
237+
{
238+
var output = {};
239+
240+
for (var key in data)
241+
{
242+
if (typeof data[key] === 'number')
243+
{
244+
output[key] = data[key];
245+
}
246+
}
247+
248+
var _this = this;
249+
250+
FBInstant.player.setStatsAsync(output).then(function() {
251+
console.log('stats saved to fb');
252+
_this.emit('savestats', output);
253+
});
254+
255+
return this;
256+
},
257+
258+
incStats: function (data)
259+
{
260+
var output = {};
261+
262+
for (var key in data)
263+
{
264+
if (typeof data[key] === 'number')
265+
{
266+
output[key] = data[key];
267+
}
268+
}
269+
270+
var _this = this;
271+
272+
FBInstant.player.incrementStatsAsync(output).then(function(stats) {
273+
console.log('stats modified');
274+
_this.emit('incstats', stats);
191275
});
192276

193277
return this;
194278
},
195279

280+
saveSession: function (data)
281+
{
282+
var test = JSON.stringify(data);
283+
284+
if (test.length <= 1000)
285+
{
286+
FBInstant.setSessionData(data);
287+
}
288+
else
289+
{
290+
console.warn('Session data too long. Max 1000 chars.');
291+
}
292+
293+
return this;
294+
},
295+
296+
openShare: function (text, key, frame, sessionData)
297+
{
298+
if (sessionData === undefined) { sessionData = {}; }
299+
300+
if (key)
301+
{
302+
var imageData = this.game.textures.getBase64(key, frame);
303+
}
304+
305+
var payload = {
306+
intent: 'SHARE',
307+
image: imageData,
308+
text: text,
309+
data: sessionData
310+
};
311+
312+
console.log(payload);
313+
314+
// intent ("INVITE" | "REQUEST" | "CHALLENGE" | "SHARE") Indicates the intent of the share.
315+
// image string A base64 encoded image to be shared.
316+
// text string A text message to be shared.
317+
// data Object? A blob of data to attach to the share. All game sessions launched from the share will be able to access this blob through FBInstant.getEntryPointData().
318+
319+
var _this = this;
320+
321+
FBInstant.shareAsync(payload).then(function() {
322+
_this.emit('resume');
323+
});
324+
},
325+
196326
/**
197327
* Destroys the FacebookInstantGamesPlugin.
198328
*

0 commit comments

Comments
 (0)