this.bga.players
Accessing player information
this.bga.players.getCurrentPlayerId(): number id of the player who is looking at the game. The player may not be part of the game (i.e. a spectator)
this.bga.players.getCurrentPlayerNo(): number | null no of the player who is looking at the game. The player may not be part of the game (i.e. a spectator); in this case, the result is null.
this.bga.players.isCurrentPlayerSpectator(): boolean Flag set to true if the user at the table is a spectator (not a player).
You may consider making a function like this, to detect if the game is in a read-only state (i.e. non-interactive):
// Returns true for spectators, instant replay (during game), archive mode (after game end)
isReadOnly: function () {
return this.bga.players.isCurrentPlayerSpectator() || typeof g_replayFrom != 'undefined' || g_archive_mode;
}
this.bga.players.isCurrentPlayerActive(): boolean Returns true if the player on whose browser the code is running is currently active (it's his turn to play). Note: see remarks above about usage of this function inside onEnteringState method.
this.bga.players.getActivePlayerId(): number | null; Return the ID of the active player, or null if we are not in an ACTIVE_PLAYER type state.
this.bga.players.getActivePlayerNo(): number | null; Return the no of the active player, or null if we are not in an ACTIVE_PLAYER type state.
this.bga.players.getActivePlayerIds(): number[] Return an array with the IDs of players who are currently active (or an empty array if there are none).
this.bga.players.getFormattedPlayerName(playerId, params?): string Get the HTML code to display the player name, in bold, with color. params is optional, { replaceByYou: true } will display a colored "You" instead of the colored player name.
this.gamedatas: object Contains the initial set of data to initialize the game, created at game start or when the game is refreshed (F5). You can update it as needed to keep an up-to-date reference of the game on the client side if you need it. However, most of the time this is unnecessary.
Note
In hotseat mode, the framework does not keep this.gamedatas of hotseat players and shares the same set as the main player to store data.
Be careful when you update this data structurally: many framework functions expect data to be structured a certain way and they will break if they see something else.
this.bga.players.getPlayerById(playerId): object Return the player data stored in gamedatas.players. Can be undefined, if the player isn't at this table (spectator).
this.bga.players.getPlayerByNo(playerNo): object Return the player data stored in gamedatas.players.
this.bga.players.getActivePlayer(): object Same as getPlayer for the active player.
this.bga.players.getCurrentPlayer(): object Same as getPlayer for the current player.
this.bga.players.getPlayerAvatarUrl(playerId, size): string Return the player avatar URL. The size of the avatar can be 32, 50, 92 or 184 (default). Set playerId to 0 to get the default avatar.
this.bga.players.getPlayerNoById(playerId): number | null Return the no of the player, by id
this.bga.players.getPlayerIdByNo(playerNo): number Return the id of the player, by no