fisrt commit
This commit is contained in:
84
node_modules/phaser/plugins/fbinstant/readme.md
generated
vendored
Normal file
84
node_modules/phaser/plugins/fbinstant/readme.md
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
Phaser 3 Facebook Instant Games Plugin
|
||||
======================================
|
||||
|
||||
Starting with version 3.13 Phaser now has a dedicated plugin that provides complete support for Facebook Instant Games.
|
||||
|
||||
If you are using the pre-built versions of Phaser then use the file `phaser-facebook-instant-games.js` which you'll find in the `dist` folder.
|
||||
|
||||
If you are creating your own builds using Webpack then make sure you enable the plugin using the Webpack DefinePlugin control:
|
||||
|
||||
```
|
||||
"typeof PLUGIN_FBINSTANT": JSON.stringify(true)
|
||||
```
|
||||
|
||||
Building Phaser via Webpack with this set to `true` will include the plugin in the build.
|
||||
|
||||
## Using the Plugin
|
||||
|
||||
You need to include the Facebook SDK in your html and wait for the `initializeAsync` Promise to resolve before you should create your game instance:
|
||||
|
||||
```
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Phaser 3 Facebook Instant Games</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="https://connect.facebook.net/en_US/fbinstant.6.2.js"></script>
|
||||
<script src="lib/phaser-facebook-instant-games.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
FBInstant.initializeAsync().then(function() {
|
||||
|
||||
var config = {
|
||||
type: Phaser.AUTO,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
scene: ...
|
||||
};
|
||||
|
||||
new Phaser.Game(config);
|
||||
|
||||
});
|
||||
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Now, when your game starts, you'll know that the FBInstant API is enabled and ready for use. To access the plugin use `this.facebook` from within any Scene, i.e.:
|
||||
|
||||
```
|
||||
this.add.text(0, 0).setText(this.facebook.playerName);
|
||||
```
|
||||
|
||||
### Preloader
|
||||
|
||||
To hook your games preloader into the Facebook Instant Games loader you should use a Preloader Scene like below:
|
||||
|
||||
```
|
||||
class Preloader extends Phaser.Scene {
|
||||
|
||||
constructor ()
|
||||
{
|
||||
super('Preloader');
|
||||
}
|
||||
|
||||
preload ()
|
||||
{
|
||||
this.facebook.showLoadProgress(this);
|
||||
this.facebook.once('startgame', this.startGame, this);
|
||||
|
||||
// Now load all of your assets
|
||||
}
|
||||
|
||||
startGame ()
|
||||
{
|
||||
this.scene.start('MainMenu');
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
In the above Scene it has hooked the Facebook preloader with the Phaser Loader, so every file that loads (once you add some) will make the Facebook loader update. When the load is over it will call the `startGame` function that just changes the Scene to another one.
|
||||
|
||||
Please look at the plugin documentation and the Facebook SDK documentation for more details about what features are available.
|
||||
26
node_modules/phaser/plugins/fbinstant/src/AdInstance.js
generated
vendored
Normal file
26
node_modules/phaser/plugins/fbinstant/src/AdInstance.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} AdInstance
|
||||
*
|
||||
* @property {any} instance - Represents an instance of an ad.
|
||||
* @property {string} placementID - The Audience Network placement ID of this ad instance.
|
||||
* @property {boolean} shown - Has this ad already been shown in-game?
|
||||
* @property {boolean} video - Is this a video ad?
|
||||
*/
|
||||
|
||||
var AdInstance = function (placementID, instance, video)
|
||||
{
|
||||
return {
|
||||
instance: instance,
|
||||
placementID: placementID,
|
||||
shown: false,
|
||||
video: video
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = AdInstance;
|
||||
2314
node_modules/phaser/plugins/fbinstant/src/FacebookInstantGamesPlugin.js
generated
vendored
Normal file
2314
node_modules/phaser/plugins/fbinstant/src/FacebookInstantGamesPlugin.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
308
node_modules/phaser/plugins/fbinstant/src/Leaderboard.js
generated
vendored
Normal file
308
node_modules/phaser/plugins/fbinstant/src/Leaderboard.js
generated
vendored
Normal file
@ -0,0 +1,308 @@
|
||||
/**
|
||||
* @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('../../../src/utils/Class');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var LeaderboardScore = require('./LeaderboardScore');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* This class represents one single Leaderboard that belongs to a Facebook Instant Game.
|
||||
*
|
||||
* You do not need to instantiate this class directly, it will be created when you use the
|
||||
* `getLeaderboard()` method of the main plugin.
|
||||
*
|
||||
* @class FacebookInstantGamesLeaderboard
|
||||
* @memberOf Phaser
|
||||
* @constructor
|
||||
* @extends Phaser.Events.EventEmitter
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {Phaser.FacebookInstantGamesPlugin} plugin - A reference to the Facebook Instant Games Plugin.
|
||||
* @param {any} data - An Instant Game leaderboard instance.
|
||||
*/
|
||||
var Leaderboard = new Class({
|
||||
|
||||
Extends: EventEmitter,
|
||||
|
||||
initialize:
|
||||
|
||||
function Leaderboard (plugin, data)
|
||||
{
|
||||
EventEmitter.call(this);
|
||||
|
||||
/**
|
||||
* A reference to the Facebook Instant Games Plugin.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#plugin
|
||||
* @type {Phaser.FacebookInstantGamesPlugin}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.plugin = plugin;
|
||||
|
||||
/**
|
||||
* An Instant Game leaderboard instance.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#ref
|
||||
* @type {any}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.ref = data;
|
||||
|
||||
/**
|
||||
* The name of the leaderboard.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#name
|
||||
* @type {string}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.name = data.getName();
|
||||
|
||||
/**
|
||||
* The ID of the context that the leaderboard is associated with, or null if the leaderboard is not tied to a particular context.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#contextID
|
||||
* @type {string}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.contextID = data.getContextID();
|
||||
|
||||
/**
|
||||
* The total number of player entries in the leaderboard.
|
||||
* This value defaults to zero. Populate it via the `getEntryCount()` method.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#entryCount
|
||||
* @type {integer}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.entryCount = 0;
|
||||
|
||||
/**
|
||||
* The players score object.
|
||||
* This value defaults to `null`. Populate it via the `getPlayerScore()` method.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#playerScore
|
||||
* @type {LeaderboardScore}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.playerScore = null;
|
||||
|
||||
/**
|
||||
* The scores in the Leaderboard from the currently requested range.
|
||||
* This value defaults to an empty array. Populate it via the `getScores()` method.
|
||||
* The contents of this array are reset each time `getScores()` is called.
|
||||
*
|
||||
* @name Phaser.FacebookInstantGamesLeaderboard#scores
|
||||
* @type {LeaderboardScore[]}
|
||||
* @since 3.13.0
|
||||
*/
|
||||
this.scores = [];
|
||||
|
||||
this.getEntryCount();
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetches the total number of player entries in the leaderboard.
|
||||
*
|
||||
* The data is requested in an async call, so the result isn't available immediately.
|
||||
*
|
||||
* When the call completes this Leaderboard will emit the `getentrycount` event along with the count and name of the Leaderboard.
|
||||
*
|
||||
* @method Phaser.FacebookInstantGamesLeaderboard#getEntryCount
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @return {this} This Leaderboard instance.
|
||||
*/
|
||||
getEntryCount: function ()
|
||||
{
|
||||
var _this = this;
|
||||
|
||||
this.ref.getEntryCountAsync().then(function (count)
|
||||
{
|
||||
_this.entryCount = count;
|
||||
|
||||
_this.emit('getentrycount', count, _this.name);
|
||||
|
||||
}).catch(function (e)
|
||||
{
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the player's score. If the player has an existing score, the old score will only be replaced if the new score is better than it.
|
||||
* NOTE: If the leaderboard is associated with a specific context, the game must be in that context to set a score for the player.
|
||||
*
|
||||
* The data is requested in an async call, so the result isn't available immediately.
|
||||
*
|
||||
* When the call completes this Leaderboard will emit the `setscore` event along with the LeaderboardScore object and the name of the Leaderboard.
|
||||
*
|
||||
* If the save fails the event will send `null` as the score value.
|
||||
*
|
||||
* @method Phaser.FacebookInstantGamesLeaderboard#setScore
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {integer} score - The new score for the player. Must be a 64-bit integer number.
|
||||
* @param {(string|any)} [data] - Metadata to associate with the stored score. Must be less than 2KB in size. If an object is given it will be passed to `JSON.stringify`.
|
||||
*
|
||||
* @return {this} This Leaderboard instance.
|
||||
*/
|
||||
setScore: function (score, data)
|
||||
{
|
||||
if (data === undefined) { data = ''; }
|
||||
|
||||
if (typeof data === 'object')
|
||||
{
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.ref.setScoreAsync(score, data).then(function (entry)
|
||||
{
|
||||
if (entry)
|
||||
{
|
||||
var score = LeaderboardScore(entry);
|
||||
|
||||
_this.playerScore = score;
|
||||
|
||||
_this.emit('setscore', score, _this.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_this.emit('setscore', null, _this.name);
|
||||
}
|
||||
|
||||
}).catch(function (e)
|
||||
{
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the players leaderboard entry and stores it in the `playerScore` property.
|
||||
*
|
||||
* The data is requested in an async call, so the result isn't available immediately.
|
||||
*
|
||||
* When the call completes this Leaderboard will emit the `getplayerscore` event along with the score and the name of the Leaderboard.
|
||||
*
|
||||
* If the player has not yet saved a score, the event will send `null` as the score value, and `playerScore` will be set to `null` as well.
|
||||
*
|
||||
* @method Phaser.FacebookInstantGamesLeaderboard#getPlayerScore
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @return {this} This Leaderboard instance.
|
||||
*/
|
||||
getPlayerScore: function ()
|
||||
{
|
||||
var _this = this;
|
||||
|
||||
this.ref.getPlayerEntryAsync().then(function (entry)
|
||||
{
|
||||
if (entry)
|
||||
{
|
||||
var score = LeaderboardScore(entry);
|
||||
|
||||
_this.playerScore = score;
|
||||
|
||||
_this.emit('getplayerscore', score, _this.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_this.emit('getplayerscore', null, _this.name);
|
||||
}
|
||||
|
||||
}).catch(function (e)
|
||||
{
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves a set of leaderboard entries, ordered by score ranking in the leaderboard.
|
||||
*
|
||||
* The data is requested in an async call, so the result isn't available immediately.
|
||||
*
|
||||
* When the call completes this Leaderboard will emit the `getscores` event along with an array of LeaderboardScore entries and the name of the Leaderboard.
|
||||
*
|
||||
* @method Phaser.FacebookInstantGamesLeaderboard#getScores
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {integer} [count=10] - The number of entries to attempt to fetch from the leaderboard. Currently, up to a maximum of 100 entries may be fetched per query.
|
||||
* @param {integer} [offset=0] - The offset from the top of the leaderboard that entries will be fetched from.
|
||||
*
|
||||
* @return {this} This Leaderboard instance.
|
||||
*/
|
||||
getScores: function (count, offset)
|
||||
{
|
||||
if (count === undefined) { count = 10; }
|
||||
if (offset === undefined) { offset = 0; }
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.ref.getEntriesAsync(count, offset).then(function (entries)
|
||||
{
|
||||
_this.scores = [];
|
||||
|
||||
entries.forEach(function (entry)
|
||||
{
|
||||
_this.scores.push(LeaderboardScore(entry));
|
||||
});
|
||||
|
||||
_this.emit('getscores', _this.scores, _this.name);
|
||||
|
||||
}).catch(function (e)
|
||||
{
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves a set of leaderboard entries, based on the current player's connected players (including the current player), ordered by local rank within the set of connected players.
|
||||
*
|
||||
* The data is requested in an async call, so the result isn't available immediately.
|
||||
*
|
||||
* When the call completes this Leaderboard will emit the `getconnectedscores` event along with an array of LeaderboardScore entries and the name of the Leaderboard.
|
||||
*
|
||||
* @method Phaser.FacebookInstantGamesLeaderboard#getConnectedScores
|
||||
* @since 3.16.0
|
||||
*
|
||||
* @return {this} This Leaderboard instance.
|
||||
*/
|
||||
getConnectedScores: function ()
|
||||
{
|
||||
var _this = this;
|
||||
|
||||
this.ref.getConnectedPlayerEntriesAsync().then(function (entries)
|
||||
{
|
||||
_this.scores = [];
|
||||
|
||||
entries.forEach(function (entry)
|
||||
{
|
||||
_this.scores.push(LeaderboardScore(entry));
|
||||
});
|
||||
|
||||
_this.emit('getconnectedscores', _this.scores, _this.name);
|
||||
|
||||
}).catch(function (e)
|
||||
{
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Leaderboard;
|
||||
34
node_modules/phaser/plugins/fbinstant/src/LeaderboardScore.js
generated
vendored
Normal file
34
node_modules/phaser/plugins/fbinstant/src/LeaderboardScore.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} LeaderboardScore
|
||||
*
|
||||
* @property {integer} score - An integer score value.
|
||||
* @property {string} scoreFormatted - The score value, formatted with the score format associated with the leaderboard.
|
||||
* @property {integer} timestamp - The Unix timestamp of when the leaderboard entry was last updated.
|
||||
* @property {integer} rank - The entry's leaderboard ranking.
|
||||
* @property {string} data - The developer-specified payload associated with the score, or null if one was not set.
|
||||
* @property {string} playerName - The player's localized display name.
|
||||
* @property {string} playerPhotoURL - A url to the player's public profile photo.
|
||||
* @property {string} playerID - The game's unique identifier for the player.
|
||||
*/
|
||||
|
||||
var LeaderboardScore = function (entry)
|
||||
{
|
||||
return {
|
||||
score: entry.getScore(),
|
||||
scoreFormatted: entry.getFormattedScore(),
|
||||
timestamp: entry.getTimestamp(),
|
||||
rank: entry.getRank(),
|
||||
data: entry.getExtraData(),
|
||||
playerName: entry.getPlayer().getName(),
|
||||
playerPhotoURL: entry.getPlayer().getPhoto(),
|
||||
playerID: entry.getPlayer().getID()
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = LeaderboardScore;
|
||||
32
node_modules/phaser/plugins/fbinstant/src/Product.js
generated
vendored
Normal file
32
node_modules/phaser/plugins/fbinstant/src/Product.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @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 GetFastValue = require('../../../src/utils/object/GetFastValue');
|
||||
|
||||
/**
|
||||
* @typedef {object} Product
|
||||
*
|
||||
* @property {string} [title] - The title of the product.
|
||||
* @property {string} [productID] - The product's game-specified identifier.
|
||||
* @property {string} [description] - The product description.
|
||||
* @property {string} [imageURI] - A link to the product's associated image.
|
||||
* @property {string} [price] - The price of the product.
|
||||
* @property {string} [priceCurrencyCode] - The currency code for the product.
|
||||
*/
|
||||
|
||||
var Product = function (data)
|
||||
{
|
||||
return {
|
||||
title: GetFastValue(data, 'title', ''),
|
||||
productID: GetFastValue(data, 'productID', ''),
|
||||
description: GetFastValue(data, 'description', ''),
|
||||
imageURI: GetFastValue(data, 'imageURI', ''),
|
||||
price: GetFastValue(data, 'price', ''),
|
||||
priceCurrencyCode: GetFastValue(data, 'priceCurrencyCode', '')
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Product;
|
||||
32
node_modules/phaser/plugins/fbinstant/src/Purchase.js
generated
vendored
Normal file
32
node_modules/phaser/plugins/fbinstant/src/Purchase.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @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 GetFastValue = require('../../../src/utils/object/GetFastValue');
|
||||
|
||||
/**
|
||||
* @typedef {object} Purchase
|
||||
*
|
||||
* @property {string} [developerPayload] - A developer-specified string, provided during the purchase of the product.
|
||||
* @property {string} [paymentID] - The identifier for the purchase transaction.
|
||||
* @property {string} [productID] - The product's game-specified identifier.
|
||||
* @property {string} [purchaseTime] - Unix timestamp of when the purchase occurred.
|
||||
* @property {string} [purchaseToken] - A token representing the purchase that may be used to consume the purchase.
|
||||
* @property {string} [signedRequest] - Server-signed encoding of the purchase request.
|
||||
*/
|
||||
|
||||
var Purchase = function (data)
|
||||
{
|
||||
return {
|
||||
developerPayload: GetFastValue(data, 'developerPayload', ''),
|
||||
paymentID: GetFastValue(data, 'paymentID', ''),
|
||||
productID: GetFastValue(data, 'productID', ''),
|
||||
purchaseTime: GetFastValue(data, 'purchaseTime', ''),
|
||||
purchaseToken: GetFastValue(data, 'purchaseToken', ''),
|
||||
signedRequest: GetFastValue(data, 'signedRequest', '')
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Purchase;
|
||||
Reference in New Issue
Block a user