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

Options and preferences: gameoptions.json, gamepreferences.json: Difference between revisions

From Board Game Arena
Jump to navigation Jump to search
No edit summary
No edit summary
Line 32: Line 32:
* '''displaycondition''' - checks the conditions before displaying the option for selection. All conditions must be true for the option to display. Supported condition types:
* '''displaycondition''' - checks the conditions before displaying the option for selection. All conditions must be true for the option to display. Supported condition types:
** ''otheroption'' condition ensures another option is set to this given value. Framework options - 201 - ELO OFF.
** ''otheroption'' condition ensures another option is set to this given value. Framework options - 201 - ELO OFF.
* '''startcondition''' - checks the conditions before starting the game. All conditions must be true for the game to start, otherwise players will get a red error message when attempting to begin the game. Supported condition types:
* '''startcondition''' - checks the conditions before starting the game. All conditions must be true for the game to start, otherwise players will get a red error message when attempting to begin the game.  
* 'notdisplayedmessage' - if option is not suppose to be visible because of displaycondition but this is set, the text will be visible instead of combo drop down
Supported condition types:
** ''minplayers'' condition ensures at least this many players
** ''minplayers'' condition ensures at least this many players
** ''maxplayers'' conditions ensure at most this many players
** ''maxplayers'' conditions ensure at most this many players
Line 139: Line 141:
</pre>
</pre>


Example of option that condition on ELO off


<pre>
$game_options = array(
        100 => array(
                'name' => totranslate('Learning Game (No Research)'),
                'values' => array(
                       
                        1 => array( 'name' => totranslate('Off'), 'tmdisplay' => totranslate('') ),
                        2 => array( 'name' => totranslate('On'), 'tmdisplay' => totranslate('Learning Game') ),
                       
                ),
                'displaycondition' => array(
                        // Note: do not display this option unless these conditions are met
                        array( 'type' => 'otheroption',
                                'id' => 201, // ELO OFF hardcoded framework option
                                'value' => 1, // 1 if OFF
                        )
                ),
                'notdisplayedmessage' => totranslate('Learning variant available only with ELO off')
                ),
);
</pre>





Revision as of 00:52, 19 May 2018

In this file, you can define your game options (= game variants) and user preferences.

Note: If your game has no variants or preferences, you don't have to modify this file.

Game Options

Game options is something selected by table creator and usually correspond to game variant, for example if game includes expansion or certain special rule.

These variants defined in gameoptions.inc.php as variable

 $game_options = array(...); // exactly named that

Each option is pair number => 'option description array'.

All options defined in this file should have a corresponding "game state label" with the same ID (see "initGameStateLabels" in yourgame.game.php)


            self::initGameStateLabels ( array (
                       ...
                       "my_first_game_variant" => 100,
             ) );

That is how you access them during runtime.

The following are the parameters of option description array:

  • name - mandartory. The name of the option visible for table creator. Value must be wrapped in totranslate function.
  • values - mandartory. The array (map) of values with additional parameters per value.
    • name - mandartory. String representation of the numeric value visible to table creator. Value must be wrapped in totranslate function.
    • tmdisplay - String representation of the option visible in the table description, usually if variant "names" are On and Off, but the description would be same as option name when On, and nothing when Off.
    • nobeginner - Set to true if not recommended for begginers
    • beta - Option in beta stage on development
    • premium - Option can be only used by premium members
  • displaycondition - checks the conditions before displaying the option for selection. All conditions must be true for the option to display. Supported condition types:
    • otheroption condition ensures another option is set to this given value. Framework options - 201 - ELO OFF.
  • startcondition - checks the conditions before starting the game. All conditions must be true for the game to start, otherwise players will get a red error message when attempting to begin the game.
  • 'notdisplayedmessage' - if option is not suppose to be visible because of displaycondition but this is set, the text will be visible instead of combo drop down

