mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Added getConnectedScores method
This commit is contained in:
parent
1a02f51fa1
commit
23cc8b84e3
2 changed files with 50 additions and 2 deletions
|
@ -4,10 +4,12 @@
|
|||
|
||||
### Facebook Instant Games Updates and Fixes
|
||||
|
||||
* Added the `Leaderboard.getConnectedScores` method, to get a list of scores from player connected entries.
|
||||
* The `loadPlayerPhoto` function in the Instant Games plugin now listens for the updated Loader event correctly, causing the `photocomplete` event to fire properly.
|
||||
* `Leaderboard.setScore` now emits the LeaderboardScore object with the `setscore` event, as the documentation said it did.
|
||||
* `Leaderboard.getPlayerScore` now only populates the `playerScore` property if the entry isn't `null`.
|
||||
* If the `setScore` or `getPlayerScore` calls fail, it will return `null` as the score instance, instead of causing a run-time error.
|
||||
* You can now pass an object or a string to `setScore` and objects will be automatically stringified.
|
||||
|
||||
### New Features
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ var Leaderboard = new Class({
|
|||
* @since 3.13.0
|
||||
*
|
||||
* @param {integer} score - The new score for the player. Must be a 64-bit integer number.
|
||||
* @param {string} [data] - Metadata to associate with the stored score. Must be less than 2KB in size.
|
||||
* @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.
|
||||
*/
|
||||
|
@ -155,6 +155,11 @@ var Leaderboard = new Class({
|
|||
{
|
||||
if (data === undefined) { data = ''; }
|
||||
|
||||
if (typeof data === 'object')
|
||||
{
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.ref.setScoreAsync(score, data).then(function (entry)
|
||||
|
@ -226,7 +231,7 @@ var Leaderboard = new Class({
|
|||
*
|
||||
* 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.
|
||||
* 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.FacebookInstantGamesPlugin.Leaderboard#getScores
|
||||
* @since 3.13.0
|
||||
|
@ -259,6 +264,47 @@ var Leaderboard = new Class({
|
|||
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.FacebookInstantGamesPlugin.Leaderboard#getConnectedScores
|
||||
* @since 3.16.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.
|
||||
*/
|
||||
getConnectedScores: function (count, offset)
|
||||
{
|
||||
if (count === undefined) { count = 10; }
|
||||
if (offset === undefined) { offset = 0; }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue