this.bga.gameui
This section lists the miscellaneous functions the framework provides.
Animations
Use the BgaAnimations library to do animations.
this.bga.gameui.bgaAnimationsActive()
Function to know if animations should be played. Animations should not be played in instantaneousMode (fast-replay mode), or if the tab is not displayed in the browser. Returns a boolean saying if animations should be played.
if (this.bga.gameui.bgaAnimationsActive()) {
// play an animation
} else {
// just apply the end situation of the animation
}
Note
BgaAnimations uses this function in its setup, to handle it automatically for all animations. It's only useful if you write custom animations.
Tooltips
Don't rely too heavily on tooltips
Tooltips are nice, but not very practical to use on mobile devices, so they should not be essential to understanding the game.
Adding static tooltips
this.bga.gameui.addTooltip(nodeId: string, helpStringTranslated: string, actionStringTranslated: string, delay?: number): void
Add a simple text tooltip to the DOM node.
Specify 'helpStringTranslated' to display some information about "what is this game element?". Specify 'actionStringTranslated' to display some information about "what happens when I click on this element?".
You must specify both strings. You can use one and specify an empty string for the other.
When you pass text directly, the function _() must be used to mark the text for translation, except for an empty string.
Parameter "delay" is optional. It is primarily used to specify a zero delay for some game element when the tooltip gives really important information for the game - but remember: no essential information must be placed in tooltips as they won't be displayed in some browsers (see Guidelines).
Example:
Note: this generates a static tooltip and attaches it to an existing DOM element. If you need to generate a tooltip more dynamically, you have to call this method every time information about the object is updated or use a different technique. See dynamic tooltips below.
this.bga.gameui.addTooltipHtml(nodeId: string, html: string, delay?: number): void
Add an HTML tooltip to the DOM node (for more elaborate content such as presenting a bigger version of a card).
this.bga.gameui.addTooltipToClass(cssClass: string, helpStringTranslated: string, actionStringTranslated: string, delay?: number ): void
Add a simple text tooltip to all the DOM nodes set with this cssClass. See more details above for this.bga.gameui.addTooltip.
Important
All concerned nodes must exist and have IDs to get tooltips.
this.bga.gameui.addTooltipHtmlToClass(cssClass: string, html: string, delay?: number): void
Add an HTML tooltip to all the DOM nodes set with this cssClass (for more elaborate content such as presenting a bigger version of a card).
Important
All concerned nodes must exist and have IDs to get tooltips.
Removing static tooltips
this.bga.gameui.removeTooltip(nodeId: string): void
Remove a tooltip from the DOM node with the given id.
Advanced tooltips
Force a tooltip to open
If you want to force a tooltip to open in reaction to another action, such as a click, you can do this:
where id is the id of the node where the tooltip was installed.
Other useful stuff
Callback on screen size change
this.bga.gameui.onScreenWidthChange = () => this.myWidthChangeCallback()
This function can be overridden in your game to manage some resizing on the client side when the browser window is resized. This function is also triggered at load time, so it can be used to adapt to the viewport size at the start of the game too.
Interface locking
this.bga.gameui.checkLock(nomessage?: boolean): boolean
When using "lock: true" in an AJAX call you can use this function to check if the interface is in a locked state (it will be locked during a server call and notification processing). This check can be used to block some other interactions which do not result in ajaxcall or if you want to suppress errors. Note: normally you only need to use this.bga.actions.checkAction(...), this is for advanced cases.
It will also show an error unless nomessage is set to true.
Deprecated globals
globalThis.g_replayFrom This global contains the replay number in a live game. It is set to undefined (i.e. not set) when the game is not in replay mode, so the appropriate check is typeof g_replayFrom != 'undefined' which returns true if the game is in replay mode during the game (the game is ongoing but the user clicked "replay from this move" in the log)
globalThis.g_archive_mode Returns true if the game is in archive mode after the game (the game has ended)
globalThis.g_tutorialwritten Returns an object if the game is in tutorial mode, or undefined otherwise. Tutorial mode is a special case of archive mode where comments have been added to a previous game to teach new players the rules.
this.bga.gameui.instantaneousMode Returns true during replay/archive mode if animations should be skipped. Only needed if you are doing custom animations. (The BGA-provided animation functions like the bga-animations, bga-cards, bga-dice libs and this.bga.gameui.slideToObject() and similar automatically handle instantaneous mode.)
Technically, when you click "replay from move #20", the system replays the game from the very beginning with moves 0 - 19 happening in instantaneous mode and moves 20+ happening in normal mode.