Supported condition types:

    • minplayers condition ensures at least this many players
    • maxplayers conditions ensure at most this many players
 $game_options = array(
     100 => array(
         'name' => totranslate('my game option'),
         'values' => array(
             // A simple value for this option:
             1 => array(
                 'name' => totranslate('option 1')
             ),

             // A simple value for this option.
             // If this value is chosen, the value of "tmdisplay" is displayed in the game lobby
             2 => array(
                 'name' => totranslate('option 2'),
                 'tmdisplay' => totranslate('option 2')
             ),

             // Another value, with other options:
             //  beta=true => this option is in beta version right now.
             //  nobeginner=true  =>  this option is not recommended for beginners
             3 => array(
                 'name' => totranslate('option 3'),
                 'beta' => true,
                 'nobeginner' => true
             ),
         )
     ),
     
     101 => array(
         'name' => totranslate('Draft variant'),
         'values' => array(
             1 => array(
                 'name' => totranslate('No draft')
             ),
             2 => array(
                 'name' => totranslate('Draft'),
                 'tmdisplay' => totranslate('Draft'),
                 'premium' => true,
                 'nobeginner' => true
             ),
         ),
         'displaycondition' => array( 
             // Note: do not display this option unless these conditions are met
             array(
                 'type' => 'otheroption',
                 'id' => 100, // Game specific option defined in the same array above
                 'value' => array(2, 3, 4)
             ),
             // Note: do not display this option unless these conditions are met
            array( 'type' => 'otheroption', 
                 'id' => 201, // ELO OFF hardcoded framework option
                 'value' => 1 // 1 if OFF
            )
         ),

         'startcondition' => array(
             1 => array(),
             2 => array(
                 array(
                     'type' => 'maxplayers',
                     'value' => 3,
                     'message' => totranslate('Draft option is available for 3 players maximum.')
                 )
             ),
         ),
         'disable' => true
     ),
     
     102 => array(
         'name' => totranslate('Takeovers'),
         'values' => array(
             2 => array(
                 'name' => totranslate('No takeover')
             ),
             1 => array(
                 'name' => totranslate('Allow takeovers'),
                 'tmdisplay' => totranslate('Takeovers'),
                 'premium' => true,
                 'nobeginner' => true
             ),
         ),
         'displaycondition' => array( // Note: do not display this option unless these conditions are met
             array(
                 'type' => 'otheroption',
                 'id' => 100,
                 'value' => array(3, 4)
             )
         ),
         'startcondition' => array(
             2 => array(),
             1 => array(
                 array(
                     'type' => 'maxplayers',
                     'value' => 2,
                     'message' => totranslate('Rebel vs Imperium Takeover Scenario is available for 2 players only.')
                 )
             ),
         ),
         'disable' => true
     )
 );

Example of option that condition on ELO off

$game_options = array(

        100 => array(
                'name' => totranslate('Learning Game (No Research)'),
                'values' => array(
                        
                        1 => array( 'name' => totranslate('Off'), 'tmdisplay' => totranslate('') ),
                        2 => array( 'name' => totranslate('On'), 'tmdisplay' => totranslate('Learning Game') ),
                        
                ),
                'displaycondition' => array(
                        // Note: do not display this option unless these conditions are met
                        array( 'type' => 'otheroption',
                                'id' => 201, // ELO OFF hardcoded framework option
                                'value' => 1, // 1 if OFF

                        )
                ),
                'notdisplayedmessage' => totranslate('Learning variant available only with ELO off')
                ),

);


IMPORTANT: After you edited and deployed this file you have to go to control panel and press "Reload game options configuration"

User Preferences

User preferences is something cosmetic about the game interface which however can create user wars, so you can satisfy all user by giving them individual preferences. Do not use this unless absolutely necessary and usually only after game has been in production for a while. If you add these currently only admins can apply these settings, so you would have to contact them after editing this file.

$game_preferences = array(
    100 => array(
			'name' => totranslate('Notation style'),
			'needReload' => true, // after user changes this preference game interface would auto-reload
			'values' => array(
					1 => array( 'name' => totranslate( 'Classic' ), 'cssPref' => 'notation_classic' ),
					2 => array( 'name' => totranslate( 'Tournament' ), 'cssPref' => 'notation_tournament' )
			)
	)
);

There is two ways to check/apply this. In java Script

 if (this.prefs[100].value == 2) ...

This checks if preferences 100 has selected value 2.

Second, if cssPref specified it will be applied to the body tag. So you can use different css styling for the preference.

As user you have to select them from the Gear menu when game is started. On studio only user0 will have it actually working (bug?).