Skip to content

this.bga.playerPanels

Player panels

Adding elements to a player panel

this.bga.playerPanels.getElement(player_id: number): HTMLElement

Returns the div in the player panel you can put your counters & other indicators in.

Example Add this piece of code in your JS file to add this template to each player panel:

Example in the setup function of Game.js
            // Setting up player boards
            for( var player_id in gamedatas.players )
            {
                var player = gamedatas.players[player_id];

                // Setting up player boards if needed
                const html = `<div class="cp_board">
                    <div id="stoneicon_p${player.id}" class="gmk_stoneicon gmk_stoneicon_${player.color}"></div><span id="stonecount_p${player.id}">0</span>
                </div>`;
                this.bga.playerPanels.getElement(player_id).insertAdjacentHTML('beforeend', html);
            }
If you have to distinguish the current player from other players, you just have to change the content of the html variable when "player_id" is different from "this.bga.players.getCurrentPlayerId()".

this.bga.playerPanels.getElementByNo(playerNo: number): HTMLElement

Same as getElement but using playerNo instead of playerId.

Adding a player panel for an automaton

this.bga.playerPanels.addAutomataPlayerPanel(id: number, name: string, params: Object): void

The id is the automaton id, used to set up the player panel score counter and getPlayerPanelElement. 0 or a negative value is recommended to avoid conflicts with real player ids.

Parameters:

  • id: the automaton id, used to set up the player panel score counter and getPlayerPanelElement. 0 or a negative value is recommended to avoid conflicts with real player ids.
  • name: the name of the automaton
  • params: object optionally containing one or more of the following:
  • color: string - the automaton player color (default black)
  • iconClass: string - the class, or list of classes separated by spaces, to apply to the player picture.
  • score: number - the automaton score (default undefined, will display '-')

Example from Glow, with the automaton Tom when playing solo :

this.bga.playerPanels.addAutomataPlayerPanel(0, 'Tom', {
    iconClass: 'tom-avatar',
    score: gamedatas.tom.score,
});

Disabling and enabling player panels

this.bga.gameui.disablePlayerPanel(player_id: number): void

Disable the given player panel (the panel background becomes gray).

Usually, this is used to signal that this player has passed or will be inactive for a while.

Note that the only effect of this is visual. There are no consequences on the behaviour of the panel itself.

this.bga.gameui.enablePlayerPanel(player_id:number): void

Enable a player panel that has been disabled before.

this.bga.gameui.enableAllPlayerPanels(): void

Enable all player panels that have been disabled before.

Player order

this.bga.gameui.updatePlayerOrdering(): void

This function makes sure that the order of player panels matches this.gamedatas.playerorder and is normally called by the framework. You can call it yourself if you change this.gamedatas.playerorder from a notification. You can also override this function to change the defaults or insert a non-player panel BGA_Studio_Cookbook#Inserting_non-player_panel.

Score counter

this.bga.playerPanels.getScoreCounter(player_id: number): Counter

Returns the score counter on the player panel.

To create other counters on the player panel, please use the "ebg/counter" library, documented at Counter.

this.bga.playerPanels.getScoreCounterByNo(playerNo: number): Counter

Same as getScoreCounter but using playerNo instead of playerId.