Skip to content

Commit

Permalink
Merge pull request #221 from getbraincloud/BCLOUD-9004_Implement-Lead…
Browse files Browse the repository at this point in the history
…erboardService-IfExists

added ifExists leaderboard methods
  • Loading branch information
bitheadCody authored Aug 6, 2024
2 parents 1fd6ec5 + f11489f commit 51409e3
Show file tree
Hide file tree
Showing 2 changed files with 521 additions and 61 deletions.
284 changes: 284 additions & 0 deletions src/brainCloudClient-social-leaderboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ function BCSocialLeaderboard() {
bc.socialLeaderboard.OPERATION_POST_SCORE_DYNAMIC_USING_CONFIG = "POST_SCORE_DYNAMIC_USING_CONFIG";
bc.socialLeaderboard.OPERATION_RESET = "RESET";
bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD = "GET_SOCIAL_LEADERBOARD";
bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD_IF_EXISTS = "GET_SOCIAL_LEADERBOARD_IF_EXISTS";
bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD_BY_VERSION = "GET_SOCIAL_LEADERBOARD_BY_VERSION";
bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS = "GET_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS";
bc.socialLeaderboard.OPERATION_GET_MULTI_SOCIAL_LEADERBOARD = "GET_MULTI_SOCIAL_LEADERBOARD";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_PAGE = "GET_GLOBAL_LEADERBOARD_PAGE";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_PAGE_IF_EXISTS = "GET_GLOBAL_LEADERBOARD_PAGE_IF_EXISTS";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_VIEW = "GET_GLOBAL_LEADERBOARD_VIEW";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_VIEW_IF_EXISTS = "GET_GLOBAL_LEADERBOARD_VIEW_IF_EXISTS";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_VERSIONS = "GET_GLOBAL_LEADERBOARD_VERSIONS";
bc.socialLeaderboard.OPERATION_GET_GROUP_SOCIAL_LEADERBOARD = "GET_GROUP_SOCIAL_LEADERBOARD";
bc.socialLeaderboard.OPERATION_GET_GROUP_SOCIAL_LEADERBOARD_BY_VERSION = "GET_GROUP_SOCIAL_LEADERBOARD_BY_VERSION";
bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD = "GET_PLAYERS_SOCIAL_LEADERBOARD";
bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD_IF_EXISTS = "GET_PLAYERS_SOCIAL_LEADERBOARD_IF_EXISTS";
bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD_BY_VERSION = "GET_PLAYERS_SOCIAL_LEADERBOARD_BY_VERSION";
bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS = "GET_PLAYERS_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS";
bc.socialLeaderboard.OPERATION_LIST_ALL_LEADERBOARDS = "LIST_ALL_LEADERBOARDS";
bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_ENTRY_COUNT = "GET_GLOBAL_LEADERBOARD_ENTRY_COUNT";
bc.socialLeaderboard.OPERATION_REMOVE_PLAYER_SCORE = "REMOVE_PLAYER_SCORE";
Expand Down Expand Up @@ -79,6 +85,43 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns a page of global leaderboard results.
*
* Leaderboards entries contain the player's score and optionally, some user-defined
* data associated with the score.
*
* Note: This method allows the client to retrieve pages from within the global leaderboard list
*
* This method returns the same data as getGlobalLeaderboardPage, but it will not return an error if the leaderboard does not exist.
*
* Service Name - SocialLeaderboard
* Service Operation - GetGlobalLeaderboardPage
*
* @param leaderboardId {string} The id of the leaderboard to retrieve.
* @param sortOrder {string} Sort key Sort order of page.
* @param startRank {int} The rank at which to start the page.
* @param endRank {int} The rank at which to end the page.
* @param callback The method to be invoked when the server response is received
*
* @see bc.socialLeaderboard.SortOrder
*/
bc.socialLeaderboard.getGlobalLeaderboardPageIfExists = function (
leaderboardId, sortOrder, startIndex, endIndex, callback) {
bc.brainCloudManager
.sendRequest({
service: bc.SERVICE_LEADERBOARD,
operation: bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_PAGE_IF_EXISTS,
data: {
leaderboardId: leaderboardId,
sort: sortOrder,
startIndex: startIndex,
endIndex: endIndex
},
callback: callback
});
};

/**
* Method returns a page of global leaderboard results.
* By using a non-current version id, the user can retrieve a historial leaderboard.
Expand Down Expand Up @@ -113,6 +156,42 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns a page of global leaderboard results.
* By using a non-current version id, the user can retrieve a historial leaderboard.
* See GetGlobalLeaderboardVersions method to retrieve the version id.
*
* This method returns the same data as getGlobalLeaderboardPageByVersion, but it will not return an error if the leaderboard does not exist.
*
* Service Name - SocialLeaderboard
* Service Operation - GetGlobalLeaderboardPage
*
* @param leaderboardId {string} The id of the leaderboard to retrieve.
* @param sortOrder {string} Sort key Sort order of page.
* @param startRank {int} The rank at which to start the page.
* @param endRank {int} The rank at which to end the page.
* @param versionId The historical version to retrieve
* @param callback The method to be invoked when the server response is received
*
* @see bc.socialLeaderboard.SortOrder
*/
bc.socialLeaderboard.getGlobalLeaderboardPageByVersionIfExists = function(
leaderboardId, sortOrder, startIndex, endIndex, versionId, callback) {
bc.brainCloudManager
.sendRequest({
service : bc.SERVICE_LEADERBOARD,
operation : bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_PAGE_IF_EXISTS,
data : {
leaderboardId : leaderboardId,
sort : sortOrder,
startIndex : startIndex,
endIndex : endIndex,
versionId : versionId
},
callback : callback
});
};

/**
* Method returns a view of global leaderboard results.
*
Expand Down Expand Up @@ -148,6 +227,43 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns a view of global leaderboard results.
*
* Leaderboards entries contain the player's score and optionally, some user-defined
* data associated with the score.
*
* Note: This method allows the client to retrieve pages from within the global leaderboard list
*
* This method returns the same data as getGlobalLeaderboardView, but it will not return an error if the leaderboard does not exist.
*
* Service Name - SocialLeaderboard
* Service Operation - GetGlobalLeaderboardPage
*
* @param leaderboardId {string} The id of the leaderboard to retrieve.
* @param sortOrder {string} Sort key Sort order of page.
* @param beforeCount {int} The count of number of players before the current player to include.
* @param afterCount {int} The count of number of players after the current player to include.
* @param callback The method to be invoked when the server response is received
*
* @see bc.socialLeaderboard.SortOrder
*/
bc.socialLeaderboard.getGlobalLeaderboardViewIfExists = function(
leaderboardId, sortOrder, beforeCount, afterCount, callback) {
bc.brainCloudManager
.sendRequest({
service : bc.SERVICE_LEADERBOARD,
operation : bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_VIEW_IF_EXISTS,
data : {
leaderboardId : leaderboardId,
sort : sortOrder,
beforeCount : beforeCount,
afterCount : afterCount
},
callback : callback
});
};

/**
* Method returns a view of global leaderboard results.
* By using a non-current version id, the user can retrieve a historial leaderboard.
Expand Down Expand Up @@ -182,6 +298,42 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns a view of global leaderboard results.
* By using a non-current version id, the user can retrieve a historial leaderboard.
* See GetGlobalLeaderboardVersions method to retrieve the version id.
*
* This method returns the same data as getGlobalLeaderboardViewByVersion, but it will not return an error if the leaderboard does not exist.
*
* Service Name - SocialLeaderboard
* Service Operation - GetGlobalLeaderboardView
*
* @param leaderboardId {string} The id of the leaderboard to retrieve.
* @param sortOrder {string} Sort key Sort order of page.
* @param beforeCount {int} The count of number of players before the current player to include.
* @param afterCount {int} The count of number of players after the current player to include.
* @param versionId The historical version to retrieve
* @param callback The method to be invoked when the server response is received
*
* @see bc.socialLeaderboard.SortOrder
*/
bc.socialLeaderboard.getGlobalLeaderboardViewByVersionIfExists = function(
leaderboardId, sortOrder, beforeCount, afterCount, versionId, callback) {
bc.brainCloudManager
.sendRequest({
service : bc.SERVICE_LEADERBOARD,
operation : bc.socialLeaderboard.OPERATION_GET_GLOBAL_LEADERBOARD_VIEW_IF_EXISTS,
data : {
leaderboardId : leaderboardId,
sort : sortOrder,
beforeCount : beforeCount,
afterCount : afterCount,
versionId : versionId
},
callback : callback
});
};

/**
* Gets the number of entries in a global leaderboard
*
Expand Down Expand Up @@ -262,6 +414,44 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns the social leaderboard. A player's social leaderboard is
* comprised of players who are recognized as being your friend.
*
* This method returns the same data as getSocialLeaderboard, but it will not return an error if the leaderboard does not exist.
*
* The getSocialLeaderboard will retrieve all friends from all friend platforms, so
* - all external friends (Facebook, Steam, PlaystationNetwork)
* - all internal friends (brainCloud)
* - plus "self".
*
* Leaderboards entries contain the player's score and optionally, some user-defined
* data associated with the score. The currently logged in player will also
* be returned in the social leaderboard.
*
* Note: If no friends have played the game, the bestScore, createdAt, updatedAt
* will contain NULL.
*
* @param leaderboardId The id of the leaderboard to retrieve
* @param replaceName If true, the currently logged in player's name will be replaced
* by the string "You".
* @param callback The method to be invoked when the server response is received
*
*/
bc.socialLeaderboard.getSocialLeaderboardIfExists = function (
leaderboardId, replaceName, callback) {
bc.brainCloudManager
.sendRequest({
service: bc.SERVICE_LEADERBOARD,
operation: bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD_IF_EXISTS,
data: {
leaderboardId: leaderboardId,
replaceName: replaceName
},
callback: callback
});
};

/**
* Method returns the social leaderboard by version. A player's social leaderboard is
* comprised of players who are recognized as being your friend.
Expand Down Expand Up @@ -300,6 +490,46 @@ function BCSocialLeaderboard() {
});
};

/**
* Method returns the social leaderboard by version. A player's social leaderboard is
* comprised of players who are recognized as being your friend.
*
* This method returns the same data as getSocialLeaderboardByVersion, but it will not return an error if the leaderboard does not exist.
*
* The getSocialLeaderboard will retrieve all friends from all friend platforms, so
* - all external friends (Facebook, Steam, PlaystationNetwork)
* - all internal friends (brainCloud)
* - plus "self".
*
* Leaderboards entries contain the player's score and optionally, some user-defined
* data associated with the score. The currently logged in player will also
* be returned in the social leaderboard.
*
* Note: If no friends have played the game, the bestScore, createdAt, updatedAt
* will contain NULL.
*
* @param leaderboardId The id of the leaderboard to retrieve
* @param replaceName If true, the currently logged in player's name will be replaced
* by the string "You".
* @param versionId the version of the social leaderboard
* @param callback The method to be invoked when the server response is received
*
*/
bc.socialLeaderboard.getSocialLeaderboardByVersionIfExists = function (
leaderboardId, replaceName, versionId, callback) {
bc.brainCloudManager
.sendRequest({
service: bc.SERVICE_LEADERBOARD,
operation: bc.socialLeaderboard.OPERATION_GET_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS,
data: {
leaderboardId: leaderboardId,
replaceName: replaceName,
versionId: versionId
},
callback: callback
});
};

/**
* Reads multiple social leaderboards.
*
Expand Down Expand Up @@ -652,6 +882,32 @@ function BCSocialLeaderboard() {
});
}

/**
* Retrieve the social leaderboard for a group.
*
* This method returns the same data as getPlayersSocialLeaderboard, but it will not return an error if the leaderboard does not exist.
*
* Service Name - leaderboard
* Service Operation - GET_GROUP_SOCIAL_LEADERBOARD
*
* @param leaderboardId The leaderboard to retrieve
* @param profileIds The IDs of the players
* @param callback The method to be invoked when the server response is received
*/
bc.socialLeaderboard.getPlayersSocialLeaderboardIfExists = function (leaderboardId, profileIds, callback) {
var message = {
leaderboardId: leaderboardId,
profileIds: profileIds
};

bc.brainCloudManager.sendRequest({
service: bc.SERVICE_LEADERBOARD,
operation: bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD_IF_EXISTS,
data: message,
callback: callback
});
}

/**
* Retrieve the social leaderboard for a player by the version.
*
Expand All @@ -678,6 +934,34 @@ function BCSocialLeaderboard() {
});
}

/**
* Retrieve the social leaderboard for a player by the version.
*
* This method returns the same data as getPlayersSocialLeaderboardByVersion, but it will not return an error if the leaderboard does not exist.
*
* Service Name - leaderboard
* Service Operation - GET_PLAYER_SOCIAL_LEADERBOARD_BY_VERSION
*
* @param leaderboardId The leaderboard to retrieve
* @param profileIds The IDs of the players
* @param versionId The version of the leaderboard
* @param callback The method to be invoked when the server response is received
*/
bc.socialLeaderboard.getPlayersSocialLeaderboardByVersionIfExists = function(leaderboardId, profileIds, versionId, callback) {
var message = {
leaderboardId : leaderboardId,
profileIds : profileIds,
versionId : versionId
};

bc.brainCloudManager.sendRequest({
service : bc.SERVICE_LEADERBOARD,
operation : bc.socialLeaderboard.OPERATION_GET_PLAYERS_SOCIAL_LEADERBOARD_BY_VERSION_IF_EXISTS,
data : message,
callback : callback
});
}

/**
* Retrieve a list of all leaderboards
*
Expand Down
Loading

0 comments on commit 51409e3

Please sign in to comment.