This is a documentation for Board Game Arena: play board games online !
Studio function reference: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
This page references useful server side and client side functions (and some interesting class variables), so that nobody needs to reinvent the wheel (unless | This page references useful server side and client side functions (and some interesting class variables), so that nobody needs to reinvent the wheel (unless they want to). | ||
This list is not exhaustive, in particular functions already well described by comments in the 'EmptyGame' game template may not be described again below. | This list is not exhaustive, in particular functions already well described by comments in the 'EmptyGame' game template may not be described again below. | ||
Line 5: | Line 5: | ||
== Server side (PHP functions) == | == Server side (PHP functions) == | ||
See [[Table]] class reference | |||
== Client side (Javascript functions) == | |||
This list is not really maintained, see https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js for up to date info | |||
; this.player_id | ; this.player_id | ||
Line 106: | Line 49: | ||
; addEventToClass: function( cssClassName, eventName, functionName ) | ; addEventToClass: function( cssClassName, eventName, functionName ) | ||
: DEPRECATED (please use connectClass below) | |||
; connectClass: function( cssClassName, eventName, functionName ) | |||
: Same as dojo.connect(), but for all the nodes set with the specified cssClassName | : Same as dojo.connect(), but for all the nodes set with the specified cssClassName | ||
; addStyleToClass: function( cssClassName, cssProperty, propertyValue ) | ; addStyleToClass: function( cssClassName, cssProperty, propertyValue ) | ||
Line 120: | Line 67: | ||
; showMessage: function( msg, type ) | ; showMessage: function( msg, type ) | ||
: Show an information message during a few seconds at the top of the page | : Show an information message during a few seconds at the top of the page, or to the log. | ||
: Type can be 'error' or 'info' | : Type can be 'error' or 'info' or 'only_to_log'. | ||
; this.scoreCtrl[ player_id ].incValue( score_delta ); | ; this.scoreCtrl[ player_id ].incValue( score_delta ); | ||
: Adds score_delta (positive or negative integer) to the current score value for player | : Adds score_delta (positive or negative integer) to the current score value for player | ||
[[Category:Studio]] |
Latest revision as of 00:44, 17 May 2022
This page references useful server side and client side functions (and some interesting class variables), so that nobody needs to reinvent the wheel (unless they want to).
This list is not exhaustive, in particular functions already well described by comments in the 'EmptyGame' game template may not be described again below.
Server side (PHP functions)
See Table class reference
Client side (Javascript functions)
This list is not really maintained, see https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js for up to date info
- this.player_id
- Id of the player on whose browser the code is running.
- this.isSpectator
- Flag set to true if the user at the table is a spectator (not a player).
- this.gamedatas
- Contains your initial set of datas to init the game, created at game start or game refresh (F5)
- You can update it as needed to keep an up to date reference of the game on the client side.
- slideToObject
- function( mobile_obj, target_obj, duration, delay )
- Return an dojo.fx animation that is sliding a DOM object from its current position over another one
- Animate a slide of the DOM object referred to by domNodeToSlide from its current position to the xpos, ypos relative to the object referred to by domNodeToSlideTo.
- slideToObjectPos
- function( mobile_obj, target_obj, target_x, target_y, duration, delay )
- Return an dojo.fx animation that is sliding a DOM object from its current position over another one at the given coordinates relative to the target object.
- updateCounters(counters)
- Useful for updating game counters in the player panel (such as resources).
- 'counters' arg is an associative array [counter_name_value => [ 'counter_name' => counter_name_value, 'counter_value' => counter_value_value], ... ]
- All counters must be referenced in this.gamedatas.counters and will be updated.
- DOM objects referenced by 'counter_name' will have their innerHTML updated with 'counter_value'.
- addTooltip( node, _( helpString ), _( actionString ), delay );
- Add a simple text tooltip to the DOM node. Only one of 'helpString' or 'actionString' must be used. _() must be used for the text to be marked for translation.
- addTooltipHtml( node, html, delay );
- Add an HTML tooltip to the DOM node (for more elaborate content such as presenting a bigger version of a card).
- addTooltipToClass( cssClass, _( helpString ), _( actionString ), delay );
- Add a simple text tooltip to all the DOM nodes set with this cssClass. Only one of 'helpString' or 'actionString' must be used. _() must be used for the text to be marked for translation.
- NB: all concerned nodes must have IDs to get tooltips
- addTooltipHtmlToClass( cssClass, html, delay );
- Add an HTML tooltip to to all the DOM nodes set with this cssClass (for more elaborate content such as presenting a bigger version of a card).
- NB: all concerned nodes must have IDs to get tooltips
- addEventToClass
- function( cssClassName, eventName, functionName )
- DEPRECATED (please use connectClass below)
- connectClass
- function( cssClassName, eventName, functionName )
- Same as dojo.connect(), but for all the nodes set with the specified cssClassName
- addStyleToClass
- function( cssClassName, cssProperty, propertyValue )
- Same as dojo.style(), but for all the nodes set with the specified cssClassName
- isCurrentPlayerActive()
- Returns true if the player on whose browser the code is running is currently active (it's his turn to play)
- checkAction
- function( action, nomessage )
- Check if player can do the specified action by taking into account: _ current game state & _ interface locking
- return true if action is authorized
- return false and display an error message if not (display no message if nomessage is specified)
- showMessage
- function( msg, type )
- Show an information message during a few seconds at the top of the page, or to the log.
- Type can be 'error' or 'info' or 'only_to_log'.
- this.scoreCtrl[ player_id ].incValue( score_delta );
- Adds score_delta (positive or negative integer) to the current score value for player