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

Game material description: material.inc.php: Difference between revisions

From Board Game Arena
Jump to navigation Jump to search
(Added navigation)
(Show more examples of usage)
Line 5: Line 5:
This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined here are accessible everywhere in your game logic file.
This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined here are accessible everywhere in your game logic file.


Using material.inc.php makes your PHP logic file smaller and clean.
Using material.inc.php makes your PHP logic file smaller and clean. Normally you put ALL static information about your cards, tokens, tiles, etc in that file which do not change. Do not store static info in database.
 
Example from "Hearts": if you define this in material.inc.php:


Example from "Eminent Domain":
<pre>
<pre>
$this->colors = array(
$this->token_types = [
    1 => array( 'name' => clienttranslate('spade'),
'card_role_survey' => [
                'nametr' => self::_('spade') ),
  'type' => 'card_role',
    2 => array( 'name' => clienttranslate('heart'),
  'name' => clienttranslate("Survey"),
                'nametr' => self::_('heart') ),
  'tooltip' => clienttranslate("ACTION: Draw 2 Cards<br/><br/>ROLE: Look at <div class='icon survey'></div> - 1 planet cards, keep 1<br/> <span class='yellow'>Leader:</span> Look at 1 additional card"),
    3 => array( 'name' => clienttranslate('club'),
  'b'=>0,
                'nametr' => self::_('club') ),
  'p'=>'',
    4 => array( 'name' => clienttranslate('diamond'),
  'i'=>'S',
                'nametr' => self::_('diamond') )
  'v'=>0,
);
  'a'=>'dd',
  'r'=>'S',  
  'l'=>'v',
  ],
'card_tech_1_51' => [
  'type' => 'tech',
  'name' => clienttranslate("Improved Trade"),
  'b' => 3,
  'p' => 'E',
  'i' => 'TP',
  'v' => 0,
  'a' => 'i',
  'side' => 0,
  'tooltip' => clienttranslate("Collect 1 Influence from the supply."),
],
...
];
</pre>
</pre>


... you can access "$this->colors" everywhere in your PHP game logic file.
So this defined all info about cards, including types, names, tooltips (to be show on client), rules, payment cost, etc.
 
To access this in PHP side:
  $type = $this->token_types['card_tech_1_51']['type'];
 
To access on JS side you have to send all variables from material file via getAllDatas first:
    protected function getAllDatas() {
        $result = array ();
        $result ['token_types'] = $this->token_types;
        ...
        return $result;
    }
 
Then you can access it in similar way:
  var type = this.gamedatas.token_types['card_tech_1_51'].type; // not translatable
  var name = _(this.gamedatas.token_types['card_tech_1_51'].name); // to be shown to user (NOI18N)
 
To send this in notification from PHP side:
  $this->notifyAllUsers('gainCard',clienttranslate('player gains ${card_name}'), [
      'i18n'=>['card_name'],
      'card_id' => $card_id,
      'card_name' => $this->token_types[$card_id]['name']
  ]);

Revision as of 16:12, 18 August 2021


Game File Reference



Useful Components

Official

  • Deck: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).
  • Draggable: a JS component to manage drag'n'drop actions.
  • Counter: a JS component to manage a counter that can increase/decrease (ex: player's score).
  • ExpandableSection: a JS component to manage a rectangular block of HTML than can be displayed/hidden.
  • 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)

  • Wrapper: a JS component to wrap a <div> element around its child, even if these elements are absolute positioned.

Unofficial



Game Development Process



Guides for Common Topics



Miscellaneous Resources

This PHP file describes all the material of your game.

This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined here are accessible everywhere in your game logic file.

Using material.inc.php makes your PHP logic file smaller and clean. Normally you put ALL static information about your cards, tokens, tiles, etc in that file which do not change. Do not store static info in database.

Example from "Eminent Domain":

$this->token_types = [
 'card_role_survey' => [
  'type' => 'card_role',
  'name' => clienttranslate("Survey"),
  'tooltip' => clienttranslate("ACTION: Draw 2 Cards<br/><br/>ROLE: Look at <div class='icon survey'></div> - 1 planet cards, keep 1<br/> <span class='yellow'>Leader:</span> Look at 1 additional card"),
  'b'=>0,
  'p'=>'',
  'i'=>'S',
  'v'=>0,
  'a'=>'dd',
  'r'=>'S', 
  'l'=>'v',
  ],
 'card_tech_1_51' => [
  'type' => 'tech',
  'name' => clienttranslate("Improved Trade"),
  'b' => 3,
  'p' => 'E',
  'i' => 'TP',
  'v' => 0,
  'a' => 'i',
  'side' => 0,
  'tooltip' => clienttranslate("Collect 1 Influence from the supply."),
 ],
...
];

So this defined all info about cards, including types, names, tooltips (to be show on client), rules, payment cost, etc.

To access this in PHP side:

 $type = $this->token_types['card_tech_1_51']['type'];

To access on JS side you have to send all variables from material file via getAllDatas first:

   protected function getAllDatas() {
       $result = array ();
       $result ['token_types'] = $this->token_types;
       ...
       return $result;
   }
 

Then you can access it in similar way:

 var type = this.gamedatas.token_types['card_tech_1_51'].type; // not translatable
 var name = _(this.gamedatas.token_types['card_tech_1_51'].name); // to be shown to user (NOI18N)

To send this in notification from PHP side:

 $this->notifyAllUsers('gainCard',clienttranslate('player gains ${card_name}'), [
      'i18n'=>['card_name'],
      'card_id' => $card_id,
      'card_name' => $this->token_types[$card_id]['name']
 ]);