This is a documentation for Board Game Arena: play board games online !

Counter: Розніца паміж версіямі

З пляцоўкі Board Game Arena
Перайсці да навігацыі Перайсці да пошуку
дрНяма тлумачэння праўкі
 
(Не паказана 13 прамежкавых версій 6 удзельнікаў)
Радок 1: Радок 1:
{{Studio_Framework_Navigation}}


This is very simple control that allow to set/get numeric value from inner html of div/span, and provides animation on from/to value.


== Dependency ==
== Dependency ==


Don't forget to add '''ebg/counter''' as a dependency:


At first, don't forget to add "ebg/counter" as a dependency:
     // in your game js
 
     // in you game js
     define([
     define([
     "dojo","dojo/_base/declare",
     "dojo","dojo/_base/declare",
Радок 12: Радок 13:
     "ebg/counter"    /// <==== HERE],
     "ebg/counter"    /// <==== HERE],


== updateCounters(counters) ==
== Setup a counter ==
 
<pre>
var counter = new ebg.counter();
counter.create(targetId);
</pre>
 
Where '''targetId''' either string or dom element, which already exists in the template, which will be used to display the counter value.
For example:
<pre>
  <span id="my_counter"></span>
</pre>
 
In reality you will have a counter per player, so probably want to cretae a counter per player, in this case target Id can be 'hand_size_player_' + player_id and you create it in the loop for all players
and store as class member. See example below on how to inject per-player sections.
 
== Functions on counter ==
;create(target)
:associate counter with existing target dom element
 
;getValue()
:return current value
 
;incValue(by);
:increment value by "by" and animate from previous value
 
;setValue(value);
:set value, no animation
 
;toValue(value);
:set value with animation
 
;disable()
:display - instead. Note it just changes display value once, it does not actually disables it, i.e. if you set it again, it will be shown again
 


: 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. Therefore if you add a counter during the game, you need to update the counters like that (through a notification management for example):
        this.gamedatas.counters['hammercount_p' + notif.args.player_id] = {'counter_name': 'hammercount_p' + notif.args.player_id, 'counter_value' : '0'};
: DOM objects referenced by 'counter_name' will have their innerHTML updated with 'counter_value'.


== Players panels ==
== Players panels ==
Радок 24: Радок 54:
=== Adding stuff to player's panel ===
=== Adding stuff to player's panel ===


At first, create a new "JS template" string in your template (tpl) file:
First, create a new JS template string in your template (tpl) file.
 
From the ''Gomoku'' example:


(from Gomoku example)
<pre>
<pre>
var jstpl_player_board = '\<div class="cp_board">\
var jstpl_player_board = '\<div class="cp_board">\
Радок 33: Радок 64:
</pre>
</pre>


Then, you add this piece of code in your JS file to add this template to each player panel:
Then, add this piece of code in the '''setup''' function of your JS file to add this template to each player panel:


<pre>
<pre>
             // Setting up player boards
             // Setting up player boards
             for( var player_id in gamedatas.players )
            this.stone_counters={};
            {
             for( var player_id in gamedatas.players )   {
                 var player = gamedatas.players[player_id];
                 var player = gamedatas.players[player_id];
                          
                          
Радок 44: Радок 75:
                 var player_board_div = $('player_board_'+player_id);
                 var player_board_div = $('player_board_'+player_id);
                 dojo.place( this.format_block('jstpl_player_board', player ), player_board_div );
                 dojo.place( this.format_block('jstpl_player_board', player ), player_board_div );
                // create counter per player
                this.stone_counters[player_id]=new ebg.counter();
                this.stone_counters[player_id].create('stoneicon_p'+player_id);
             }
             }
</pre>
</pre>


(Note: the code above is of course from your "setup" function in your Javascript).
Often, you have to distinguish between the current player and other players. In this case, create another JS template (ex: jstpl_otherplayer_board) and use it where "player_id" is different than "this.player_id".
 
Very often, you have to distinguish current player and others players. In this case, you just have to create another JS template (ex: jstpl_otherplayer_board) and use it when "player_id" is different than "this.player_id".

Актуальная версія на 03:13, 17 кастрычніка 2020

Studio Framework Navigation

File structure of a BGA game

Game logic (Server side)
Game interface (Client side)
Other components
BGA Studio game components reference
  • Deck: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).
  • Counter: a JS component to manage a counter that can increase/decrease (ex: player's score).
  • Scrollmap: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples: Saboteur or Takenoko games).
  • Stock: a JS component to manage and display a set of game elements displayed at a position.
  • Zone: a JS component to manage a zone of the board where several game elements can come and leave, but should be well displayed together (See for example: token's places at Can't Stop).

Undocumented component (if somebody knows please help with docs)

  • Draggable: a JS component to manage drag'n'drop actions.
  • ExpandableSection: a JS component to manage a rectangular block of HTML than can be displayed/hidden.
  • Wrapper: a JS component to wrap a <div> element around its child, even if these elements are absolute positioned.
BGA Studio user guide


This is very simple control that allow to set/get numeric value from inner html of div/span, and provides animation on from/to value.

Dependency

Don't forget to add ebg/counter as a dependency:

   // in your game js
   define([
   "dojo","dojo/_base/declare",
   "ebg/core/gamegui",
   "ebg/counter"    /// <==== HERE],

Setup a counter

var counter = new ebg.counter();
counter.create(targetId);

Where targetId either string or dom element, which already exists in the template, which will be used to display the counter value. For example:

  <span id="my_counter"></span>

In reality you will have a counter per player, so probably want to cretae a counter per player, in this case target Id can be 'hand_size_player_' + player_id and you create it in the loop for all players and store as class member. See example below on how to inject per-player sections.

Functions on counter

create(target)
associate counter with existing target dom element
getValue()
return current value
incValue(by);
increment value by "by" and animate from previous value
setValue(value);
set value, no animation
toValue(value);
set value with animation
disable()
display - instead. Note it just changes display value once, it does not actually disables it, i.e. if you set it again, it will be shown again


Players panels

Adding stuff to player's panel

First, create a new JS template string in your template (tpl) file.

From the Gomoku example:

var jstpl_player_board = '\<div class="cp_board">\
    <div id="stoneicon_p${id}" class="gmk_stoneicon gmk_stoneicon_${color}"></div><span id="stonecount_p${id}">0</span>\
</div>';

Then, add this piece of code in the setup function of your JS file to add this template to each player panel:

            // Setting up player boards
            this.stone_counters={};
            for( var player_id in gamedatas.players )   {
                var player = gamedatas.players[player_id];
                         
                // Setting up players boards if needed
                var player_board_div = $('player_board_'+player_id);
                dojo.place( this.format_block('jstpl_player_board', player ), player_board_div );

                // create counter per player
                this.stone_counters[player_id]=new ebg.counter();
                this.stone_counters[player_id].create('stoneicon_p'+player_id);
            }

Often, you have to distinguish between the current player and other players. In this case, create another JS template (ex: jstpl_otherplayer_board) and use it where "player_id" is different than "this.player_id".