This is a documentation for Board Game Arena: play board games online !
ผลต่างระหว่างรุ่นของ "Counter"
ไปยังการนำทาง
ไปยังการค้นหา
Tilalilalou (คุย | ส่วนร่วม) ไม่มีความย่อการแก้ไข |
|||
(ไม่แสดง 6 รุ่นระหว่างกลางโดยผู้ใช้ 2 คน) | |||
บรรทัดที่ 3: | บรรทัดที่ 3: | ||
== Dependency == | == Dependency == | ||
Don't forget to add "ebg/counter" as a dependency: | |||
// in you game js | // in you game js | ||
บรรทัดที่ 12: | บรรทัดที่ 11: | ||
"ebg/counter" /// <==== HERE], | "ebg/counter" /// <==== HERE], | ||
== | == Setup a counter == | ||
<pre> | |||
player.handSizeCounter = new ebg.counter(); | |||
player.handSizeCounter.create('hand_size_player_' + player_id); | |||
</pre> | |||
== Update counter == | |||
<pre> | |||
player.handSizeCounter.setValue(player.handSize); | |||
</pre> | |||
== Players panels == | == Players panels == | ||
บรรทัดที่ 24: | บรรทัดที่ 28: | ||
=== Adding stuff to player's panel === | === Adding stuff to player's panel === | ||
First, create a new JS template string in your template (tpl) file. | |||
From the ''Gomoku'' example: | |||
<pre> | <pre> | ||
var jstpl_player_board = '\<div class="cp_board">\ | var jstpl_player_board = '\<div class="cp_board">\ | ||
บรรทัดที่ 33: | บรรทัดที่ 38: | ||
</pre> | </pre> | ||
Then, | Then, add this piece of code in the '''setup''' function of your JS file to add this template to each player panel: | ||
<pre> | <pre> | ||
บรรทัดที่ 47: | บรรทัดที่ 52: | ||
</pre> | </pre> | ||
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". | |||
รุ่นแก้ไขปัจจุบันเมื่อ 16:46, 1 กุมภาพันธ์ 2562
Dependency
Don't forget to add "ebg/counter" as a dependency:
// in you game js define([ "dojo","dojo/_base/declare", "ebg/core/gamegui", "ebg/counter" /// <==== HERE],
Setup a counter
player.handSizeCounter = new ebg.counter(); player.handSizeCounter.create('hand_size_player_' + player_id);
Update counter
player.handSizeCounter.setValue(player.handSize);
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 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 ); }
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".