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

BGA Studio Migration Guide: Difference between revisions

From Board Game Arena
Jump to navigation Jump to search
m (proper formatring)
(editorial changes)
Line 5: Line 5:


See announcement here https://studio.boardgamearena.com/forum/viewtopic.php?f=12&t=45248
See announcement here https://studio.boardgamearena.com/forum/viewtopic.php?f=12&t=45248




πŸ“Œ This symbol: information about migration, if you want to migrate an old game to the most recent ways
πŸ“Œ This symbol: information about migration, if you want to migrate an old game to the most recent ways
== Structural changes ==
== Structural changes ==


Line 16: Line 13:


Previously, options and preferences were specified in a single gameoptions.inc.php file.
Previously, options and preferences were specified in a single gameoptions.inc.php file.
Now options and preferences are 2 json files, follow Migration steps on this pageΒ  https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Migration
Now options and preferences are 2 json files, follow Migration steps on this pageΒ  https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Migration
See [[BGA Studio Migration Guide#User%20preferences|#User preferences]] and [[BGA Studio Migration Guide#Game%20options|#Game options]] for API changes.
When building the game with this file you will see deprecation warning.


'''''<gamename>.game.php''''' => modules/php/Game.php
'''''<gamename>.game.php''''' => modules/php/Game.php
Move and refactor, see section [[BGA Studio Migration Guide#Namespaced game class|Namespaced game class]]
'''<gamename>.action.php => remove'''
See section [[BGA Studio Migration Guide#Autowire game actions|Autowire game actions]]


'''''<gamename>.view.php, <gamename>_<gamename>.tpl''''' => remove
'''''<gamename>.view.php, <gamename>_<gamename>.tpl''''' => remove
See section [[BGA Studio Migration Guide#Removal of view and template|Removal of view and template]]


'''''material.inc.php''''' => optional
'''''material.inc.php''''' => optional
See section [[#Material]]


'''''states.inc.php''''' => modules/php/States
'''''states.inc.php''''' => modules/php/States


'''<gamename>.action.php => remove'''
See section [[#States]]


== PHP migration ==
'''<gamename>.js'''


Oct 2025: The migration was made from PHP7.4 to PHP8.4 new syntax and functions.
File still there but massive API changes, see bottom sections
Things to watch: ...


== User preferences ==
==PHP migration ==


Access to user preferences and listener: https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#User_preferences
Oct 2025: The migration was made from PHP7.4 to PHP8.4 new syntax and functions.


πŸ“Œ If you had a custom function called setupPreferences() reading the <select> values, you can now use onGameUserPreferenceChanged instead.
New projects are generated using the strict mode


If you had a copy of the user preferences on a DB table, it's not needed anymore.
πŸ“Œ


== Game options ==
* Replace all <code>self::</code> to <code>$this-></code>Β  - The new project template has been updated to remove this bad practice (that may be unsupported in a future PHP version)


New function to access the table options without needing the old global way: $this->tableOptions->get(int $optionId): int
* Add <code>declare(strict_types=1);</code> to all .php files and fix compiler warnings (if you use IDE it will detect it before upload).


https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Game_Options
==User preferences==


πŸ“Œ It was before done with either $this->getGameStateValue or $this->gamestate->table_globals


This new object can also return the Real-time/Turn-based information: https://en.doc.boardgamearena.com/Main_ ... exion_time
Access to user preferences and listener: https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#User_preferences


== Legacy ==
πŸ“Œ
New object to access the legacy functions, removing the need to manually decode the JSON result when getting the values.
*If you had a custom function called <code>setupPreferences()</code> reading the <select> values, you can now use <code>onGameUserPreferenceChanged</code> instead.
*If you had a copy of the user preferences on a DB table, it's not needed anymore. Remove all support of writing to this table. Replace access to this table with
Β  Β  Β  Β  $pref = (int) $this->userPreferences->get($playerId, $prefCode);


https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Legacy_games_API
=== Instant cssPref on user preferences ===
A reload is not needed anymore to apply cssPref on a user preference change.


πŸ“Œ Use $this->legacy->actionname instead of $this->actionnameLegacy and remove JSON decoding on getters
πŸ“Œ Remove forceReload: true if it was only set to update the cssPref. The player will appreciate to not reload the whole page!


== Globals of any type ==
== Game options==
New functions to handle any type variables instead of numerical values only


https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Use_globals
New functions to access the table options (game options) without hassle


== Simplify front->back calls ==
https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Game_Options
Introduce bgaPerformAction to replace ajaxcall and checkAction combination, with a simpler syntax:


https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Actions
πŸ“Œ
*Remove declaration of game optionsΒ  from "<code>initGameStateLabels</code>"
*Instead of using <code>$this->getGameStateValue</code> or <code>$this->gamestate->table_globals</code> use
$this->tableOptions->get(int $optionId)


πŸ“Œ Replace combination of checkAction/ajaxcall by bgaPerformAction. Beware of the options (3rd param) if it was an ajaxcall without checkAction.
This new object can also return the Real-time/Turn-based setting: https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Reflexion_time


== Autowire game actions ==
==Namespaced game class==
Simplify the action calls by removing the use of the action.php file
Game class from '''''<gamename>.game.php''''' are now namespaced (and moved to modules/php/Game.php) and can autoload other classes of the same namespace


https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Actions_%28autowired%29
[[Main game logic: Game.php#Creating other classes]]


πŸ“Œ Autowired actions needs to start with "act", so it's risky to change them (if you change all actions names in the states.php, game, action and JS file, Real-time players will call the old name until they refresh. So, it needs to be done in two steps with duplicates on back side, or to be deployed when there is no Realt-time table running.
πŸ“Œ The class file should be moved to modules/php/Game.php and start with this adapted part:


When migration is done, the action.php file can be deleted.
<code>namespace Bga\Games\YourGameName;</code>


== Namespaced game class ==
<code>class Game extends \Bga\GameFramework\Table { ... }</code>
Game classes are now namespaced (and moved to modules/php/Game.php) and can autoload other classes of the same namespace


https://en.doc.boardgamearena.com/Main_ ... er_classes
All references to non-namespaced classes in this file should be defined on top of the file with "use", for example "use \BgaUserException;" as it is this non-namespaced exception is used in the zombieTurn function.


πŸ“Œ The class file should be moved to modules/php/Game.php and start with this adapted part:
All includes with relative path will need to be updated too.
Code: Select all


namespace Bga\Games\YourGameName;
The material.inc.php to have be moved (see below)


class Game extends \Bga\GameFramework\Table
Multiple functions of "Table" base class are now deprecated, see how to migrate in corresponding section
All references to non-namespaced classes in this file should be defined on top of the file with "use", for example "use \BgaUserException;" as it is this non-namespaced exception is used in the zombieTurn function.


All includes with relative path will need to be updated too
* notifyAllPlayers
* notifyPlayer
* mysql_fetch_assoc
* Table (class access without namespace)
* isMutiactiveState (misspelled version)
* ...


== IDE Helper & bga-framework.d.ts ==
== Material ==
A new _ide_helper.php file is now provided in every project dir, allowing IDE to provide syntax error highlighting for the framework functions. This file is regularly updated to match the latest framework updates.
Material file '''material.inc.php''' is now optional. You can define all your material directly in php class. If you still like to keep it, and using namespaced Game.php you have to move it to subfolder and include directly [[Game material description: material.inc.php#Move it to modules/php]]


Same with bga-framework.d.ts for those using TypeScript.
==Autowire game actions==
Simplify the action calls by removingΒ  '''<gamename>.action.php'''Β  file


πŸ“Œ Sync the files from the FTP dir to your local copy to benefit from it. Most of the IDE like Visual Studio Code should handle _ide_helper.php if you already followed https://en.doc.boardgamearena.com/Setting_up_BGA_Development_environment_using_VSCode
https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Actions_%28autowired%29


== Strict mode set in new project template ==
πŸ“Œ Autowired actions needs to start with "act", so it's risky to change them (if you change all actions names in the states.php, game, action and JS file, Real-time players will call the old name until they refresh. So, it needs to be done in two steps with duplicates on back side, or to be deployed when there is no Realt-time table running.
New projects are generated using the strict mode activated (for typings). The examples in the doc have been updated to handle old framework function returning bad typings, for example (int) $this->getActivePlayerId();


πŸ“Œ Make sure the typings are correct on the Game.php file, a global check of the game is recommended
When migration is done, the action.php file can be deleted.


πŸ“Œ A global replace should work on the Game.php files
==Notifications==
Functions notifyAllPlayers and notifyPlayer from main game.php are deprecated


== Access template elements ==
πŸ“Œ Replace notifyAllPlayers by <code>$this->notify->all()</code> and notifyPlayer by <code>$this->notify->player()</code>
New functions getPlayerPanelElement(player_id) and this.getGameAreaElement()


https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_stuff_to_player%27s_panel
=== Notification Decorators ===
New notify function that handles decorators, reducing the duplicate code on notification args.


πŸ“Œ Code like dojo.place(html, player_board_${player.id}); would be replaced by this.getGameAreaElement().insertAdjacentHTML('beforeend', html);
https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Notification_decorators


== Optional files: action/view/template/material ==
=== Notification args consistency ===
Action/view/template/material files are now optional and are not generated anymore on a new project. The new project templates demonstrate how to work without them.
Previously, when you sent an arg that was transformed by format_string_recursive or bgaFormatText, the args object was mutated and you got the transformed value in the notif_ handler.


πŸ“Œ See Autowiring to delete the action file.
The solution was to send the values in 2 different names like this:
The template should be built on the JS side to remove the view/template files, so it can be complicated for old projects using them intensively. It would look like this:
Code: Select all
this.getGameAreaElement().insertAdjacentHTML('beforeend', `<span>${_('My translated text')}</span>`);


== Easier notification setup ==
[
Notifications can now be automatically scanned and called without needing to register them one by one. They'll handle Promises, so they end synchronously when the Promise resolves.
Β  'roundNumber' => $roundNumber, // number, to update the round counter
Β  'round_number' => $roundNumber, // number that will be transformed to string by bgaFormatText, when shown in bold in the logs
]
πŸ“Œ Do not duplicate the value, as the notif_ handler will now get unmutated args


https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Notifications
== Deprecated getGameName ==
The getGameName() function is now useless in the Game PHP file and can be deleted


A wait function has been added to return a Promise when a delay is passed (compatible with fast-replay mode)
πŸ“Œ Delete the getGameName function in the Game PHP file.


A new utility function has been added to support Promises for old Dojo animations
==Legacy==
New object to access the legacy functions, removing the need to manually decode the JSON result when getting the values.


https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Animation_Callbacks
https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Legacy_games_API


πŸ“Œ Dojo.subscribe calls in setupNotifications must be removed if bgaSetupPromiseNotifications is used. Notif_ function should be async and return a Promise, make sure they wait for the expected amount of time if the sync setup was using a numerical duration
πŸ“Œ Use $this->legacy->actionname instead of $this->actionnameLegacy and remove JSON decoding on getters


If you used Dojo animation, make them Promise compatible with "await this.bgaPlayDojoAnimation(dojoAnim);"
==Any Globals==
New database table and API to handle any type variables instead of numerical values only


== Status bar manipulation ==
https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Use_globals
Function to change the title from the JS
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Title_bar


πŸ“Œ Replace direct title div manipulation with this.statusBar.setTitle(title: string, args?: object), and benefit from replacement of ${actplayer}/${you}/... (see example in the link above).
πŸ“Œ If you had custom tables just for that you can drop them and use standard table


This also includes a new function to create action buttons, that are more screen-reader compatible than the previous version. The new button parameters also allow you to set a confirm popin or an autoclick for confirmation buttons
==Server Counters==
2 new counter classes have been added to easily handle the various counters your game might have. You also have 2 prebuilt counters: playerScore and playerScoreAux, to handle the scoring values, so you don't need to update manually the DB when setting the scores.


πŸ“Œ Replace this.addActionButton by this.statusBar.addActionButton. Notice the parameters have changed, so they need to be adapted too! Remove manual setActionTimer or manual confirm with the new parameters.
https://en.doc.boardgamearena.com/PlayerCounter_and_TableCounter


== Notification decorators ==
πŸ“Œ Replace setting player_score/player_score_aux using db queries with use of $this->playerScore and $this->playerScoreAux. Remove the notifications, or part of notifications, updating the scoreCtrl counter (if you had some custom notification you may still need them).
New notify function that handles decorators, reducing the duplicate code on notification args.
== Updated Zombie Mode documentation and recommendations==
We now recommend making the zombie player playing randomly, instead of passing as a default. A new "Zombie Mode level" field has been added to the Game Metadata Manager, to indicated the Zombie Mode you implemented in your game.


https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Notification_decorators
https://en.doc.boardgamearena.com/Zombie_Mode


πŸ“Œ Replace notifyAllPlayers by notify->all and notifyPlayer by notify->player
==IDE Support==
A new _ide_helper.php file is now provided in every project dir, allowing IDE to provide syntax error highlighting for the framework functions. This file is regularly updated to match the latest framework updates.


== Forbid access to global BGA variables and direct DB access on action/view files ==
Same with bga-framework.d.ts for those using TypeScript.
A new getCurrentPlayerId() function has been added to those action/view classes for easier migration


πŸ“Œ Replace $g_user->get_id() by $this-> getCurrentPlayerId()[
πŸ“Œ Sync the files from the FTP dir to your local copy to benefit from it. Most of the IDE like Visual Studio Code should handle _ide_helper.php if you already followed https://en.doc.boardgamearena.com/Setting_up_BGA_Development_environment_using_VSCode


Replace DB calls by $this->game->myFunctionCallingTheDB()
== View and template files: deprecated==
'''''<gamename>.view.php, <gamename>_<gamename>.tpl''''' are now optional and are not generated anymore on a new project. The new project templates demonstrate how to work without them.


== Instant cssPref on user preferences ==
πŸ“Œ The DOM should be built on the JS side to remove the view/template files, so it can be complicated for old projects using them intensively. It would look like this:
A reload is not needed anymore to apply cssPref on a user preference change.
this.getGameAreaElement().insertAdjacentHTML('beforeend', `
Β  <nowiki><span>${_('My translated text')}</span></nowiki><nowiki><div id="player-tables"></div></nowiki>
`);
Β 


πŸ“Œ Remove forceReload: true if it was only set to update the cssPref. The player will appreciate to not reload the whole page!
See more in [[BGA Studio Migration Guide#Access%20template%20elements|#Access template elements]]


== Dojo usage ==
=== Forbid access to global BGA variables and direct DB access on action/view files ===
Dojo usage has been reduced to minimum in the new project template and the doc, as native JS is now able to do almost the same things, with better performance and more knowledge for newcomers of the native (vanilla) JS.
If you did not remove action and view files, you cannot longer use some stuff in them, such $g_user global and db access functions.


πŸ“Œ Replace dojo by vanilla JS where possible
A new getCurrentPlayerId() function has been added to those action/view classes for easier migration


== Skip a state ==
πŸ“Œ Replace $g_user->get_id() by $this-> getCurrentPlayerId()
When you skip a state on PHP side (directly move to another state on the "st" function), the JS is still notified that the skipped state is activated, then it activates the next state just after, but you may see the skipped state buttons being created then deleted.


You can set up the _no_notify flag so that the JS notification of this skipped state is not sent, and from the JS side it considers the state was never loaded. For example, if you have a confirm step and a user preference allows to disable it, the user doesn't need to see the Confirm buttons showing then removed just after.
Replace DB calls by $this->game->DbQuery() (and such...)


https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php#Flag_to_indicate_a_skipped_state
==States==
There is now a way to describe each game state in a State class, that will handle all logic and description of the state. It helps splitting the code into multiple files, instead of one big Game.php file.


πŸ“Œ Add _no_notify in the args when a state is skipped
https://en.doc.boardgamearena.com/State_classes:_State_directory


== Sound loading ==
πŸ“Œ Create a State class for each state of the game (except 1 and 99 if they are still described in states.inc.php), move the state definition in it, and adapt the "st", "arg", "actXXX" and "zombie" functions in the class. When all classes are migrated, you can remove the states.inc.php file in the FTP folder.
New functions load/play have been added for the sounds:


https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Sounds
=== If still using states.php ===
The new class GameStateBuilder helps you build the state machine, allowing auto-completion, and avoid typo errors on state types. Complete example: πŸ“Œ https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php


πŸ“Œ Replace template loading of sounds and global function playSound
States 1 and 99, that must not be changed, are now optional.


Useless getGameName function on Game PHP file
πŸ“Œ Replace the array definition by GameStateBuilder use. You can remove the declaration of states 1 and 99.


The getGameName function is now useless in the Game PHP file and can be deleted
Note: it's only useful if you don't migrate to State classes described above


πŸ“Œ Delete the getGameName function in the Game PHP file.
==Deprecation of ajaxcall==
Introduced function bgaPerformAction to replace ajaxcall and checkAction combination, with a simpler syntax:


== GameStateBuilder ==
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Actions
This new class helps you build the state machine, allowing auto-completion, and avoid typo errors on state types. Complete example: πŸ“Œ https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php


States 1 and 99, that must not be changed, are now optional.
πŸ“Œ Replace combination of checkAction/ajaxcall by bgaPerformAction. Beware of the options (3rd param) if it was an ajaxcall without checkAction.
==Access template elements==
New functions getPlayerPanelElement(player_id) and this.getGameAreaElement()


πŸ“Œ Replace the array definition by GameStateBuilder use. You can remove the declaration of states 1 and 99.
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_stuff_to_player%27s_panel


Note: it's only useful if you don't migrate to State classes described later on.
πŸ“Œ Code like dojo.place(html, player_board_${player.id}); would be replaced by this.getGameAreaElement().insertAdjacentHTML('beforeend', html);
==Easier notification setup==
Notifications can now be automatically scanned and called without needing to register them one by one. They'll handle Promises, so they end synchronously when the Promise resolves.


== bgaFormatText ==
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Notifications
This function, if defined, will allow you to insert HTML in the logs without overriding format_string_recursive. Example: πŸ“Œhttps://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Define_this.bgaFormatText%28%29_method


πŸ“Œ Replace the override of format_string_recursive by bgaFormatText (the last line will change)
A wait function has been added to return a Promise when a delay is passed (compatible with fast-replay mode)


== Future support of dark mode ==
A new utility function has been added to support Promises for old Dojo animations
BGA doesn't support dark mode yet. To have some games compatible when we do, we added a theme data tag you can use as described here:


https://en.doc.boardgamearena.com/Game_interface_stylesheet:_yourgamename.css#Support_of_the_Dark_mode
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Animation_Callbacks


== Framework function for automata player panel ==
πŸ“Œ Dojo.subscribe calls in setupNotifications must be removed if bgaSetupPromiseNotifications is used. Notif_ function should be async and return a Promise, make sure they wait for the expected amount of time if the sync setup was using a numerical duration
A new framework function to add a player panel for your game automatas https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_a_player_panel_for_an_automata


πŸ“Œ Replace manually created automata player panel with this new function
If you used Dojo animation, make them Promise compatible with "await this.bgaPlayDojoAnimation(dojoAnim);"


== New JS libraries ==
== Status bar manipulation==
We will provide new libraries to help you design your games, especially for components that you will find on numerous games. The first available libraries are:
Function to change the title from the JS
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Title_bar


[bga-animations https://en.doc.boardgamearena.com/BgaAnimations]Β  : a JS component to make animations, compatible with scaled or rotated containers.
πŸ“Œ Replace direct title div manipulation with this.statusBar.setTitle(title: string, args?: object), and benefit from replacement of ${actplayer}/${you}/... (see example in the link above).


bga-cards : a JS component to handle cards.
This also includes a new function to create action buttons, that are more screen-reader compatible than the previous version. The new button parameters also allow you to set a confirm popin or an autoclick for confirmation buttons


bga-dice : a JS component to handle dice.
πŸ“Œ Replace this.addActionButton by this.statusBar.addActionButton. Notice the parameters have changed, so they need to be adapted too! Remove manual setActionTimer or manual confirm with the new parameters.


bga-autofit : a JS component to make text fit on a fixed size div.
== Dojo usage==
Dojo usage has been reduced to minimum in the new project template and the doc, as native JS is now able to do almost the same things, with better performance and more knowledge for newcomers of the native (vanilla) JS.


bga-score-sheet : a JS component to help you display an animated score sheet at the end of the game.
πŸ“Œ Replace dojo by vanilla JS where possible


πŸ“Œ Try them, and hopefully use them instead of the very old components! Each lib has a demo in the beginning of the wiki page to show what it can do.
examples are coming...


== Notification args consistency ==
==Sound loading==
Previously, when you sent an arg that was transformed by format_string_recursive or bgaFormatText, the args object was mutated and you got the transformed value in the notif_ handler.
New functions load/play have been added for the sounds:


The solution was to send the values in 2 different names like this:
https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Sounds
Code: Select all


[
πŸ“Œ Replace template loading of sounds and global function playSound
Β  'roundNumber' => $roundNumber, // number, to update the round counter
Β  'round_number' => $roundNumber, // number that will be transformed to string by bgaFormatText, when shown in bold in the logs
]
πŸ“Œ Do not duplicate the value, as the notif_ handler will now get unmutated args


== Updated Zombie Mode documentation and recommendations ==
==Formatting of log message using bgaFormatText==
We now recommend making the zombie player playing randomly, instead of passing as a default. A new "Zombie Mode level" field has been added to the Game Metadata Manager, to indicated the Zombie Mode you implemented in your game.
This function, if defined, will allow you to insert HTML in the logs without overriding format_string_recursive. Example: πŸ“Œhttps://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Define_this.bgaFormatText%28%29_method


https://en.doc.boardgamearena.com/Zombie_Mode
πŸ“Œ Replace the override of format_string_recursive by bgaFormatText (the last line will change)


== State classes ==
==Future support of dark mode==
There is now a way to describe each game state in a State class, that will handle all logic and description of the state. It helps splitting the code into multiple files, instead of one big Game.php file.
BGA doesn't support dark mode yet. To have some games compatible when we do, we added a theme data tag you can use as described here:


https://en.doc.boardgamearena.com/State_classes:_State_directory
https://en.doc.boardgamearena.com/Game_interface_stylesheet:_yourgamename.css#Support_of_the_Dark_mode


πŸ“Œ Create a State class for each state of the game (except 1 and 99 if they are still described in states.inc.php), move the state definition in it, and adapt the "st", "arg", "actXXX" and "zombie" functions in the class. When all classes are migrated, you can remove the states.inc.php file in the FTP folder.
==Automata player panel==
A new framework function to add a player panel for your game automas https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_a_player_panel_for_an_automata


== Counters ==
πŸ“Œ Replace manually created automata player panel with this new function
2 new counter classes have been added to easily handle the various counters your game might have. You also have 2 prebuild PlayerCounter: playerScore and playerScoreAux, to handle the scoring values, so you don't need to update manually the DB when setting the scores.
Β 
https://en.doc.boardgamearena.com/PlayerCounter_and_TableCounter


πŸ“Œ Replace setting manually player_score/player_score_aux with new $this->playerScore and $this->playerScoreAux. Remove the notifications, or part of notifications, updating the scoreCtrl counter.
== New JS libraries==
New JS libraries are created to help you design your games, especially for components that you will find on numerous games. See [[Studio#BGA Studio game components reference]]


== Use $this-> instead of self:: by default ==
πŸ“Œ Replace manually created animation, stocks, etc with components (check the list above, don't want to duplicate it here)
The new project template has been updated to remove this bad practice (that may be unsupported in a future PHP version)

Revision as of 01:15, 16 October 2025

under construction

This page is only for people who started long time ago and now need to re-write older projects into more modern versions. Also if you trying to fix older game you may have to look here.

See announcement here https://studio.boardgamearena.com/forum/viewtopic.php?f=12&t=45248


πŸ“Œ This symbol: information about migration, if you want to migrate an old game to the most recent ways

Structural changes

gameoptions.inc.php => gameoptions.json, gamepreferences.json

Previously, options and preferences were specified in a single gameoptions.inc.php file.

Now options and preferences are 2 json files, follow Migration steps on this page https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Migration

See #User preferences and #Game options for API changes.

When building the game with this file you will see deprecation warning.

<gamename>.game.php => modules/php/Game.php

Move and refactor, see section Namespaced game class

<gamename>.action.php => remove

See section Autowire game actions

<gamename>.view.php, <gamename>_<gamename>.tpl => remove

See section Removal of view and template

material.inc.php => optional

See section #Material

states.inc.php => modules/php/States

See section #States

<gamename>.js

File still there but massive API changes, see bottom sections

PHP migration

Oct 2025: The migration was made from PHP7.4 to PHP8.4 new syntax and functions.

New projects are generated using the strict mode

πŸ“Œ

  • Replace all self:: to $this-> - The new project template has been updated to remove this bad practice (that may be unsupported in a future PHP version)
  • Add declare(strict_types=1); to all .php files and fix compiler warnings (if you use IDE it will detect it before upload).

User preferences

Access to user preferences and listener: https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#User_preferences

πŸ“Œ

  • If you had a custom function called setupPreferences() reading the <select> values, you can now use onGameUserPreferenceChanged instead.
  • If you had a copy of the user preferences on a DB table, it's not needed anymore. Remove all support of writing to this table. Replace access to this table with
       $pref = (int) $this->userPreferences->get($playerId, $prefCode);

Instant cssPref on user preferences

A reload is not needed anymore to apply cssPref on a user preference change.

πŸ“Œ Remove forceReload: true if it was only set to update the cssPref. The player will appreciate to not reload the whole page!

Game options

New functions to access the table options (game options) without hassle

https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json#Game_Options

πŸ“Œ

  • Remove declaration of game options from "initGameStateLabels"
  • Instead of using $this->getGameStateValue or $this->gamestate->table_globals use
$this->tableOptions->get(int $optionId)

This new object can also return the Real-time/Turn-based setting: https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Reflexion_time

Namespaced game class

Game class from <gamename>.game.php are now namespaced (and moved to modules/php/Game.php) and can autoload other classes of the same namespace

Main game logic: Game.php#Creating other classes

πŸ“Œ The class file should be moved to modules/php/Game.php and start with this adapted part:

namespace Bga\Games\YourGameName;

class Game extends \Bga\GameFramework\Table { ... }

All references to non-namespaced classes in this file should be defined on top of the file with "use", for example "use \BgaUserException;" as it is this non-namespaced exception is used in the zombieTurn function.

All includes with relative path will need to be updated too.

The material.inc.php to have be moved (see below)

Multiple functions of "Table" base class are now deprecated, see how to migrate in corresponding section

  • notifyAllPlayers
  • notifyPlayer
  • mysql_fetch_assoc
  • Table (class access without namespace)
  • isMutiactiveState (misspelled version)
  • ...

Material

Material file material.inc.php is now optional. You can define all your material directly in php class. If you still like to keep it, and using namespaced Game.php you have to move it to subfolder and include directly Game material description: material.inc.php#Move it to modules/php

Autowire game actions

Simplify the action calls by removing <gamename>.action.php file

https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Actions_%28autowired%29

πŸ“Œ Autowired actions needs to start with "act", so it's risky to change them (if you change all actions names in the states.php, game, action and JS file, Real-time players will call the old name until they refresh. So, it needs to be done in two steps with duplicates on back side, or to be deployed when there is no Realt-time table running.

When migration is done, the action.php file can be deleted.

Notifications

Functions notifyAllPlayers and notifyPlayer from main game.php are deprecated

πŸ“Œ Replace notifyAllPlayers by $this->notify->all() and notifyPlayer by $this->notify->player()

Notification Decorators

New notify function that handles decorators, reducing the duplicate code on notification args.

https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Notification_decorators

Notification args consistency

Previously, when you sent an arg that was transformed by format_string_recursive or bgaFormatText, the args object was mutated and you got the transformed value in the notif_ handler.

The solution was to send the values in 2 different names like this:

[
 'roundNumber' => $roundNumber, // number, to update the round counter
 'round_number' => $roundNumber, // number that will be transformed to string by bgaFormatText, when shown in bold in the logs
]

πŸ“Œ Do not duplicate the value, as the notif_ handler will now get unmutated args

Deprecated getGameName

The getGameName() function is now useless in the Game PHP file and can be deleted

πŸ“Œ Delete the getGameName function in the Game PHP file.

Legacy

New object to access the legacy functions, removing the need to manually decode the JSON result when getting the values.

https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Legacy_games_API

πŸ“Œ Use $this->legacy->actionname instead of $this->actionnameLegacy and remove JSON decoding on getters

Any Globals

New database table and API to handle any type variables instead of numerical values only

https://en.doc.boardgamearena.com/Main_game_logic:_Game.php#Use_globals

πŸ“Œ If you had custom tables just for that you can drop them and use standard table

Server Counters

2 new counter classes have been added to easily handle the various counters your game might have. You also have 2 prebuilt counters: playerScore and playerScoreAux, to handle the scoring values, so you don't need to update manually the DB when setting the scores.

https://en.doc.boardgamearena.com/PlayerCounter_and_TableCounter

πŸ“Œ Replace setting player_score/player_score_aux using db queries with use of $this->playerScore and $this->playerScoreAux. Remove the notifications, or part of notifications, updating the scoreCtrl counter (if you had some custom notification you may still need them).

Updated Zombie Mode documentation and recommendations

We now recommend making the zombie player playing randomly, instead of passing as a default. A new "Zombie Mode level" field has been added to the Game Metadata Manager, to indicated the Zombie Mode you implemented in your game.

https://en.doc.boardgamearena.com/Zombie_Mode

IDE Support

A new _ide_helper.php file is now provided in every project dir, allowing IDE to provide syntax error highlighting for the framework functions. This file is regularly updated to match the latest framework updates.

Same with bga-framework.d.ts for those using TypeScript.

πŸ“Œ Sync the files from the FTP dir to your local copy to benefit from it. Most of the IDE like Visual Studio Code should handle _ide_helper.php if you already followed https://en.doc.boardgamearena.com/Setting_up_BGA_Development_environment_using_VSCode

View and template files: deprecated

<gamename>.view.php, <gamename>_<gamename>.tpl are now optional and are not generated anymore on a new project. The new project templates demonstrate how to work without them.

πŸ“Œ The DOM should be built on the JS side to remove the view/template files, so it can be complicated for old projects using them intensively. It would look like this:

this.getGameAreaElement().insertAdjacentHTML('beforeend', `
  <span>${_('My translated text')}</span><div id="player-tables"></div>
`);
 

See more in #Access template elements

Forbid access to global BGA variables and direct DB access on action/view files

If you did not remove action and view files, you cannot longer use some stuff in them, such $g_user global and db access functions.

A new getCurrentPlayerId() function has been added to those action/view classes for easier migration

πŸ“Œ Replace $g_user->get_id() by $this-> getCurrentPlayerId()

Replace DB calls by $this->game->DbQuery() (and such...)

States

There is now a way to describe each game state in a State class, that will handle all logic and description of the state. It helps splitting the code into multiple files, instead of one big Game.php file.

https://en.doc.boardgamearena.com/State_classes:_State_directory

πŸ“Œ Create a State class for each state of the game (except 1 and 99 if they are still described in states.inc.php), move the state definition in it, and adapt the "st", "arg", "actXXX" and "zombie" functions in the class. When all classes are migrated, you can remove the states.inc.php file in the FTP folder.

If still using states.php

The new class GameStateBuilder helps you build the state machine, allowing auto-completion, and avoid typo errors on state types. Complete example: πŸ“Œ https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php

States 1 and 99, that must not be changed, are now optional.

πŸ“Œ Replace the array definition by GameStateBuilder use. You can remove the declaration of states 1 and 99.

Note: it's only useful if you don't migrate to State classes described above

Deprecation of ajaxcall

Introduced function bgaPerformAction to replace ajaxcall and checkAction combination, with a simpler syntax:

https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Actions

πŸ“Œ Replace combination of checkAction/ajaxcall by bgaPerformAction. Beware of the options (3rd param) if it was an ajaxcall without checkAction.

Access template elements

New functions getPlayerPanelElement(player_id) and this.getGameAreaElement()

https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_stuff_to_player%27s_panel

πŸ“Œ Code like dojo.place(html, player_board_${player.id}); would be replaced by this.getGameAreaElement().insertAdjacentHTML('beforeend', html);

Easier notification setup

Notifications can now be automatically scanned and called without needing to register them one by one. They'll handle Promises, so they end synchronously when the Promise resolves.

https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Notifications

A wait function has been added to return a Promise when a delay is passed (compatible with fast-replay mode)

A new utility function has been added to support Promises for old Dojo animations

https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Animation_Callbacks

πŸ“Œ Dojo.subscribe calls in setupNotifications must be removed if bgaSetupPromiseNotifications is used. Notif_ function should be async and return a Promise, make sure they wait for the expected amount of time if the sync setup was using a numerical duration

If you used Dojo animation, make them Promise compatible with "await this.bgaPlayDojoAnimation(dojoAnim);"

Status bar manipulation

Function to change the title from the JS https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Title_bar

πŸ“Œ Replace direct title div manipulation with this.statusBar.setTitle(title: string, args?: object), and benefit from replacement of ${actplayer}/${you}/... (see example in the link above).

This also includes a new function to create action buttons, that are more screen-reader compatible than the previous version. The new button parameters also allow you to set a confirm popin or an autoclick for confirmation buttons

πŸ“Œ Replace this.addActionButton by this.statusBar.addActionButton. Notice the parameters have changed, so they need to be adapted too! Remove manual setActionTimer or manual confirm with the new parameters.

Dojo usage

Dojo usage has been reduced to minimum in the new project template and the doc, as native JS is now able to do almost the same things, with better performance and more knowledge for newcomers of the native (vanilla) JS.

πŸ“Œ Replace dojo by vanilla JS where possible

examples are coming...

Sound loading

New functions load/play have been added for the sounds:

https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Sounds

πŸ“Œ Replace template loading of sounds and global function playSound

Formatting of log message using bgaFormatText

This function, if defined, will allow you to insert HTML in the logs without overriding format_string_recursive. Example: πŸ“Œhttps://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Define_this.bgaFormatText%28%29_method

πŸ“Œ Replace the override of format_string_recursive by bgaFormatText (the last line will change)

Future support of dark mode

BGA doesn't support dark mode yet. To have some games compatible when we do, we added a theme data tag you can use as described here:

https://en.doc.boardgamearena.com/Game_interface_stylesheet:_yourgamename.css#Support_of_the_Dark_mode

Automata player panel

A new framework function to add a player panel for your game automas https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Adding_a_player_panel_for_an_automata

πŸ“Œ Replace manually created automata player panel with this new function

New JS libraries

New JS libraries are created to help you design your games, especially for components that you will find on numerous games. See Studio#BGA Studio game components reference

πŸ“Œ Replace manually created animation, stocks, etc with components (check the list above, don't want to duplicate it here)