<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.doc.boardgamearena.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NevinAF</id>
	<title>Board Game Arena - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.doc.boardgamearena.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NevinAF"/>
	<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/Special:Contributions/NevinAF"/>
	<updated>2026-09-21T17:44:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.0</generator>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template_Tutorials&amp;diff=20773</id>
		<title>BGA-ts-template Tutorials</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template_Tutorials&amp;diff=20773"/>
		<updated>2024-04-12T13:58:59Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: NevinAF moved page BGA-ts-template Tutorials to BGA Type Safe Template: Tutorials: Cleaner and more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[BGA Type Safe Template: Tutorials]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Tutorials&amp;diff=20772</id>
		<title>BGA Type Safe Template: Tutorials</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Tutorials&amp;diff=20772"/>
		<updated>2024-04-12T13:58:59Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: NevinAF moved page BGA-ts-template Tutorials to BGA Type Safe Template: Tutorials: Cleaner and more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;This page was generated from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md BGA TS Template: README.md]. It is recommended to view this document from the source file. All links will redirect to source documentation, and images will only be included via link.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;ts-template-tutorials&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= TS Template: Tutorials =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#board-game-arena-type-safe-template &#039;&#039;BGA Type Safe Template&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
All tutorials are beginner friendly and are designed to help you get started with the BGA Type Safe Template. Each tutorial will link to this page for the first four steps which are shared for any project you are working.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;tutorial-list&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Tutorial List ==&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/reversi.md Reversi]: A two player turn-based, perfect knowledge strategy game. Great starting point, meant for learning the purpose of each file and quickly getting a game up and running. Less good for learning internal components and framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-0---development-environment-setup&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 0 - Development Environment Setup ==&lt;br /&gt;
&lt;br /&gt;
No matter what you are doing, the first step is to always prepare your development tools. There are many different ways to set up your development environment, and many different tools to choose from.&lt;br /&gt;
&lt;br /&gt;
Board Game Arena requires some sort of [https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol SFTP client], but that’s about it. Adding on to that, the Type Safe Template requires [https://nodejs.org/en/ Node.js] to initialize and build the project. Everything else is up to the developer or team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&#039;&#039;&#039;S&#039;&#039;&#039;ecure &#039;&#039;&#039;F&#039;&#039;&#039;ile &#039;&#039;&#039;T&#039;&#039;&#039;ransfer &#039;&#039;&#039;P&#039;&#039;&#039;rotocol (SFTP) essentially describes how to upload and download files from a network drive, not that different from Google Drive or Dropbox.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The official BGA team recommends [https://code.visualstudio.com/ Visual Studio Code] and a specific set of extensions for development. Based on this, the following steps are a quick guide for anyone who is starting from scratch or unsure of what to do.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;This is labeled as step 0 because it only ever needs to be down once. If you already have these tools installed and set up, you can skip this step.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;recommended-tools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Recommended Tools ===&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;[https://code.visualstudio.com/ Visual Studio Code]&#039;&#039;&#039;: A code editor with a wide range of extensions and features. Using VS Code will provide automatic code completion, syntax highlighting, and many other features that make development easier. Download [https://code.visualstudio.com/download VS Code here.]&lt;br /&gt;
# &#039;&#039;&#039;[https://nodejs.org/en/download/ Node.js]&#039;&#039;&#039;: A JavaScript runtime which is used to initialize and build source files to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;A node version manager is also recommended for managing multiple versions of node.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;[https://docs.npmjs.com/about-npm Node Package Manager (npm)]&#039;&#039;&#039;: A package manager for JavaScript. This will be used to automatically install and manage the dependencies,including the BGA Type Safe Template.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Once you have node.js installed, you can install npm by simply running the following in the terminal:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;bash&amp;quot;&amp;gt;npm install -g npm&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;[https://marketplace.visualstudio.com/items?itemName=nevinfoster.bga-extension-pack BGA Extension Pack]&#039;&#039;&#039;: A collection of VS Code extensions that are useful for BGA development. This includes syntax highlighting for BGA files, a BGA icon theme, and more.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;(optional) &#039;&#039;&#039;[https://git-scm.com/downloads Git]&#039;&#039;&#039;: One of the most populate version control systems. This is used to track changes to your code and collaborate easily with others. Nearly all BGA developers use [https://github.com GitHub] to share their code, which is built on top of Git.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_vscode.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_nodejs.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_npm.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_git.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-1---create-a-new-project&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 1 - Create a New Project ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Go to [https://studio.boardgamearena.com studio.boardgamearena.com] and login. Then navigate to your [https://studio.boardgamearena.com/studio manage games] page:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on your profile icon on the top right of any page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the Control Panel button on the top right. This is only visible if you are on a developer account.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the Manage Games button on the left side of the page.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_create_new_project.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Create new project&#039;&#039;&#039;. You only need to fill out the name of the game, usually something like &amp;lt;code&amp;gt;&amp;amp;lt;UserName&amp;amp;gt;Tutorial&amp;amp;lt;Game&amp;amp;gt;&amp;lt;/code&amp;gt; for a first project.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;This should always be in upper camel case (Pascal Case) with no spaces or special characters. This is because the project name is used in the URL of the game, and the URL is case sensitive.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Create a local folder&#039;&#039;&#039; for the project files. Something like &amp;lt;code&amp;gt;C:\Users\&amp;amp;lt;UserName&amp;amp;gt;\Documents\BGA\&amp;amp;lt;project-name&amp;amp;gt;&amp;lt;/code&amp;gt; is a good place to start.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Use SFTP client to download the project files&#039;&#039;&#039; to the folder you just created. If you are using the recommended tools for development, you can do the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: lower-alpha;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Open the new folder in VS Code&#039;&#039;&#039;. You can open VS Code and use the &amp;lt;code&amp;gt;File &amp;amp;gt; Open Folder&amp;lt;/code&amp;gt; to open the specific folder you created.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the [[command:sftp.config|SFTP: Config]] command&#039;&#039;&#039;. You can do this by pressing &amp;lt;code&amp;gt;Ctrl+Shift+P&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;F1&amp;lt;/code&amp;gt;) to open the command palette, then typing &amp;lt;code&amp;gt;SFTP: Config&amp;lt;/code&amp;gt; and pressing enter.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Paste the following&#039;&#039;&#039; into the created &amp;lt;code&amp;gt;.vscode/sftp.json&amp;lt;/code&amp;gt; file, then update the username, password, and remotePath fields with your own information. The username and password will have been emailed when signing up for a developer account::&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;___YourUsername___&amp;quot;,&lt;br /&gt;
    &amp;quot;password&amp;quot;: &amp;quot;___yourpassword_hexstring___&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/___lowercaseprojectname___/&amp;quot;,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.vscode&amp;quot;,&lt;br /&gt;
        &amp;quot;.git&amp;quot;,&lt;br /&gt;
        &amp;quot;.idea&amp;quot;,&lt;br /&gt;
        &amp;quot;.gitignore&amp;quot;,&lt;br /&gt;
        &amp;quot;.DS_Store&amp;quot;,&lt;br /&gt;
        &amp;quot;node_modules&amp;quot;,&lt;br /&gt;
        &amp;quot;package-lock.json&amp;quot;,&lt;br /&gt;
        &amp;quot;yarn.lock&amp;quot;,&lt;br /&gt;
        &amp;quot;nmp-debug.log&amp;quot;,&lt;br /&gt;
        &amp;quot;yarn-error.log&amp;quot;,&lt;br /&gt;
        &amp;quot;source/client/build&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: lower-alpha;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;&#039;Run the [[command:sftp.sync.remoteToLocal|SFTP: Sync Remote -&amp;amp;gt; Local]]&#039;&#039;&#039; command. This will download all initial files from the BGA server to your local folder.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot; width=&amp;quot;50%&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_starting_files.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;When viewing files in VS Code, the php files will have errors because the shared codes in not yet linked. This will be resolved in the next step.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;5&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the game&#039;&#039;&#039; to make sure everything is working correctly. You can run tests filled with your developer accounts by using &amp;lt;code&amp;gt;Express Start&amp;lt;/code&amp;gt; when setting up to play a game.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Navigate to the &amp;lt;code&amp;gt;Manage Games&amp;lt;/code&amp;gt; page as described in step 1.1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on any games in your list of games.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Play&amp;lt;/code&amp;gt; from within the list of options on one of your game’s versions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Create A Table&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Express Start&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_test_game.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_open_dev_player.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You can play as any of the connected developer accounts by clicking on the red &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt; next to any of the players’ names.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-2---initialize-the-bga-type-safe-template&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 2 - Initialize the BGA Type Safe Template ==&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;Create a &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; file&#039;&#039;&#039;, and fill it with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
        &amp;quot;init&amp;quot;: &amp;quot;npm install bga-ts-template &amp;amp;&amp;amp; npx bga-init YourGameName \&amp;quot;developers\&amp;quot; source --typescript --scss --vscode-extension-pack --php-8.2 --gameinfos.jsonc --gameoptions.jsonc --gamepreferences.jsonc --stats.jsonc --gamestates.jsonc&amp;quot;,&lt;br /&gt;
        &amp;quot;build&amp;quot;: &amp;quot;npx bga-build&amp;quot;,&lt;br /&gt;
        &amp;quot;watch&amp;quot;: &amp;quot;npx bga-build --watch&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Change the &amp;lt;code&amp;gt;YourGameName&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;developers&amp;lt;/code&amp;gt; arguments&#039;&#039;&#039; to fit your project. You can also change any of the other arguments to fit your needs. See the [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#configurations BGA Type Safe Template: Configurations] for more information.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt; script&#039;&#039;&#039;. This can be done using a terminal on the project directory, or in VS Code by hovering over the &amp;lt;code&amp;gt;scripts: &amp;amp;quot;init&amp;amp;quot;&amp;lt;/code&amp;gt; line in the &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; file. You can see more information about the package.json scripts at [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#package-scripts BGA Type Safe Template: Package Scripts].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/package_json_run_script.gif&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;View your files.&#039;&#039;&#039; You should now only have a trhee error among all of your files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;One issue in &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file, usually on line 75, and is a syntax error caused by a minor bug in the starting files.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Error: Expected type &#039;null|array&#039;. Found &#039;string&#039;&lt;br /&gt;
$sql .= implode( $values, &#039;,&#039; ); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Fixed!&lt;br /&gt;
$sql .= implode( &#039;,&#039;, $values ); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Two issues in &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt;, one for each player action. This is a type error stating that your main game code does not have the player action functions defined (which is true!). This will be fixed later when adding player actions.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;public function playCard()&lt;br /&gt;
{&lt;br /&gt;
    self::setAjaxMode();&lt;br /&gt;
&lt;br /&gt;
    /** @var int $card_id */&lt;br /&gt;
    $card_id = self::getArg(&#039;card_id&#039;, AT_int, true);&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;playCard( $card_id ); // Error: Undefined method&lt;br /&gt;
    self::ajaxResponse();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;public function pass()&lt;br /&gt;
{&lt;br /&gt;
    self::setAjaxMode();&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;pass(  ); // Error: Undefined method&lt;br /&gt;
    self::ajaxResponse();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Sync your local files to the BGA server. When using VS Code SFTP extension, &#039;&#039;&#039;run the [[command:sftp.sync.localToRemote|SFTP: Sync Local -&amp;amp;gt; Remote]] command&#039;&#039;&#039;. &#039;&#039;This is only needed the first time you upload, or if you change files when VS code is not running (ie, the extension is not active).&#039;&#039;&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the game in the BGA studio&#039;&#039;&#039;. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-1---create-a-new-project step 1.5] for more information on how to do this.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Hard Refresh the client page&#039;&#039;&#039;. You should ALWAYS do a hard refresh when making changes, otherwise you will likely be using old cached files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;Windows&#039;&#039;: Chrome, Firefox, or Edge =&amp;amp;gt; Press &amp;lt;code&amp;gt;Ctrl+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Shift+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Ctrl+Shift+R&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;Mac&#039;&#039;: Chrome or Firefox =&amp;amp;gt; Press &amp;lt;code&amp;gt;Cmd+Shift+R&amp;lt;/code&amp;gt;. Safari =&amp;amp;gt; Press &amp;lt;code&amp;gt;Cmd+Option+E&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;There are no differences, but running the game makes sure that everything is working correctly.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-3---game-information-metadata&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 3 - Game Information + Metadata ==&lt;br /&gt;
&lt;br /&gt;
A good portion of this information is optional, but it is always good practice to fill out as much as possible for all projects.&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;Update &amp;lt;code&amp;gt;shared/gameinfos.jsonc&amp;lt;/code&amp;gt;&#039;&#039;&#039;. The [https://en.doc.boardgamearena.com/Game_meta-information:_gameinfos.inc.php Game Infos] contains all meta-information for the game such as the full name and number of players. Each value in the file has hover-able tooltips for more information and will show error if there are any validation issues.&lt;br /&gt;
# &#039;&#039;&#039;Run &amp;lt;code&amp;gt;npm run build&amp;lt;/code&amp;gt;&#039;&#039;&#039;. This will convert your json to the &amp;lt;code&amp;gt;gameinfos.inc.php&amp;lt;/code&amp;gt; file which is used by the BGA server. See the [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#package-scripts BGA Type Safe Template: Package Scripts] for more information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You can also run &amp;lt;code&amp;gt;npm run watch&amp;lt;/code&amp;gt; to automatically build any files whenever they are changed.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go to the manage game page for your game and &#039;&#039;&#039;select Reload game informations&#039;&#039;&#039;. This must be clicked whenever the &amp;lt;code&amp;gt;gameinfos&amp;lt;/code&amp;gt; file is updated.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;The manage game page for a game can always be found by going to the &amp;lt;code&amp;gt;Manage Games&amp;lt;/code&amp;gt; page from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-1---create-a-new-project Step 1.1], then clicking on the game you want to manage.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/game_configuration.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;From the same location in step 3.3, click on &amp;lt;code&amp;gt;Manage metadata images&amp;lt;/code&amp;gt; to edit all visual/informational metadata of the game. See the [https://en.doc.boardgamearena.com/Game_metadata_manager Game Metadata Manager] wiki page for more information.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After steps 3.3 and 3.4, your can view your game’s &amp;lt;code&amp;gt;game page&amp;lt;/code&amp;gt; verify that you see the corrected information.&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20771</id>
		<title>Setting up BGA Development environment using VSCode</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20771"/>
		<updated>2024-04-12T13:55:37Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Fixed redirect on bga type safe template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Microsoft Visual Studio Code is light weight IDE/Editor. All desktops.&lt;br /&gt;
&lt;br /&gt;
== Downloads ==&lt;br /&gt;
&lt;br /&gt;
* Download and install vscode from https://code.visualstudio.com&lt;br /&gt;
* Download and install php (7.4) command line interface (for local tests and debugging)&lt;br /&gt;
&lt;br /&gt;
== Extensions ==&lt;br /&gt;
Use [https://marketplace.visualstudio.com/items?itemName=NevinFoster.bga-extension-pack&amp;amp;ssr=false#overview BGA Extension Pack] to download all of the recommended extensions with one click.&lt;br /&gt;
* PHP Intelephense - https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client&lt;br /&gt;
* Or PHP IntelliSense - https://marketplace.visualstudio.com/items?itemName=zobo.php-intellisense&lt;br /&gt;
* PHP Debug - https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug&lt;br /&gt;
* SQLTools - https://marketplace.visualstudio.com/items?itemName=mtxr.sqltools&lt;br /&gt;
* Prettier - code formatter - https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&lt;br /&gt;
* SFTP (by Natizyskunk) -  https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp&lt;br /&gt;
&lt;br /&gt;
== Intellisense - Navigation/Auto-complete ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Intellisense ===&lt;br /&gt;
The IntelliSense for JavaScript code is to &#039;&#039;&#039;use the [[BGA Type Safe Template]]&#039;&#039;&#039;. It offers a much cleaner initial file, clearer workflow, and nearly complete type and autofill support for whatever you may need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:Stripped base Typescript file.png|alt=Starting TS file with comments/template code removed|thumb|696x696px|Starting TS file with comments/template code removed]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:Typescript autofill.gif|alt=Typescript Autocomplete using BGA Type Safe Template|thumb|542x542px|Typescript Autocomplete using BGA Type Safe Template]] &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this does not interest you, you can also revert to the old ways of getting better intellisense:&lt;br /&gt;
&lt;br /&gt;
- Because of dojo style class/method declarations most IDE won&#039;t be able to index main JavaScript file properly (i.e. go to definition of function and such).&lt;br /&gt;
If you manage to get it working in VS code, let us know how.&lt;br /&gt;
&lt;br /&gt;
- There is a way to re-structure code to avoid using this style, but this is not for beginners. Do not use this on your first game!&lt;br /&gt;
https://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Avoiding_code_in_dojo_declare_style&lt;br /&gt;
&lt;br /&gt;
- There is also a complete example of a &amp;quot;dojo-less&amp;quot; project, it also includes a (incomplete) typescript definition file (.d.ts) for auto-completion of js BGA interfaces&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===PHP Intellisense===&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t do anything PHP will complain about undefined symbols from BGA framework (as well as from the material file).&lt;br /&gt;
To solve the warning about framework issues, you need a stubs for the BGA APIs:&lt;br /&gt;
&lt;br /&gt;
*git clone git@github.com:elaskavaia/bga-sharedcode.git (you can also get and unzip it from the GitHub page) &lt;br /&gt;
** if that doesn&#039;t work, try git clone &amp;lt;nowiki&amp;gt;https://github.com/elaskavaia/bga-sharedcode.git&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
**you can do this in a terminal from VS Code - Terminal menu -&amp;gt; New Terminal&lt;br /&gt;
*add reference (include path) to bga-sharedcode/misc using settings of PHP extension, see example below&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using the Intelephense plugin, add this to global user settings (modify the path obviously)&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;intelephense.environment.includePaths&amp;quot;: [&lt;br /&gt;
        &amp;quot;/home/victoria/git/bga-sharedcode/misc/&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To solve the warning about the material file class members&lt;br /&gt;
&lt;br /&gt;
Option 1)&lt;br /&gt;
If you don&#039;t have too many class members you can define them, for example if I have $this-&amp;gt;token_types = [...] in the material file I can define them in in the class of game.php&lt;br /&gt;
&lt;br /&gt;
    private $token_types;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Option 2) &lt;br /&gt;
&lt;br /&gt;
Put this line in the settings.json if you using Intelliphense extension to ignore them:&lt;br /&gt;
&lt;br /&gt;
   &amp;quot;intelephense.diagnostics.undefinedProperties&amp;quot;: false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
If using phpunit, install it via composer somewhere in home directory, i.e.&lt;br /&gt;
   cd /home/victoria/php-composer&lt;br /&gt;
   composer require --dev phpunit/phpunit ^9&lt;br /&gt;
&lt;br /&gt;
Then add this path (e.x.  /home/victoria/php-composer) to include paths as above&lt;br /&gt;
&lt;br /&gt;
See more about unit testing in [[Testing by developer]]&lt;br /&gt;
&lt;br /&gt;
== File Sync==&lt;br /&gt;
You can set up your sync using other methods, not related to vscode (such as rsync), if you want to do that see [[Tools_and_tips_of_BGA_Studio#File_Sync]] otherwise see below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You might rely on your IDE to sync the files with the SFTP server. Each time you &amp;quot;save&amp;quot; a file with your modifications, the IDE will also submit it to the sFTP server. These are instructions for VS Code&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Install this extension&#039;&#039;&#039; https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp (File-&amp;gt;Preferences-&amp;gt;Extensions ... type SFTP and make sure its by Natizyskunk)&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Open VSCode on an empty folder&#039;&#039;&#039; that will be the local root of your project.&lt;br /&gt;
&lt;br /&gt;
*Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: config&amp;quot;&#039;&#039;&#039; - the edit will open with json config &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Update the json&#039;&#039;&#039; as below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;your SFTP username&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;password&amp;quot;: &amp;quot;&amp;lt;your SFTP password&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;your project name&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.vscode&amp;quot;,&lt;br /&gt;
        &amp;quot;.git&amp;quot;,&lt;br /&gt;
        &amp;quot;.DS_Store&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, # syncs new files&lt;br /&gt;
        &amp;quot;delete&amp;quot;: true # syncs deleted files&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===One time only - first sync ===&lt;br /&gt;
&lt;br /&gt;
- Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: Download Project&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This will download all the files locally. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Daily use===&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to do anything else! Each time you modify/save a file in VSCode, it will upload it to the SFTP Server.&lt;br /&gt;
&lt;br /&gt;
To force upload to a server, execute Ctrl+Shift+P -&amp;gt; &#039;&#039;&#039;&amp;quot;SFTP: Sync Local -&amp;gt; Remote&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note: the SFTP sync may fail with a permissions error when create or delete nested folders. To fix this, execute `chmod -R 755 &amp;lt;your directory name&amp;gt;` in your terminal, then force sync to remote.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Split settings for version control===&lt;br /&gt;
If you want to commit this file to version control, use private key (upload ssh key https://studio.boardgamearena.com/controlpanel) instead and move user/password settings into vscode user settings&lt;br /&gt;
&lt;br /&gt;
I.e. in user setting add this (have to edit settings.js manually, google for location its os specific)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;quot;remotefs.remote&amp;quot;: {&lt;br /&gt;
        &amp;quot;bgadev&amp;quot;: {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
            &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
            &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
            &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
            &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;yourdevusername&amp;gt;&amp;quot;,&lt;br /&gt;
            &amp;quot;privateKeyPath&amp;quot;: &amp;quot;~/.ssh/id_rsa&amp;quot;,&lt;br /&gt;
        },&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in project folder sftp.json (replace &amp;lt;yourproject&amp;gt; with project name)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;remote&amp;quot;: &amp;quot;bgadev&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;yourproject&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.git&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, &lt;br /&gt;
        &amp;quot;delete&amp;quot;: true &lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;watcher&amp;quot;: {&lt;br /&gt;
        &amp;quot;files&amp;quot;: &amp;quot;**/*.{js,css}&amp;quot;,&lt;br /&gt;
        &amp;quot;autoUpload&amp;quot;: true,&lt;br /&gt;
        &amp;quot;autoDelete&amp;quot;: true&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: you don&#039;t need watcher section if you don&#039;t use code generators, but its needed if you use typescript, scss or similar code generator tools.&lt;br /&gt;
&lt;br /&gt;
==Code Formatter==&lt;br /&gt;
I think Prettier has better format, you can install Prettier plugin to do the formatting, for PHP add the following in package.json&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
    &amp;quot;@prettier/plugin-php&amp;quot;: &amp;quot;^0.19.1&amp;quot;,&lt;br /&gt;
    &amp;quot;prettier&amp;quot;: &amp;quot;^2.7.1&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;prettier&amp;quot;: {&lt;br /&gt;
    &amp;quot;braceStyle&amp;quot;: &amp;quot;1tbs&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== Code generators==&lt;br /&gt;
If you want to run code generators for example for typescript or scss you can install this extension:&lt;br /&gt;
*https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave&lt;br /&gt;
&lt;br /&gt;
In settings.json add these (example only):&lt;br /&gt;
    &amp;quot;emeraldwalk.runonsave&amp;quot;: {&lt;br /&gt;
        &amp;quot;commands&amp;quot;: [&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.ts$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:ts&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.scss$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:scss&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        ]&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
In this example &amp;lt;code&amp;gt;build:ts&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;build:scss&amp;lt;/code&amp;gt; are scripts configured via package.json&lt;br /&gt;
&lt;br /&gt;
Another example - you can run php script that will generate material.inc.php from misc/xxx_material.csv&lt;br /&gt;
      {&lt;br /&gt;
        &amp;quot;match&amp;quot;: &amp;quot;misc/.*material\\.csv$&amp;quot;,&lt;br /&gt;
        &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
        &amp;quot;cmd&amp;quot;: &amp;quot;php7.4 ${env.HOME}/git/bga-sharedcode/misc/genmat.php ${file}&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
== User templates==&lt;br /&gt;
&lt;br /&gt;
You can define user template to avoid writing boilerplate code, here is example of php template for states&lt;br /&gt;
(it is placed in global location php.json - you can open it from the gui File-&amp;gt;Preferences-&amp;gt;Configure User Snippets and type php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Single player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;state&amp;quot;, &amp;quot;playerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT playerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;\\${actplayer} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;activeplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;st_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_PLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create single player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Multiple player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;mstate&amp;quot;, &amp;quot;multiplayerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT mplayerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;Other players must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;multipleactiveplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;stMakeEveryoneActive&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_MPLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create multi player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Action in action.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;action&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;public function ${1:actionName}() {&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::setAjaxMode();&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$${2:arg} = self::getArg(&#039;${2:arg}&#039;, AT_posint, false, 0);&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$this-&amp;gt;game-&amp;gt;action_${1:actionName}(\\$${2:arg});&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::ajaxResponse();&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Player loop in game.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;players&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;\\$players = \\$this-&amp;gt;loadPlayersBasicInfos();&amp;quot;,&lt;br /&gt;
      &amp;quot;foreach (\\$players as \\$player_id =&amp;gt; \\$player_info) {&amp;quot;,&lt;br /&gt;
      &amp;quot;${1}&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20770</id>
		<title>Using Typescript and Scss</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20770"/>
		<updated>2024-04-12T13:53:23Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Fixed redirect on bga type safe template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will help you set up your project to use Typescript client file and Scss style files, and automatically build Javascript (in ES5) files and CSS files so your project stay compatible to BGA framework requirements.&lt;br /&gt;
You can use only TS or only SCSS part if you want, they are not linked.&lt;br /&gt;
&lt;br /&gt;
== BGA Type Safe Template ==&lt;br /&gt;
If you are interested in all of the BGA Framework being typed for you, &#039;&#039;&#039;check out the [[BGA Type Safe Template]]&#039;&#039;&#039;. It will let you set up full typescript support and more with the fewest, easy-to-follow steps.&lt;br /&gt;
[[File:Typescript autofill.gif|alt=Typescript Autocomplete|center|thumb|734x734px|Typescript Autocomplete using BGA Type Safe Template]]&#039;&#039;&#039;The following document is geared towards setting up a custom project where you will be in charge of typing all components that you want to use.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Install and configure ==&lt;br /&gt;
&lt;br /&gt;
=== Install dev stack  ===&lt;br /&gt;
Install node/npm.  Here is an example to activate auto-build in Visual Studio Code, if you use another tool I strongly recommend to find an equivalent so you don&#039;t have to launch build manually after each modification.&lt;br /&gt;
&lt;br /&gt;
=== Configure package.json and tsconfig.json ===&lt;br /&gt;
&lt;br /&gt;
Create a file named &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; on the root folder, not on the src folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;package.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
   &amp;quot;name&amp;quot;: &amp;quot;yourgamename&amp;quot;,&lt;br /&gt;
   &amp;quot;version&amp;quot;: &amp;quot;1.0.0&amp;quot;,&lt;br /&gt;
   &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
   &amp;quot;main&amp;quot;: &amp;quot;YourGameName.js&amp;quot;,&lt;br /&gt;
   &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
     &amp;quot;build:ts&amp;quot;: &amp;quot;tsc&amp;quot;,&lt;br /&gt;
     &amp;quot;build:scss&amp;quot;: &amp;quot;sass --no-source-map src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:ts&amp;quot;: &amp;quot;tsc --watch&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:scss&amp;quot;: &amp;quot;sass --watch src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch&amp;quot;: &amp;quot;npm run watch:ts &amp;amp;&amp;amp; npm run watch:scss&amp;quot;,&lt;br /&gt;
     &amp;quot;build&amp;quot;: &amp;quot;npm run build:ts &amp;amp;&amp;amp; npm run build:scss&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;author&amp;quot;: &amp;quot;yourname&amp;quot;,&lt;br /&gt;
   &amp;quot;license&amp;quot;: &amp;quot;MIT&amp;quot;,&lt;br /&gt;
   &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
     &amp;quot;sass&amp;quot;: &amp;quot;^1.32.6&amp;quot;,&lt;br /&gt;
     &amp;quot;typescript&amp;quot;: &amp;quot;^4.1.3&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: if you not using scss - remove corresponding scripts and deps.&lt;br /&gt;
&lt;br /&gt;
When package.json is created, run &amp;lt;code&amp;gt;npm i&amp;lt;/code&amp;gt; on the root folder to install builders (will generate a node_modules folder).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For Typescript compilation we also need to set up a &amp;lt;code&amp;gt;tsconfig.json&amp;lt;/code&amp;gt; on the root folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tsconfig.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;rootDir&amp;quot;: &amp;quot;.&amp;quot;, &lt;br /&gt;
     &amp;quot;compilerOptions&amp;quot;: {&lt;br /&gt;
       &amp;quot;target&amp;quot;: &amp;quot;es5&amp;quot;,&lt;br /&gt;
       &amp;quot;module&amp;quot;: &amp;quot;none&amp;quot;,&lt;br /&gt;
       &amp;quot;lib&amp;quot;: [&amp;quot;dom&amp;quot;, &amp;quot;esnext&amp;quot;],  &lt;br /&gt;
       &amp;quot;sourceMap&amp;quot;: false,&lt;br /&gt;
       &amp;quot;typeRoots&amp;quot;: [&amp;quot;src/types&amp;quot;, &amp;quot;./types&amp;quot;, &amp;quot;./node_modules/@types&amp;quot;],&lt;br /&gt;
       &amp;quot;outFile&amp;quot;: &amp;quot;YourGameName.js&amp;quot;&lt;br /&gt;
     },&lt;br /&gt;
     &amp;quot;files&amp;quot;: [&lt;br /&gt;
         &amp;quot;src/GameBody.ts&amp;quot;,&lt;br /&gt;
         &amp;quot;src/define.ts&amp;quot;&lt;br /&gt;
     ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: it only works now with es5&lt;br /&gt;
&lt;br /&gt;
If you want to split your code onto multiple files, just add them in the file list (order is important for dependencies, new subpart should go on top of the list). No need to import classes or types from one file to another. In fact, you can&#039;t with this configuration. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create skeleton ==&lt;br /&gt;
When you create your game in BGA Studio, a JS and CSS file are generated. As we will overwrite them with autobuild. You can put the TS/SCSS files on a &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; folder to separate them from built files, but that&#039;s not mandatory.&lt;br /&gt;
Note to myself: check if &#039;src&#039; dir will be svn version control, if not cannot really use it (even if duplicated in git).&lt;br /&gt;
&lt;br /&gt;
=== Typescript file skeleton ===&lt;br /&gt;
Typescript example here have been stripped down of all comments for clarity. &lt;br /&gt;
Your TS code can be splitted in multiple files, you can have a look [https://github.com/thoun/bga-ts-example here] for inspiration.&lt;br /&gt;
To make this page concise, I removed comments and code samples. If it&#039;s your first game, well - don&#039;t do it if your first game - you won&#039;t be able to apply other code samples from docs, they all using dojo style and have to completely rewritten.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/GameBody.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// @ts-ignore&lt;br /&gt;
GameGui = (function () { // this hack required so we fake extend GameGui&lt;br /&gt;
  function GameGui() {}&lt;br /&gt;
  return GameGui;&lt;br /&gt;
})();&lt;br /&gt;
&lt;br /&gt;
// Note: it does not really extend it in es6 way, you cannot call super you have to use dojo way &lt;br /&gt;
class GameBody extends GameGui { &lt;br /&gt;
     constructor() {}&lt;br /&gt;
     &lt;br /&gt;
     public setup(gamedatas: any) {&lt;br /&gt;
         this.setupNotifications();&lt;br /&gt;
     } &lt;br /&gt;
     public onEnteringState(stateName: string, args: any) {}&lt;br /&gt;
     public onLeavingState(stateName: string) {}&lt;br /&gt;
     public onUpdateActionButtons(stateName: string, args: any) {} &lt;br /&gt;
     public setupNotifications() {}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To plug the class with BGA framework, we&#039;ll also create another file:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/define.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;,&amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/stock&amp;quot;&lt;br /&gt;
 ],&lt;br /&gt;
 function (dojo, declare) {&lt;br /&gt;
     return declare(&amp;quot;bgagame.yourgamename&amp;quot;, ebg.core.gamegui, new GameBody());             &lt;br /&gt;
 });&lt;br /&gt;
Copy &amp;lt;code&amp;gt;bgagame.yourgamename&amp;lt;/code&amp;gt; from original JS to avoid name mistakes with letter case.&lt;br /&gt;
&lt;br /&gt;
If you try to compile it you will be missing definitions of bunch of methods and variables for that we will add special ts type definition file .d.ts, this is not a complete version but you can get more complete from git projects below&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/types/bga-framework.d.ts&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare var gameui: GameGui;&lt;br /&gt;
declare var g_replayFrom: number | undefined;&lt;br /&gt;
declare var g_gamethemeurl: string;&lt;br /&gt;
declare var g_themeurl: string;&lt;br /&gt;
declare var g_archive_mode: string;&lt;br /&gt;
declare function _(str: string): string;&lt;br /&gt;
&lt;br /&gt;
declare const define;&lt;br /&gt;
declare const ebg;&lt;br /&gt;
&lt;br /&gt;
declare class GameGui {&lt;br /&gt;
    page_is_unloading: any;&lt;br /&gt;
    game_name: string;&lt;br /&gt;
    instantaneousMode: any;&lt;br /&gt;
    player_id: string;&lt;br /&gt;
    interface_min_width: number;&lt;br /&gt;
    gamedatas: any;&lt;br /&gt;
    &lt;br /&gt;
  &lt;br /&gt;
    isCurrentPlayerActive(): boolean;&lt;br /&gt;
    addActionButton(id: string, label: string, callback: (event?: any) =&amp;gt; void);&lt;br /&gt;
    checkAction(action: any);&lt;br /&gt;
    ajaxcall(url: string, args: object, bind: GameGui, resultHandler: (result: any) =&amp;gt; void, allHandler: any);&lt;br /&gt;
    &lt;br /&gt;
    setup(gamedatas: any): void;&lt;br /&gt;
    onEnteringState(stateName: string, args: any): void;&lt;br /&gt;
    onLeavingState(stateName: string ): void;&lt;br /&gt;
    onUpdateActionButtons(stateName: string, args: any): void;&lt;br /&gt;
    setupNotifications(): void;&lt;br /&gt;
&lt;br /&gt;
    onScriptError(msg: string, url?: string, linenumber?:number);&lt;br /&gt;
    inherited(args: any);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Above is barebone definition of gameui interface,  you can find more complete one here&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless/blob/main/src/types/bga-framework.d.ts&lt;br /&gt;
&lt;br /&gt;
=== SCSS file ===&lt;br /&gt;
Nothing special here, just write classic SCSS (will be compiled by Dart scss) and name it &#039;&#039;&#039;src/yourgamename.scss&#039;&#039;&#039;.&lt;br /&gt;
Original content same as original .css, i.e&lt;br /&gt;
&lt;br /&gt;
  @import url(../../../css/csslayer.css);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your SCSS code can be splitted in multiple files, for example :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;yourgamename.scss&#039;&#039;&#039;&lt;br /&gt;
  @import &#039;gametable&#039;;&lt;br /&gt;
 &lt;br /&gt;
  /* some classes */&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;_gametable.scss&#039;&#039;&#039;&lt;br /&gt;
  /* _gametable related classes */&lt;br /&gt;
&lt;br /&gt;
== Auto build and auto upload ==&lt;br /&gt;
&lt;br /&gt;
=== Auto build JS and CSS files ===&lt;br /&gt;
&lt;br /&gt;
To build and watch (i.e. re-build continiously changed files) run in terminal:&lt;br /&gt;
  npm run watch&lt;br /&gt;
&lt;br /&gt;
Alternately you can make vscode to do it for you by installing Run on Save extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
Note: to build without watch&lt;br /&gt;
  npm run build&lt;br /&gt;
&lt;br /&gt;
=== Auto-upload generated files ===&lt;br /&gt;
You can setup stanard file sync or use vscode SFTP extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hint ===&lt;br /&gt;
Make sure &amp;lt;code&amp;gt;.vscode&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;node_modules&amp;lt;/code&amp;gt; are in &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; if you commit your project somewhere.&lt;br /&gt;
&lt;br /&gt;
=== Code completion ===&lt;br /&gt;
To add code completion on framework, dojo, stock, ... you&#039;ll need more type definition files. Feel free to copy them from [https://github.com/thoun/bga-ts-example this repo] and reference them at the top of files array, even before your subpart files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Referenced Projects ==&lt;br /&gt;
&lt;br /&gt;
* https://github.com/thoun/bga-ts-example&lt;br /&gt;
* https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
* https://github.com/NevinAF/bga-ts-template&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Studio_Cookbook&amp;diff=20769</id>
		<title>BGA Studio Cookbook</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Studio_Cookbook&amp;diff=20769"/>
		<updated>2024-04-12T13:51:25Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Fixed redirect on bga type safe template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
This page is a cookbook of design and implementation recipes for BGA Studio framework.&lt;br /&gt;
For tooling and usage recipes see [[Tools and tips of BGA Studio]].&lt;br /&gt;
If you have your own recipes feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Visual Effects, Layout and Animation ==&lt;br /&gt;
&lt;br /&gt;
=== DOM manipulatons ===&lt;br /&gt;
&lt;br /&gt;
==== Create pieces dynamically (using template) ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.js&lt;br /&gt;
&lt;br /&gt;
Note: this method is recommended by BGA guildlines&lt;br /&gt;
&lt;br /&gt;
Declared js template with variables in .tpl file, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
    // Javascript HTML templates&lt;br /&gt;
    var jstpl_ipiece = &#039;&amp;lt;div class=&amp;quot;${type} ${type}_${color} inlineblock&amp;quot; aria-label=&amp;quot;${name}&amp;quot; title=&amp;quot;${name}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use it like this in .js file&lt;br /&gt;
  div = this.format_block(&#039;jstpl_ipiece&#039;, {&lt;br /&gt;
                                type : &#039;meeple&#039;,&lt;br /&gt;
                                color : &#039;ff0000&#039;,&lt;br /&gt;
                                name : &#039;Bob&#039;,&lt;br /&gt;
                            });&lt;br /&gt;
  &lt;br /&gt;
Then you do whatever you need to do with that div, this one specifically design to go to log entries, because it has embedded title (otherwise its a picture only) and no id.&lt;br /&gt;
&lt;br /&gt;
Note: you could have place this variable in js itself, but keeping it in .tpl allows you to have your js code be free of HTML. Normally it never happens but&lt;br /&gt;
it is good to strive for it.&lt;br /&gt;
Note: you can also use string concatenation, its less readable. You can also use dojo dom object creation api&#039;s but its brutally verbose and its more unreadable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Create pieces dynamically (using string concatenation) ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  div = &amp;quot;&amp;lt;div class=&#039;meeple_&amp;quot;+color+&amp;quot;&#039;&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or modern way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  div = `&amp;lt;div class=&#039;meeple_${color}&#039;&amp;gt;&amp;lt;/div&amp;gt;`;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create all pieces statically ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.css, ggg.view.php (optional) &lt;br /&gt;
&lt;br /&gt;
* Create ALL game pieces in html template (.tpl)&lt;br /&gt;
* ALL pieces should have unique id, and it should be meaningful, i.e. meeple_red_1&lt;br /&gt;
* Do not use inline styling&lt;br /&gt;
* Id of player&#039;s specific pieces should use some sort of &#039;color&#039; identification, since player id cannot be used in static layout, you can use english color name, hex 6 char value, or color &amp;quot;number&amp;quot; (1,2,3...)&lt;br /&gt;
* Pieces should have separated class for its color, type, etc, so it can be easily styled in groups. In example below you now can style all meeples, all red meeples or all red tokens, or all &amp;quot;first&amp;quot; meeples&lt;br /&gt;
&lt;br /&gt;
ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
  &amp;lt;div id=&amp;quot;home_red&amp;quot; class=&amp;quot;home_red home&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;div id=&amp;quot;meeple_red_1&amp;quot; class=&amp;quot;meeple red n1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
     &amp;lt;div id=&amp;quot;meeple_red_2&amp;quot; class=&amp;quot;meeple red n2&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ggg.css:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	width: 32px;&lt;br /&gt;
	height: 39px;&lt;br /&gt;
	background-image: url(img/78_64_stand_meeples.png);&lt;br /&gt;
	background-size: 352px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.meeple.red {&lt;br /&gt;
	background-position: 30% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* There should be straight forward mapping between server id and js id (or 1:1)&lt;br /&gt;
* You place objects in different zones of the layout, and setup css to take care of layout&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.home .meeple{&lt;br /&gt;
   display: inline-block;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If you need to have a temporary object that look like original you can use dojo.clone (and change id to some temp id)&lt;br /&gt;
* If there is lots of repetition or zone grid you can use template generator, but inject style declaration in css instead of inline style for flexibility&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* If you use this model you cannot use premade js components such as Stock and Zone&lt;br /&gt;
* You have to use alternative methods of animation (slightly altered) since default method will leave object with inline style attributes which you don&#039;t need&lt;br /&gt;
&lt;br /&gt;
=== Animation ===&lt;br /&gt;
&lt;br /&gt;
==== Attach to new parent without destroying the object ====&lt;br /&gt;
&lt;br /&gt;
BGA function attachToNewParent for some reason destroys the original, if you want similar function that does not you can use this&lt;br /&gt;
ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        /**&lt;br /&gt;
         * This method will attach mobile to a new_parent without destroying, unlike original attachToNewParent which destroys mobile and&lt;br /&gt;
         * all its connectors (onClick, etc)&lt;br /&gt;
         */&lt;br /&gt;
        attachToNewParentNoDestroy: function (mobile_in, new_parent_in, relation, place_position) {&lt;br /&gt;
&lt;br /&gt;
            const mobile = $(mobile_in);&lt;br /&gt;
            const new_parent = $(new_parent_in);&lt;br /&gt;
&lt;br /&gt;
            var src = dojo.position(mobile);&lt;br /&gt;
            if (place_position)&lt;br /&gt;
                mobile.style.position = place_position;&lt;br /&gt;
            dojo.place(mobile, new_parent, relation);&lt;br /&gt;
            mobile.offsetTop;//force re-flow&lt;br /&gt;
            var tgt = dojo.position(mobile);&lt;br /&gt;
            var box = dojo.marginBox(mobile);&lt;br /&gt;
            var cbox = dojo.contentBox(mobile);&lt;br /&gt;
            var left = box.l + src.x - tgt.x;&lt;br /&gt;
            var top = box.t + src.y - tgt.y;&lt;br /&gt;
&lt;br /&gt;
            mobile.style.position = &amp;quot;absolute&amp;quot;;&lt;br /&gt;
            mobile.style.left = left + &amp;quot;px&amp;quot;;&lt;br /&gt;
            mobile.style.top = top + &amp;quot;px&amp;quot;;&lt;br /&gt;
            box.l += box.w - cbox.w;&lt;br /&gt;
            box.t += box.h - cbox.h;&lt;br /&gt;
            mobile.offsetTop;//force re-flow&lt;br /&gt;
            return box;&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Animation on oversurface ====&lt;br /&gt;
If you use non-absolute position for your game elements (i.e you use layouts) - you cannot really use BGA animation functions. After years of fidding with different options I use&lt;br /&gt;
techique which I call animation on oversurface that works when parents use different zoom, rotation, etc&lt;br /&gt;
&lt;br /&gt;
* You need another layer on top of everything - oversurface&lt;br /&gt;
* We create copy of the object on oversurface - to move&lt;br /&gt;
* We move the real object on final position - but make it invisible for now&lt;br /&gt;
* We move the phantom to final position applying required zoom and rotation (using css animation), then destroy it&lt;br /&gt;
* When animation is done we make original object visible in new position&lt;br /&gt;
&lt;br /&gt;
The code is bit complex it can be found here&lt;br /&gt;
&lt;br /&gt;
https://codepen.io/VictoriaLa/pen/gORvdJo&lt;br /&gt;
&lt;br /&gt;
Game using it: century, ultimaterailroads&lt;br /&gt;
&lt;br /&gt;
==== Scroll element into view ====&lt;br /&gt;
Ingredients: game.js&lt;br /&gt;
&lt;br /&gt;
This function will scroll given node (div) into view and respect replays and archive mode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    scrollIntoViewAfter: function (node, delay) {&lt;br /&gt;
      if (this.instantaneousMode || this.inSetup) {&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      if (typeof g_replayFrom != &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
        $(node).scrollIntoView();&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      if (!delay) delay = 0;&lt;br /&gt;
      setTimeout(() =&amp;gt; {&lt;br /&gt;
        $(node).scrollIntoView({ behavior: &amp;quot;smooth&amp;quot;, block: &amp;quot;center&amp;quot; });&lt;br /&gt;
      }, delay);&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Logs ===&lt;br /&gt;
&lt;br /&gt;
==== Inject icon images in the log ====&lt;br /&gt;
&lt;br /&gt;
Here is an example of what was done for Terra Mystica which is simple and straightforward:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//Define the proper message&lt;br /&gt;
		$message = clienttranslate(&#039;${player_name} gets ${power_income} via Structures&#039;);&lt;br /&gt;
		if ($price &amp;gt; 0) {&lt;br /&gt;
			$this-&amp;gt;DbQuery(&amp;quot;UPDATE player SET player_score = player_score - $price WHERE player_id = $player_id&amp;quot;);&lt;br /&gt;
			$message = clienttranslate(&#039;${player_name} pays ${vp_price} and gets ${power_income} via Structures&#039;);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
// Notify&lt;br /&gt;
		$this-&amp;gt;notifyAllPlayers( &amp;quot;powerViaStructures&amp;quot;, $message, array(&lt;br /&gt;
			&#039;i18n&#039; =&amp;gt; array( ),&lt;br /&gt;
			&#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
			&#039;player_name&#039; =&amp;gt; $this-&amp;gt;getUniqueValueFromDb( &amp;quot;SELECT player_name FROM player WHERE player_id = $player_id&amp;quot; ),&lt;br /&gt;
			&#039;power_tokens&#039; =&amp;gt; $power_tokens,&lt;br /&gt;
			&#039;vp_price&#039; =&amp;gt; $this-&amp;gt;getLogsVPAmount($price),&lt;br /&gt;
			&#039;power_income&#039; =&amp;gt; $this-&amp;gt;getLogsPowerAmount($power_income),&lt;br /&gt;
			&#039;newScore&#039; =&amp;gt; $this-&amp;gt;getUniqueValueFromDb( &amp;quot;SELECT player_score FROM player WHERE player_id = $player_id&amp;quot; ),&lt;br /&gt;
			&#039;counters&#039; =&amp;gt; $this-&amp;gt;getGameCounters(null),&lt;br /&gt;
		) );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With some functions to have the needed html added inside the substitution variable, such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function getLogsPowerAmount( $amount ) {&lt;br /&gt;
		return &amp;quot;&amp;lt;div class=&#039;tmlogs_icon&#039; title=&#039;Power&#039;&amp;gt;&amp;lt;div class=&#039;power_amount&#039;&amp;gt;$amount&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: injecting html from php is not ideal but easy, if you want more clean solution, use method below but it is a lot more sophisticated.&lt;br /&gt;
&lt;br /&gt;
==== Inject images and styled html in the log ====&lt;br /&gt;
&lt;br /&gt;
{{InfoBox|title=Warning — Translation|maxWidth=500|color=#c00|body=&#039;&#039;&#039;In order to prevent interference with the translation process, keep in mind that you must only apply modifications to the args object, and not try to substitute the keys (the &amp;lt;code&amp;gt;${player_name}&amp;lt;/code&amp;gt; parts of your string) in the log string.&#039;&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
So you want nice pictures in the game log. What do you do? The first idea that comes to mind is to send html from php in notifications (see method above). &lt;br /&gt;
&lt;br /&gt;
This is a bad idea for many reasons:&lt;br /&gt;
&lt;br /&gt;
* It&#039;s bad architecture. ui elements leak into the server, and now you have to manage the ui in multiple places.&lt;br /&gt;
* If you decided to change something in the ui in future version, replay logs for old games and tutorials may not work, since they use stored notifications.&lt;br /&gt;
* Log previews for old games become unreadable. (This is the log state before you enter the game replay, which is useful for troubleshooting and game analysis.)&lt;br /&gt;
* It&#039;s more data to transfer and store in the db.&lt;br /&gt;
* It&#039;s a nightmare for translators.&lt;br /&gt;
&lt;br /&gt;
So what else can you do? You can use client side log injection to intercept log arguments (which come from the server) and replace them with html on the client side. Here are three different method you can use to achieve this.&lt;br /&gt;
&lt;br /&gt;
===== Override &amp;lt;code&amp;gt;this.format_string_recursive()&amp;lt;/code&amp;gt; method =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php&lt;br /&gt;
&lt;br /&gt;
I use this recipe for &#039;&#039;&#039;client side log injection&#039;&#039;&#039; to intercept log arguments (which come from the server) and replace them with html on the client side.&lt;br /&gt;
&lt;br /&gt;
[[File:clientloginjection.png|left]] &lt;br /&gt;
&lt;br /&gt;
ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
        /** Override this function to inject html into log items. This is a built-in BGA method.  */&lt;br /&gt;
&lt;br /&gt;
        /* @Override */&lt;br /&gt;
        format_string_recursive : function format_string_recursive(log, args) {&lt;br /&gt;
            try {&lt;br /&gt;
                if (log &amp;amp;&amp;amp; args &amp;amp;&amp;amp; !args.processed) {&lt;br /&gt;
                    args.processed = true;&lt;br /&gt;
                    &lt;br /&gt;
&lt;br /&gt;
                    // list of special keys we want to replace with images&lt;br /&gt;
                    var keys = [&#039;place_name&#039;,&#039;token_name&#039;];&lt;br /&gt;
                    &lt;br /&gt;
                  &lt;br /&gt;
                    for ( var i in keys) {&lt;br /&gt;
                        var key = keys[i];&lt;br /&gt;
                        key in args &amp;amp;&amp;amp; args[key] = this.getTokenDiv(key, args);                            &lt;br /&gt;
&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            } catch (e) {&lt;br /&gt;
                console.error(log,args,&amp;quot;Exception thrown&amp;quot;, e.stack);&lt;br /&gt;
            }&lt;br /&gt;
            return this.inherited({callee: format_string_recursive}, arguments);&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; In the &#039;&#039;format_string_recursive&#039;&#039; method, the &#039;args&#039; parameter will only contain arguments passed to it from the notify method in ggg.game.php (see below).&lt;br /&gt;
&lt;br /&gt;
The &#039;log&#039; parameter is the actual string that is inserted into the logs. You can perform additional js string manipulation on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        getTokenDiv : function(key, args) {&lt;br /&gt;
            // ... implement whatever html you want here, example from sharedcode.js&lt;br /&gt;
            var token_id = args[key];&lt;br /&gt;
            var item_type = getPart(token_id,0);&lt;br /&gt;
            var logid = &amp;quot;log&amp;quot; + (this.globalid++) + &amp;quot;_&amp;quot; + token_id;&lt;br /&gt;
            switch (item_type) {&lt;br /&gt;
                case &#039;wcube&#039;:&lt;br /&gt;
                    var tokenDiv = this.format_block(&#039;jstpl_resource_log&#039;, {&lt;br /&gt;
                        &amp;quot;id&amp;quot; : logid,&lt;br /&gt;
                        &amp;quot;type&amp;quot; : &amp;quot;wcube&amp;quot;,&lt;br /&gt;
                        &amp;quot;color&amp;quot; : getPart(token_id,1),&lt;br /&gt;
                    });&lt;br /&gt;
                    return tokenDiv;&lt;br /&gt;
             &lt;br /&gt;
                case &#039;meeple&#039;:&lt;br /&gt;
                    if ($(token_id)) {&lt;br /&gt;
                        var clone = dojo.clone($(token_id));&lt;br /&gt;
    &lt;br /&gt;
                        dojo.attr(clone, &amp;quot;id&amp;quot;, logid);&lt;br /&gt;
                        this.stripPosition(clone);&lt;br /&gt;
                        dojo.addClass(clone, &amp;quot;logitem&amp;quot;);&lt;br /&gt;
                        return clone.outerHTML;&lt;br /&gt;
                    }&lt;br /&gt;
                    break;&lt;br /&gt;
     &lt;br /&gt;
                default:&lt;br /&gt;
                    break;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            return &amp;quot;&#039;&amp;quot; + this.clienttranslate_string(this.getTokenName(token_id)) + &amp;quot;&#039;&amp;quot;;&lt;br /&gt;
       },&lt;br /&gt;
       getTokenName : function(key) {&lt;br /&gt;
           return this.gamedatas.token_types[key].name; // get name for the key, from static table for example&lt;br /&gt;
       },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in this case the server simply injects token_id as a name, and the client substitutes it for the translated name or the picture.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ggg.game.php:&lt;br /&gt;
&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;playerLog&#039;,clienttranslate(&#039;Game moves ${token_name}&#039;),[&#039;token_name&#039;=&amp;gt;$token_id]);&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; As noted above, only arguments actually passed by this method are available to the args parameter received in the client-side &#039;&#039;format_string_recursive&#039;&#039; method.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is the case that you want to pass arguments that are not actually included in the output message. For example, suppose we have a method like this:&lt;br /&gt;
&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;tokenPlaced&#039;,clienttranslate(&#039;Player placed ${token_name}&#039;),array(&lt;br /&gt;
              &#039;token_name&#039; =&amp;gt; $token_id,&lt;br /&gt;
              &#039;zone_played&#039; =&amp;gt; $zone);&lt;br /&gt;
&lt;br /&gt;
This will output &amp;quot;Player placed ${token_name}&amp;quot; in the log, and if we subscribe to a notification method activated by the &amp;quot;tokenPlaced&amp;quot; event in the client-side code, that method can make use of the &#039;zone_played&#039; argument. &lt;br /&gt;
&lt;br /&gt;
Now if you want to make some really cool things with game log, most probably you would need more arguments than are included in log message. The problem with that,&lt;br /&gt;
it will work at first, but if you reload game using F5 or when the game loads in turn based mode, you will loose your additional parameters, why? Because when game reloads it does not actually send same notifications, it sends special &amp;quot;hitstorical_log&amp;quot; notification where all  parameters not listed in the message are removed. In example above, field zone_played would be removed from historical log as it is not included in message of the notification. You can till preserve specific arguments in historical log by adding special field preserve to notification arguments like this:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;tokenPlaced&#039;,clienttranslate(&#039;Player placed ${token_name}&#039;),array(&lt;br /&gt;
              &#039;token_name&#039; =&amp;gt; $token_id,&lt;br /&gt;
              &#039;zone_played&#039; =&amp;gt; $zone,&lt;br /&gt;
              &#039;preserve&#039; =&amp;gt; [ &#039;zone_played&#039; ]&lt;br /&gt;
           );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you can use zone_played in format_string_recursive even in historical logs.&lt;br /&gt;
&lt;br /&gt;
===== Use &amp;lt;code&amp;gt;:formatFunction&amp;lt;/code&amp;gt; option provided by &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg_ggg.tpl, ggg.css&lt;br /&gt;
&lt;br /&gt;
The above method will work in most of the cases, but if you use dotted keys such as &amp;lt;code&amp;gt;${card.name}&amp;lt;/code&amp;gt; (which is supported by the framework, for private state args), the key won&#039;t be substituted because the &amp;lt;code&amp;gt;key in arg&amp;lt;/code&amp;gt; test will fail. If so you need to rely either on this way, or the one after.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING:&#039;&#039;&#039; using this method on an already advanced project will require you to go through all your notifications to change keys !&lt;br /&gt;
&lt;br /&gt;
Under the hood, the &#039;&#039;&#039;this.format_string_recursive()&#039;&#039;&#039; function calls the &#039;&#039;&#039;dojo.string.substitute&#039;&#039;&#039; method which substitutes &amp;lt;code&amp;gt;${keys}&amp;lt;/code&amp;gt; with the value provided. If you take a look at the [https://dojotoolkit.org/reference-guide/1.7/dojo/string.html#substitute documentation] and [https://github.com/dojo/dojo/blob/c3ceb017cfa25b703f5662dc83d1c8aae9bc5d81/string.js#L163 source code] you can notice that the key can be suffixed with a colon (&amp;lt;code&amp;gt;:&amp;lt;/code&amp;gt;) followed by a function name. This will allow you to specify directly in the substitution string which keys need HTML injection.&lt;br /&gt;
&lt;br /&gt;
First of all, you need to define your formatting function in the ggg.js file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[[ggg.js]]&lt;br /&gt;
        getTokenDiv : function(value, key) {&lt;br /&gt;
            //This is only an example implementation, you need to write your own.&lt;br /&gt;
            //The method should return HTML code&lt;br /&gt;
            switch (key) {&lt;br /&gt;
                case &#039;html_injected_argument1&#039;:&lt;br /&gt;
                    return this.format_block(&#039;jstpl_HTMLLogElement1&#039;,{value: value});&lt;br /&gt;
                case &#039;html_injected_argument2&#039;:&lt;br /&gt;
                    return this.format_block(&#039;jstpl_HTMLLogElement2&#039;,{value: value});&lt;br /&gt;
                ...&lt;br /&gt;
            }&lt;br /&gt;
       }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously you need to define the appropriate templates in the ggg_ggg.tpl file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[[ggg_ggg.tpl]]&lt;br /&gt;
let jstpl_HTMLLogElement1 = &#039;&amp;lt;div class=&amp;quot;log-element log-element-1-${value}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
let jstpl_HTMLLogElement2 = &#039;&amp;lt;div class=&amp;quot;log-element log-element-2-${value}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And the appropriate classes in ggg.css.&lt;br /&gt;
&lt;br /&gt;
Then you need to add the &amp;lt;code&amp;gt;dojo/aspect&amp;lt;/code&amp;gt; module at the top of the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;quot;dojo/aspect&amp;quot;,&amp;lt;/span&amp;gt;                 //MUST BE IN THIRD POSITION&#039;&#039;&#039; (see [[#Including your own JavaScript module (II)|below]])&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
 ], function (dojo, declare, &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&#039;&#039;&#039;aspect&#039;&#039;&#039;&amp;lt;/span&amp;gt;) {&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
And you also need to add the following code in your &amp;lt;code&amp;gt;contructor&amp;lt;/code&amp;gt; method in the ggg.js:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         constructor: function(){&lt;br /&gt;
&lt;br /&gt;
             // ... skipped code ...&lt;br /&gt;
             let gameObject = this;            //Needed as the this object in aspect.before will not refer to the game object in which the formatting function resides&lt;br /&gt;
             aspect.before(dojo.string, &amp;quot;substitute&amp;quot;, function(template, map, transform) {      //This allows you to modify the arguments of the dojo.string.substitute method before they&#039;re actually passed to it&lt;br /&gt;
                 return [template, map, transform, gameObject];&lt;br /&gt;
             });&lt;br /&gt;
&lt;br /&gt;
Now you&#039;re all set to inject HTML in your logs. To actually achieve this, you must specify the function name with the key like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.game.php]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 $this-&amp;gt;notifyAllPlayers(&amp;quot;notificationName&amp;quot;, clienttranslate(&amp;quot;This log message contains ${plainTextArgument} and the following will receive HTML injection: ${html_injected_argument1:getTokenDiv}&amp;quot;), [&lt;br /&gt;
     &amp;quot;plainTextArgument&amp;quot; =&amp;gt; &amp;quot;some plain text here&amp;quot;,&lt;br /&gt;
     &amp;quot;html_injected_argument1&amp;quot; =&amp;gt; &amp;quot;some value used by getTokenDiv&amp;quot;,&lt;br /&gt;
 ]);&lt;br /&gt;
&lt;br /&gt;
You&#039;re not limited writing only one function, you can write as many functions as you like, and have them each inject a specific type of HTML. You just need to specify the relevant function name after the column in the substitution key.&lt;br /&gt;
&lt;br /&gt;
===== Use &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; argument of &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg_ggg.tpl, ggg.css&lt;br /&gt;
&lt;br /&gt;
This method is also relying on the use of &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; by the framework, and will use the &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; argument, which, accordting to [https://github.com/dojo/dojo/blob/c3ceb017cfa25b703f5662dc83d1c8aae9bc5d81/string.js#L163 source code] and [https://dojotoolkit.org/reference-guide/1.7/dojo/string.html#substitute documentation] will be run on all the messages going through dojo.string.substitute.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING:&#039;&#039;&#039; This method will be applied to all strings that go through dojo.string.substitute. As such you must take extra care not to substitute keys that may be used by the framework (i.e. ${id}). In order to do so, a good practise would be to prefix all keys that need substitution with a trigram of the game name.&lt;br /&gt;
&lt;br /&gt;
Since all the keys will be fed to the tranform function, by default, it must return the value, substituted or not per your needs. You can define the function like this in the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         getTokenDiv : function(value, key) {&lt;br /&gt;
             //This is only an example implementation, you need to write your own.&lt;br /&gt;
             //The method should return HTML code&lt;br /&gt;
             switch (key) {&lt;br /&gt;
                 case &#039;html_injected_argument1&#039;:&lt;br /&gt;
                     return this.format_block(&#039;jstpl_HTMLLogElement1&#039;,{value: value});&lt;br /&gt;
                 case &#039;html_injected_argument2&#039;:&lt;br /&gt;
                     return this.format_block(&#039;jstpl_HTMLLogElement2&#039;,{value: value});&lt;br /&gt;
                 ...&lt;br /&gt;
                 default:&lt;br /&gt;
                     return value; //Needed otherwise regular strings won&#039;t appear since since the value isn&#039;t returned by the function&lt;br /&gt;
             }&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
The templates must be defined in the ggg_ggg.tpl file and the corresponding CSS classes in the ggg.css file.&lt;br /&gt;
&lt;br /&gt;
You need to add the following code at the beginning of the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;quot;dojo/aspect&amp;quot;,&amp;lt;/span&amp;gt;                 //MUST BE IN THIRD POSITION&#039;&#039;&#039; (see [[#Including your own JavaScript module (II)|below]])&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
 ], function (dojo, declare, &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&#039;&#039;&#039;aspect&#039;&#039;&#039;&amp;lt;/span&amp;gt;) {&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
And the following code to the &amp;lt;code&amp;gt;constructor&amp;lt;/code&amp;gt; method in ggg.js:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         constructor: function(){&lt;br /&gt;
             // ... skipped code ...&lt;br /&gt;
             let transformFunction = dojo.hitch(this, &amp;quot;getTokenDiv&amp;quot;);          //Needed as the this object in aspect.before will not refer to the game object in which the formatting function resides&lt;br /&gt;
             aspect.before(dojo.string, &amp;quot;substitute&amp;quot;, function(template, map, transform) {&lt;br /&gt;
                 if (undefined === transform) {    //Check for a transform function presence, just in case&lt;br /&gt;
                     return [template, map, transformFunction];&lt;br /&gt;
                 }&lt;br /&gt;
             });&lt;br /&gt;
&lt;br /&gt;
Then you&#039;re all set for log injection, no need to change anything on the PHP side.&lt;br /&gt;
&lt;br /&gt;
==== Processing logs on re-loading ====&lt;br /&gt;
&lt;br /&gt;
You rarely need to process logs when reloading, but if you want to do something fancy you may have to do it after logs are loaded. &lt;br /&gt;
Logs are loaded asyncronously so you have to listen for logs to be fully loaded.&lt;br /&gt;
Unfortunately there is no direct way of doing it so this is the hack.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hack alert&#039;&#039;&#039; - this extends undocumented function and may be broken when framework is updated&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			/*&lt;br /&gt;
  			* [Undocumented] Override BGA framework functions to call onLoadingLogsComplete when loading is done&lt;br /&gt;
                        @Override&lt;br /&gt;
   			*/&lt;br /&gt;
			setLoader: function(image_progress, logs_progress) {&lt;br /&gt;
				this.inherited(arguments); // required, this is &amp;quot;super()&amp;quot; call, do not remove&lt;br /&gt;
				//console.log(&amp;quot;loader&amp;quot;, image_progress, logs_progress)&lt;br /&gt;
				if (!this.isLoadingLogsComplete &amp;amp;&amp;amp; logs_progress &amp;gt;= 100) {&lt;br /&gt;
					this.isLoadingLogsComplete = true; // this is to prevent from calling this more then once&lt;br /&gt;
					this.onLoadingLogsComplete();&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&lt;br /&gt;
			onLoadingLogsComplete: function() {&lt;br /&gt;
				console.log(&#039;Loading logs complete&#039;);&lt;br /&gt;
				// do something here&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Player Panel ===&lt;br /&gt;
&lt;br /&gt;
==== Inserting non-player panel ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg_ggg.tpl&lt;br /&gt;
&lt;br /&gt;
If you want to insert non-player panel on the right side (for example to hold extra preferences, zooming controls, etc)&lt;br /&gt;
&lt;br /&gt;
this can go pretty much anywhere in template it will be moved later&lt;br /&gt;
&lt;br /&gt;
ggg_ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&#039;player_board_config&#039; id=&amp;quot;player_board_config&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;!-- here is whatever you want, buttons just example --&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;zoom-out&amp;quot; class=&amp;quot; fa fa-search-minus fa-2x config-control&amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;zoom-in&amp;quot; class=&amp;quot; fa fa-search-plus fa-2x config-control&amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;show-settings&amp;quot; class=&amp;quot;fa fa-cog fa-2x config-control &amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
some hackery required in js&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* @Override */&lt;br /&gt;
	updatePlayerOrdering() {&lt;br /&gt;
		this.inherited(arguments);&lt;br /&gt;
		dojo.place(&#039;player_board_config&#039;, &#039;player_boards&#039;, &#039;first&#039;);&lt;br /&gt;
	},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Images and Icons ===&lt;br /&gt;
&lt;br /&gt;
==== Accessing images from js ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
     // your game resources&lt;br /&gt;
     &lt;br /&gt;
     var my_img = &#039;&amp;lt;img src=&amp;quot;&#039;+g_gamethemeurl+&#039;img/cards.jpg&amp;quot;/&amp;gt;&#039;;&lt;br /&gt;
     &lt;br /&gt;
     // shared resources&lt;br /&gt;
     var my_help_img = &amp;quot;&amp;lt;img class=&#039;imgtext&#039; src=&#039;&amp;quot; + g_themeurl + &amp;quot;img/layout/help_click.png&#039; alt=&#039;action&#039; /&amp;gt; &amp;lt;span class=&#039;tooltiptext&#039;&amp;gt;&amp;quot; +&lt;br /&gt;
                    text + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== High-Definition Graphics ====&lt;br /&gt;
&lt;br /&gt;
Some users will have screens which can display text and images at a greater resolution than the usual 72 dpi, e.g. the &amp;quot;Retina&amp;quot; screens on the 5k iMac, all iPads, and high-DPI screens on laptops from many manufacturers. If you can get art assets at this size, they will make your game look extra beautiful. You &#039;&#039;could&#039;&#039; just use large graphics and scale them down, but that would increase the download time and bandwidth for users who can&#039;t display them. Instead, a good way is to prepare a separate graphics file at exactly twice the size you would use otherwise, and add &amp;quot;@2x&amp;quot; at the end of the filename, e.g. if pieces.png is 240x320, then pieces@2x.png is 480x640.&lt;br /&gt;
&lt;br /&gt;
There are two changes required in order to use the separate graphics files. First in your css, where you use a file, add a media query which overrides the original definition and uses the bigger version on devices which can display them. Ensuring that the &amp;quot;background-size&amp;quot; attribute is set means that the size of the displayed object doesn&#039;t change, but only is drawn at the improved dot pitch.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.piece {&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/pieces.png&#039;);&lt;br /&gt;
    background-size:240px 320px;&lt;br /&gt;
    z-index: 10;&lt;br /&gt;
}&lt;br /&gt;
@media (-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 192dpi)&lt;br /&gt;
{&lt;br /&gt;
    .piece {&lt;br /&gt;
        background-image: url(&#039;img/pieces@2x.png&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Secondly, in your setup function in javascript, you must ensure than only the appropriate one version of the file gets pre-loaded (otherwise you more than waste the bandwidth saved by maintaining the standard-resolution file). Note that the media query is the same in both cases:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            var isRetina = &amp;quot;(-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 192dpi)&amp;quot;;&lt;br /&gt;
            if (window.matchMedia(isRetina).matches)&lt;br /&gt;
            {&lt;br /&gt;
                this.dontPreloadImage( &#039;pieces.png&#039; );&lt;br /&gt;
                this.dontPreloadImage( &#039;board.jpg&#039; );&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                this.dontPreloadImage( &#039;pieces@2x.png&#039; );&lt;br /&gt;
                this.dontPreloadImage( &#039;board@2x.jpg&#039; );&lt;br /&gt;
            }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using CSS to create different colors of game pieces if you have only white piece ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
background-color: #${color}; &lt;br /&gt;
background-blend-mode: multiply;&lt;br /&gt;
background-image: url( &#039;img/mypiece.png&#039;);&lt;br /&gt;
mask: url(&#039;img/mypiece.png&#039;);&lt;br /&gt;
-webkit-mask: url(&#039;img/mypiece.png&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ${color} - is color you want&lt;br /&gt;
&lt;br /&gt;
Note: piece has to be white (shades of gray). Sprite can be used too, just add add blackground-position as usual.&lt;br /&gt;
&lt;br /&gt;
==== Accessing player avatar URLs ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      getPlayerAvatar(playerId) {&lt;br /&gt;
         let avatarURL = &#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
         if (null != $(&#039;avatar_&#039; + playerId)) {&lt;br /&gt;
            let smallAvatarURL = dojo.attr(&#039;avatar_&#039; + playerId, &#039;src&#039;);&lt;br /&gt;
            avatarURL = smallAvatarURL.replace(&#039;_32.&#039;, &#039;_184.&#039;);&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
            avatarURL = &#039;https://x.boardgamearena.net/data/data/avatar/default_184.jpg&#039;;&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
         return avatarURL;&lt;br /&gt;
      },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note:  This gets avatar URLs at 184x184 resolution.  You can also use 92, 50, and 32 depending on which resolution you want.&lt;br /&gt;
&lt;br /&gt;
==== Adding Image buttons ====&lt;br /&gt;
&lt;br /&gt;
Its pretty trivial but just in case you need a working function:&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
                addImageActionButton: function (id, div_html, handler) { // div_html is string not node&lt;br /&gt;
                    this.addActionButton(id, div_html, handler, &#039;&#039;, false, &#039;gray&#039;); &lt;br /&gt;
                    dojo.style(id, &amp;quot;border&amp;quot;, &amp;quot;none&amp;quot;); // remove ugly border&lt;br /&gt;
                    dojo.addClass(id, &amp;quot;bgaimagebutton&amp;quot;); // add css class to do more styling&lt;br /&gt;
                    return $(id); // return node for chaining&lt;br /&gt;
                },&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    this.addImageActionButton(&#039;button_coin&#039;,&amp;quot;&amp;lt;div class=&#039;coin&#039;&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;, ()=&amp;gt;{ alert(&#039;Ha!&#039;); });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Other Fluff ===&lt;br /&gt;
&lt;br /&gt;
==== Use thematic fonts ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.css&lt;br /&gt;
&lt;br /&gt;
Sometime game elements use specific fonts of text, if you want to match it up you can load some specific font (IMPORTANT: from some &#039;&#039;&#039;free font&#039;&#039;&#039; source. See notes below).&lt;br /&gt;
&lt;br /&gt;
[[File:Dragonline_font.png]]&lt;br /&gt;
&lt;br /&gt;
.css&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* latin-ext */&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: 400;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(https://fonts.gstatic.com/s/qwigley/v6/2Dy1Unur1HJoklbsg4iPJ_Y6323mHUZFJMgTvxaG2iE.woff2) format(&#039;woff2&#039;);&lt;br /&gt;
  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;&lt;br /&gt;
}&lt;br /&gt;
/* latin */&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: normal;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(https://fonts.gstatic.com/s/qwigley/v6/gThgNuQB0o5ITpgpLi4Zpw.woff2) format(&#039;woff2&#039;);&lt;br /&gt;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;&lt;br /&gt;
}&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: normal;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(http://ff.static.1001fonts.net/q/w/qwigley.regular.ttf) format(&#039;ttf&#039;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.zone_title {&lt;br /&gt;
	display: inline-block;&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	font: italic 32px/32px &amp;quot;Qwigley&amp;quot;, cursive;	   &lt;br /&gt;
	height: 32px;&lt;br /&gt;
	width: auto;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB:&#039;&#039;&#039; if you need to include a font that&#039;s not available online, an extra action will be needed from an admin. Please include the font file(s) in your img directory, and mention it to admins when requesting your game to be moved to alpha. &#039;&#039;&#039;Please remember that the font has to be free, and include a .txt with all appropriate license information about the font.&#039;&#039;&#039;&lt;br /&gt;
You can look for free fonts (for example) on https://fonts.google.com or https://www.fontsquirrel.com/)&lt;br /&gt;
&lt;br /&gt;
===== Content Security Policy =====&lt;br /&gt;
&lt;br /&gt;
BGA runs a Content Security Policy which will limit the origins from which you can load external fonts, in order to prevent license abuse.&lt;br /&gt;
&lt;br /&gt;
The CSP is a whitelist of allowed origins. To see the list, view the response headers of any page on Studio, and look for the &amp;quot;Content-Security-Policy&amp;quot; header.&lt;br /&gt;
&lt;br /&gt;
You will specifically want to check for the font-src token within these headers, and limit any external fonts to these sources.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This list is subject to change&#039;&#039;&#039; but as of the time of writing, the only acceptabled external sites are use.typekit.net and fonts.gstatic.com.&lt;br /&gt;
&lt;br /&gt;
=== Use player color in template ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.view.php&lt;br /&gt;
&lt;br /&gt;
.view.php:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function build_page($viewArgs) {&lt;br /&gt;
        // Get players &amp;amp; players number&lt;br /&gt;
        $players = $this-&amp;gt;game-&amp;gt;loadPlayersBasicInfos();&lt;br /&gt;
        $players_nbr = count($players);&lt;br /&gt;
        /**&lt;br /&gt;
         * ********* Place your code below: ***********&lt;br /&gt;
         */&lt;br /&gt;
        &lt;br /&gt;
        // Set PCOLOR to the current player color hex&lt;br /&gt;
        global $g_user;&lt;br /&gt;
        $cplayer = $g_user-&amp;gt;get_id();&lt;br /&gt;
        if (array_key_exists($cplayer, $players)) { // may be not set if spectator&lt;br /&gt;
            $player_color = $players [$cplayer] [&#039;player_color&#039;];&lt;br /&gt;
        } else {&lt;br /&gt;
            $player_color = &#039;ffffff&#039;; // spectator&lt;br /&gt;
        }&lt;br /&gt;
        $this-&amp;gt;tpl [&#039;PCOLOR&#039;] = $player_color;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scale to fit for big boards ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lets say you have huge game board, and lets say you want it to be 1400px wide. Besides the board there will be side bar which is 240 and trim. &lt;br /&gt;
My display is 1920 wide so it fits, but there is big chance other people won&#039;t have that width. What do you do?&lt;br /&gt;
&lt;br /&gt;
You have to decide:&lt;br /&gt;
* If board does not fit you want scale whole thing down, the best way is probably use viewport (see https://en.doc.boardgamearena.com/Your_game_mobile_version)&lt;br /&gt;
* You can leave the board as is and make sure it is scrollable horizonatally&lt;br /&gt;
* You add custom scale just for the board (can add user controls  - and hook to transform: scale())&lt;br /&gt;
&lt;br /&gt;
I tried to auto-scale but this just does work, too many variables - browser zoom, 3d mode, viewport, custom bga scaling, devicePixelRatio - all create some impossible coctail of zooming...&lt;br /&gt;
Here is scaling functing for custom user scaling&lt;br /&gt;
&lt;br /&gt;
ggg_ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;thething&amp;quot; class=&amp;quot;thething&amp;quot;&amp;gt;&lt;br /&gt;
            ... everything else you declare ...&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    onZoomPlus: function() {&lt;br /&gt;
       this.setZoom(this.zoom + 0.1);&lt;br /&gt;
    },&lt;br /&gt;
    onZoomMinus: function() {&lt;br /&gt;
       this.setZoom(this.zoom - 0.1);&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    setZoom: function (zoom) {&lt;br /&gt;
      zoom = parseInt(zoom) || 0;&lt;br /&gt;
      if (zoom === 0 || zoom &amp;lt; 0.1 || zoom &amp;gt; 10) {&lt;br /&gt;
        zoom = 1;&lt;br /&gt;
      }&lt;br /&gt;
      this.zoom = zoom;&lt;br /&gt;
      var inner = document.getElementById(&amp;quot;thething&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
      if (zoom == 1) {&lt;br /&gt;
        inner.style.removeProperty(&amp;quot;transform&amp;quot;);&lt;br /&gt;
        inner.style.removeProperty(&amp;quot;width&amp;quot;);&lt;br /&gt;
      } else {&lt;br /&gt;
        inner.style.transform = &amp;quot;scale(&amp;quot; + zoom + &amp;quot;)&amp;quot;;&lt;br /&gt;
        inner.style.transformOrigin = &amp;quot;0 0&amp;quot;;&lt;br /&gt;
        inner.style.width = 100 / zoom + &amp;quot;%&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
      localStorage.setItem(`${this.game_name}_zoom`, &amp;quot;&amp;quot; + this.zoom);&lt;br /&gt;
      this.onScreenWidthChange();&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dynamic tooltips ===&lt;br /&gt;
&lt;br /&gt;
If you really need a dynamic tooltip you can use this technique. (Only use it if the static tooltips provided by the BGA framework are not sufficient.)&lt;br /&gt;
&lt;br /&gt;
            new dijit.Tooltip({&lt;br /&gt;
                connectId: [&amp;quot;divItemId&amp;quot;],&lt;br /&gt;
                getContent: function(matchedNode){&lt;br /&gt;
                    return &amp;quot;... calculated ...&amp;quot;; &lt;br /&gt;
                }&lt;br /&gt;
            });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is an out-of-the-box djit.Tooltip. It has a &#039;&#039;getContent&#039;&#039; method which is called dynamically.&lt;br /&gt;
&lt;br /&gt;
The string returned by getContent() becomes the innerHTML of the tooltip, so it can be anything. In this example matchedNode is a dojo node representing dom object with id of &amp;quot;divItemId&amp;quot; but there are more parameters which I am not posting here which allows more sophisticated subnode queries (i.e. you can attach tooltip to all nodes with class or whatever).&lt;br /&gt;
&lt;br /&gt;
[https://dojotoolkit.org/reference-guide/1.10/dijit/Tooltip.html dijit.Tooltip]&lt;br /&gt;
&lt;br /&gt;
It&#039;s not part of the BGA API so use at your own risk.&lt;br /&gt;
&lt;br /&gt;
=== Rendering text with players color and proper background ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        /* Implementation of proper colored You with background in case of white or light colors  */&lt;br /&gt;
 &lt;br /&gt;
        divYou: function() {&lt;br /&gt;
            var color = this.gamedatas.players[this.player_id].color;&lt;br /&gt;
            var color_bg = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.gamedatas.players[this.player_id] &amp;amp;&amp;amp; this.gamedatas.players[this.player_id].color_back) {&lt;br /&gt;
                color_bg = &amp;quot;background-color:#&amp;quot; + this.gamedatas.players[this.player_id].color_back + &amp;quot;;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            var you = &amp;quot;&amp;lt;span style=\&amp;quot;font-weight:bold;color:#&amp;quot; + color + &amp;quot;;&amp;quot; + color_bg + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + __(&amp;quot;lang_mainsite&amp;quot;, &amp;quot;You&amp;quot;) + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
            return you;&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        /* Implementation of proper colored player name with background in case of white or light colors  */&lt;br /&gt;
&lt;br /&gt;
        divColoredPlayer: function(player_id) {&lt;br /&gt;
            var color = this.gamedatas.players[player_id].color;&lt;br /&gt;
            var color_bg = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.gamedatas.players[player_id] &amp;amp;&amp;amp; this.gamedatas.players[player_id].color_back) {&lt;br /&gt;
                color_bg = &amp;quot;background-color:#&amp;quot; + this.gamedatas.players[player_id].color_back + &amp;quot;;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            var div = &amp;quot;&amp;lt;span style=\&amp;quot;color:#&amp;quot; + color + &amp;quot;;&amp;quot; + color_bg + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + this.gamedatas.players[player_id].name + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
            return div;&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cool realistic shadow effect with CSS ===&lt;br /&gt;
&lt;br /&gt;
==== Rectangles and circles ====&lt;br /&gt;
&lt;br /&gt;
It is often nice to have a drop shadow around tiles and tokens, to separate them from the table visually. It is very easy to add a shadow to rectangular elements, just add this to your css:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.xxx-tile {&lt;br /&gt;
    box-shadow: 3px 3px 3px #000000a0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
box-shadow obeys &#039;&#039;&#039;border-radius&#039;&#039;&#039; of the element, so it will look good for rounded rectangles, and hence also circles (if border-radius is set appropriately).&lt;br /&gt;
&lt;br /&gt;
box-shadow also supports various other parameters and can be used to achieve effects such as glowing, borders, inner shadows etc. If you need to animate a box-shadow, you may be able to get better performance (avoiding redraws) if you attach the shadow to another element (possibly an ::after pseudo-element) and change only the &#039;&#039;&#039;opacity&#039;&#039;&#039; of that element.&lt;br /&gt;
&lt;br /&gt;
==== Irregular Shapes ====&lt;br /&gt;
&lt;br /&gt;
If you wish to make a shadow effect for game pieces that are not a rectangle, but your game pieces are drawn from rectangles in a PNG image, you can apply the shadow to the piece using any art package and save it inside the image. This usually will yield the best performance. Remember to account for the size of the shadow when you lay out images in the sprite sheet.&lt;br /&gt;
&lt;br /&gt;
However that sometimes will not be an option, for example if the image needs to be rotated while the shadow remains offset in the same direction. In this case, one option is to not use box-shadow but use filter, which is supported by recent major browsers.  This way, you can use the alpha channel of your element to drop a shadow.  This even work for transparent backgrounds, so that if you are using the &amp;quot;CSS-sprite&amp;quot; method, it will work!&lt;br /&gt;
&lt;br /&gt;
For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.xxx-token {&lt;br /&gt;
    filter: drop-shadow(0px 0px 1px #000000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Beware that some browsers still do not always draw drop-shadow correctly. In particular, Safari frequently leaves bits of shadow behind when objects move around the screen. In Chrome, shadows sometimes flicker badly if another element is animating close by. Some of these correctness issues can be solved by adding &#039;&#039;&#039;isolation: isolate; will-change: filter;&#039;&#039;&#039; to affected elements, but this significantly affects redraw performance.&lt;br /&gt;
&lt;br /&gt;
Beware of performance issues - particularly on Safari (MacOS, iPhone and iPad). Keep in mind that drop-shadow are very GPU intensive. This becomes noticeable once you have about 40 components with drop-shadow filter. If that is your case, you can quite easily implement a user preference to disable shadows for users on slower machines:&lt;br /&gt;
&lt;br /&gt;
gameoptions.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
100 =&amp;gt; array(&lt;br /&gt;
			&#039;name&#039; =&amp;gt; totranslate(&#039;Shadows&#039;),&lt;br /&gt;
			&#039;needReload&#039; =&amp;gt; true, // after user changes this preference game interface would auto-reload&lt;br /&gt;
			&#039;values&#039; =&amp;gt; array(&lt;br /&gt;
					1 =&amp;gt; array( &#039;name&#039; =&amp;gt; totranslate( &#039;Enabled&#039; ), &#039;cssPref&#039; =&amp;gt; &#039;&#039; ),&lt;br /&gt;
					2 =&amp;gt; array( &#039;name&#039; =&amp;gt; totranslate( &#039;Disabled&#039; ), &#039;cssPref&#039; =&amp;gt; &#039;no-shadow&#039; )&lt;br /&gt;
			)&lt;br /&gt;
	),&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[game].css&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.no-shadow * {&lt;br /&gt;
	filter: none !important; &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;For Safari, it is usually better to simply disable drop-shadow completely: [[Game interface stylesheet: yourgamename.css#Warning: using drop-shadow]].&lt;br /&gt;
&lt;br /&gt;
==== Shadows with clip-path ====&lt;br /&gt;
&lt;br /&gt;
For some reason, a shadow will not work together with clip-path on one element. To use both clip-path (when for example using .svg to cut out cardboard components from your .jpg spritesheet) and drop-shadow, you need to wrap the element into another one, and apply drop-shadow to the outer one, and clip-path to the inner one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;my-token-wrap&#039;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&#039;my-token&#039;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.my-token-wrap {&lt;br /&gt;
    filter: drop-shadow(0px 0px 1px #000000);&lt;br /&gt;
}&lt;br /&gt;
.my-token-wrap .my-token {&lt;br /&gt;
    clip-path: url(#my-token-path);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using the CSS classes from the state machine ===&lt;br /&gt;
&lt;br /&gt;
If you need to hide or show stuff depending on the state of your game, you can of course use javascript, but CSS is hand enough for that.  The #overall-content element does change class depending on the game state.  For instance, if you are in state &#039;&#039;playerTurn&#039;&#039;, it will have the class &#039;&#039;gamestate_playerTurn&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now, if you want to show the discard pile only during player turns, you may use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#discard_pile { display: none }&lt;br /&gt;
.gamestate_playerTurn #discard_pile { display: block }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be used if you want to change sizing of elements, position, layout or visual appearance.&lt;br /&gt;
&lt;br /&gt;
== Game Model and Database design ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Database for The euro game ===&lt;br /&gt;
Lets say we have a game with workers, dice, tokens, board, resources, money and vp. Workers and dice can be placed in various zones on the board, and you can get resources, money, tokens and vp in your home zone. Also tokens can be flipped or not flipped.&lt;br /&gt;
&lt;br /&gt;
[[File:Madeira board.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets try to map it, we have&lt;br /&gt;
* (meeple,zone)&lt;br /&gt;
* (die, zone, sideup)&lt;br /&gt;
* (resource cube/money token/vp token,player home zone)&lt;br /&gt;
* (token, player home zone, flip state)&lt;br /&gt;
We can notice that resource and money are uncountable, and don&#039;t need to be track individually so we can replace our mapping to&lt;br /&gt;
* (resource type/money,player home zone, count)&lt;br /&gt;
And vp stored already for us in player table, so we can remove it from that list.&lt;br /&gt;
&lt;br /&gt;
Now when we get to encode it we can see that everything can be encoded as (object,zone,state) form, where object and zone is string and state is integer. The resource mapping is slightly different semantically so you can go with two table, or counting using same table with state been used as count for resources.&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based games can be in most case represented by (string: token_key, string: token_location, int: token_state), example of such database schema can be found here: [https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php table.game.php].&lt;br /&gt;
&lt;br /&gt;
Variant 1: Minimalistic&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|meeple_red_1&lt;br /&gt;
|home_red&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|dice_black_2&lt;br /&gt;
|board_guard&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|dice_green_1&lt;br /&gt;
|board_action_mayor&lt;br /&gt;
|3&lt;br /&gt;
|-&lt;br /&gt;
|bread&lt;br /&gt;
|home_red&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now how we represent resource counters such as bread?&lt;br /&gt;
Using same table from we simply add special counter token for bread and use state to indicate the count. Note to keep first column unique we have to add player identification for that counter, i.e. ff0000 is red player.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|bread_ff0000&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See php module for this table here https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php&lt;br /&gt;
&lt;br /&gt;
Variant 2: Additional resource table, resource count for each player id&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `resource` (&lt;br /&gt;
  `player_id` int(10) unsigned NOT NULL,&lt;br /&gt;
  `resource_key` varchar(32) NOT NULL,&lt;br /&gt;
  `resource_count` int(10) signed NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`player_id`,`resource_key`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE resource ADD CONSTRAINT fk_player_id FOREIGN KEY (player_id) REFERENCES player(player_id);&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+resource&lt;br /&gt;
! player_id&lt;br /&gt;
! resource_key&lt;br /&gt;
! resource_count&lt;br /&gt;
|-&lt;br /&gt;
|123456&lt;br /&gt;
|bread&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Variant 3: More normalised&lt;br /&gt;
&lt;br /&gt;
This version is similar to &amp;quot;card&amp;quot; table from hearts tutorial, you can also use exact cards database schema and Deck implementation for most purposes (even you not dealing with cards). &lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `token_type` varchar(16) NOT NULL,&lt;br /&gt;
  `token_arg` int(11) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_id`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_id&lt;br /&gt;
! token_type&lt;br /&gt;
! token_arg&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|22&lt;br /&gt;
|meeple&lt;br /&gt;
|123456&lt;br /&gt;
|home_123456&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|23&lt;br /&gt;
|dice&lt;br /&gt;
|2&lt;br /&gt;
|board_guard&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|26&lt;br /&gt;
|dice&lt;br /&gt;
|1&lt;br /&gt;
|board_action_mayor&lt;br /&gt;
|3&lt;br /&gt;
|-&lt;br /&gt;
|49&lt;br /&gt;
|bread&lt;br /&gt;
|0&lt;br /&gt;
|home_123456&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Advantages of this would be is a bit more straightforward to do some queries in db, disadvantage its hard to read (as you can compare with previous example, you&lt;br /&gt;
cannot just look at say, ah I know what it means). Another questionable advantage is it allows you to do id randomisation, so it hard to do crafted queries to &lt;br /&gt;
cheat, the down side of that you cannot understand it either, and handcraft db states for debugging or testing.&lt;br /&gt;
&lt;br /&gt;
=== Database for The card game ===&lt;br /&gt;
&lt;br /&gt;
Lets say you have a standard card game, player have hidden cards in hand, you can draw card from draw deck, play card on tableau and discard to discard pile.&lt;br /&gt;
We have to design database for such game.&lt;br /&gt;
&lt;br /&gt;
In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it.&lt;br /&gt;
&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in our database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
&lt;br /&gt;
Lets see what we have for that:&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real coordinates x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what information changes and what information is static, later is always candidate for material file&lt;br /&gt;
* For dynamic information we should try to reduce amount of fields we need&lt;br /&gt;
**  we need at least a field for card, so its one&lt;br /&gt;
**  we need to know what zone cards belong to, its 2&lt;br /&gt;
**  and we have possibly few other fields, if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
Variant 1: Minimalistic&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_key` varchar(32) unsigned NOT NULL,&lt;br /&gt;
  `card_location` varchar(32) NOT NULL,&lt;br /&gt;
  `card_state` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Variant 2: More normalised&lt;br /&gt;
&lt;br /&gt;
This version supported by Deck php class, so unless you want to rewrite db access layer go with this one&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you using this schema, some zones/locations have special semantic. The &#039;hand&#039; location is actually multiple locations - one per player, but player id is encoded as card_location_arg. If &#039;hand&#039; in your game is ordered, visible or can have some other card states, you cannot use hand location (replacement is hand_&amp;lt;player_id&amp;gt; or hand_&amp;lt;color_id&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== Code Organization ==&lt;br /&gt;
&lt;br /&gt;
=== Including your own JavaScript module ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, modules/ggg_other.js&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.js in modules/ folder and sync&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define([&lt;br /&gt;
    &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;&lt;br /&gt;
], function( dojo, declare )&lt;br /&gt;
{&lt;br /&gt;
return declare(&amp;quot;bgagame.other&amp;quot;, null, { // null here if we don&#039;t want to inherit from anything&lt;br /&gt;
        constructor: function(){},&lt;br /&gt;
        mystuff: function(){},&lt;br /&gt;
    });&lt;br /&gt;
        &lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Modify ggg.js to include it&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  define([ &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;, &amp;quot;ebg/core/gamegui&amp;quot;, &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
    g_gamethemeurl + &amp;quot;modules/ggg_other.js&amp;quot;     // load my own module!!!&lt;br /&gt;
  ], function(dojo,&lt;br /&gt;
        declare) {&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
use it&lt;br /&gt;
&lt;br /&gt;
  foo = new bgagame.other();&lt;br /&gt;
&lt;br /&gt;
=== Including your own JavaScript module (II) ===&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.js in modules/ folder and sync&lt;br /&gt;
&lt;br /&gt;
  define([], function () {&lt;br /&gt;
    return &amp;quot;value&amp;quot;;&lt;br /&gt;
  });&lt;br /&gt;
&lt;br /&gt;
* Modify ggg.js to include it&lt;br /&gt;
&lt;br /&gt;
  define([ &lt;br /&gt;
    &amp;quot;dojo&amp;quot;, &lt;br /&gt;
    &amp;quot;dojo/_base/declare&amp;quot;, &lt;br /&gt;
    &amp;quot;bgagame/modules/ggg_other&amp;quot;, &lt;br /&gt;
    &amp;quot;ebg/core/gamegui&amp;quot;, &lt;br /&gt;
    &amp;quot;ebg/counter&amp;quot;&lt;br /&gt;
  ], function(dojo, declare, other) {&lt;br /&gt;
  &lt;br /&gt;
  });&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
This is maybe a little bit more the idea of the AMD Loader than the first option, although the first option should work as well.&lt;br /&gt;
&lt;br /&gt;
A little explanation to this:&lt;br /&gt;
The define function loads all the modules listed in the array and calls the following function with these loaded modules as parameters.&lt;br /&gt;
By putting your module at the third position in the array it is passed as the third parameter to the function. Be aware that the modules are resolved by position only, not by name. So you can load the module &#039;&#039;&#039;ggg_other&#039;&#039;&#039; and pass it as a parameter with the name &#039;&#039;&#039;other&#039;&#039;&#039;. &#039;&#039;&#039;gamegui&#039;&#039;&#039; and &#039;&#039;&#039;counter&#039;&#039;&#039; are passed in as well, but when the parameters are not defined they are just skipped. Because these modules put their content into the global scope it does not matter and you can use them from there.&lt;br /&gt;
&lt;br /&gt;
In the example above the string &amp;quot;value&amp;quot; is passed for the parameter &#039;&#039;&#039;other&#039;&#039;&#039;, but the function in your module can return whatever you want. It can be an object, an array, something you declared with dojo.declare, you can return even functions. &lt;br /&gt;
Your module can load other modules. Just put them in the array at the beginning and pass them as parameters to your function.&lt;br /&gt;
The advantage of passing the values as parameter is that you do not need to put these values in the global scope, so they can&#039;t be collisions with values defined in other scripts or the BGA Framework.&lt;br /&gt;
&lt;br /&gt;
The dojo toolkit provides good documentation to all of its components, the complete documentation for the AMD-Loader is here:&lt;br /&gt;
https://dojotoolkit.org/documentation/tutorials/1.10/modules/index.html It should be still correct, even as it seems to be only for version 1.10&lt;br /&gt;
&lt;br /&gt;
=== Including your own PHP module ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.game.php, modules/ggg_other.php&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.php in modules/ folder and sync&lt;br /&gt;
* Modify ggg.game.php to include it&lt;br /&gt;
&lt;br /&gt;
 require_once (&#039;modules/ggg_other.php&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Creating a test class to run PHP locally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.game.php, stubs&lt;br /&gt;
For this you need stubs of other method you can use this for example&lt;br /&gt;
https://github.com/elaskavaia/bga-sharedcode/raw/master/misc/module/table/table.game.php&lt;br /&gt;
&lt;br /&gt;
Create another php files, i.e ggg_test.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
define(&amp;quot;APP_GAMEMODULE_PATH&amp;quot;, &amp;quot;misc/&amp;quot;); // include path to stubs, which defines &amp;quot;table.game.php&amp;quot; and other classes&lt;br /&gt;
require_once (&#039;eminentdomaine.game.php&#039;);&lt;br /&gt;
&lt;br /&gt;
class MyGameTest1 extends MyGame { // this is your game class defined in ggg.game.php&lt;br /&gt;
    function __construct() {&lt;br /&gt;
        parent::__construct();&lt;br /&gt;
        include &#039;../material.inc.php&#039;;// this is how this normally included, from constructor&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // override/stub methods here that access db and stuff&lt;br /&gt;
    function getGameStateValue($var) {&lt;br /&gt;
        if ($var == &#039;round&#039;)&lt;br /&gt;
            return 3;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$x = new MyGameTest1(); // instantiate your class&lt;br /&gt;
$p = $x-&amp;gt;getGameProgression(); // call one of the methods to test&lt;br /&gt;
if ($p != 50)&lt;br /&gt;
    echo &amp;quot;Test1: FAILED&amp;quot;;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;Test1: PASSED&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run from command line like&lt;br /&gt;
 php7 ggg_test.php&lt;br /&gt;
&lt;br /&gt;
If you do it this way - you can also use local php debugger (i.e. integrated with IDE or command line).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Avoiding code in dojo declare style ===&lt;br /&gt;
Dojo class declarations are rather bizzare and do not work with most IDEs.&lt;br /&gt;
If you want to write in plain JS with classes, you can stub all the dojo define/declare stuff&lt;br /&gt;
and hook your class into that, so the classes are outside of this mess.&lt;br /&gt;
&lt;br /&gt;
NOTE: this technique is for experienced developers, do not try it if you do not understand&lt;br /&gt;
the consequences.&lt;br /&gt;
&lt;br /&gt;
This is complete example of game .js class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // Testla is game name is has to be changed&lt;br /&gt;
class Testla {&lt;br /&gt;
	constructor(game) {&lt;br /&gt;
		console.log(&#039;game constructor&#039;);&lt;br /&gt;
		this.game = game;&lt;br /&gt;
		this.varfoo = new MyFoo(); // this example of class from custom module&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	setup(gamedatas) {&lt;br /&gt;
		console.log(&amp;quot;Starting game setup&amp;quot;, this.varfoo);&lt;br /&gt;
		this.gamedatas = gamedatas;&lt;br /&gt;
		this.dojo.create(&amp;quot;div&amp;quot;, { class: &#039;whiteblock&#039;, innerHTML: _(&amp;quot;hello&amp;quot;) }, &#039;thething&#039;);&lt;br /&gt;
		console.log(&amp;quot;Ending game setup&amp;quot;);&lt;br /&gt;
	};&lt;br /&gt;
	onEnteringState(stateName, args) {&lt;br /&gt;
		console.log(&#039;onEnteringState : &#039; + stateName, args);&lt;br /&gt;
		this.game.addActionButton(&#039;b1&#039;,_(&#039;Click Me&#039;), (e)=&amp;gt;this.onButtonClick(e));&lt;br /&gt;
	};&lt;br /&gt;
	onLeavingState(stateName) {&lt;br /&gt;
		console.log(&#039;onLeavingState : &#039; + stateName, args);&lt;br /&gt;
	};&lt;br /&gt;
	onUpdateActionButtons(stateName, args) {&lt;br /&gt;
		console.log(&#039;onUpdateActionButtons : &#039; + stateName, args);&lt;br /&gt;
	};&lt;br /&gt;
	onButtonClick(event) {&lt;br /&gt;
		console.log(&#039;onButtonClick&#039;,event);&lt;br /&gt;
	};&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
define([&lt;br /&gt;
	&amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
	&amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
	&amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
	g_gamethemeurl + &#039;/modules/foo.js&#039; // custom module if needed&lt;br /&gt;
],&lt;br /&gt;
	function(dojo, declare) {&lt;br /&gt;
                // testla is game name is has to be changed&lt;br /&gt;
		return declare(&amp;quot;bgagame.testla&amp;quot;, ebg.core.gamegui, {&lt;br /&gt;
			constructor: function() {&lt;br /&gt;
				this.xapp = new Testla(this);&lt;br /&gt;
				this.xapp.dojo = dojo;&lt;br /&gt;
			},&lt;br /&gt;
			setup: function(gamedatas) {&lt;br /&gt;
				this.xapp.setup(gamedatas);&lt;br /&gt;
			},&lt;br /&gt;
			onEnteringState: function(stateName, args) {&lt;br /&gt;
				this.xapp.onEnteringState(stateName, args?.args);&lt;br /&gt;
			},&lt;br /&gt;
			onLeavingState: function(stateName) {&lt;br /&gt;
				this.xapp.onLeavingState(stateName, args);&lt;br /&gt;
			},&lt;br /&gt;
			onUpdateActionButtons: function(stateName, args) {&lt;br /&gt;
				this.xapp.onUpdateActionButtons(stateName, args);&lt;br /&gt;
			},&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== More readable JS: onEnteringState ===&lt;br /&gt;
&lt;br /&gt;
If you have a lot of states in onEnteringState or onUpdateActionButtons and friends - it becomes rather wild, you can do this trick to call some methods dynamically.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     onEnteringState: function(stateName, args) {&lt;br /&gt;
       console.log(&#039;Entering state: &#039; + stateName, args);&lt;br /&gt;
&lt;br /&gt;
       // Call appropriate method&lt;br /&gt;
       var methodName = &amp;quot;onEnteringState_&amp;quot; + stateName;&lt;br /&gt;
       if (this[methodName] !== undefined) {             &lt;br /&gt;
          console.log(&#039;Calling &#039; + methodName, args.args);&lt;br /&gt;
          this[methodName](args.args);&lt;br /&gt;
       }&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
     onEnteringState_playerTurn: function(args) { // this is args directly, not args.args &lt;br /&gt;
         // process&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
     onEnteringState_playerSomethingElse: function(args) { &lt;br /&gt;
         // process&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: since its ignores the undefined functions you don&#039;t have define function for each state, but on the other hand you cannot make typos.&lt;br /&gt;
Same applies to onUpdateActionButtons except you pass &#039;args&#039; to method, not args.args, and for onLeavingState where you don&#039;t pass anything.&lt;br /&gt;
&lt;br /&gt;
=== Frameworks and Preprocessors ===&lt;br /&gt;
&lt;br /&gt;
* [[BGA Type Safe Template]] - Setting up a fully typed project using typescript and more!&lt;br /&gt;
* [[Using Vue]] - work-in-progress guide on using the modern framework Vue.js to create a game&lt;br /&gt;
* [[Using Typescript and Scss]] - How to auto-build Typescript and SCSS files to make your code cleaner&lt;br /&gt;
&lt;br /&gt;
== Assorted Stuff ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Out-of-turn actions: Un-pass ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg.action.php, states.inc.php&lt;br /&gt;
&lt;br /&gt;
In multiplayer game sometimes players passes but than they think more and want to un-Pass and redo their choice. &lt;br /&gt;
To re-active a player who passes some trickery required.&lt;br /&gt;
&lt;br /&gt;
Define a special action that does that and hook it up.&lt;br /&gt;
&lt;br /&gt;
In states.inc.php add an action to mmultipleactiveplayer state to &amp;quot;unpass&amp;quot;, lets call it &amp;quot;actionCancel&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In ggg.action.php add action hook&lt;br /&gt;
    public function actionCancel() {&lt;br /&gt;
        $this-&amp;gt;setAjaxMode();&lt;br /&gt;
        $this-&amp;gt;game-&amp;gt;actionCancel();&lt;br /&gt;
        $this-&amp;gt;ajaxResponse();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
In ggg.game.php add action handler&lt;br /&gt;
    function actionCancel() {&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;checkPossibleAction(&#039;actionCancel&#039;);&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;setPlayersMultiactive(array ($this-&amp;gt;getCurrentPlayerId() ), &#039;error&#039;, false);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Finally to call this in client ggg.js you would do something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 onUpdateActionButtons:  function(stateName, args) {&lt;br /&gt;
   if (this.isCurrentPlayerActive()) { &lt;br /&gt;
     // ...&lt;br /&gt;
   } else if (!this.isSpectator) { // player is NOT active but not spectator&lt;br /&gt;
       switch (stateName) {&lt;br /&gt;
          case &#039;playerTurnMultiPlayerState&#039;:&lt;br /&gt;
		this.addActionButton(&#039;button_unpass&#039;, _(&#039;Oh no!&#039;), &#039;onUnpass&#039;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
				&lt;br /&gt;
 onUnpass: function(e) {&lt;br /&gt;
    this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; +  this.game_name + &amp;quot;/actionCancel.html&amp;quot;, {}, this); // no checkAction!&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although be careful that if the turn comes back to the player while he is about to click cancel, the action buttons will be updated and the player will misclick which can be quite frustrating. To avoid this, move the cancel button to another position, like to the left of pagemaintitletext:&lt;br /&gt;
  dojo.place(&#039;button_unpass&#039;, &#039;pagemaintitletext&#039;, &#039;before&#039;);&lt;br /&gt;
Being out of the generalactions div, it won&#039;t be automatically destroyed like normal buttons, so you&#039;ll have to handle that yourself in onLeavingState. You might also want to change the button color to red (blue buttons for active player only, red buttons also for inactive players?)&lt;br /&gt;
&lt;br /&gt;
Note: same technique can be used to do other out-of-turn actions, such as re-arranging cards in hand, exchanging resources, etc (i.e. if permitted by rules, such as &amp;quot;at any time player can...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
=== Multi Step Interactions: Select Worker/Place Worker - Using Selection ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
Simple way to implement something like that without extra states is to use &amp;quot;selection&amp;quot; mechanism. When user click on worker add some sort of class into that element i.e. &#039;selected&#039; (which also have to have some indication by css i.e. outline).&lt;br /&gt;
&lt;br /&gt;
Than user can click on placement zone, you can use dojo.query for &amp;quot;selected&amp;quot; element and use it along with zone id to send data to server. If proper worker is not selected yet can give a error message using this.showMessage(...) function.&lt;br /&gt;
&lt;br /&gt;
Extra code required to properly cleanup selection between states.&lt;br /&gt;
Also when you do that sometimes you want to change the state prompt, see below &#039;Change state prompt&#039;&lt;br /&gt;
&lt;br /&gt;
=== Multi Step Interactions: Select Worker/Place Worker - Using Client States ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
I don&#039;t think its documented feature but there is a way to do client-only states, which is absolutely wonderful for few reasons&lt;br /&gt;
* When player interaction is two step process, such as select worker, place worker, or place worker, pick one of two resources of your choice&lt;br /&gt;
* When multi-step process can result of impossible situation and has to be undone (by rules)&lt;br /&gt;
* When multi-step process is triggered from multiple states (such as you can do same thing as activated card action, pass action or main action)&lt;br /&gt;
&lt;br /&gt;
So lets do Select Worker/Place Worker&lt;br /&gt;
&lt;br /&gt;
Define your server state as usual, i.e. playerMainTurn -&amp;gt; &amp;quot;You must pick up a worker&amp;quot;.&lt;br /&gt;
Now define a client state, we only need &amp;quot;name&amp;quot; and &amp;quot;descriptionmyturn&amp;quot;, lets say &amp;quot;client_playerPicksLocation&amp;quot;. Always prefix names of client state with &amp;quot;client_&amp;quot; to avoid confusion. Now we have to do the following:&lt;br /&gt;
* Have a handler for onUpdateActionButtons for playerMainTurn to activate all possible workers he can pick&lt;br /&gt;
* When player clicks workers, remember the worker in one of the members of the main class, I usually use one called this.clientStateArgs.&lt;br /&gt;
* Transition to new client state&lt;br /&gt;
  onWorker: function(e) {&lt;br /&gt;
      var id = event.currentTarget.id;&lt;br /&gt;
      dojo.stopEvent(event);&lt;br /&gt;
      ... // do validity checks&lt;br /&gt;
      this.clientStateArgs.worker_id = id;&lt;br /&gt;
      this.setClientState(&amp;quot;client_playerPicksLocation&amp;quot;, {&lt;br /&gt;
                                descriptionmyturn : _(&amp;quot;${you} must select location&amp;quot;),&lt;br /&gt;
                            });&lt;br /&gt;
   }&lt;br /&gt;
* Have a handler for onUpdateActionButtons for client_playerPicksLocation to activate all possible locations this worker can go AND add Cancel button (see below)&lt;br /&gt;
* Have a location handler which will eventually send a server request, using stored this.clientStateArgs.worker_id as worker id&lt;br /&gt;
* The cancel button should call a method to restore server state, also if you doing it for more than one state you can add this universally using this.on_client_state check&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if (this.isCurrentPlayerActive()) {&lt;br /&gt;
          if (this.on_client_state &amp;amp;&amp;amp; !$(&#039;button_cancel&#039;)) {&lt;br /&gt;
               this.addActionButton(&#039;button_cancel&#039;, _(&#039;Cancel&#039;), dojo.hitch(this, function() {&lt;br /&gt;
                                             this.restoreServerGameState();&lt;br /&gt;
               }));&lt;br /&gt;
          }&lt;br /&gt;
        } &lt;br /&gt;
Note: usually I call my own function call this.cancelLocalStateEffects() which will do more stuff first then call restoreServerGameState(), same function is usually needs to be called when server request has failed (i.e. invalid move)&lt;br /&gt;
&lt;br /&gt;
Note: If you need more than 2 steps, you may have to do client side animation to reflect the new state, which gets trickier because you have to undo that also on cancellation.&lt;br /&gt;
&lt;br /&gt;
Code is available here [https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js sharedcode.js] (its using playerTurnPlayCubes and client_selectCubeLocation).&lt;br /&gt;
&lt;br /&gt;
=== Action Stack - Using Client States ===&lt;br /&gt;
&lt;br /&gt;
Action stack required where game is very complex and use triggered effects that can &amp;quot;stack&amp;quot;. It not always actual stack, it can be queue or random access&lt;br /&gt;
Examples:&lt;br /&gt;
* Magic the Gathering - classic card game where effects go on Stack, that allows to counter spell and counter spell of counter spell (not on bga - it just example of mechanics)&lt;br /&gt;
* Ultimate Railroads - action taking game where effects can be executed in any order&lt;br /&gt;
* Lewis and Clark - card game where actions executed as queue&lt;br /&gt;
&lt;br /&gt;
There is two ways of implementing it - on the server or the client.&lt;br /&gt;
For the server see article below.&lt;br /&gt;
The requirement for client side stack implementation is - all action can be undone, which means&lt;br /&gt;
* No dice rolls&lt;br /&gt;
* No card drawn&lt;br /&gt;
* No other players interaction&lt;br /&gt;
&lt;br /&gt;
No snippets are here, as this will be too complex but basically flow is:&lt;br /&gt;
* You have a action/effect stack (queue/list) as js object attached to &amp;quot;this&amp;quot;, i.e. this.unprocessed_actions&lt;br /&gt;
* When player plays a card, worker, etc, you read the effect of that card from the material file (client copy), and place into stack&lt;br /&gt;
* Then we call dispatch method which pulls the next action from the stack and change client state accordinly, i.e. this.setClientState(&amp;quot;client_playerGainsCubes&amp;quot;)&lt;br /&gt;
* When players acts on it - the action is removed from the stack and added to &amp;quot;server action arguments&amp;quot; list, this is another object which be used to send ajax call, i.e. this.clientStateArgs&lt;br /&gt;
* If nothing left in stack we can submit the ajax call assembling parameters from collected arguments (that can include action name)&lt;br /&gt;
* This method allows cheap undo - by restoring server state you will wipe out all user actions (but if you need intermediate aninmation you have to handle it yourself)&lt;br /&gt;
&lt;br /&gt;
Code can be found in Ultimate Railroads game (but it is random access list - so it a bit complex) and Lewis and Clark (complexity - user can always deny part of any effect)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Action Stack - Using Server States ===&lt;br /&gt;
&lt;br /&gt;
See definition of Action Stack above.&lt;br /&gt;
&lt;br /&gt;
To implement you usually need another db table that has the following fields: index of effect - which is used for sorted access, type - which is essense of the effect (i.e. collect resource), some extra arguments (i.e. resource type and resource count), and usually owner of the effect (i.e. player id)&lt;br /&gt;
The flow is:&lt;br /&gt;
* There is some initial player state, where player can play card for example&lt;br /&gt;
* Player main action - pushes the card effect on stack, which also can cause triggered effects which also go on stack&lt;br /&gt;
* After action processing is finished switch to game state which is &amp;quot;dispatcher&amp;quot;&lt;br /&gt;
* Dispatcher pulls the top effect (whatever definition of the top is), changes the active player and changes the state to appropriate player state to collect response&lt;br /&gt;
* Player state knows about the stack and pulls arguments (argX) from the effect arguments of the db&lt;br /&gt;
* Player action should clear up the top effect, and can possibly add more effects, then switch to &amp;quot;dispatcher&amp;quot; state again&lt;br /&gt;
* If stack is empty, dispatcher can either pick next player itself or use another game state which responsible for picking next player&lt;br /&gt;
&lt;br /&gt;
Code can be found in Tapestry.&lt;br /&gt;
&lt;br /&gt;
=== Changing state prompt ===&lt;br /&gt;
&lt;br /&gt;
State prompt is message displayed for player which usually comes from state description.&lt;br /&gt;
Sometimes you want to change it without changing state (one way is change state but locally, see client states above).&lt;br /&gt;
&lt;br /&gt;
Simple way just change the html&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        setMainTitle: function(text) {&lt;br /&gt;
            $(&#039;pagemaintitletext&#039;).innerHTML = text;&lt;br /&gt;
        },&lt;br /&gt;
         // usage&lt;br /&gt;
        onMeeple: function(event) {&lt;br /&gt;
              //... &lt;br /&gt;
              this.setMainTitle(_(&#039;You must select where meeple is going&#039;));&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This however will not work with parameters and will not draw You in color, if you want this its more sophisticated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        setDescriptionOnMyTurn : function(text) {&lt;br /&gt;
            this.gamedatas.gamestate.descriptionmyturn = text;&lt;br /&gt;
            var tpl = dojo.clone(this.gamedatas.gamestate.args);&lt;br /&gt;
            if (tpl === null) {&lt;br /&gt;
                tpl = {};&lt;br /&gt;
            }&lt;br /&gt;
            var title = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.isCurrentPlayerActive() &amp;amp;&amp;amp; text !== null) {&lt;br /&gt;
                tpl.you = this.divYou(); &lt;br /&gt;
            }&lt;br /&gt;
            title = this.format_string_recursive(text, tpl);&lt;br /&gt;
&lt;br /&gt;
            if (!title) {&lt;br /&gt;
                this.setMainTitle(&amp;quot;&amp;amp;nbsp;&amp;quot;);&lt;br /&gt;
            } else {&lt;br /&gt;
                this.setMainTitle(title);&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this method uses &#039;&#039;&#039;setMainTitle&#039;&#039;&#039; defined above and &#039;&#039;&#039;divYou&#039;&#039;&#039; defined in another section of this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assigning Player Order ===&lt;br /&gt;
Normally when game starts there is &amp;quot;natural&amp;quot; player order assigned randomly.&lt;br /&gt;
&lt;br /&gt;
If you want to deliberatly assign player order at the start of the game (for example, in a game with teams options), you can do so by retrieving the initialization-only player attribute &#039;&#039;&#039;player_table_order&#039;&#039;&#039; and using it to assign values to &#039;&#039;&#039;player_no&#039;&#039;&#039; (which is normally assigned at the start of a game in the order in which players come to the table). (See [https://en.doc.boardgamearena.com/Game_database_model:_dbmodel.sql#The_player_table Game database model] for more details.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
                // Retrieve inital player order ([0=&amp;gt;playerId1, 1=&amp;gt;playerId2, ...])&lt;br /&gt;
		$playerInitialOrder = [];&lt;br /&gt;
		foreach ($players as $playerId =&amp;gt; $player) {&lt;br /&gt;
			$playerInitialOrder[$player[&#039;player_table_order&#039;]] = $playerId;&lt;br /&gt;
		}&lt;br /&gt;
		ksort($playerInitialOrder);&lt;br /&gt;
		$playerInitialOrder = array_flip(array_values($playerInitialOrder));&lt;br /&gt;
&lt;br /&gt;
		// Player order based on &#039;playerTeams&#039; option&lt;br /&gt;
		$playerOrder = [0, 1, 2, 3];&lt;br /&gt;
		switch ($this-&amp;gt;getGameStateValue(&#039;playerTeams&#039;)) {&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_2:&lt;br /&gt;
				$playerOrder = [0, 2, 1, 3];&lt;br /&gt;
				break;&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_4:&lt;br /&gt;
				$playerOrder = [0, 1, 3, 2];&lt;br /&gt;
				break;&lt;br /&gt;
			case $this-&amp;gt;TEAM_RANDOM:&lt;br /&gt;
				shuffle($playerOrder);&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_3:&lt;br /&gt;
				// Default order&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
                // Create players&lt;br /&gt;
		// Note: if you added some extra field on &amp;quot;player&amp;quot; table in the database (dbmodel.sql), you can initialize it there.&lt;br /&gt;
		$sql =&lt;br /&gt;
			&#039;INSERT INTO player (player_id, player_color, player_canal, player_name, player_avatar, player_no) VALUES &#039;;&lt;br /&gt;
		$values = [];&lt;br /&gt;
&lt;br /&gt;
		foreach ($players as $playerId =&amp;gt; $player) {&lt;br /&gt;
			$color = array_shift($default_colors);&lt;br /&gt;
			$values[] =&lt;br /&gt;
				&amp;quot;(&#039;&amp;quot; .&lt;br /&gt;
				$playerId .&lt;br /&gt;
				&amp;quot;&#039;,&#039;$color&#039;,&#039;&amp;quot; .&lt;br /&gt;
				$player[&#039;player_canal&#039;] .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				addslashes($player[&#039;player_name&#039;]) .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				addslashes($player[&#039;player_avatar&#039;]) .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				$playerOrder[$playerInitialOrder[$playerId]] .&lt;br /&gt;
				&amp;quot;&#039;)&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
		$sql .= implode(&#039;,&#039;, $values);&lt;br /&gt;
		$this-&amp;gt;DbQuery($sql);&lt;br /&gt;
		$this-&amp;gt;reattributeColorsBasedOnPreferences(&lt;br /&gt;
			$players,&lt;br /&gt;
			$gameinfos[&#039;player_colors&#039;]&lt;br /&gt;
		);&lt;br /&gt;
		$this-&amp;gt;reloadPlayersBasicInfos();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send different notifications to active player vs everybody else ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
Hack alert. This is a hack. We were hoping for proper solution by bga framework.&lt;br /&gt;
&lt;br /&gt;
This will allow you to send notification with two message one for specific player and one for everybody else including spectators.&lt;br /&gt;
Note that this does not split the data - all data must be shared.&lt;br /&gt;
&lt;br /&gt;
Add this to .js file (if you already overriding it merge obviously)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/** @Override */&lt;br /&gt;
format_string_recursive: function(log, args) {&lt;br /&gt;
   if (typeof args.log_others != &#039;undefined&#039; &amp;amp;&amp;amp; typeof args.player_id != &#039;undefined&#039; &amp;amp;&amp;amp; this.player_id != args.player_id)&lt;br /&gt;
	log = args.log_others;&lt;br /&gt;
   return this.inherited(arguments); // you must call this to call super &lt;br /&gt;
},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of usage (from eminentdomain)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    $this-&amp;gt;notifyAllPlayers(&#039;tokenMoved&#039;, &lt;br /&gt;
             clienttranslate(&#039;${player_name} adds +2 Colonies to ${place_name}&#039;), // notification with show for player with player_id&lt;br /&gt;
             [&#039;player_id&#039;=&amp;gt;$player_id, // this is mandatory&lt;br /&gt;
             &#039;log_others&#039;=&amp;gt;clienttranslate(&#039;${player_name} adds +2 Colonies to an unknown planet&#039;), // notification will show for others&lt;br /&gt;
              ...&lt;br /&gt;
             ]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send transient notifications without incrementing move ID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.php&lt;br /&gt;
&lt;br /&gt;
Hack alert. This is a hack.&lt;br /&gt;
&lt;br /&gt;
Use this if you need to send some transient notification that should not create a new move ID. The notification should be idempotent -- it should have no practical effect on the game state and would be &#039;&#039;&#039;safe to drop&#039;&#039;&#039; (e.g., it would not matter if a player never received this notification). For example, in a co-op game you want all players to see a real-time preview of some action, before the active player commits their turn.&lt;br /&gt;
&lt;br /&gt;
Doing this mainly affects the instant replay &amp;amp; archive modes. During replay, the BGA framework automatically inserts a 1.5-second pause between each &amp;quot;move&amp;quot;. With this hack, your transient notifications are not considered to be a &amp;quot;move&amp;quot;, so no pause gets added.&lt;br /&gt;
&lt;br /&gt;
; In ggg.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;not_a_move_notification = true; // note: do not increase the move counter&lt;br /&gt;
$this-&amp;gt;notifyAllPlayers(&#039;cardsPreview&#039;, &#039;&#039;, $args);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: you cannot have code that send notification or even changes state after this, and you cannot reset this variable back either because it only takes effect when you exit action handling function&lt;br /&gt;
&lt;br /&gt;
=== Ajax Call wrapper ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
The current ajaxcall is super vebose and prone to errors, I suggest using a helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
Most beginner mistakes come from missing part of this code (which is understandstandable - this is a huge snippet to clone every time).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
		if (!args) args = {}; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
			&lt;br /&gt;
		args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
		if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
			this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
				this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                               handler); // this is real result handler - it called both on success and error, it has optional param  &amp;quot;is_error&amp;quot; - you rarely need it&lt;br /&gt;
			}&lt;br /&gt;
		},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   this.ajaxcallwrapper(&#039;pass&#039;); // no args&lt;br /&gt;
   this.ajaxcallwrapper(&#039;playCard&#039;, {card: card_id}); // with args&lt;br /&gt;
   this.ajaxcallwrapper(&#039;playCard&#039;, {card: card_id}, (is_error)=&amp;gt;{if (!is_error) dojo.query(&amp;quot;.selected&amp;quot;).removeClass(&#039;selected&#039;);}) // with handler that cleans up &#039;selected&#039; class on success&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this always will lock interface and always check for action, you can modify this method to do it optionally, i.e replace &#039;args.lock = true;&#039; in the code above with this&lt;br /&gt;
  if (args.lock!==false) args.lock = true; else delete args.lock; // it does not work with false value - it has to be removed&lt;br /&gt;
&lt;br /&gt;
=== Custom error/exception handling in JavaScript ===&lt;br /&gt;
&lt;br /&gt;
; In ggg.php&lt;br /&gt;
Throw BgaUserException with some easy-to-identify prefix such as &amp;quot;!!!&amp;quot; and a custom error code. DO NOT TRANSLATE this message text. The exception will rollback database transaction and cancel all changes (including any notifications).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function foo(bool $didConfirm = false): void&lt;br /&gt;
    {&lt;br /&gt;
        // do processing for the user&#039;s move&lt;br /&gt;
        // afterwards, you determine this move will end the game&lt;br /&gt;
        // so you want to rollback the transaction and require the user to confirm the move first&lt;br /&gt;
&lt;br /&gt;
        if ($gameIsEnding &amp;amp;&amp;amp; !$didConfirm) {&lt;br /&gt;
            throw new BgaUserException(&#039;!!!endGameConfirm&#039;, 9001);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; In ggg.js&lt;br /&gt;
Override framework function showMessage to suppress the red banner message and gamelog message when you detect the &amp;quot;!!!&amp;quot; prefix&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    /* @Override */&lt;br /&gt;
    showMessage: function (msg, type) {&lt;br /&gt;
      if (type == &amp;quot;error&amp;quot; &amp;amp;&amp;amp; msg &amp;amp;&amp;amp; msg.startsWith(&amp;quot;!!!&amp;quot;)) {&lt;br /&gt;
        return; // suppress red banner and gamelog message&lt;br /&gt;
      }&lt;br /&gt;
      this.inherited(arguments);&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Deal with the error in your callback:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    fooAction: function (didConfirm) {&lt;br /&gt;
      var data = {&lt;br /&gt;
        foo: &amp;quot;bar&amp;quot;,&lt;br /&gt;
        didConfirm: !!didConfirm,&lt;br /&gt;
      };&lt;br /&gt;
      this.ajaxcallwrapper(&amp;quot;fooAction&amp;quot;, data, function (error, errorMsg) {&lt;br /&gt;
        if (error &amp;amp;&amp;amp; errorMsg == &amp;quot;!!!endGameConfirm&amp;quot;) {&lt;br /&gt;
          // your custom error handling goes here&lt;br /&gt;
          // for example, show a confirmation dialog and repeat the action with additional param&lt;br /&gt;
          this.confirmationDialog(&lt;br /&gt;
            _(&amp;quot;Doing the foo action now will end the game&amp;quot;),&lt;br /&gt;
            () =&amp;gt; {&lt;br /&gt;
              this.fooAction(true);&lt;br /&gt;
            }&lt;br /&gt;
          );&lt;br /&gt;
        }&lt;br /&gt;
      });&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For custom global error handling, you could modify ajaxcallwrapper:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  ajaxcallwrapper: function (action, args, handler) {&lt;br /&gt;
    if (!args) args = {};&lt;br /&gt;
    args.lock = true;&lt;br /&gt;
    args.version = this.gamedatas.version;&lt;br /&gt;
    if (this.checkAction(action)) {&lt;br /&gt;
      this.ajaxcall(&lt;br /&gt;
        &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;,&lt;br /&gt;
        args,&lt;br /&gt;
        this,&lt;br /&gt;
        (result) =&amp;gt; {},&lt;br /&gt;
        (error, errorMsg, errorCode) =&amp;gt; {&lt;br /&gt;
          if (error &amp;amp;&amp;amp; errorMsg == &amp;quot;!!!checkVersion&amp;quot;) {&lt;br /&gt;
            this.infoDialog(&lt;br /&gt;
              _(&amp;quot;A new version of this game is now available&amp;quot;),&lt;br /&gt;
              _(&amp;quot;Reload Required&amp;quot;),&lt;br /&gt;
              () =&amp;gt; {&lt;br /&gt;
                window.location.reload();&lt;br /&gt;
              },&lt;br /&gt;
              true&lt;br /&gt;
            );&lt;br /&gt;
          } else {&lt;br /&gt;
            if (handler) handler(error, errorMsg, errorCode);&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      );&lt;br /&gt;
    }&lt;br /&gt;
  },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force players to refresh after new deploy ===&lt;br /&gt;
&lt;br /&gt;
When you deploy a new version of your game, the PHP backend code is immediately updated but the JavaScript/HTML/CSS frontend code *does not update* for active players until they manually refresh the page (F5) in their browser. Obviously this is not ideal. In the best case, real-time tables don&#039;t see your shiny new enhancements. In the worst case, your old JS code isn&#039;t compatible with your new PHP code and the game breaks in strange ways (any bug reports filed will be false positives and unable to reproduce). To avoid any problems, you should force all players to immediately reload the page following a new deploy.&lt;br /&gt;
&lt;br /&gt;
By throwing a &amp;quot;visible&amp;quot; exception (simplest solution), you&#039;ll get something like this which instructs the user to reload:&lt;br /&gt;
&lt;br /&gt;
[[File:Force-refresh.png|950x950px]]&lt;br /&gt;
&lt;br /&gt;
Or, if you combine this technique with the above custom error handling technique, you could do something a bit nicer. You could show a dialog box and automatically refresh the page when the user clicks &amp;quot;OK&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
[[File:Reload-required.png|500x500px]]&lt;br /&gt;
; In ggg.php&lt;br /&gt;
Transmit the server version number in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    protected function getAllDatas(): array&lt;br /&gt;
    {&lt;br /&gt;
        $players = $this-&amp;gt;getCollectionFromDb(&amp;quot;SELECT player_id id, player_score score FROM player&amp;quot;);&lt;br /&gt;
        return [&lt;br /&gt;
            &#039;players&#039; =&amp;gt; $players,&lt;br /&gt;
            &#039;version&#039; =&amp;gt; intval($this-&amp;gt;gamestate-&amp;gt;table_globals[300]), // &amp;lt;-- ADD HERE&lt;br /&gt;
            ...&lt;br /&gt;
        ];&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a helper function to fail if the client and server versions mismatch. Note the version check uses &amp;lt;code&amp;gt;!=&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt; so it can support rollback to a previous deploy as well. ;-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    public function checkVersion(int $clientVersion): void&lt;br /&gt;
    {&lt;br /&gt;
        if ($clientVersion != intval($this-&amp;gt;gamestate-&amp;gt;table_globals[300])) {&lt;br /&gt;
            // Simplest way is to throw a &amp;quot;visible&amp;quot; exception&lt;br /&gt;
            // It&#039;s ugly but comes with a &amp;quot;click here&amp;quot; link to refresh&lt;br /&gt;
            throw new BgaVisibleSystemException($this-&amp;gt;_(&amp;quot;A new version of this game is now available. Please reload the page (F5).&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
            // For something prettier, throw a &amp;quot;user&amp;quot; exception and handle in JS&lt;br /&gt;
            // (see BGA cookbook section above on custom error handling)&lt;br /&gt;
            throw new BgaUserException(&#039;!!!checkVersion&#039;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
; In ggg.action.php&lt;br /&gt;
Create a helper function for actions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  private function checkVersion()&lt;br /&gt;
  {&lt;br /&gt;
    $clientVersion = (int) $this-&amp;gt;getArg(&#039;version&#039;, AT_int, false);&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;checkVersion($clientVersion);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Call &amp;lt;code&amp;gt;$this-&amp;gt;checkVersion()&amp;lt;/code&amp;gt; at the top of &amp;lt;b&amp;gt;every action function&amp;lt;/b&amp;gt;, immediately after &amp;lt;code&amp;gt;$this-&amp;gt;setAjaxMode()&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  public function move()&lt;br /&gt;
  {&lt;br /&gt;
    $this-&amp;gt;setAjaxMode();&lt;br /&gt;
    $this-&amp;gt;checkVersion(); // &amp;lt;-- ADD HERE&lt;br /&gt;
    ...&lt;br /&gt;
    $this-&amp;gt;ajaxResponse();&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; In ggg.js&lt;br /&gt;
Transmit the version (from gamedatas) as a parameter with every ajax call. For example, if you&#039;re already using a wrapper function for every ajax call, add it like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  ajaxcallwrapper: function (action, args, handler) {&lt;br /&gt;
    if (!args) args = {};&lt;br /&gt;
    args.lock = true;&lt;br /&gt;
    args.version = this.gamedatas.version; // &amp;lt;-- ADD HERE&lt;br /&gt;
    if (this.checkAction(action)) {&lt;br /&gt;
      this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, this, () =&amp;gt; {}, handler);&lt;br /&gt;
    }&lt;br /&gt;
  },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable / lock table creation for new deploy ===&lt;br /&gt;
&lt;br /&gt;
If you are deploying a major new game version, especially if it involves upgrading production game databases, you may have a lot of angry players if you break their tables.  Depending on your changes, you may be able to restore the previous version and fix the tables easily.&lt;br /&gt;
&lt;br /&gt;
However, if a new deploy turns out bad and players created turn-based tables while it was live, it may be quite difficult to fix those tables, since they were created from a bad deploy.&lt;br /&gt;
&lt;br /&gt;
The solution?  You can announce in your game group that you are locking table creation, and then in your new version, add an impossible startcondition to an existing option.  &lt;br /&gt;
Note: This only makes sense if you have a few games running in real time mode in the time of deployment, otherwise it won&#039;t achieve much, unless you wait at least a day for other turn based games to break (or not)&lt;br /&gt;
&lt;br /&gt;
Here is an example of an option with only 2 values (if you don&#039;t have options at all you have to create a fake option to use this method, if you have more values - you have to list them all):&lt;br /&gt;
&lt;br /&gt;
; In gameoptions.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// TODO NEXT remove after testing deploy to upgrade, here 0 and 1 - replace with values of your option!&lt;br /&gt;
&#039;startcondition&#039; =&amp;gt; [&lt;br /&gt;
   0 =&amp;gt; [ [ &#039;type&#039; =&amp;gt; &#039;minplayers&#039;, &#039;value&#039; =&amp;gt; 32, &#039;message&#039; =&amp;gt; totranslate(&#039;Maintenance in progress.  Table creation disabled.&#039;) ] ],&lt;br /&gt;
   1 =&amp;gt; [ [ &#039;type&#039; =&amp;gt; &#039;minplayers&#039;, &#039;value&#039; =&amp;gt; 32, &#039;message&#039; =&amp;gt; totranslate(&#039;Maintenance in progress.  Table creation disabled.&#039;) ] ],&lt;br /&gt;
],&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Be sure to click &amp;quot;Reload game options configuration&amp;quot; after making this change, then test in studio (test that you cannot create any table)&lt;br /&gt;
* Deploy to production&lt;br /&gt;
* Now, when a player attempts to create a new table, they will see a red error bar with your &amp;quot;Maintenance in progress&amp;quot; message.  &lt;br /&gt;
* Wait for screaming (if you have real times games in progress waiting 15 min probably ok, if you have only turn based games, probably a day)&lt;br /&gt;
* Once you confirm the new deploy looks good, you can revert the change in gameoptions.inc.php and do another deploy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Local Storage ===&lt;br /&gt;
&lt;br /&gt;
There is not much you can store in localStorage (https://developer.mozilla.org/docs/Web/API/Window/localStorage), since most stuff should be stored either in game db or in user prefrences,&lt;br /&gt;
but some stuff makes sense to store there, for example &amp;quot;zoom&amp;quot; level (if you use custom zooming). This setting really affect this specific host and specific browser, setting it localStorage makes most sense.&lt;br /&gt;
&lt;br /&gt;
game.js&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   setup: function (gamedatas) {&lt;br /&gt;
        let zoom = localStorage.getItem(`${this.game_name}_zoom`);&lt;br /&gt;
        this.setZoom(zoom);&lt;br /&gt;
...&lt;br /&gt;
   },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this case setZoom is custom function to actually set it.&lt;br /&gt;
When zoom changed, for example when some buttons pressed, store current value (but sanitize it so it never so bad that game cannot be viewed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    setZoom: function (zoom) {&lt;br /&gt;
      zoom = parseInt(zoom) || 0;&lt;br /&gt;
      if (zoom === 0 || zoom &amp;lt; 0.1 || zoom &amp;gt; 10) {&lt;br /&gt;
        zoom = 1;&lt;br /&gt;
      }&lt;br /&gt;
      this.zoom = zoom;&lt;br /&gt;
      localStorage.setItem(`${this.game_name}_zoom`, &amp;quot;&amp;quot; + this.zoom);&lt;br /&gt;
... do actual zooming stuff&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Algorithms ==&lt;br /&gt;
&lt;br /&gt;
=== Generate permutations in lexicographic order ===&lt;br /&gt;
&lt;br /&gt;
Use this when you have an array like [1, 2, 3, 4] and need to loop over some/all 24 permutations of possible ordering. This type of [https://www.php.net/manual/en/language.generators.syntax.php generator function] computes each possibility one at a time, making it vastly more efficient than either a normal iteration or recursive function that produce all possibilities up front.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function generatePermutations(array $array): Generator&lt;br /&gt;
{&lt;br /&gt;
    // https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order&lt;br /&gt;
    // Sort the array and this is the first permutation&lt;br /&gt;
    sort($array);&lt;br /&gt;
    yield $array;&lt;br /&gt;
&lt;br /&gt;
    $count = count($array);&lt;br /&gt;
    do {&lt;br /&gt;
        // Find the largest index k where a[k] &amp;lt; a[k + 1]&lt;br /&gt;
        // End when no such index exists&lt;br /&gt;
        $found = false;&lt;br /&gt;
        for ($k = $count - 2; $k &amp;gt;= 0; $k--) {&lt;br /&gt;
            $kvalue = $array[$k];&lt;br /&gt;
            $knext = $array[$k + 1];&lt;br /&gt;
            if ($kvalue &amp;lt; $knext) {&lt;br /&gt;
                // Find the largest index l greater than k where a[k] &amp;lt; a[l]&lt;br /&gt;
                for ($l = $count - 1; $l &amp;gt; $k; $l--) {&lt;br /&gt;
                    $lvalue = $array[$l];&lt;br /&gt;
                    if ($kvalue &amp;lt; $lvalue) {&lt;br /&gt;
                        // Swap a[k] and a[l]&lt;br /&gt;
                        [$array[$k], $array[$l]] = [$array[$l], $array[$k]];&lt;br /&gt;
&lt;br /&gt;
                        // Reverse the sequence from a[k + 1] up to and including the final element&lt;br /&gt;
                        $reverse = array_reverse(array_slice($array, $k + 1));&lt;br /&gt;
                        array_splice($array, $k + 1, $count, $reverse);&lt;br /&gt;
                        yield $array;&lt;br /&gt;
&lt;br /&gt;
                        // Restart with the new array to find the next permutation&lt;br /&gt;
                        $found = true;&lt;br /&gt;
                        break 2;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    } while ($found);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$cash = [4, 1, 2, 3, 4];&lt;br /&gt;
foreach ($this-&amp;gt;generatePermutations($cash) as $p) {&lt;br /&gt;
    // your code here to evaluate permutation $p&lt;br /&gt;
    // first iteration: $p = [1, 2, 3, 4, 4]&lt;br /&gt;
    // last (60th) iteration: $p = [4, 4, 3, 2, 1]&lt;br /&gt;
    // break from loop once you achieve your goal&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=20768</id>
		<title>Tutorial reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=20768"/>
		<updated>2024-04-12T13:49:49Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Fixed redirect on bga type safe template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Check out an update version&#039;&#039;&#039; of the [[BGA Type Safe Template: Reversi|Reversi Tutorial]] which uses the [[BGA Type Safe Template]]. {{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Using this tutorial, you can build a complete working game on the BGA environment: Reversi.&lt;br /&gt;
&lt;br /&gt;
Before you read this tutorial, you must:&lt;br /&gt;
* Read the overall presentations of the BGA Framework ([[Studio|see here]]).&lt;br /&gt;
* Know the [http://en.wikipedia.org/wiki/Reversi#Rules rules of Reversi].&lt;br /&gt;
* Know the languages used on BGA: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* &#039;&#039;&#039;Setup your development environment&#039;&#039;&#039; [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
&lt;br /&gt;
== Create your first game ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: you should already have created a project following instructions in [[First_steps_with_BGA_Studio#Create_a_new_game_project|Create a new game project]]. While you will find a &#039;&#039;&#039;reversi&#039;&#039;&#039; directory in your SFTP folder, do not use it for this tutorial. Instead, use the project you have created as an (empty) starting point.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
With the initial skeleton of code provided in your project, you can already start a game from the BGA Studio:&lt;br /&gt;
* Go to your [https://studio.boardgamearena.com/controlpanel studio Control panel], then Manage games and select your initial project. &#039;&#039;Note: there are warnings displayed about a missing BGG_ID and presentation text. You can ignore that for now.&#039;&#039;&lt;br /&gt;
* Click the Play link next to your project name. This will open the Play page and offer to create a new table for your project. &#039;&#039;Optional: click the Heart icon to add your project to your favorite games list.&#039;&#039;&lt;br /&gt;
* On the Play page, on the top of the page, make sure that your settings are &amp;quot;Simple game&amp;quot;, &amp;quot;Real time&amp;quot; and &amp;quot;Manual&amp;quot;.&lt;br /&gt;
* Click &amp;quot;Create table&amp;quot; to create a table of your project. &lt;br /&gt;
* For now, we are going to work with one player only, so use the (-) button to set the number of players to 1. Most of the time it is simpler to proceed with only one player during the early phase of development of your game, as it&#039;s easy and fast to start/stop games. If you choose to start with 2 players, you should see two names on the right: testdude0 and testdude1. To switch between them, press the red arrow button near their names; it will open another tab. This way you don&#039;t need to login and logout from multiple accounts.) &lt;br /&gt;
* Reminder: Always use the &amp;quot;Express Start&amp;quot; button to start the game.&lt;br /&gt;
&lt;br /&gt;
Thus, you can start a &amp;quot;Reversi&amp;quot; game, and arrive on a void, empty game. Yeah.&lt;br /&gt;
&lt;br /&gt;
End the game by clicking on the game options icon on the top right, and then on &amp;quot;Express Stop&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Editing the game information (Optional) ==&lt;br /&gt;
&lt;br /&gt;
This step is optional and will fix the warnings on the project page (missing BGG_ID and presentation).&lt;br /&gt;
&lt;br /&gt;
==== Edits to fix Errors ====&lt;br /&gt;
* Edit your local copy of the gameinfos.inc.php file:&lt;br /&gt;
** Change the &amp;lt;code&amp;gt;bgg_id&amp;lt;/code&amp;gt; value from &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;2389&amp;lt;/code&amp;gt; - that&#039;s around line 37.&lt;br /&gt;
** Add &amp;lt;code&amp;gt;1,&amp;lt;/code&amp;gt; to the players array - that&#039;s around line 41.&lt;br /&gt;
** Change the presentation array content - that&#039;s around line 134. Uncomment one line and change the text. Remove the final comma if you keep only one line!&lt;br /&gt;
* Upload the &amp;lt;code&amp;gt;gameinfos.inc.php&amp;lt;/code&amp;gt; file to the SFTP server (see [[First_steps_with_BGA_Studio#Connect_to_your_SFTP_folder|Connect to your SFTP folder]]).&lt;br /&gt;
&lt;br /&gt;
==== Test your Edits ====&lt;br /&gt;
* Go back to your project page, and in the &amp;quot;Game Information&amp;quot; section, click &amp;quot;Reload game informations&amp;quot;.&lt;br /&gt;
* Finally, refresh the project page in your browser (usually CTRL-F5).&lt;br /&gt;
&lt;br /&gt;
===== Not working? =====&lt;br /&gt;
Some changes will require bypassing the cache. It is often worth doing a hard refresh to make sure the&lt;br /&gt;
&lt;br /&gt;
Sometimes the cache will keep your changes from showing. Since this is a possibility, it will be useful to know how to bypass the cache. To do so you may manually clear cache or use a shortcut to refresh and ignore the cached version of the page. Here&#039;s how&lt;br /&gt;
&lt;br /&gt;
====== Windows ======&lt;br /&gt;
Chrome, Firefox, or Edge: Press &amp;lt;code&amp;gt;Ctrl+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Shift+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Ctrl+Shift+R&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Mac ======&lt;br /&gt;
Chrome or Firefox: Press &amp;lt;code&amp;gt;Shift+Command+R&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Safari for Mac: Press &amp;lt;code&amp;gt;Command+Option+E&amp;lt;/code&amp;gt; to empty the cache, then hold down Shift and click Reload in the toolbar&lt;br /&gt;
&lt;br /&gt;
== Make it look like Reversi ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start with the board. This will give you a good idea of how things will look and where tokens should go.&lt;br /&gt;
&lt;br /&gt;
Be careful designing the layout of your game: you must always keep in mind that players with a 1024px screen width must be able to play. Usually, it means that the width of the play area can be 750px (in the worst case).&lt;br /&gt;
&lt;br /&gt;
For Reversi, it&#039;s useless to have a 750x750px board - much too big, so we chose this one which fit perfectly (536x528):&lt;br /&gt;
&lt;br /&gt;
[[File:Board.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note that we are using a jpg file. Jpg filesare lighter than png, so they are faster to load. Later, we are going to use PNGs for tokens because they allow for transparency.&lt;br /&gt;
&lt;br /&gt;
==== Add the board ====&lt;br /&gt;
use lowercase file names&lt;br /&gt;
* upload &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;img/&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
* edit &amp;lt;code&amp;gt;reversi_reversi.tpl&amp;lt;/code&amp;gt; to add a &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; for your board.&lt;br /&gt;
&lt;br /&gt;
Note: If you are building this game by following the tutorial, you will have a different project name than &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; (i.e. &amp;lt;code&amp;gt;mygame_mygame.tpl&amp;lt;/code&amp;gt;). The file names in your project will be different than shown in this tutorial, replacing &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; with your project name. Be sure that any code (other than comments) that references &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; is changed to your actual project name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* edit your &amp;lt;code&amp;gt;reversi.css&amp;lt;/code&amp;gt; file to transform it into a visible board:&lt;br /&gt;
&lt;br /&gt;
 #board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: refresh your page.&#039;&#039;&#039; Here&#039;s your board:[[File:reversi1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If the board does not appear, refresh the page (always do this when you update the CSS file), and check the image filename. Remember file names are case sensitive!&lt;br /&gt;
&lt;br /&gt;
==== Code the Grid ====&lt;br /&gt;
Now, we need to create some invisible HTML elements where squares are. These elements will be used as position references for the white and black tokens. &lt;br /&gt;
&lt;br /&gt;
===== Make a Square Template =====&lt;br /&gt;
The board is 8 squares by 8 squares. This means we need 64 squares. To avoid writing 64 individual &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; elements on our template, we are going to use the &amp;quot;block&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s modify our template (the &amp;lt;code&amp;gt;.tpl&amp;lt;/code&amp;gt; file) like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- BEGIN square --&amp;gt;&lt;br /&gt;
        &amp;lt;div id=&amp;quot;square_{X}_{Y}&amp;quot; class=&amp;quot;square&amp;quot; style=&amp;quot;left: {LEFT}px; top: {TOP}px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we created a &amp;quot;square&amp;quot; block, with 4 variable elements: &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LEFT&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;TOP&amp;lt;/code&amp;gt;. We are going to use this block 64 times during page load.&lt;br /&gt;
&lt;br /&gt;
===== Use Square Template to Build Grid =====&lt;br /&gt;
Let&#039;s do it in our &amp;lt;code&amp;gt;reversi.view.php&amp;lt;/code&amp;gt; file, inside the &amp;lt;code&amp;gt;build_page&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
Note that &amp;quot;reversi_reversi&amp;quot; is the name of the game and if you named your differently you will have to change that when you copy and paste. Example &amp;quot;testreversi_testreversi&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $this-&amp;gt;page-&amp;gt;begin_block( &amp;quot;reversi_reversi&amp;quot;, &amp;quot;square&amp;quot; );&lt;br /&gt;
        &lt;br /&gt;
        $hor_scale = 64.8;&lt;br /&gt;
        $ver_scale = 64.4;&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $this-&amp;gt;page-&amp;gt;insert_block( &amp;quot;square&amp;quot;, array(&lt;br /&gt;
                    &#039;X&#039; =&amp;gt; $x,&lt;br /&gt;
                    &#039;Y&#039; =&amp;gt; $y,&lt;br /&gt;
                    &#039;LEFT&#039; =&amp;gt; round( ($x-1)*$hor_scale+10 ),&lt;br /&gt;
                    &#039;TOP&#039; =&amp;gt; round( ($y-1)*$ver_scale+7 )&lt;br /&gt;
                ) );&lt;br /&gt;
            }        &lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: as you can see, squares in our &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; files do not have an exact width/height in pixels, and that&#039;s the reason we are using floating point numbers here.&lt;br /&gt;
&lt;br /&gt;
===== Style Those Squares =====&lt;br /&gt;
Now, to finish our work and check if everything works fine, we are going to style our square a little bit in our CSS stylesheet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
    position: relative;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.square {&lt;br /&gt;
    width: 62px;&lt;br /&gt;
    height: 62px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-color: red;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explanations:&lt;br /&gt;
* With &amp;quot;position: relative&amp;quot; on board, we ensure square elements are positioned relatively to board.&lt;br /&gt;
* &amp;lt;code&amp;gt;background-color: red;&amp;lt;/code&amp;gt; is used for testing. This allows us to see the invisible elements. (You could instead do something like &amp;lt;code&amp;gt;border: 1px solid orange;&amp;lt;/code&amp;gt;. have fun and be creative)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s refresh and check our (beautiful) squares:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now that you know the squares are there, you can remove the test line &amp;lt;code&amp;gt;background-color: red;&amp;lt;/code&amp;gt;  from your &amp;lt;code&amp;gt;.square&amp;lt;/code&amp;gt; class in the CSS stylesheet.&lt;br /&gt;
&lt;br /&gt;
===== Not Working? =====&lt;br /&gt;
If the styled squares do not appear, inspect and check your css (Chrome DevTools: Application &amp;gt; Frames &amp;gt; top &amp;gt; Stylesheets &amp;gt; reversi.css). &lt;br /&gt;
&lt;br /&gt;
If your changes are not there try clearing your cache. Remember, you can bybass cache&lt;br /&gt;
&lt;br /&gt;
== The Tokens ==&lt;br /&gt;
&lt;br /&gt;
Now, our board is ready for some tokens!&lt;br /&gt;
&lt;br /&gt;
[Note: Throughout this tutorial, sometimes &amp;quot;tokens&amp;quot; is used, and sometimes &amp;quot;discs&amp;quot; is used. They are often swapped if you&#039;re looking at code in the reversi example project.]&lt;br /&gt;
&lt;br /&gt;
=== Build the Token ===&lt;br /&gt;
There are quite a few steps before the tokens will appear. You may be used to testing after every change, but that won&#039;t work well here. The token will &#039;&#039;&#039;not&#039;&#039;&#039; show until you have add a div to the tpl, styles to the css, js template to the tpl, utility method in the js,  adjusted the php file, and added the token to the board in the js file.&lt;br /&gt;
&lt;br /&gt;
==== HTML in the .tpl file ====&lt;br /&gt;
At first, we introduce a new &#039;div&#039; element as a child of &amp;quot;board&amp;quot; to host all these tokens (in our template):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;div id=&amp;quot;tokens&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt; is plural. This div will be used to hold the token divs. Shortly, we will use javascript to add individual tokens to the board.&lt;br /&gt;
&lt;br /&gt;
==== Add Token to img directory ====&lt;br /&gt;
Here&#039;s a new piece of art with the tokens. We need transparency here so we are using a png file:&lt;br /&gt;
&lt;br /&gt;
[[File:tokens.png]]&lt;br /&gt;
&lt;br /&gt;
Upload this image file &amp;lt;code&amp;gt;tokens.png&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;img/&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
Important Fun Fact: we are using ONE file for both tokens. It is really important to use a minimum number of graphic files for your game. This is called the &amp;quot;CSS sprite&amp;quot; technique, because it makes the game load faster and more reliable. [http://www.w3schools.com/css/css_image_sprites.asp Read more about CSS sprites].&lt;br /&gt;
&lt;br /&gt;
==== Style the Tokens in .css file ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.token {&lt;br /&gt;
    width: 56px;&lt;br /&gt;
    height: 56px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/tokens.png&#039;);&lt;br /&gt;
}&lt;br /&gt;
.tokencolor_ffffff { background-position: 0px 0px;   }&lt;br /&gt;
.tokencolor_000000 { background-position: -56px 0px;   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this CSS code, we could apply the classes &amp;quot;token&amp;quot; and &amp;quot;tokencolor_ffffff&amp;quot; to a div element and we&#039;d got a white token.&lt;br /&gt;
&lt;br /&gt;
Note the &amp;quot;position: absolute&amp;quot; which allows us to position tokens on the board and make them &amp;quot;slide&amp;quot; to their positions.&lt;br /&gt;
&lt;br /&gt;
==== Build Token JS Template in .tpl file ====&lt;br /&gt;
Now, let&#039;s make the first token appear on our board. Tokens are not visible at the beginning of the game: they appear dynamically during the game. For this reason, we are going to make them appear from our Javascript code, with a BGA Framework technique called &amp;quot;JS template&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In our template file (&amp;lt;code&amp;gt;reversi_reversi.tpl&amp;lt;/code&amp;gt;), let&#039;s create the piece of HTML needed to display our token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Templates&lt;br /&gt;
&lt;br /&gt;
var jstpl_token=&#039;&amp;lt;div class=&amp;quot;token tokencolor_${color}&amp;quot; id=&amp;quot;token_${x_y}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: we already created the &amp;quot;templates&amp;quot; section for you in the game skeleton.&lt;br /&gt;
&lt;br /&gt;
As you can see, we defined a JS template named &amp;lt;code&amp;gt;jstpl_token&amp;lt;/code&amp;gt; with a piece of HTML and two variables: the color of the token and its x/y coordinates. Note that the syntax of the argument is different for template block variables (braces &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;) and JS template variables (dollar and braces &amp;lt;code&amp;gt;${}&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Add Token Utility Method in .js file ====&lt;br /&gt;
Now, let&#039;s create a method in our Javascript code (in the &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt; file) that will make a token appear on the board, using this template. Add under the section //// Utility methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        addTokenOnBoard: function( x, y, player )&lt;br /&gt;
        {&lt;br /&gt;
            dojo.place( this.format_block( &#039;jstpl_token&#039;, {&lt;br /&gt;
                x_y: x+&#039;_&#039;+y,&lt;br /&gt;
                color: this.gamedatas.players[ player ].color&lt;br /&gt;
            } ) , &#039;tokens&#039; );&lt;br /&gt;
            &lt;br /&gt;
            this.placeOnObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;overall_player_board_&#039;+player );&lt;br /&gt;
            this.slideToObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;square_&#039;+x+&#039;_&#039;+y ).play();&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Utility Method Explanation =====&lt;br /&gt;
* with &amp;lt;code&amp;gt;dojo.place&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;this.format_block&amp;lt;/code&amp;gt; methods, we create a HTML piece of code and insert it as a new child of &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt; div element.&lt;br /&gt;
* with BGA &amp;lt;code&amp;gt;this.placeOnObject&amp;lt;/code&amp;gt; method, we place this element over the panel of some player. &lt;br /&gt;
* Immediately after, using BGA &amp;lt;code&amp;gt;this.slideToObject&amp;lt;/code&amp;gt; method, we make the token slide to the &amp;lt;code&amp;gt;square&amp;lt;/code&amp;gt; element, its final destination.&lt;br /&gt;
* &amp;lt;code&amp;gt;&#039;overall_player_board_&#039;+player&amp;lt;/code&amp;gt; refers to the div element that contains each player&#039;s information and avatar. By initially placing the token here, it gives the effect that the player&#039;s avatar is throwing the token onto the board.&lt;br /&gt;
&lt;br /&gt;
Note: don&#039;t forget to call the &amp;lt;code&amp;gt;play()&amp;lt;/code&amp;gt;, otherwise the token will remain at its original location.&lt;br /&gt;
&lt;br /&gt;
Note: during this process, the parent of the new token HTML element will stay &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;placeOnObject&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;slideToObject&amp;lt;/code&amp;gt; methods are &#039;&#039;only&#039;&#039; moving the position of elements on screen, and they are &#039;&#039;not&#039;&#039; modifying the HTML tree.&lt;br /&gt;
&lt;br /&gt;
==== Set Token Colors in setupNewGame in .game.php file ====&lt;br /&gt;
Before we can show a token, we need to set the player colors in the setupNewGame function in reversi.game.php:&lt;br /&gt;
&lt;br /&gt;
Replace &amp;lt;code&amp;gt;$default_colors = $gameinfos[&#039;player_colors&#039;];&amp;lt;/code&amp;gt; with the following line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $default_colors = array( &amp;quot;ffffff&amp;quot;, &amp;quot;000000&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: A few lines below, you may have to remove the line &amp;lt;code&amp;gt;self::reattributeColorsBasedOnPreferences( $players, $gameinfos[&#039;player_colors&#039;] );&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test the Token ===&lt;br /&gt;
Now, to test if everything works fine&lt;br /&gt;
&lt;br /&gt;
==== addTokenOnBoard() in .js file to Test ====&lt;br /&gt;
In &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt;, in &amp;lt;code&amp;gt;setup: function&amp;lt;/code&amp;gt;, under &amp;lt;code&amp;gt;// TODO: Set up your game interface here&amp;lt;/code&amp;gt; add &lt;br /&gt;
 this.addTokenOnBoard( 2, 2, this.player_id );&lt;br /&gt;
Now restart the game.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: if the page fails to load with a &amp;lt;code&amp;gt;Javascript error: n is null&amp;lt;/code&amp;gt; message, make sure you have added the &amp;quot;tokens&amp;quot; div in your template as instructed above.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A token should appear and slide immediately to its position, like this:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi3.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The database ==&lt;br /&gt;
&lt;br /&gt;
We did most of the client-side programming, so let&#039;s have a look on the other side now. To design the database model of our game, you will need to access the database. You won&#039;t need to do anything in database UI, yet.&lt;br /&gt;
&lt;br /&gt;
=== Accessing the Database ===&lt;br /&gt;
To access the database, start a game, then click &amp;quot;Go to game database&amp;quot; link at the bottom of our game, to access the database directly with a PhpMyAdmin instance.&lt;br /&gt;
&lt;br /&gt;
After the first time you&#039;ve acess the database, you could skip opening a game and instead, go to https://studio.boardgamearena.com/db/ . Your PhpMyAdmin username/password is in your welcome email.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: do not remove existing tables&lt;br /&gt;
&lt;br /&gt;
=== Create Table in .sql file ===&lt;br /&gt;
Now, you are able to create the table(s) you need for your game, and report every SQL command used in your &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
The database model of Reversi is short: just one table with the squares of the board. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `board` (&lt;br /&gt;
  `board_x` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_y` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_player` int(10) unsigned DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`board_x`,`board_y`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the above SQL to &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt;. Pay special attention to the backtick &amp;lt;code&amp;gt;`&amp;lt;/code&amp;gt; character vs. the single quote &amp;lt;code&amp;gt;&#039;&amp;lt;/code&amp;gt; when working with SQL. &lt;br /&gt;
&lt;br /&gt;
=== Test the Table ===&lt;br /&gt;
Now, a new database with a &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt; table will be created each time we start a Reversi game. This is why after modifying our &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; it&#039;s a good time to stop your current game &amp;amp; start a new game.&lt;br /&gt;
&lt;br /&gt;
Start a new game and verify a table is created.&lt;br /&gt;
&lt;br /&gt;
== Setup the initial game position ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: From now on, you must launch the game with &#039;&#039;&#039;two players&#039;&#039;&#039; to get two &amp;lt;code&amp;gt;player_id&amp;lt;/code&amp;gt;s within the database. Otherwise, the game will crash.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;setupNewGame&amp;lt;/code&amp;gt; method of our &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; is called during initial setup. This initializes our data and places the starting tokens on the board. At the beginning of the game, there should be 4 tokens on the board.&lt;br /&gt;
&lt;br /&gt;
=== Initialize the Board in .game.php file ===&lt;br /&gt;
Under &amp;lt;code&amp;gt;// TODO: setup the initial game situation here&amp;lt;/code&amp;gt;, initialize the board&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Init the board&lt;br /&gt;
        $sql = &amp;quot;INSERT INTO board (board_x,board_y,board_player) VALUES &amp;quot;;&lt;br /&gt;
        $sql_values = array();&lt;br /&gt;
        list( $blackplayer_id, $whiteplayer_id ) = array_keys( $players );&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $token_value = &amp;quot;NULL&amp;quot;;&lt;br /&gt;
                if( ($x==4 &amp;amp;&amp;amp; $y==4) || ($x==5 &amp;amp;&amp;amp; $y==5) )  // Initial positions of white player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$whiteplayer_id&#039;&amp;quot;;&lt;br /&gt;
                else if( ($x==4 &amp;amp;&amp;amp; $y==5) || ($x==5 &amp;amp;&amp;amp; $y==4) )  // Initial positions of black player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$blackplayer_id&#039;&amp;quot;;&lt;br /&gt;
                    &lt;br /&gt;
                $sql_values[] = &amp;quot;(&#039;$x&#039;,&#039;$y&#039;,$token_value)&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        $sql .= implode( &#039;,&#039;, $sql_values );&lt;br /&gt;
        self::DbQuery( $sql );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Board Initialization Explanation ====&lt;br /&gt;
&lt;br /&gt;
* We create one table entry for each square, with a &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; value which means &amp;quot;empty square&amp;quot;&lt;br /&gt;
* On 4 of the squares, we place an initial token.&lt;br /&gt;
&lt;br /&gt;
After this, we set &amp;lt;code&amp;gt;activeNextPlayer&amp;lt;/code&amp;gt; to make the first player active at the beginning of the game (this line is already present in the default code template).&lt;br /&gt;
&lt;br /&gt;
If you didn&#039;t do it earlier, you need to remove the call to &amp;lt;code&amp;gt;self::reattributeColorsBasedOnPreferences()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;SetupNewGame()&amp;lt;/code&amp;gt;. If you don&#039;t, player color preferences will try (and fail) to override the two colors supported here.&lt;br /&gt;
&lt;br /&gt;
=== Show the Initial Token Setup ===&lt;br /&gt;
Now, we need to make these tokens appear on the client side. The first step is to return the token positions with our &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; PHP method. &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; is called during each page reload.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; method, after &amp;lt;code&amp;gt;// TODO: Gather all information about current game situation (visible by player $current_player_id)&amp;lt;/code&amp;gt;, add the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Get reversi board token&lt;br /&gt;
        $result[&#039;board&#039;] = self::getObjectListFromDB( &amp;quot;SELECT board_x x, board_y y, board_player player&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       WHERE board_player IS NOT NULL&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you may need to modify the query that gets player information to also get the player&#039;s colors. This is in the variable &amp;lt;code&amp;gt;$sql&amp;lt;/code&amp;gt;, above the lines you just inserted in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt;. Below is what the line will look like. Notice how we&#039;ve added &amp;lt;code&amp;gt;player_color color&amp;lt;/code&amp;gt; to the sql query.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$sql = &amp;quot;SELECT player_id id, player_score score, player_color color FROM player &amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are using the BGA framework&#039;s &amp;lt;code&amp;gt;getObjectListFromDB()&amp;lt;/code&amp;gt; that formats the result of this SQL query in a PHP array with x, y and player attributes. We add it to the result associative array with the key &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Last, we process this array client side. Let&#039;s place a token on the board for each array item. We&#039;ll do this in our Javascript &amp;lt;code&amp;gt;setup&amp;lt;/code&amp;gt; method under &amp;lt;code&amp;gt;// TODO: Set up your game interface here, according to &amp;quot;gamedatas&amp;quot;&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This will result in a removal or edit of the previously added line &amp;lt;code&amp;gt;this.addTokenOnBoard(2, 2, this.player_id);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            for( var i in gamedatas.board )&lt;br /&gt;
            {&lt;br /&gt;
                var square = gamedatas.board[i];&lt;br /&gt;
                &lt;br /&gt;
                if( square.player !== null )&lt;br /&gt;
                {&lt;br /&gt;
                    this.addTokenOnBoard( square.x, square.y, square.player );&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt; entry created in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; is used here as &amp;lt;code&amp;gt;gamedatas.board&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test the Game Start ===&lt;br /&gt;
Reload... and here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi5.jpg]]&lt;br /&gt;
&lt;br /&gt;
It starts to feel like Reversi here...&lt;br /&gt;
&lt;br /&gt;
== The game state machine ==&lt;br /&gt;
&lt;br /&gt;
Stop your game, again. You&#039;re about to start the core game logic.&lt;br /&gt;
&lt;br /&gt;
You already read [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine], so you know that this is the heart of your game logic. For reversi, it&#039;s relatively simple. Here&#039;s a diagram of our game state machine:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi6.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Build your States ===&lt;br /&gt;
And here&#039;s our &amp;lt;code&amp;gt;states.inc.php&amp;lt;/code&amp;gt;, according to this diagram:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$machinestates = array(&lt;br /&gt;
&lt;br /&gt;
    1 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;Game setup&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;&amp;quot; =&amp;gt; 10 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    10 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;playerTurn&amp;quot;,&lt;br /&gt;
		&amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&#039;${actplayer} must play a disc&#039;),&lt;br /&gt;
		&amp;quot;descriptionmyturn&amp;quot; =&amp;gt; clienttranslate(&#039;${you} must play a disc&#039;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;activeplayer&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argPlayerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;possibleactions&amp;quot; =&amp;gt; array( &#039;playDisc&#039; ),&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;playDisc&amp;quot; =&amp;gt; 11, &amp;quot;zombiePass&amp;quot; =&amp;gt; 11 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    11 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;nextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;game&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stNextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;updateGameProgression&amp;quot; =&amp;gt; true,        &lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;nextTurn&amp;quot; =&amp;gt; 10, &amp;quot;cantPlay&amp;quot; =&amp;gt; 11, &amp;quot;endGame&amp;quot; =&amp;gt; 99 )&lt;br /&gt;
    ),&lt;br /&gt;
   &lt;br /&gt;
    99 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;End of game&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argGameEnd&amp;quot;&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; let&#039;s create the methods that are declared in this game states description file:&lt;br /&gt;
* &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt;: referenced in the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; property of the &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; state; this is the name of the method to call to retrieve arguments for this gamestate. Arguments are sent to the client side to be used on &amp;lt;code&amp;gt;onEnteringState&amp;lt;/code&amp;gt; or to set arguments in the gamestate description.&lt;br /&gt;
* &amp;lt;code&amp;gt;stNextPlayer&amp;lt;/code&amp;gt;: referenced in the &amp;lt;code&amp;gt;action&amp;lt;/code&amp;gt; property of the &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt; state; this is the name of the method to call when this game state become the current game state. &lt;br /&gt;
&lt;br /&gt;
=== Test Your States ===&lt;br /&gt;
... and start a new Reversi game.&lt;br /&gt;
&lt;br /&gt;
As you can see on the screen capture below, the BGA framework makes the game jump to our first game state &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; right after the initial setup. That&#039;s why the status bar contains the description of &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; state (&amp;quot;XXXX must play a disc&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
[[File:reversi7.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The rules ==&lt;br /&gt;
&lt;br /&gt;
We will use the &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt; PHP method to:&lt;br /&gt;
* Indicate to the current player where she is allowed to play by returning a list of coordinates&lt;br /&gt;
* Check if the player has the right to play in the spot they choose&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Example of getPossibleMoves here https://gist.github.com/leocaseiro/a8bc2851bd0caddd06685b5035937d15&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is pure PHP programming here, and there are no special things from the BGA framework that can be used. This is why we won&#039;t go into details here. The overall idea is:&lt;br /&gt;
* Create a &amp;lt;code&amp;gt;getTurnedOverDiscs(x,y)&amp;lt;/code&amp;gt; method that returns coordinates of discs that would be turned over if a token would be played at &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;,&amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Loop through all free squares of the board and call the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; method on each of them. If at least 1 token is turned over, this is a valid move.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: Making a database query is slow! Please don&#039;t load the entire game board with a SQL query multiple times. In our implementation, we load the entire board once at the beginning of &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt;, and then pass the board as an argument to all methods.&lt;br /&gt;
&lt;br /&gt;
If you want to look into details, please look at the &amp;quot;utility method&amp;quot; sections of &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;. If building the tutorial yourself, copy the functions under &amp;quot;Utility functions&amp;quot; comment from the Reversi tutorial.&lt;br /&gt;
&lt;br /&gt;
== Display allowed moves ==&lt;br /&gt;
&lt;br /&gt;
Now we want to highlight the squares where the player can place a disc.&lt;br /&gt;
&lt;br /&gt;
To do this, we add a &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;. This method is called on the server each time we enter into &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state, and its result is transferred automatically to the client-side:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function argPlayerTurn()&lt;br /&gt;
    {&lt;br /&gt;
        return array(&lt;br /&gt;
            &#039;possibleMoves&#039; =&amp;gt; self::getPossibleMoves( self::getActivePlayerId() )&lt;br /&gt;
        );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt; method we just developed.&lt;br /&gt;
&lt;br /&gt;
Each time we enter into a new game state, we use the &amp;lt;code&amp;gt;onEnteringState&amp;lt;/code&amp;gt; Javascript method (in the &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt; file, under &amp;quot;Game &amp;amp; client states&amp;quot;). This lets us use the data returned by the method above on the client side.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onEnteringState: function( stateName, args )&lt;br /&gt;
        {&lt;br /&gt;
           console.log( &#039;Entering state: &#039;+stateName );&lt;br /&gt;
            &lt;br /&gt;
            switch( stateName )&lt;br /&gt;
            {&lt;br /&gt;
            case &#039;playerTurn&#039;:&lt;br /&gt;
                this.updatePossibleMoves( args.args.possibleMoves );&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, when we enter into &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state, we call our &amp;lt;code&amp;gt;updatePossibleMoves&amp;lt;/code&amp;gt; method (under the &amp;quot;Utility methods&amp;quot; section). This method looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        updatePossibleMoves: function( possibleMoves )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );&lt;br /&gt;
&lt;br /&gt;
            for( var x in possibleMoves )&lt;br /&gt;
            {&lt;br /&gt;
                for( var y in possibleMoves[ x ] )&lt;br /&gt;
                {&lt;br /&gt;
                    // x,y is a possible move&lt;br /&gt;
                    dojo.addClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; );&lt;br /&gt;
                }            &lt;br /&gt;
            }&lt;br /&gt;
                        &lt;br /&gt;
            this.addTooltipToClass( &#039;possibleMove&#039;, &#039;&#039;, _(&#039;Place a disc here&#039;) );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here&#039;s what this does. At first, it removes all &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; classes currently applied with the very useful combination of &amp;lt;code&amp;gt;dojo.query&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;removeClass&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
Then it loops through all possible moves our PHP &amp;lt;code&amp;gt;updatePossibleMoves&amp;lt;/code&amp;gt; function created for us, and adds the &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; class to each corresponding square.&lt;br /&gt;
&lt;br /&gt;
Finally, it uses the BGA framework &amp;lt;code&amp;gt;addTooltipToClass&amp;lt;/code&amp;gt; method to associate a tooltip to all those highlighted squares so that players can understand their meaning.&lt;br /&gt;
&lt;br /&gt;
To see the possible moves we need to create a CSS class (&amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt;) that can be applied to a &amp;lt;code&amp;gt;square&amp;lt;/code&amp;gt; element to highlight it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.possibleMove {&lt;br /&gt;
    background-color: white;&lt;br /&gt;
    opacity: 0.2;&lt;br /&gt;
    filter:alpha(opacity=20); /* For IE8 and earlier */  &lt;br /&gt;
    cursor: pointer;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi8.jpg.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s play ==&lt;br /&gt;
&lt;br /&gt;
From now, it&#039;s better to restart a game with 2 players, because we are going to implement a complete Reversi turn. The summary of what we are going to do is:&lt;br /&gt;
* When we click on a &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; square, send the move to the server.&lt;br /&gt;
* Server side, check the move is correct, apply Reversi rules and jump to next player.&lt;br /&gt;
* Client side, change the token position to reflect the move.&lt;br /&gt;
&lt;br /&gt;
First we associate each click on a square to one of our methods using our Javascript &amp;lt;code&amp;gt;setup&amp;lt;/code&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.query( &#039;.square&#039; ).connect( &#039;onclick&#039;, this, &#039;onPlayDisc&#039; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the &amp;quot;dojo.query&amp;quot; method to get all HTML elements with &amp;quot;square&amp;quot; class in just one function call. Now, our &amp;quot;onPlayDisc&amp;quot; method is called each time someone clicks on a square.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s our &amp;quot;onPlayDisc&amp;quot; method below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onPlayDisc: function( evt )&lt;br /&gt;
        {&lt;br /&gt;
            // Stop this event propagation&lt;br /&gt;
            dojo.stopEvent( evt );&lt;br /&gt;
&lt;br /&gt;
            // Get the clicked square x and y&lt;br /&gt;
            // Note: square id format is &amp;quot;square_X_Y&amp;quot;&lt;br /&gt;
            var coords = evt.currentTarget.id.split(&#039;_&#039;);&lt;br /&gt;
            var x = coords[1];&lt;br /&gt;
            var y = coords[2];&lt;br /&gt;
&lt;br /&gt;
            if( ! dojo.hasClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; ) )&lt;br /&gt;
            {&lt;br /&gt;
                // This is not a possible move =&amp;gt; the click does nothing&lt;br /&gt;
                return ;&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            if( this.checkAction( &#039;playDisc&#039; ) )    // Check that this action is possible at this moment&lt;br /&gt;
            {            &lt;br /&gt;
                this.ajaxcall( &amp;quot;/reversi/reversi/playDisc.html&amp;quot;, {&lt;br /&gt;
                    x:x,&lt;br /&gt;
                    y:y&lt;br /&gt;
                }, this, function( result ) {} );&lt;br /&gt;
            }            &lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Warning: Make sure to replace &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; in line &amp;lt;code&amp;gt;this.ajaxcall( &amp;quot;/reversi/reversi/playDisc.html&amp;quot;, {&amp;lt;/code&amp;gt; with the name of your project. E.g. &amp;lt;code&amp;gt;&amp;quot;/yourgamename/yourgamename/playDisc.html&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What we do here is:&lt;br /&gt;
* We stop the propagation of the Javascript &amp;lt;code&amp;gt;onclick&amp;lt;/code&amp;gt; event. Otherwise, it can lead to random behavior so it&#039;s always a good idea.&lt;br /&gt;
* We get the x/y coordinates of the square by using &amp;lt;code&amp;gt;evt.currentTarget.id&amp;lt;/code&amp;gt;&lt;br /&gt;
* We check that clicked square has the &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; class, otherwise we know for sure that we can&#039;t play there.&lt;br /&gt;
* We check that &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; action is possible, according to current game state (see &amp;lt;code&amp;gt;possibleactions&amp;lt;/code&amp;gt; entry in our &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state defined above). This check is important to avoid issues if a player double clicks on a square.&lt;br /&gt;
* Finally, we make a call to the server using BGA &amp;lt;code&amp;gt;ajaxcall&amp;lt;/code&amp;gt; method with argument x and y.&lt;br /&gt;
&lt;br /&gt;
Now, we have to manage this &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; action on the server side. At first, we introduce a &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; entry point in our &amp;lt;code&amp;gt;reversi.action.php&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    public function playDisc()&lt;br /&gt;
    {&lt;br /&gt;
        self::setAjaxMode();     &lt;br /&gt;
        $x = self::getArg( &amp;quot;x&amp;quot;, AT_posint, true );&lt;br /&gt;
        $y = self::getArg( &amp;quot;y&amp;quot;, AT_posint, true );&lt;br /&gt;
        $result = $this-&amp;gt;game-&amp;gt;playDisc( $x, $y );&lt;br /&gt;
        self::ajaxResponse( );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we get the 2 arguments x and y from the javascript call, and call a corresponding &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; method in our game logic (&amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s have a look of this &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function playDisc( $x, $y )&lt;br /&gt;
    {&lt;br /&gt;
        // Check that this player is active and that this action is possible at this moment&lt;br /&gt;
        self::checkAction( &#039;playDisc&#039; );  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... at first, we check that this action is possible according to current game state (see &amp;quot;possible action&amp;quot;). We already did it on client side, but it&#039;s important to do it on server side too (otherwise it would be possible to cheat).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Now, check if this is a possible move&lt;br /&gt;
        $board = self::getBoard();&lt;br /&gt;
        $player_id = self::getActivePlayerId();&lt;br /&gt;
        $turnedOverDiscs = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
        &lt;br /&gt;
        if( count( $turnedOverDiscs ) &amp;gt; 0 )&lt;br /&gt;
        {&lt;br /&gt;
            // This move is possible!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...now, we are using the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; method again to check that this move is possible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
            &lt;br /&gt;
            $sql = &amp;quot;UPDATE board SET board_player=&#039;$player_id&#039;&lt;br /&gt;
                    WHERE ( board_x, board_y) IN ( &amp;quot;;&lt;br /&gt;
            &lt;br /&gt;
            foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                $sql .= &amp;quot;(&#039;&amp;quot;.$turnedOver[&#039;x&#039;].&amp;quot;&#039;,&#039;&amp;quot;.$turnedOver[&#039;y&#039;].&amp;quot;&#039;),&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            $sql .= &amp;quot;(&#039;$x&#039;,&#039;$y&#039;) ) &amp;quot;;&lt;br /&gt;
                       &lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... we update the database to change the color of all turned over disc + the disc we just placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Update scores according to the number of disc on board&lt;br /&gt;
            $sql = &amp;quot;UPDATE player&lt;br /&gt;
                    SET player_score = (&lt;br /&gt;
                    SELECT COUNT( board_x ) FROM board WHERE board_player=player_id&lt;br /&gt;
                    )&amp;quot;;&lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
            &lt;br /&gt;
            // Statistics&lt;br /&gt;
            self::incStat( count( $turnedOverDiscs ), &amp;quot;turnedOver&amp;quot;, $player_id );&lt;br /&gt;
            if( ($x==1 &amp;amp;&amp;amp; $y==1) || ($x==8 &amp;amp;&amp;amp; $y==1) || ($x==1 &amp;amp;&amp;amp; $y==8) || ($x==8 &amp;amp;&amp;amp; $y==8) )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCorner&#039;, $player_id );&lt;br /&gt;
            else if( $x==1 || $x==8 || $y==1 || $y==8 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnBorder&#039;, $player_id );&lt;br /&gt;
            else if( $x&amp;gt;=3 &amp;amp;&amp;amp; $x&amp;lt;=6 &amp;amp;&amp;amp; $y&amp;gt;=3 &amp;amp;&amp;amp; $y&amp;lt;=6 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCenter&#039;, $player_id );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... now, we update both player score by counting all disc, and we manage game statistics.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Notify&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;playDisc&amp;quot;, clienttranslate( &#039;${player_name} plays a disc and turns over ${returned_nbr} disc(s)&#039; ), array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;player_name&#039; =&amp;gt; self::getActivePlayerName(),&lt;br /&gt;
                &#039;returned_nbr&#039; =&amp;gt; count( $turnedOverDiscs ),&lt;br /&gt;
                &#039;x&#039; =&amp;gt; $x,&lt;br /&gt;
                &#039;y&#039; =&amp;gt; $y&lt;br /&gt;
            ) );&lt;br /&gt;
&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;turnOverDiscs&amp;quot;, &#039;&#039;, array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;turnedOver&#039; =&amp;gt; $turnedOverDiscs&lt;br /&gt;
            ) );&lt;br /&gt;
            &lt;br /&gt;
            $newScores = self::getCollectionFromDb( &amp;quot;SELECT player_id, player_score FROM player&amp;quot;, true );&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;newScores&amp;quot;, &amp;quot;&amp;quot;, array(&lt;br /&gt;
                &amp;quot;scores&amp;quot; =&amp;gt; $newScores&lt;br /&gt;
            ) );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... then we notify about all these changes. We are using for that 3 notifications (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;newScores&amp;lt;/code&amp;gt; that we are going to implement on client side later). Note that the description of the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; notification will be logged in the game log.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Then, go to the next state&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
            throw new BgaSystemException( &amp;quot;Impossible move&amp;quot; );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... finally, we jump to the next game state if everything goes fine (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; is the name of a transition in the &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state description above which leads to state 11 which is &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
To make the statistics work, we have to initialize them in &amp;lt;code&amp;gt;stats.json&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;player&amp;quot;: {&lt;br /&gt;
    &amp;quot;discPlayedOnCorner&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 10,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on a corner&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;discPlayedOnBorder&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 11,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on a border&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;discPlayedOnCenter&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 12,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on board center part&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;turnedOver&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 13,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Number of discs turned over&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A last thing to do on the server side is to activate the next player when we enter the &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt; game state (in the &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; file, under &amp;quot;Game state reactions&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function stNextPlayer()&lt;br /&gt;
    {&lt;br /&gt;
        // Active next player&lt;br /&gt;
        $player_id = self::activeNextPlayer();&lt;br /&gt;
&lt;br /&gt;
        // Check if both player has at least 1 discs, and if there are free squares to play&lt;br /&gt;
        $player_to_discs = self::getCollectionFromDb( &amp;quot;SELECT board_player, COUNT( board_x )&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       GROUP BY board_player&amp;quot;, true );&lt;br /&gt;
&lt;br /&gt;
        if( ! isset( $player_to_discs[ null ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Index 0 has not been set =&amp;gt; there&#039;s no more free place on the board !&lt;br /&gt;
            // =&amp;gt; end of the game&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        else if( ! isset( $player_to_discs[ $player_id ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Active player has no more disc on the board =&amp;gt; he looses immediately&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Can this player play?&lt;br /&gt;
&lt;br /&gt;
        $possibleMoves = self::getPossibleMoves( $player_id );&lt;br /&gt;
        if( count( $possibleMoves ) == 0 )&lt;br /&gt;
        {&lt;br /&gt;
&lt;br /&gt;
            // This player can&#039;t play&lt;br /&gt;
            // Can his opponent play ?&lt;br /&gt;
            $opponent_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039; &amp;quot; );&lt;br /&gt;
            if( count( self::getPossibleMoves( $opponent_id ) ) == 0 )&lt;br /&gt;
            {&lt;br /&gt;
                // Nobody can move =&amp;gt; end of the game&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {            &lt;br /&gt;
                // =&amp;gt; pass his turn&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;cantPlay&#039; );&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            // This player can play. Give him some extra time&lt;br /&gt;
            self::giveExtraTime( $player_id );&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;nextTurn&#039; );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, when we play a token, the rules are checked and the token appears in the database.&lt;br /&gt;
&lt;br /&gt;
[[File:reversi9.jpg]]&lt;br /&gt;
&lt;br /&gt;
Of course, as we don&#039;t manage notifications on client side, we need to press F5 after each move to see the changes on the board.&lt;br /&gt;
&lt;br /&gt;
== Make the move appear automatically ==&lt;br /&gt;
&lt;br /&gt;
Now, what we have to do is process the notifications sent by the server and make the move appear on the interface.&lt;br /&gt;
&lt;br /&gt;
In our &amp;lt;code&amp;gt;setupNotifications&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt;, we register 2 methods for the 2 notifications we created at the previous step (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.subscribe( &#039;playDisc&#039;, this, &amp;quot;notif_playDisc&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;playDisc&#039;, 500 );&lt;br /&gt;
            dojo.subscribe( &#039;turnOverDiscs&#039;, this, &amp;quot;notif_turnOverDiscs&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;turnOverDiscs&#039;, 1500 );&lt;br /&gt;
            dojo.subscribe( &#039;newScores&#039;, this, &amp;quot;notif_newScores&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;newScores&#039;, 500 );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we associate each of our 3 notifications with a method prefixed with &amp;lt;code&amp;gt;notif_&amp;lt;/code&amp;gt;. We also define these notifications as &amp;quot;synchronous&amp;quot;, with a duration in millisecond. It tells the user interface to wait some time after executing the notification, to let the animation end before starting the next notification. In our specific case, the animation will be the following:&lt;br /&gt;
* Make a disc slide from the player panel to its place on the board&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
* Make all turned over discs blink (and of course turned them over)&lt;br /&gt;
* (wait 1500ms)&lt;br /&gt;
* Update the player scores&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
&lt;br /&gt;
The 2nd parameter in &amp;lt;code&amp;gt;dojo.subscribe&amp;lt;/code&amp;gt; call (this) is the &amp;lt;code&amp;gt;context&amp;lt;/code&amp;gt;, and will be passed in as a parameter to the specified method.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s have a look now on the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; notification handler method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_playDisc: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves (makes the board more clear)&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );        &lt;br /&gt;
        &lt;br /&gt;
            this.addTokenOnBoard( notif.args.x, notif.args.y, notif.args.player_id );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No surprise here, we re-used some existing stuff to:&lt;br /&gt;
* Remove the highlighted squares.&lt;br /&gt;
* Add a new disc on board, coming from player panel.&lt;br /&gt;
&lt;br /&gt;
Now, here&#039;s the method that handles the &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt; notification:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_turnOverDiscs: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Get the color of the player who is returning the discs&lt;br /&gt;
            var targetColor = this.gamedatas.players[ notif.args.player_id ].color;&lt;br /&gt;
&lt;br /&gt;
            // Make these discs blink and set them to the specified color&lt;br /&gt;
            for( var i in notif.args.turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                var token = notif.args.turnedOver[ i ];&lt;br /&gt;
                &lt;br /&gt;
                // Make the token blink 2 times&lt;br /&gt;
                var anim = dojo.fx.chain( [&lt;br /&gt;
                    dojo.fadeOut( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeOut( { &lt;br /&gt;
                                    node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y,&lt;br /&gt;
                                    onEnd: function( node ) {&lt;br /&gt;
&lt;br /&gt;
                                        // Remove any color class&lt;br /&gt;
                                        dojo.removeClass( node, [ &#039;tokencolor_000000&#039;, &#039;tokencolor_ffffff&#039; ] );&lt;br /&gt;
                                        // ... and add the good one&lt;br /&gt;
                                        dojo.addClass( node, &#039;tokencolor_&#039;+targetColor );&lt;br /&gt;
                                                             &lt;br /&gt;
                                    } &lt;br /&gt;
                                  } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y  } )&lt;br /&gt;
                                 &lt;br /&gt;
                ] ); // end of dojo.fx.chain&lt;br /&gt;
&lt;br /&gt;
                // ... and launch the animation&lt;br /&gt;
                anim.play();                &lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The list of the discs to be turned over has been made available by our server side code in &amp;lt;code&amp;gt;notif.args.turnedOver&amp;lt;/code&amp;gt; (see previous paragraph). We loop through all these discs, and create a complex animation using &amp;lt;code&amp;gt;dojo.Animation&amp;lt;/code&amp;gt; for each of them. The complete documentation on dojo animations [http://dojotoolkit.org/documentation/tutorials/1.6/animation/ can be found here].&lt;br /&gt;
&lt;br /&gt;
In few words: we create a chain of 4 animations to make the disc fade out, fade in, fade out again, and fade in again. At the end of the second fade out, we change the color of the disc. Finally, we launch the animation with &amp;lt;code&amp;gt;play()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And Also the notification to update the scores:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
notif_newScores: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            for( var player_id in notif.args.scores )&lt;br /&gt;
            {&lt;br /&gt;
                var newScore = notif.args.scores[ player_id ];&lt;br /&gt;
                this.scoreCtrl[ player_id ].toValue( newScore );&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template_Reversi&amp;diff=20767</id>
		<title>BGA-ts-template Reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template_Reversi&amp;diff=20767"/>
		<updated>2024-04-12T13:48:12Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: NevinAF moved page BGA-ts-template Reversi to BGA Type Safe Template: Reversi: Cleaner and more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[BGA Type Safe Template: Reversi]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Reversi&amp;diff=20766</id>
		<title>BGA Type Safe Template: Reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Reversi&amp;diff=20766"/>
		<updated>2024-04-12T13:48:12Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: NevinAF moved page BGA-ts-template Reversi to BGA Type Safe Template: Reversi: Cleaner and more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;This page was generated from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/reversi.md BGA TS Template: Reversi.md]. It is recommended to view this document from the source file. All links will redirect to source documentation, and images will only be included via link.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;ts-template-reversi-tutorial&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= TS Template: Reversi Tutorial =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#board-game-arena-type-safe-template &#039;&#039;BGA Type Safe Template&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Project Files:&#039;&#039;&#039; [[BGA-TS-Template-Reversi]]&lt;br /&gt;
&lt;br /&gt;
This page is a beginner friendly tutorial which mimics the official [https://en.doc.boardgamearena.com/Tutorial_reversi Tutorial Reversi] page, but is more approachable and uses the BGA Type Safe Template. If you are not a new Board Game Arena developer, you may want to follow along with the [https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#getting-started BGA Type Safe Template: Getting Started] guide for a more concise overview of the template.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;All steps are recorded as a git branch so you can track the exact changes that were made, and view the project files from any point in the tutorial.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/reversi_steps_branches.gif&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;steps-0-1-2-3&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Steps 0, 1, 2, 3 ==&lt;br /&gt;
&lt;br /&gt;
Go to [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md TS Template: Tutorial] for the first four steps of the tutorial. The first four steps for any project are the same. To avoid redundancy, they are not repeated here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-3.5---from-here-on-out&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 3.5 - From here on out ==&lt;br /&gt;
&lt;br /&gt;
At this point, your are ready to start developing your game. You can choose to follow any of the tutorials or guides on the [https://en.doc.boardgamearena.com/Main_Page BGA Studio Documentation] to continue.&lt;br /&gt;
&lt;br /&gt;
From this point in the tutorial and on:&lt;br /&gt;
&lt;br /&gt;
* It will be assumed that files are built and synced before running the game in the BGA studio.&lt;br /&gt;
* It will be assumed that you do a hard refresh of the client page after making changes.&lt;br /&gt;
* It will be assumed that you are using all of the default settings for initializing the typescript template. Adjustments can be made as needed and all sections have links to original file documentation for reference.&lt;br /&gt;
* Most steps will have specific instructions, but you can always adjust at your own discretion.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Make sure the following game information is set for Reversi:&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;// gameinfos.jsonc&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;players&amp;quot;: [ 2 ],&lt;br /&gt;
    &amp;quot;bgg_id&amp;quot;: 2389,&lt;br /&gt;
    &amp;quot;player_colors&amp;quot;: [ &amp;quot;cbcbcb&amp;quot;, &amp;quot;363636&amp;quot; ],&lt;br /&gt;
    &amp;quot;favorite_colors_support&amp;quot;: false&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-4---game-board&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 4 - Game Board ==&lt;br /&gt;
&lt;br /&gt;
# Download the following board image for Reversi, and place it in the &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder of your project. It should be named &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; to match the SCSS background-image in the next step.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/board.jpg&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the board to the DOM by adding the following Smarty template code to the &amp;lt;code&amp;gt;yourgamename_yourgamename.tpl&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- BEGIN square --&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;square_{X}_{Y}&amp;quot; class=&amp;quot;square&amp;quot; style=&amp;quot;left: {LEFT}px; top: {TOP}px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;The &amp;lt;code&amp;gt;&amp;amp;lt;!-- BEGIN &amp;amp;lt;block&amp;amp;gt; --&amp;amp;gt;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;amp;lt;!-- END &amp;amp;lt;block&amp;amp;gt; --&amp;amp;gt;&amp;lt;/code&amp;gt; are Smarty template tags that let you programmatically generate HTML as you will use in a following step. See [https://en.doc.boardgamearena.com/Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl X_X.tpl] for more information about the template file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following SCSS to the &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to style the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;#board {&lt;br /&gt;
    // Setup Image&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
    // Center the board&lt;br /&gt;
    margin: auto;&lt;br /&gt;
    left: 0; top: 0; right: 0; bottom: 0;&lt;br /&gt;
    // Tokens and squares are absolutely placed relative to the board&lt;br /&gt;
    position: relative;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.square {&lt;br /&gt;
    // Size of a square&lt;br /&gt;
    width: 62px;&lt;br /&gt;
    height: 62px;&lt;br /&gt;
    // Position relative to the board, not affected by other elements.&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    // Placeholder for validating the positions.&lt;br /&gt;
    background-color: red;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_interface_stylesheet:_yourgamename.css X.css] for more information about the style sheet for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step4-3.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following code to the &amp;lt;code&amp;gt;yourgamename.view.php&amp;lt;/code&amp;gt; file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// function build_page( $viewArgs ) {&lt;br /&gt;
// ...&lt;br /&gt;
/*********** Place your code below:  ************/&lt;br /&gt;
&lt;br /&gt;
// States that we should start inserting at the &#039;square&#039; block&lt;br /&gt;
// &amp;lt;yourgamename&amp;gt;_&amp;lt;yourgamename&amp;gt; should be replaced with your game name: tstemplatereversi_tstemplatereversi&lt;br /&gt;
$this-&amp;gt;page-&amp;gt;begin_block( &amp;quot;&amp;lt;yourgamename&amp;gt;_&amp;lt;yourgamename&amp;gt;&amp;quot;, &amp;quot;square&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
$hor_scale = 64.8; // Constant for square width&lt;br /&gt;
$ver_scale = 64.4; // Constant for square height&lt;br /&gt;
for( $x=1; $x&amp;lt;=8; $x++ ) // Loop the 8 columns..&lt;br /&gt;
{&lt;br /&gt;
    for( $y=1; $y&amp;lt;=8; $y++ ) // Loop the 8 rows..&lt;br /&gt;
    {&lt;br /&gt;
        // Inserts the code found at the square block based on the variables.&lt;br /&gt;
        $this-&amp;gt;page-&amp;gt;insert_block( &amp;quot;square&amp;quot;, array(&lt;br /&gt;
            &#039;X&#039; =&amp;gt; $x,&lt;br /&gt;
            &#039;Y&#039; =&amp;gt; $y,&lt;br /&gt;
            &#039;LEFT&#039; =&amp;gt; round( ($x-1)*$hor_scale+10 ),&lt;br /&gt;
            &#039;TOP&#039; =&amp;gt; round( ($y-1)*$ver_scale+7 )&lt;br /&gt;
        ) );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl X.view.php] for more information about the view file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step4-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-5---the-tokens&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 5 - The Tokens ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following token image to the &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder of your project. It should be named &amp;lt;code&amp;gt;tokens.png&amp;lt;/code&amp;gt; to match the SCSS background-image in the next step.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/tokens.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a template variable to the &amp;lt;code&amp;gt;yourgamename_yourgamename.tpl&amp;lt;/code&amp;gt; file to represent the tokens:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var jstpl_token=&#039;&amp;lt;div class=&amp;quot;token tokencolor_${color}&amp;quot; id=&amp;quot;token_${x_y}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;Note that this does not have any information that needs to be populated by the server, so this could be directly defined in the TypeScript file.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following SCSS to the &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to style the tokens:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;// Same as square, but matching the token size/image.&lt;br /&gt;
.token {&lt;br /&gt;
    width: 56px;&lt;br /&gt;
    height: 56px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/tokens.png&#039;);&lt;br /&gt;
}&lt;br /&gt;
// For clarity, but doesn&#039;t actually do anything.&lt;br /&gt;
.tokencolor_cbcbcb { background-position: 0px 0px; }&lt;br /&gt;
// Translate the background the exact size of the white token, so the black one shows instead.&lt;br /&gt;
.tokencolor_363636 { background-position: -56px 0px; }&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a TypeScript function to the &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file to place the tokens on the board. You can hover over any function/property in the TypeScript file to see the documentation and usage.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;///////////////////////////////////////////////////&lt;br /&gt;
//// Utility methods&lt;br /&gt;
&lt;br /&gt;
/** Adds a token matching the given player to the board at the specified location. */&lt;br /&gt;
addTokenOnBoard( x: number, y: number, player_id: number )&lt;br /&gt;
{&lt;br /&gt;
    let player = this.gamedatas.players[ player_id ];&lt;br /&gt;
    if (!player)&lt;br /&gt;
        throw new Error( &#039;Unknown player id: &#039; + player_id );&lt;br /&gt;
&lt;br /&gt;
    dojo.place( this.format_block( &#039;jstpl_token&#039;, {&lt;br /&gt;
        x_y: `${x}_${y}`,&lt;br /&gt;
        color: player.color&lt;br /&gt;
    } ) , &#039;board&#039; );&lt;br /&gt;
&lt;br /&gt;
    this.placeOnObject( `token_${x}_${y}`, `overall_player_board_${player_id}` );&lt;br /&gt;
    this.slideToObject( `token_${x}_${y}`, `square_${x}_${y}` ).play();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js X.js] for more information about the script file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For a placeholder, test your tokens by manually placing some in the setup function. you can also remove the boilerplate code.:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;///////////////////////////////////////////////////&lt;br /&gt;
//// Game setup&lt;br /&gt;
&lt;br /&gt;
setup(gamedatas: Gamedatas): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &amp;quot;Starting game setup&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    this.addTokenOnBoard( 2, 2, this.player_id );&lt;br /&gt;
    this.addTokenOnBoard( 6, 3, this.player_id );&lt;br /&gt;
&lt;br /&gt;
    this.setupNotifications(); // &amp;lt;-- Keep this line&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step5-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-6---the-database-and-initial-setup&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 6 - The Database and Initial Setup ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Create a database for your board in the &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;sql&amp;quot;&amp;gt;CREATE TABLE IF NOT EXISTS `board` (&lt;br /&gt;
    `board_x` smallint(5) unsigned NOT NULL,&lt;br /&gt;
    `board_y` smallint(5) unsigned NOT NULL,&lt;br /&gt;
    `board_player` int(10) unsigned DEFAULT NULL,&lt;br /&gt;
    PRIMARY KEY (`board_x`,`board_y`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Pay special attention to the backtick &amp;lt;code&amp;gt;`&amp;lt;/code&amp;gt; character vs. the single quote &amp;lt;code&amp;gt;&#039;&amp;lt;/code&amp;gt; when working with SQL. You can quit and restart your game to see if the file is correct.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_database_model:_dbmodel.sql dbmodel.sql] for more information about the database file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Setup the board in your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file. This is initializing the data in the database and setting the four discs in the center of the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;protected function setupNewGame( $players, $options = array() )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    $sql .= implode( &#039;,&#039;, $values );&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
    // self::reattributeColorsBasedOnPreferences( $players, $gameinfos[&#039;player_colors&#039;] );&lt;br /&gt;
    self::reloadPlayersBasicInfos();&lt;br /&gt;
&lt;br /&gt;
    /************ Start the game initialization *****/&lt;br /&gt;
    $sql = &amp;quot;INSERT INTO board (board_x,board_y,board_player) VALUES &amp;quot;;&lt;br /&gt;
    $sql_values = array();&lt;br /&gt;
    list( $whiteplayer_id, $blackplayer_id ) = array_keys( $players );&lt;br /&gt;
    for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
    {&lt;br /&gt;
        for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
        {&lt;br /&gt;
            // Initial positions of white player&lt;br /&gt;
            if( ($x==4 &amp;amp;&amp;amp; $y==4) || ($x==5 &amp;amp;&amp;amp; $y==5) )&lt;br /&gt;
                $token_value = &amp;quot;&#039;$whiteplayer_id&#039;&amp;quot;;&lt;br /&gt;
            // Initial positions of black player&lt;br /&gt;
            else if( ($x==4 &amp;amp;&amp;amp; $y==5) || ($x==5 &amp;amp;&amp;amp; $y==4) )&lt;br /&gt;
                $token_value = &amp;quot;&#039;$blackplayer_id&#039;&amp;quot;;&lt;br /&gt;
            // Not a starting position&lt;br /&gt;
            else&lt;br /&gt;
                $token_value = &amp;quot;NULL&amp;quot;;&lt;br /&gt;
            $sql_values[] = &amp;quot;(&#039;$x&#039;,&#039;$y&#039;,$token_value)&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    $sql .= implode( &#039;,&#039;, $sql_values );&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Now we need to send the board information to the client whenever the page is reloaded. In your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file, add the following code to the &amp;lt;code&amp;gt;getAllDatas&amp;lt;/code&amp;gt; function:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;protected function getAllDatas()&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    $sql = &amp;quot;SELECT board_x x, board_y y, board_player player&lt;br /&gt;
            FROM board WHERE board_player IS NOT NULL&amp;quot;;&lt;br /&gt;
    $result[&#039;board&#039;] = self::getObjectListFromDB( $sql );&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the board data to the &amp;lt;code&amp;gt;Gamedatas&amp;lt;/code&amp;gt; interface in the &amp;lt;code&amp;gt;yourgamename.d.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;interface Gamedatas {&lt;br /&gt;
    board: { x: number, y: number, player: number }[];&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file place the discs at the start of a page load:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;setup(gamedatas: Gamedatas): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &amp;quot;Starting game setup&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    // Place the tokens on the board&lt;br /&gt;
    for( let i in gamedatas.board )&lt;br /&gt;
    {&lt;br /&gt;
        let square = gamedatas.board[i];&lt;br /&gt;
&lt;br /&gt;
        if( square?.player ) // If square is defined and has a player&lt;br /&gt;
            this.addTokenOnBoard( square.x, square.y, square.player );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    this.setupNotifications(); // &amp;lt;-- Keep this line&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step6-5.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-7---game-states&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 7 - Game States ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the gamestates.jsonc file with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gamestates.schema.json&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    // The initial state. Please do not modify.&lt;br /&gt;
    &amp;quot;1&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;gameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stGameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: { &amp;quot;&amp;quot;: 10 }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;10&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;playerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;${actplayer} must play a disc&amp;quot;,&lt;br /&gt;
        &amp;quot;descriptionmyturn&amp;quot;: &amp;quot;${you} must play a disc&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;activeplayer&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot;: &amp;quot;argPlayerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;argsType&amp;quot;: {&lt;br /&gt;
            &amp;quot;possibleMoves&amp;quot;: &amp;quot;boolean[][]&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;possibleactions&amp;quot;: {&lt;br /&gt;
            &amp;quot;playDisc&amp;quot;: [&lt;br /&gt;
                { &amp;quot;name&amp;quot;: &amp;quot;x&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;AT_int&amp;quot; },&lt;br /&gt;
                { &amp;quot;name&amp;quot;: &amp;quot;y&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;AT_int&amp;quot; }&lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: {&lt;br /&gt;
            &amp;quot;playDisc&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;zombiePass&amp;quot;: 11&lt;br /&gt;
        }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;11&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;nextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;game&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stNextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;updateGameProgression&amp;quot;: true,&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: {&lt;br /&gt;
            &amp;quot;nextTurn&amp;quot;: 10,&lt;br /&gt;
            &amp;quot;cantPlay&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;endGame&amp;quot;: 99&lt;br /&gt;
        }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    // Final state.&lt;br /&gt;
    // Please do not modify (and do not overload action/args methods}.&lt;br /&gt;
    &amp;quot;99&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;gameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;End of game&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot;: &amp;quot;argGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;argsType&amp;quot;: &amp;quot;object&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;There is a lot of information in this file. Most information can be found in the hover-over tooltips, but the [https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php Game States] page has more information about the concepts.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;This will automatically be converted to &amp;lt;code&amp;gt;gamestates.inc.php&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;build/gamestates.d.ts&amp;lt;/code&amp;gt; when you run &amp;lt;code&amp;gt;npm run build&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add placeholder functions to remove &amp;lt;code&amp;gt;Undefined method&amp;lt;/code&amp;gt; errors. Add the following to your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file. Note that this replaces the large section of comments in the file describing the player actions, state arguments, and state actions.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Player actions&lt;br /&gt;
function playDisc( int $x, int $y ) {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game state arguments&lt;br /&gt;
function argPlayerTurn() {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game state actions&lt;br /&gt;
function stNextPlayer() {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fix the &amp;lt;code&amp;gt;dummmy&amp;lt;/code&amp;gt; state errors in your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file. These are added as a placeholder and now cause issues because there is no gamestate with the name &amp;lt;code&amp;gt;dummmy&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;onEnteringState(stateName: GameStateName, args: CurrentStateArgs): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Entering state: &#039; + stateName );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
onLeavingState(stateName: GameStateName): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Leaving state: &#039; + stateName );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
onUpdateActionButtons(stateName: GameStateName, args: AnyGameStateArgs | null): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;onUpdateActionButtons: &#039; + stateName, args );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You should no longer have any type issues in any of your files.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
When you reload your game (this will cause current games to fail), your should see the banner change to &amp;lt;code&amp;gt;{actplayer} must play a disc&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;You must play a disc&amp;lt;/code&amp;gt;. This will be the only visible change in the game at this point.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step7-3.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-8---game-rules-and-possible-moves&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 8 - Game Rules and Possible Moves ==&lt;br /&gt;
&lt;br /&gt;
There are a couple of variations on the rules for Reversi, but the most common is with &amp;lt;code&amp;gt;outflanking rules&amp;lt;/code&amp;gt;. You can see the official rules at [https://www.worldothello.org/about/about-othello/othello-rules/official-rules/ World Othello]. There rules have been implemented with the following utility functions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Copy these functions into your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Get the complete board with a double associative array&lt;br /&gt;
function getBoard()&lt;br /&gt;
{&lt;br /&gt;
    $sql = &amp;quot;SELECT board_x x, board_y y, board_player player FROM board&amp;quot;;&lt;br /&gt;
    return self::getDoubleKeyCollectionFromDB( $sql, true );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the list of possible moves (x =&amp;gt; y =&amp;gt; true)&lt;br /&gt;
function getPossibleMoves( $player_id )&lt;br /&gt;
{&lt;br /&gt;
    $result = array();&lt;br /&gt;
&lt;br /&gt;
    $board = self::getBoard();&lt;br /&gt;
&lt;br /&gt;
    for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
    {&lt;br /&gt;
        for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
        {&lt;br /&gt;
            $returned = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
            if( count( $returned ) == 0 )&lt;br /&gt;
            {&lt;br /&gt;
                // No discs returned =&amp;gt; not a possible move&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // Okay =&amp;gt; set this coordinate to &amp;quot;true&amp;quot;&lt;br /&gt;
                if( ! isset( $result[$x] ) )&lt;br /&gt;
                    $result[$x] = array();&lt;br /&gt;
&lt;br /&gt;
                $result[$x][$y] = true;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return $result;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the list of returned disc when &amp;quot;player&amp;quot; we play at this place (&amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;),&lt;br /&gt;
//  or a void array if no disc is returned (invalid move)&lt;br /&gt;
function getTurnedOverDiscs( $x, $y, $player, $board )&lt;br /&gt;
{&lt;br /&gt;
    $turnedOverDiscs = array();&lt;br /&gt;
&lt;br /&gt;
    if( $board[ $x ][ $y ] === null ) // If there is already a disc on this place, this can&#039;t be a valid move&lt;br /&gt;
    {&lt;br /&gt;
        // For each directions...&lt;br /&gt;
        $directions = array(&lt;br /&gt;
            array( -1,-1 ), array( -1,0 ), array( -1, 1 ), array( 0, -1),&lt;br /&gt;
            array( 0,1 ), array( 1,-1), array( 1,0 ), array( 1, 1 )&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        foreach( $directions as $direction )&lt;br /&gt;
        {&lt;br /&gt;
            // Starting from the square we want to place a disc...&lt;br /&gt;
            $current_x = $x;&lt;br /&gt;
            $current_y = $y;&lt;br /&gt;
            $bContinue = true;&lt;br /&gt;
            $mayBeTurnedOver = array();&lt;br /&gt;
&lt;br /&gt;
            while( $bContinue )&lt;br /&gt;
            {&lt;br /&gt;
                // Go to the next square in this direction&lt;br /&gt;
                $current_x += $direction[0];&lt;br /&gt;
                $current_y += $direction[1];&lt;br /&gt;
&lt;br /&gt;
                if( $current_x&amp;lt;1 || $current_x&amp;gt;8 || $current_y&amp;lt;1 || $current_y&amp;gt;8 )&lt;br /&gt;
                    $bContinue = false; // Out of the board =&amp;gt; stop here for this direction&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] === null )&lt;br /&gt;
                    $bContinue = false; // An empty square =&amp;gt; stop here for this direction&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] != $player )&lt;br /&gt;
                {&lt;br /&gt;
                    // There is a disc from our opponent on this square&lt;br /&gt;
                    // =&amp;gt; add it to the list of the &amp;quot;may be turned over&amp;quot;, and continue on this direction&lt;br /&gt;
                    $mayBeTurnedOver[] = array( &#039;x&#039; =&amp;gt; $current_x, &#039;y&#039; =&amp;gt; $current_y );&lt;br /&gt;
                }&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] == $player )&lt;br /&gt;
                {&lt;br /&gt;
                    // This is one of our disc&lt;br /&gt;
&lt;br /&gt;
                    if( count( $mayBeTurnedOver ) == 0 )&lt;br /&gt;
                    {&lt;br /&gt;
                        // There is no disc to be turned over between our 2 discs =&amp;gt; stop here for this direction&lt;br /&gt;
                        $bContinue = false;&lt;br /&gt;
                    }&lt;br /&gt;
                    else&lt;br /&gt;
                    {&lt;br /&gt;
                        // We found some disc to be turned over between our 2 discs&lt;br /&gt;
                        // =&amp;gt; add them to the result and stop here for this direction&lt;br /&gt;
                        $turnedOverDiscs = array_merge( $turnedOverDiscs, $mayBeTurnedOver );&lt;br /&gt;
                        $bContinue = false;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return $turnedOverDiscs;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the list of possible moves to the &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function argPlayerTurn()&lt;br /&gt;
{&lt;br /&gt;
    $possibleMoves = self::getPossibleMoves( self::getActivePlayerId() );&lt;br /&gt;
    return array(&lt;br /&gt;
        &#039;possibleMoves&#039; =&amp;gt; $possibleMoves&lt;br /&gt;
    );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a css class to represent the possible moves in your &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;.possibleMove {&lt;br /&gt;
    background-color: rgba(255, 255, 255, 0.15);&lt;br /&gt;
    cursor: pointer;&lt;br /&gt;
    transition: 100ms;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.possibleMove:hover {&lt;br /&gt;
    background-color: rgba(255, 255, 255, 0.3);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the possible moves to the board when entering a new state by adding the following to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;// Utility methods&lt;br /&gt;
&lt;br /&gt;
/** Removes the &#039;possibleMove&#039; class from all elements. */&lt;br /&gt;
clearPossibleMoves() {&lt;br /&gt;
    document.querySelectorAll(&#039;.possibleMove&#039;).forEach(element =&amp;gt; {&lt;br /&gt;
        element.classList.remove(&#039;possibleMove&#039;);&lt;br /&gt;
    });&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/** Updates the squares on the board matching the possible moves. */&lt;br /&gt;
updatePossibleMoves( possibleMoves: boolean[][] )&lt;br /&gt;
{&lt;br /&gt;
    this.clearPossibleMoves();&lt;br /&gt;
&lt;br /&gt;
    for( var x in possibleMoves )&lt;br /&gt;
    {&lt;br /&gt;
        for( var y in possibleMoves[ x ] )&lt;br /&gt;
        {&lt;br /&gt;
            let square = $(`square_${x}_${y}`);&lt;br /&gt;
            if( !square )&lt;br /&gt;
                throw new Error( `Unknown square element: ${x}_${y}. Make sure the board grid was set up correctly in the tpl file.` );&lt;br /&gt;
            square.classList.add(&#039;possibleMove&#039;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    this.addTooltipToClass( &#039;possibleMove&#039;, &#039;&#039;, _(&#039;Place a disc here&#039;) );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game &amp;amp; client states&lt;br /&gt;
&lt;br /&gt;
onEnteringState(stateName: GameStateName, args: CurrentStateArgs): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Entering state: &#039;+stateName );&lt;br /&gt;
&lt;br /&gt;
    switch( stateName )&lt;br /&gt;
    {&lt;br /&gt;
        case &#039;playerTurn&#039;:&lt;br /&gt;
            this.updatePossibleMoves( args.args!.possibleMoves );&lt;br /&gt;
            break;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step8-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The game is still not playable, but you can now see the possible moves for the first turn.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-9---player-actions&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 9 - Player Actions ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fill in the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    // Check that this player is active and that this action is possible at this moment&lt;br /&gt;
    self::checkAction( &#039;playDisc&#039; );&lt;br /&gt;
&lt;br /&gt;
    // Now, check if this is a possible move&lt;br /&gt;
    $board = self::getBoard();&lt;br /&gt;
    $player_id = self::getActivePlayerId();&lt;br /&gt;
    $turnedOverDiscs = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
&lt;br /&gt;
    if( count( $turnedOverDiscs ) &amp;lt;= 0 )&lt;br /&gt;
        throw new BgaSystemException( &amp;quot;Impossible move&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    // This move is possible!&lt;br /&gt;
&lt;br /&gt;
    // Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
    $sql = &amp;quot;UPDATE board SET board_player=&#039;$player_id&#039;&lt;br /&gt;
            WHERE ( board_x, board_y) IN ( &amp;quot;;&lt;br /&gt;
    foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
        $sql .= &amp;quot;(&#039;&amp;quot;.$turnedOver[&#039;x&#039;].&amp;quot;&#039;,&#039;&amp;quot;.$turnedOver[&#039;y&#039;].&amp;quot;&#039;),&amp;quot;;&lt;br /&gt;
    $sql .= &amp;quot;(&#039;$x&#039;,&#039;$y&#039;) ) &amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
    // Update scores according to the number of disc on board&lt;br /&gt;
    $sql = &amp;quot;UPDATE player&lt;br /&gt;
            SET player_score = (&lt;br /&gt;
            SELECT COUNT( board_x ) FROM board WHERE board_player=player_id&lt;br /&gt;
            )&amp;quot;;&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
    // Then, go to the next state&lt;br /&gt;
    $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fill in the &amp;lt;code&amp;gt;stNextPlayer&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function stNextPlayer()&lt;br /&gt;
{&lt;br /&gt;
    // Active next player&lt;br /&gt;
    $player_id = self::activeNextPlayer();&lt;br /&gt;
&lt;br /&gt;
    // Check if both player has at least 1 discs, and if there are free squares to play&lt;br /&gt;
    $sql = &amp;quot;SELECT board_player, COUNT( board_x ) FROM board&lt;br /&gt;
            GROUP BY board_player&amp;quot;;&lt;br /&gt;
    $player_to_discs = self::getCollectionFromDb( $sql, true );&lt;br /&gt;
&lt;br /&gt;
    if( ! isset( $player_to_discs[ null ] ) )&lt;br /&gt;
    {&lt;br /&gt;
        // Index 0 has not been set =&amp;gt; there&#039;s no more free place on the board !&lt;br /&gt;
        // =&amp;gt; end of the game&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        return ;&lt;br /&gt;
    }&lt;br /&gt;
    else if( ! isset( $player_to_discs[ $player_id ] ) )&lt;br /&gt;
    {&lt;br /&gt;
        // Active player has no more disc on the board =&amp;gt; he looses immediately&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        return ;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Can this player play?&lt;br /&gt;
&lt;br /&gt;
    $possibleMoves = self::getPossibleMoves( $player_id );&lt;br /&gt;
    if( count( $possibleMoves ) == 0 )&lt;br /&gt;
    {&lt;br /&gt;
        // This player can&#039;t play&lt;br /&gt;
        // Can his opponent play ?&lt;br /&gt;
        $opponent_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039; &amp;quot; );&lt;br /&gt;
        if( count( self::getPossibleMoves( $opponent_id ) ) == 0 )&lt;br /&gt;
        {&lt;br /&gt;
            // Nobody can move =&amp;gt; end of the game&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {            &lt;br /&gt;
            // =&amp;gt; pass his turn&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;cantPlay&#039; );&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
        // This player can play. Give him some extra time&lt;br /&gt;
        self::giveExtraTime( $player_id );&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;nextTurn&#039; );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Connect an &amp;lt;code&amp;gt;onclick&amp;lt;/code&amp;gt; function to all of the squares on the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;```typescript setup(gamedatas: Gamedatas): void { // … dojo.query( ‘.square’ ).connect( ‘onclick’, this, ‘onPlayDisc’ ); // … }&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the &amp;lt;code&amp;gt;onPlayDisc&amp;lt;/code&amp;gt; function to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;// Player&#039;s action&lt;br /&gt;
&lt;br /&gt;
/** Called when a square is clicked, check if it is a possible move and send the action to the server. */&lt;br /&gt;
onPlayDisc( evt: Event )&lt;br /&gt;
{&lt;br /&gt;
    // Stop this event propagation&lt;br /&gt;
    evt.preventDefault();&lt;br /&gt;
&lt;br /&gt;
    if (!(evt.currentTarget instanceof HTMLElement))&lt;br /&gt;
        throw new Error(&#039;evt.currentTarget is null! Make sure that this function is being connected to a DOM HTMLElement.&#039;);&lt;br /&gt;
&lt;br /&gt;
    // Check if this is a possible move&lt;br /&gt;
    if( !evt.currentTarget.classList.contains(&#039;possibleMove&#039;) )&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // Check that this action is possible at this moment (shows error dialog if not possible)&lt;br /&gt;
    if( !this.checkAction( &#039;playDisc&#039; ) )&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // Get the clicked square x and y&lt;br /&gt;
    // Note: square id format is &amp;quot;square_X_Y&amp;quot;&lt;br /&gt;
    let [_square_, x, y] = evt.currentTarget.id.split(&#039;_&#039;);&lt;br /&gt;
&lt;br /&gt;
    this.ajaxcall( `/${this.game_name}/${this.game_name}/playDisc.html`, {&lt;br /&gt;
        x, y, lock: true&lt;br /&gt;
    }, this, function() {} );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you should be able to play the game! However, you will need to reload the game after every move to force the board to update.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-10---notifications&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 10 - Notifications ==&lt;br /&gt;
&lt;br /&gt;
Notifications are used to inform players when something happens in the game. In our case, we only need to send one notification stating when the player has played a disc; however, it is often much more useful to send the notifications as a sequence of events so they can be automatically sequenced in the client. In this case, we will send three notifications:=, all of which can be sent from the player action function: - When a player plays a disc - When discs are converted because of a move - When the scores&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    // ...&lt;br /&gt;
&lt;br /&gt;
    // Notify&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;playDisc&amp;quot;, clienttranslate( &#039;${player_name} plays a disc and turns over ${returned_nbr} disc(s)&#039; ), array(&lt;br /&gt;
        &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
        &#039;player_name&#039; =&amp;gt; self::getActivePlayerName(),&lt;br /&gt;
        &#039;returned_nbr&#039; =&amp;gt; count( $turnedOverDiscs ),&lt;br /&gt;
        &#039;x&#039; =&amp;gt; $x,&lt;br /&gt;
        &#039;y&#039; =&amp;gt; $y&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;turnOverDiscs&amp;quot;, &#039;&#039;, array(&lt;br /&gt;
        &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
        &#039;turnedOver&#039; =&amp;gt; $turnedOverDiscs&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    $newScores = self::getCollectionFromDb( &amp;quot;SELECT player_id, player_score FROM player&amp;quot;, true );&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;newScores&amp;quot;, &amp;quot;&amp;quot;, array(&lt;br /&gt;
        &amp;quot;scores&amp;quot; =&amp;gt; $newScores&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    // Then, go to the next state&lt;br /&gt;
    $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the notifications to your &amp;lt;code&amp;gt;NotifTypes&amp;lt;/code&amp;gt; interface in the &amp;lt;code&amp;gt;yourgamename.d.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;interface NotifTypes {&lt;br /&gt;
    &#039;playDisc&#039;: { x: number, y: number, player_id: number };&lt;br /&gt;
    &#039;turnOverDiscs&#039;: {&lt;br /&gt;
        player_id: number,&lt;br /&gt;
        turnedOver: { x: number, y: number }[]&lt;br /&gt;
    },&lt;br /&gt;
    &#039;newScores&#039;: { scores: Record&amp;lt;number, number&amp;gt; };&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file to listen and handle the notifications:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;setupNotifications()&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;notifications subscriptions setup&#039; );&lt;br /&gt;
&lt;br /&gt;
    dojo.subscribe( &#039;playDisc&#039;, this, &amp;quot;notif_playDisc&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;playDisc&#039;, 500 );&lt;br /&gt;
    dojo.subscribe( &#039;turnOverDiscs&#039;, this, &amp;quot;notif_turnOverDiscs&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;turnOverDiscs&#039;, 1000 );&lt;br /&gt;
    dojo.subscribe( &#039;newScores&#039;, this, &amp;quot;notif_newScores&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;newScores&#039;, 500 );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_playDisc( notif: NotifAs&amp;lt;&#039;playDisc&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    this.clearPossibleMoves();&lt;br /&gt;
    this.addTokenOnBoard( notif.args.x, notif.args.y, notif.args.player_id );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_turnOverDiscs( notif: NotifAs&amp;lt;&#039;turnOverDiscs&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    // Change the color of the turned over discs&lt;br /&gt;
    for( var i in notif.args.turnedOver )&lt;br /&gt;
    {&lt;br /&gt;
        let token_data = notif.args.turnedOver[ i ]!;&lt;br /&gt;
        let token = $&amp;lt;HTMLElement&amp;gt;( `token_${token_data.x}_${token_data.y}` );&lt;br /&gt;
&lt;br /&gt;
        if (!token)&lt;br /&gt;
            throw new Error( `Unknown token element: ${token_data.x}_${token_data.y}. Make sure the board grid was set up correctly in the tpl file.` );&lt;br /&gt;
&lt;br /&gt;
        token.classList.toggle(&#039;tokencolor_cbcbcb&#039;);&lt;br /&gt;
        token.classList.toggle(&#039;tokencolor_363636&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_newScores( notif: NotifAs&amp;lt;&#039;newScores&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    for( var player_id in notif.args.scores )&lt;br /&gt;
    {&lt;br /&gt;
        let counter = this.scoreCtrl[ player_id ];&lt;br /&gt;
        let newScore = notif.args.scores[ player_id ];&lt;br /&gt;
        if (counter &amp;amp;&amp;amp; newScore)&lt;br /&gt;
            counter.toValue( newScore );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;(optional) Add a flipping animation to the token when the classes:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;yourgamename_yourgamename.tpl&#039;&#039; &amp;lt;code&amp;gt;html  // Updated token template  var jstpl_token = &#039;&amp;amp;lt;div class=&amp;amp;quot;token-container tokencolor_${color}&amp;amp;quot; id=&amp;amp;quot;token_${x_y}&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-flip&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-white&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-black&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&#039;;&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;yourgamename.scss&#039;&#039; ```scss .token-container { background-color: transparent; width: 56px; height: 56px; perspective: 250px; position: absolute; }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-flip { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 1.2s; transform-style: preserve-3d; border-radius:50%; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.25); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.tokencolor_363636 &amp;amp;gt; .token-flip { transform: rotateY(180deg); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-white, .token-black { position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; background-image: url(“img/tokens.png”); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-white { background-position: 0px 0px; }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-black { background-position: -56px 0px; transform: rotateY(180deg); } ```&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step10-4.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, you now have a fully functional game that can be played on BGA. The following steps are to add flurishes and additional features to the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;optional-step-11---statistics&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== (optional) Step 11 - Statistics ==&lt;br /&gt;
&lt;br /&gt;
Statistics are mostly optional and are a fun way to compare player strategies or how much they have played the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the contents of &amp;lt;code&amp;gt;shared/stats.jsonc&amp;lt;/code&amp;gt; with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/stats.schema.json&amp;quot;,&lt;br /&gt;
    // All of these stats are tracked per player&lt;br /&gt;
    &amp;quot;player&amp;quot;: {&lt;br /&gt;
        &amp;quot;discPlayedOnCorner&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 10,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on a corner&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;discPlayedOnBorder&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on a border&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;discPlayedOnCenter&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 12,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on board center part&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;turnedOver&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 13,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Number of discs turned over&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_statistics:_stats.json stats.json] for more information about the stats file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    // Update scores...&lt;br /&gt;
&lt;br /&gt;
    // Statistics&lt;br /&gt;
    self::incStat( count( $turnedOverDiscs ), &amp;quot;turnedOver&amp;quot;, $player_id );&lt;br /&gt;
    if( ($x==1 &amp;amp;&amp;amp; $y==1) || ($x==8 &amp;amp;&amp;amp; $y==1) || ($x==1 &amp;amp;&amp;amp; $y==8) || ($x==8 &amp;amp;&amp;amp; $y==8) )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnCorner&#039;, $player_id );&lt;br /&gt;
    else if( $x==1 || $x==8 || $y==1 || $y==8 )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnBorder&#039;, $player_id );&lt;br /&gt;
    else if( $x&amp;gt;=3 &amp;amp;&amp;amp; $x&amp;lt;=6 &amp;amp;&amp;amp; $y&amp;gt;=3 &amp;amp;&amp;amp; $y&amp;lt;=6 )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnCenter&#039;, $player_id );&lt;br /&gt;
&lt;br /&gt;
    // Notify...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the statistics configuration on the manage game page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Play a game and verify that your new statistics are visible at the end of the game:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step11-3.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;optional-step-12---game-options&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== (Optional) Step 12 - Game Options ==&lt;br /&gt;
&lt;br /&gt;
Game options are a way for users to change game behavior or rules. As an example, we will be adding another rule variant called “Reversi Bombs” that flips all 8 adjacent discs when a disc is played.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/reversi_bombs_rules.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace your gameoptions with the following in the &amp;lt;code&amp;gt;shared/gameoptions.jsonc&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gameoptions.schema.json&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;100&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;Variant&amp;quot;,&lt;br /&gt;
        &amp;quot;values&amp;quot;: {&lt;br /&gt;
            // This is the current rule set we have implemented&lt;br /&gt;
            &amp;quot;1&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Standard&amp;quot;,&lt;br /&gt;
                &amp;quot;description&amp;quot;: &amp;quot;Flip all outflanked discs.&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;2&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Reversi Bombs&amp;quot;,&lt;br /&gt;
                &amp;quot;description&amp;quot;: &amp;quot;Flip all 8 adjacent discs.&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json gameoptions.json] for more information about the options file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Modify the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file to handle the new game option:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function getTurnedOverDiscs( $x, $y, $player, $board )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
&lt;br /&gt;
    foreach( $directions as $direction )&lt;br /&gt;
    {&lt;br /&gt;
        // If game option &#039;100&#039; is set to 2 (reversi bombs)&lt;br /&gt;
        if ($this-&amp;gt;gamestate-&amp;gt;table_globals[100] == 2)&lt;br /&gt;
        {&lt;br /&gt;
            $current_x = $x + $direction[0];&lt;br /&gt;
            $current_y = $y + $direction[1];&lt;br /&gt;
            if( $current_x&amp;lt;1 || $current_x&amp;gt;8 || $current_y&amp;lt;1 || $current_y&amp;gt;8 )&lt;br /&gt;
                continue; // Out of the board =&amp;gt; stop here for this direction&lt;br /&gt;
&lt;br /&gt;
            if ($board[ $current_x ][ $current_y ] !== null)&lt;br /&gt;
                // push the disc to be turned over&lt;br /&gt;
                $turnedOverDiscs[] = array( &#039;x&#039; =&amp;gt; $current_x, &#039;y&#039; =&amp;gt; $current_y );&lt;br /&gt;
&lt;br /&gt;
            continue; // Don&#039;t do standard game logic&lt;br /&gt;
        }&lt;br /&gt;
        // Standard...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fix the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function to flip all turned disc instead of setting them to the active player:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
$other_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039;&amp;quot; );&lt;br /&gt;
$sql = &amp;quot;UPDATE board SET board_player = CASE WHEN board_player = &#039;$player_id&#039; THEN &#039;$other_id&#039; ELSE &#039;$player_id&#039; END WHERE (board_x, board_y) IN (&amp;quot;;&lt;br /&gt;
foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
    //...&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the game options from within the game manager page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step12-4.gif&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;user-preferences&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== User Preferences ==&lt;br /&gt;
&lt;br /&gt;
User preferences is something cosmetic about the game interface which you want users to be able to controll. Reversi has a classic athstetic, but in this example, we will add a user preference to change the color of the board. This is not a great use case for user preferences, but it is a simple example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the contents of &amp;lt;code&amp;gt;shared/gamepreferences.jsonc&amp;lt;/code&amp;gt; with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gamepreferences.schema.json&amp;quot;,&lt;br /&gt;
    &amp;quot;101&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;Game Style&amp;quot;,&lt;br /&gt;
        &amp;quot;needReload&amp;quot;: true,&lt;br /&gt;
        &amp;quot;values&amp;quot;: {&lt;br /&gt;
            &amp;quot;1&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Classic&amp;quot;,&lt;br /&gt;
                &amp;quot;cssPref&amp;quot;: &amp;quot;game_style_classic&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;2&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Wooden&amp;quot;,&lt;br /&gt;
                // Then this is added to the page, we will override the image urls in the css.&lt;br /&gt;
                &amp;quot;cssPref&amp;quot;: &amp;quot;game_style_wooden&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;default&amp;quot;: 1&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json gamepreferences.json] for more information about the options file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Download the following images and add them to your &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder. They should be named ‘wooden_board.jpg’ and ‘wooden_tokens.png’.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot; width=&amp;quot;50%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/wooden_board.jpg&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/wooden_tokens.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to your &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to change the board and token images:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;// This overrides the #board + .token- images when the .game_style_wooden is automatically added to the page (by the user preference).&lt;br /&gt;
.game_style_wooden {&lt;br /&gt;
    #board {&lt;br /&gt;
        background-image: url(&#039;img/wooden_board.jpg&#039;);&lt;br /&gt;
    }&lt;br /&gt;
    .token-white, .token-black {&lt;br /&gt;
        background-image: url(&#039;img/wooden_tokens.png&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Refresh the game options in the game manager page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the game and change the user preference to see the new board and token images:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step13-5.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Studio&amp;diff=20765</id>
		<title>Studio</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Studio&amp;diff=20765"/>
		<updated>2024-04-12T13:45:29Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Fixed redirect on bga type safe template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[File:Bga_studio_small.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note: Please DO NOT translate Studio Documentation, so that there can be one place where you can find the latest information available.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== What is Board Game Arena Studio? ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Board Game Arena Studio&#039;&#039;&#039; is a platform to build online board game adaptations using the Board Game Arena platform.&lt;br /&gt;
&lt;br /&gt;
It is open to any gamer with software development skills :)&lt;br /&gt;
&lt;br /&gt;
BGA Studio website: https://studio.boardgamearena.com&lt;br /&gt;
&lt;br /&gt;
Original announcement on BGA forum: https://forum.boardgamearena.com/viewtopic.php?f=10&amp;amp;t=1973&lt;br /&gt;
&lt;br /&gt;
== Discover BGA Studio in 5 presentations ==&lt;br /&gt;
&lt;br /&gt;
Why, how, what... to start discovering BGA Studio, we prepared 5 &amp;quot;powerpoint&amp;quot; presentations for you:&lt;br /&gt;
&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/5-reasons-why-you-should-use-bga-studio-for-your-online-board-game 5 reasons why you should use BGA Studio for your online board game] (or [http://en.doc.boardgamearena.com/images/5/58/1-why-developing.pdf ‎Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/the-8-steps-to-create-a-board-game-on-board-game-arena The 8 steps to create a board game on Board Game Arena] (or [http://en.doc.boardgamearena.com/images/1/1e/2-8-steps-to-realize.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/the-bga-framework-at-a-glance The BGA Framework at a glance] (or [http://en.doc.boardgamearena.com/images/7/79/3-thebgaframework.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine] (or [http://en.doc.boardgamearena.com/images/9/98/4-gamestates.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] (or [http://en.doc.boardgamearena.com/images/7/76/5-guidelines.pdf ‎Download as PDF])&lt;br /&gt;
&lt;br /&gt;
== How to join the BGA developer team? ==&lt;br /&gt;
&lt;br /&gt;
Please see this page: [[How to join BGA developer team?]]&lt;br /&gt;
&lt;br /&gt;
== Great, I&#039;m in! ... How should I start? ==&lt;br /&gt;
&lt;br /&gt;
If you didn&#039;t already, check the presentations at the top of this page to get the basics.&lt;br /&gt;
&lt;br /&gt;
Then, you should checkout the [[First steps with BGA Studio]] to make sure that runs fine.&lt;br /&gt;
&lt;br /&gt;
After that, we strongly advise you to take one of these game creation tutorials:&lt;br /&gt;
* [[Tutorial reversi]] - an abstract strategy game played on an 8×8 uncheckered board for 2 players&lt;br /&gt;
* [[Tutorial gomoku]] - an abstract strategy game tic-tac-toe style for 2 players&lt;br /&gt;
* [[Tutorial hearts]] - a card game for 4 players&lt;br /&gt;
&lt;br /&gt;
Then start editing files and see what happens! ;)&lt;br /&gt;
&lt;br /&gt;
Once you&#039;re done with tutorials, you can start a real game (or join existing project)&lt;br /&gt;
* [[Create a game in BGA Studio: Complete Walkthrough]] &lt;br /&gt;
&lt;br /&gt;
If you have any questions, please check out the [[Studio FAQ]] or [[Contact BGA Studio]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To search wiki pages on studio enter this text in search bar: &lt;br /&gt;
  &amp;quot;Category:Studio&amp;quot; white rabbit &lt;br /&gt;
That is if you want to search for white rabbit&lt;br /&gt;
&lt;br /&gt;
== BGA Studio documentation ==&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio Framework reference ===&lt;br /&gt;
&lt;br /&gt;
This part of the documentation focuses on the development framework itself: functions and methods available to build your game.&lt;br /&gt;
&lt;br /&gt;
[[Studio file reference|File structure of a BGA game]]&lt;br /&gt;
&lt;br /&gt;
==== Game logic (Server side) ====&lt;br /&gt;
&lt;br /&gt;
* [[Main game logic: yourgamename.game.php]]&lt;br /&gt;
* [[Your game state machine: states.inc.php]]&lt;br /&gt;
* [[Game database model: dbmodel.sql]]&lt;br /&gt;
* [[Players actions: yourgamename.action.php]]&lt;br /&gt;
* [[Game material description: material.inc.php]]&lt;br /&gt;
* [[Game statistics: stats.inc.php]]&lt;br /&gt;
&lt;br /&gt;
==== Game interface (Client side) ====&lt;br /&gt;
&lt;br /&gt;
* [[Game interface logic: yourgamename.js]]&lt;br /&gt;
* [[Game art: img directory]]&lt;br /&gt;
* [[Game interface stylesheet: yourgamename.css]]&lt;br /&gt;
* [[Game layout: view and template: yourgamename.view.php and yourgamename_yourgamename.tpl]]&lt;br /&gt;
* [[Your game mobile version]]&lt;br /&gt;
&lt;br /&gt;
==== Other components ====&lt;br /&gt;
&lt;br /&gt;
* [[Translations]] (how to make your game translatable)&lt;br /&gt;
* [[Game options and preferences: gameoptions.inc.php]]&lt;br /&gt;
* [[Game meta-information: gameinfos.inc.php]]&lt;br /&gt;
* [[Game replay]]&lt;br /&gt;
* [[3D]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio game components reference ===&lt;br /&gt;
&lt;br /&gt;
Game components are useful tools you can use in your game adaptations.&lt;br /&gt;
&lt;br /&gt;
JS:&lt;br /&gt;
&lt;br /&gt;
* [[Counter]]: a JS component to manage a counter that can increase/decrease (ex: player&#039;s score).&lt;br /&gt;
* [[Scrollmap]]: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples:  Saboteur or Takenoko games).&lt;br /&gt;
* [[Stock]]: a JS component to manage and display a set of game elements displayed at a position.&lt;br /&gt;
* [[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&#039;s places at Can&#039;t Stop).&lt;br /&gt;
* [[Draggable]]: a JS component to manage drag&#039;n&#039;drop actions.&lt;br /&gt;
* [[ExpandableSection]]: a JS component to manage a rectangular block of HTML than can be displayed/hidden.&lt;br /&gt;
* [[Anti-Stock]]:Code snippets in ValinaJS/HTML5 to do what stock does (that is if you cannot beat Stock into submission)&lt;br /&gt;
&lt;br /&gt;
PHP:&lt;br /&gt;
* [[Deck]]: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).&lt;br /&gt;
&lt;br /&gt;
Reference for classes in game class hierarchy&lt;br /&gt;
&lt;br /&gt;
* [[Table]]: a PHP class that you inherit from for the game php&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio user guide ===&lt;br /&gt;
&lt;br /&gt;
This part of the documentation is a user guide for the BGA Studio online development environment.&lt;br /&gt;
&lt;br /&gt;
Lifecycle&lt;br /&gt;
&lt;br /&gt;
* [[BGA game Lifecycle]]&lt;br /&gt;
* [[Create a game in BGA Studio: Complete Walkthrough]]&lt;br /&gt;
* [[Pre-release checklist]] - Go throught this list if you think you done development&lt;br /&gt;
* [[Post-release phase]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools and Advice&lt;br /&gt;
* [[BGA Studio Guidelines]]&lt;br /&gt;
* [[Tutorials checklist]]&lt;br /&gt;
* [[I wish I knew this when I started]] - one liners on most common missed features, mistakes, etc with further doc references&lt;br /&gt;
* [[Tools and tips of BGA Studio]] - Tips and instructions on setting up development environment&lt;br /&gt;
** [[Setting up BGA Development environment using VSCode]]&lt;br /&gt;
** [[Practical debugging]] - Tips focused on debugging&lt;br /&gt;
** [[Testing by developer]]&lt;br /&gt;
** [[Studio logs]] - Instructions for log access&lt;br /&gt;
** [[Troubleshooting]] - Most common &amp;quot;I am really stuck&amp;quot; situations&lt;br /&gt;
* [[BGA Studio Cookbook]] - Tips and instructions on using API&#039;s, libraries and frameworks&lt;br /&gt;
** [[BGA Type Safe Template]] - Setting up a fully typed project using typescript and more!&lt;br /&gt;
** [[Using Vue]] - work-in-progress guide on using the modern framework Vue.js to create a game&lt;br /&gt;
** [[Using Typescript and Scss]] - How to auto-build Typescript and SCSS files to make your code cleaner&lt;br /&gt;
** [[Bots and Artificial Intelligence]] - How to add AI/Bots to the game&lt;br /&gt;
* [[Studio FAQ]]&lt;br /&gt;
&lt;br /&gt;
Sharing&lt;br /&gt;
* [[Common board game elements image resources]] - Dice, meeples, cubes, etc&lt;br /&gt;
* [[BGA Code Sharing]] - Shared resources, projects on git hub, common code, other links&lt;br /&gt;
&lt;br /&gt;
== Software Versions ==&lt;br /&gt;
&lt;br /&gt;
Versions currently used by BGA framework:&lt;br /&gt;
&lt;br /&gt;
* Dojo Toolkit 1.15&lt;br /&gt;
* PHP: 7.4 (8.2 on studio - choice in control panel, also see announcement on forum)&lt;br /&gt;
* SQL: MySQL 5.7&lt;br /&gt;
* JS/CSS/HTML: limited by what minimization tools support [[Game_interface_logic:_yourgamename.js#Javascript_minimization_.28after_July_2020.29]]&lt;br /&gt;
* Font Awesome: 4.7 https://fontawesome.com/v4.7/icons/ (available as &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;i class=&amp;quot;fa fa-clock&amp;quot; /&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;)&lt;br /&gt;
* Font Awesome: 6.4.0 https://fontawesome.com/v6/search?o=r&amp;amp;m=free (available as &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;i class=&amp;quot;fa6 fa6-clock&amp;quot; /&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
=== PHP Extensions Used ===&lt;br /&gt;
&lt;br /&gt;
The following PHP extensions are - as of May 8th, 2022 - in use in BGA Studio and available:&lt;br /&gt;
&lt;br /&gt;
date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, sodium, apache2handler, mysqlnd, PDO, xml, apcu, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, gmp, iconv, igbinary, json, exif, msgpack, mysqli, pdo_mysql, apc, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, v8js, xmlreader, xmlwriter, xsl, zip, Phar, memcached, Zend OPcache&lt;br /&gt;
&lt;br /&gt;
== Other resources ==&lt;br /&gt;
&lt;br /&gt;
[http://forum.boardgamearena.com/viewforum.php?f=12 Development forum]&lt;br /&gt;
&lt;br /&gt;
[https://studio.boardgamearena.com/bugs Bug tracking system FOR STUDIO issues and APIs]&lt;br /&gt;
&lt;br /&gt;
DISCORD chat server/room invite link https://discord.gg/YxEUacY if it does not work check this topic https://forum.boardgamearena.com/viewtopic.php?f=12&amp;amp;t=17403&amp;amp;hilit=discord&lt;br /&gt;
&lt;br /&gt;
Developer BLOGS https://bga-devs.github.io/blog/&lt;br /&gt;
&lt;br /&gt;
[[Contact BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template&amp;diff=20764</id>
		<title>BGA-ts-template</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA-ts-template&amp;diff=20764"/>
		<updated>2024-04-12T13:43:23Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: NevinAF moved page BGA-ts-template to BGA Type Safe Template: Cleaner and more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[BGA Type Safe Template]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Studio_Cookbook&amp;diff=20753</id>
		<title>BGA Studio Cookbook</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Studio_Cookbook&amp;diff=20753"/>
		<updated>2024-04-11T21:15:12Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: /* Frameworks and Preprocessors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
This page is a cookbook of design and implementation recipes for BGA Studio framework.&lt;br /&gt;
For tooling and usage recipes see [[Tools and tips of BGA Studio]].&lt;br /&gt;
If you have your own recipes feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Visual Effects, Layout and Animation ==&lt;br /&gt;
&lt;br /&gt;
=== DOM manipulatons ===&lt;br /&gt;
&lt;br /&gt;
==== Create pieces dynamically (using template) ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.js&lt;br /&gt;
&lt;br /&gt;
Note: this method is recommended by BGA guildlines&lt;br /&gt;
&lt;br /&gt;
Declared js template with variables in .tpl file, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
    // Javascript HTML templates&lt;br /&gt;
    var jstpl_ipiece = &#039;&amp;lt;div class=&amp;quot;${type} ${type}_${color} inlineblock&amp;quot; aria-label=&amp;quot;${name}&amp;quot; title=&amp;quot;${name}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use it like this in .js file&lt;br /&gt;
  div = this.format_block(&#039;jstpl_ipiece&#039;, {&lt;br /&gt;
                                type : &#039;meeple&#039;,&lt;br /&gt;
                                color : &#039;ff0000&#039;,&lt;br /&gt;
                                name : &#039;Bob&#039;,&lt;br /&gt;
                            });&lt;br /&gt;
  &lt;br /&gt;
Then you do whatever you need to do with that div, this one specifically design to go to log entries, because it has embedded title (otherwise its a picture only) and no id.&lt;br /&gt;
&lt;br /&gt;
Note: you could have place this variable in js itself, but keeping it in .tpl allows you to have your js code be free of HTML. Normally it never happens but&lt;br /&gt;
it is good to strive for it.&lt;br /&gt;
Note: you can also use string concatenation, its less readable. You can also use dojo dom object creation api&#039;s but its brutally verbose and its more unreadable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Create pieces dynamically (using string concatenation) ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  div = &amp;quot;&amp;lt;div class=&#039;meeple_&amp;quot;+color+&amp;quot;&#039;&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or modern way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  div = `&amp;lt;div class=&#039;meeple_${color}&#039;&amp;gt;&amp;lt;/div&amp;gt;`;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create all pieces statically ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.css, ggg.view.php (optional) &lt;br /&gt;
&lt;br /&gt;
* Create ALL game pieces in html template (.tpl)&lt;br /&gt;
* ALL pieces should have unique id, and it should be meaningful, i.e. meeple_red_1&lt;br /&gt;
* Do not use inline styling&lt;br /&gt;
* Id of player&#039;s specific pieces should use some sort of &#039;color&#039; identification, since player id cannot be used in static layout, you can use english color name, hex 6 char value, or color &amp;quot;number&amp;quot; (1,2,3...)&lt;br /&gt;
* Pieces should have separated class for its color, type, etc, so it can be easily styled in groups. In example below you now can style all meeples, all red meeples or all red tokens, or all &amp;quot;first&amp;quot; meeples&lt;br /&gt;
&lt;br /&gt;
ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
  &amp;lt;div id=&amp;quot;home_red&amp;quot; class=&amp;quot;home_red home&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;div id=&amp;quot;meeple_red_1&amp;quot; class=&amp;quot;meeple red n1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
     &amp;lt;div id=&amp;quot;meeple_red_2&amp;quot; class=&amp;quot;meeple red n2&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ggg.css:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	width: 32px;&lt;br /&gt;
	height: 39px;&lt;br /&gt;
	background-image: url(img/78_64_stand_meeples.png);&lt;br /&gt;
	background-size: 352px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.meeple.red {&lt;br /&gt;
	background-position: 30% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* There should be straight forward mapping between server id and js id (or 1:1)&lt;br /&gt;
* You place objects in different zones of the layout, and setup css to take care of layout&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.home .meeple{&lt;br /&gt;
   display: inline-block;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If you need to have a temporary object that look like original you can use dojo.clone (and change id to some temp id)&lt;br /&gt;
* If there is lots of repetition or zone grid you can use template generator, but inject style declaration in css instead of inline style for flexibility&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* If you use this model you cannot use premade js components such as Stock and Zone&lt;br /&gt;
* You have to use alternative methods of animation (slightly altered) since default method will leave object with inline style attributes which you don&#039;t need&lt;br /&gt;
&lt;br /&gt;
=== Animation ===&lt;br /&gt;
&lt;br /&gt;
==== Attach to new parent without destroying the object ====&lt;br /&gt;
&lt;br /&gt;
BGA function attachToNewParent for some reason destroys the original, if you want similar function that does not you can use this&lt;br /&gt;
ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        /**&lt;br /&gt;
         * This method will attach mobile to a new_parent without destroying, unlike original attachToNewParent which destroys mobile and&lt;br /&gt;
         * all its connectors (onClick, etc)&lt;br /&gt;
         */&lt;br /&gt;
        attachToNewParentNoDestroy: function (mobile_in, new_parent_in, relation, place_position) {&lt;br /&gt;
&lt;br /&gt;
            const mobile = $(mobile_in);&lt;br /&gt;
            const new_parent = $(new_parent_in);&lt;br /&gt;
&lt;br /&gt;
            var src = dojo.position(mobile);&lt;br /&gt;
            if (place_position)&lt;br /&gt;
                mobile.style.position = place_position;&lt;br /&gt;
            dojo.place(mobile, new_parent, relation);&lt;br /&gt;
            mobile.offsetTop;//force re-flow&lt;br /&gt;
            var tgt = dojo.position(mobile);&lt;br /&gt;
            var box = dojo.marginBox(mobile);&lt;br /&gt;
            var cbox = dojo.contentBox(mobile);&lt;br /&gt;
            var left = box.l + src.x - tgt.x;&lt;br /&gt;
            var top = box.t + src.y - tgt.y;&lt;br /&gt;
&lt;br /&gt;
            mobile.style.position = &amp;quot;absolute&amp;quot;;&lt;br /&gt;
            mobile.style.left = left + &amp;quot;px&amp;quot;;&lt;br /&gt;
            mobile.style.top = top + &amp;quot;px&amp;quot;;&lt;br /&gt;
            box.l += box.w - cbox.w;&lt;br /&gt;
            box.t += box.h - cbox.h;&lt;br /&gt;
            mobile.offsetTop;//force re-flow&lt;br /&gt;
            return box;&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Animation on oversurface ====&lt;br /&gt;
If you use non-absolute position for your game elements (i.e you use layouts) - you cannot really use BGA animation functions. After years of fidding with different options I use&lt;br /&gt;
techique which I call animation on oversurface that works when parents use different zoom, rotation, etc&lt;br /&gt;
&lt;br /&gt;
* You need another layer on top of everything - oversurface&lt;br /&gt;
* We create copy of the object on oversurface - to move&lt;br /&gt;
* We move the real object on final position - but make it invisible for now&lt;br /&gt;
* We move the phantom to final position applying required zoom and rotation (using css animation), then destroy it&lt;br /&gt;
* When animation is done we make original object visible in new position&lt;br /&gt;
&lt;br /&gt;
The code is bit complex it can be found here&lt;br /&gt;
&lt;br /&gt;
https://codepen.io/VictoriaLa/pen/gORvdJo&lt;br /&gt;
&lt;br /&gt;
Game using it: century, ultimaterailroads&lt;br /&gt;
&lt;br /&gt;
==== Scroll element into view ====&lt;br /&gt;
Ingredients: game.js&lt;br /&gt;
&lt;br /&gt;
This function will scroll given node (div) into view and respect replays and archive mode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    scrollIntoViewAfter: function (node, delay) {&lt;br /&gt;
      if (this.instantaneousMode || this.inSetup) {&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      if (typeof g_replayFrom != &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
        $(node).scrollIntoView();&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      if (!delay) delay = 0;&lt;br /&gt;
      setTimeout(() =&amp;gt; {&lt;br /&gt;
        $(node).scrollIntoView({ behavior: &amp;quot;smooth&amp;quot;, block: &amp;quot;center&amp;quot; });&lt;br /&gt;
      }, delay);&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Logs ===&lt;br /&gt;
&lt;br /&gt;
==== Inject icon images in the log ====&lt;br /&gt;
&lt;br /&gt;
Here is an example of what was done for Terra Mystica which is simple and straightforward:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//Define the proper message&lt;br /&gt;
		$message = clienttranslate(&#039;${player_name} gets ${power_income} via Structures&#039;);&lt;br /&gt;
		if ($price &amp;gt; 0) {&lt;br /&gt;
			$this-&amp;gt;DbQuery(&amp;quot;UPDATE player SET player_score = player_score - $price WHERE player_id = $player_id&amp;quot;);&lt;br /&gt;
			$message = clienttranslate(&#039;${player_name} pays ${vp_price} and gets ${power_income} via Structures&#039;);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
// Notify&lt;br /&gt;
		$this-&amp;gt;notifyAllPlayers( &amp;quot;powerViaStructures&amp;quot;, $message, array(&lt;br /&gt;
			&#039;i18n&#039; =&amp;gt; array( ),&lt;br /&gt;
			&#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
			&#039;player_name&#039; =&amp;gt; $this-&amp;gt;getUniqueValueFromDb( &amp;quot;SELECT player_name FROM player WHERE player_id = $player_id&amp;quot; ),&lt;br /&gt;
			&#039;power_tokens&#039; =&amp;gt; $power_tokens,&lt;br /&gt;
			&#039;vp_price&#039; =&amp;gt; $this-&amp;gt;getLogsVPAmount($price),&lt;br /&gt;
			&#039;power_income&#039; =&amp;gt; $this-&amp;gt;getLogsPowerAmount($power_income),&lt;br /&gt;
			&#039;newScore&#039; =&amp;gt; $this-&amp;gt;getUniqueValueFromDb( &amp;quot;SELECT player_score FROM player WHERE player_id = $player_id&amp;quot; ),&lt;br /&gt;
			&#039;counters&#039; =&amp;gt; $this-&amp;gt;getGameCounters(null),&lt;br /&gt;
		) );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With some functions to have the needed html added inside the substitution variable, such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function getLogsPowerAmount( $amount ) {&lt;br /&gt;
		return &amp;quot;&amp;lt;div class=&#039;tmlogs_icon&#039; title=&#039;Power&#039;&amp;gt;&amp;lt;div class=&#039;power_amount&#039;&amp;gt;$amount&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: injecting html from php is not ideal but easy, if you want more clean solution, use method below but it is a lot more sophisticated.&lt;br /&gt;
&lt;br /&gt;
==== Inject images and styled html in the log ====&lt;br /&gt;
&lt;br /&gt;
{{InfoBox|title=Warning — Translation|maxWidth=500|color=#c00|body=&#039;&#039;&#039;In order to prevent interference with the translation process, keep in mind that you must only apply modifications to the args object, and not try to substitute the keys (the &amp;lt;code&amp;gt;${player_name}&amp;lt;/code&amp;gt; parts of your string) in the log string.&#039;&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
So you want nice pictures in the game log. What do you do? The first idea that comes to mind is to send html from php in notifications (see method above). &lt;br /&gt;
&lt;br /&gt;
This is a bad idea for many reasons:&lt;br /&gt;
&lt;br /&gt;
* It&#039;s bad architecture. ui elements leak into the server, and now you have to manage the ui in multiple places.&lt;br /&gt;
* If you decided to change something in the ui in future version, replay logs for old games and tutorials may not work, since they use stored notifications.&lt;br /&gt;
* Log previews for old games become unreadable. (This is the log state before you enter the game replay, which is useful for troubleshooting and game analysis.)&lt;br /&gt;
* It&#039;s more data to transfer and store in the db.&lt;br /&gt;
* It&#039;s a nightmare for translators.&lt;br /&gt;
&lt;br /&gt;
So what else can you do? You can use client side log injection to intercept log arguments (which come from the server) and replace them with html on the client side. Here are three different method you can use to achieve this.&lt;br /&gt;
&lt;br /&gt;
===== Override &amp;lt;code&amp;gt;this.format_string_recursive()&amp;lt;/code&amp;gt; method =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php&lt;br /&gt;
&lt;br /&gt;
I use this recipe for &#039;&#039;&#039;client side log injection&#039;&#039;&#039; to intercept log arguments (which come from the server) and replace them with html on the client side.&lt;br /&gt;
&lt;br /&gt;
[[File:clientloginjection.png|left]] &lt;br /&gt;
&lt;br /&gt;
ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
        /** Override this function to inject html into log items. This is a built-in BGA method.  */&lt;br /&gt;
&lt;br /&gt;
        /* @Override */&lt;br /&gt;
        format_string_recursive : function format_string_recursive(log, args) {&lt;br /&gt;
            try {&lt;br /&gt;
                if (log &amp;amp;&amp;amp; args &amp;amp;&amp;amp; !args.processed) {&lt;br /&gt;
                    args.processed = true;&lt;br /&gt;
                    &lt;br /&gt;
&lt;br /&gt;
                    // list of special keys we want to replace with images&lt;br /&gt;
                    var keys = [&#039;place_name&#039;,&#039;token_name&#039;];&lt;br /&gt;
                    &lt;br /&gt;
                  &lt;br /&gt;
                    for ( var i in keys) {&lt;br /&gt;
                        var key = keys[i];&lt;br /&gt;
                        key in args &amp;amp;&amp;amp; args[key] = this.getTokenDiv(key, args);                            &lt;br /&gt;
&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            } catch (e) {&lt;br /&gt;
                console.error(log,args,&amp;quot;Exception thrown&amp;quot;, e.stack);&lt;br /&gt;
            }&lt;br /&gt;
            return this.inherited({callee: format_string_recursive}, arguments);&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; In the &#039;&#039;format_string_recursive&#039;&#039; method, the &#039;args&#039; parameter will only contain arguments passed to it from the notify method in ggg.game.php (see below).&lt;br /&gt;
&lt;br /&gt;
The &#039;log&#039; parameter is the actual string that is inserted into the logs. You can perform additional js string manipulation on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        getTokenDiv : function(key, args) {&lt;br /&gt;
            // ... implement whatever html you want here, example from sharedcode.js&lt;br /&gt;
            var token_id = args[key];&lt;br /&gt;
            var item_type = getPart(token_id,0);&lt;br /&gt;
            var logid = &amp;quot;log&amp;quot; + (this.globalid++) + &amp;quot;_&amp;quot; + token_id;&lt;br /&gt;
            switch (item_type) {&lt;br /&gt;
                case &#039;wcube&#039;:&lt;br /&gt;
                    var tokenDiv = this.format_block(&#039;jstpl_resource_log&#039;, {&lt;br /&gt;
                        &amp;quot;id&amp;quot; : logid,&lt;br /&gt;
                        &amp;quot;type&amp;quot; : &amp;quot;wcube&amp;quot;,&lt;br /&gt;
                        &amp;quot;color&amp;quot; : getPart(token_id,1),&lt;br /&gt;
                    });&lt;br /&gt;
                    return tokenDiv;&lt;br /&gt;
             &lt;br /&gt;
                case &#039;meeple&#039;:&lt;br /&gt;
                    if ($(token_id)) {&lt;br /&gt;
                        var clone = dojo.clone($(token_id));&lt;br /&gt;
    &lt;br /&gt;
                        dojo.attr(clone, &amp;quot;id&amp;quot;, logid);&lt;br /&gt;
                        this.stripPosition(clone);&lt;br /&gt;
                        dojo.addClass(clone, &amp;quot;logitem&amp;quot;);&lt;br /&gt;
                        return clone.outerHTML;&lt;br /&gt;
                    }&lt;br /&gt;
                    break;&lt;br /&gt;
     &lt;br /&gt;
                default:&lt;br /&gt;
                    break;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            return &amp;quot;&#039;&amp;quot; + this.clienttranslate_string(this.getTokenName(token_id)) + &amp;quot;&#039;&amp;quot;;&lt;br /&gt;
       },&lt;br /&gt;
       getTokenName : function(key) {&lt;br /&gt;
           return this.gamedatas.token_types[key].name; // get name for the key, from static table for example&lt;br /&gt;
       },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in this case the server simply injects token_id as a name, and the client substitutes it for the translated name or the picture.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ggg.game.php:&lt;br /&gt;
&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;playerLog&#039;,clienttranslate(&#039;Game moves ${token_name}&#039;),[&#039;token_name&#039;=&amp;gt;$token_id]);&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; As noted above, only arguments actually passed by this method are available to the args parameter received in the client-side &#039;&#039;format_string_recursive&#039;&#039; method.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is the case that you want to pass arguments that are not actually included in the output message. For example, suppose we have a method like this:&lt;br /&gt;
&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;tokenPlaced&#039;,clienttranslate(&#039;Player placed ${token_name}&#039;),array(&lt;br /&gt;
              &#039;token_name&#039; =&amp;gt; $token_id,&lt;br /&gt;
              &#039;zone_played&#039; =&amp;gt; $zone);&lt;br /&gt;
&lt;br /&gt;
This will output &amp;quot;Player placed ${token_name}&amp;quot; in the log, and if we subscribe to a notification method activated by the &amp;quot;tokenPlaced&amp;quot; event in the client-side code, that method can make use of the &#039;zone_played&#039; argument. &lt;br /&gt;
&lt;br /&gt;
Now if you want to make some really cool things with game log, most probably you would need more arguments than are included in log message. The problem with that,&lt;br /&gt;
it will work at first, but if you reload game using F5 or when the game loads in turn based mode, you will loose your additional parameters, why? Because when game reloads it does not actually send same notifications, it sends special &amp;quot;hitstorical_log&amp;quot; notification where all  parameters not listed in the message are removed. In example above, field zone_played would be removed from historical log as it is not included in message of the notification. You can till preserve specific arguments in historical log by adding special field preserve to notification arguments like this:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
           $this-&amp;gt;notifyAllPlayers(&#039;tokenPlaced&#039;,clienttranslate(&#039;Player placed ${token_name}&#039;),array(&lt;br /&gt;
              &#039;token_name&#039; =&amp;gt; $token_id,&lt;br /&gt;
              &#039;zone_played&#039; =&amp;gt; $zone,&lt;br /&gt;
              &#039;preserve&#039; =&amp;gt; [ &#039;zone_played&#039; ]&lt;br /&gt;
           );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you can use zone_played in format_string_recursive even in historical logs.&lt;br /&gt;
&lt;br /&gt;
===== Use &amp;lt;code&amp;gt;:formatFunction&amp;lt;/code&amp;gt; option provided by &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg_ggg.tpl, ggg.css&lt;br /&gt;
&lt;br /&gt;
The above method will work in most of the cases, but if you use dotted keys such as &amp;lt;code&amp;gt;${card.name}&amp;lt;/code&amp;gt; (which is supported by the framework, for private state args), the key won&#039;t be substituted because the &amp;lt;code&amp;gt;key in arg&amp;lt;/code&amp;gt; test will fail. If so you need to rely either on this way, or the one after.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING:&#039;&#039;&#039; using this method on an already advanced project will require you to go through all your notifications to change keys !&lt;br /&gt;
&lt;br /&gt;
Under the hood, the &#039;&#039;&#039;this.format_string_recursive()&#039;&#039;&#039; function calls the &#039;&#039;&#039;dojo.string.substitute&#039;&#039;&#039; method which substitutes &amp;lt;code&amp;gt;${keys}&amp;lt;/code&amp;gt; with the value provided. If you take a look at the [https://dojotoolkit.org/reference-guide/1.7/dojo/string.html#substitute documentation] and [https://github.com/dojo/dojo/blob/c3ceb017cfa25b703f5662dc83d1c8aae9bc5d81/string.js#L163 source code] you can notice that the key can be suffixed with a colon (&amp;lt;code&amp;gt;:&amp;lt;/code&amp;gt;) followed by a function name. This will allow you to specify directly in the substitution string which keys need HTML injection.&lt;br /&gt;
&lt;br /&gt;
First of all, you need to define your formatting function in the ggg.js file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[[ggg.js]]&lt;br /&gt;
        getTokenDiv : function(value, key) {&lt;br /&gt;
            //This is only an example implementation, you need to write your own.&lt;br /&gt;
            //The method should return HTML code&lt;br /&gt;
            switch (key) {&lt;br /&gt;
                case &#039;html_injected_argument1&#039;:&lt;br /&gt;
                    return this.format_block(&#039;jstpl_HTMLLogElement1&#039;,{value: value});&lt;br /&gt;
                case &#039;html_injected_argument2&#039;:&lt;br /&gt;
                    return this.format_block(&#039;jstpl_HTMLLogElement2&#039;,{value: value});&lt;br /&gt;
                ...&lt;br /&gt;
            }&lt;br /&gt;
       }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously you need to define the appropriate templates in the ggg_ggg.tpl file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[[ggg_ggg.tpl]]&lt;br /&gt;
let jstpl_HTMLLogElement1 = &#039;&amp;lt;div class=&amp;quot;log-element log-element-1-${value}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
let jstpl_HTMLLogElement2 = &#039;&amp;lt;div class=&amp;quot;log-element log-element-2-${value}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And the appropriate classes in ggg.css.&lt;br /&gt;
&lt;br /&gt;
Then you need to add the &amp;lt;code&amp;gt;dojo/aspect&amp;lt;/code&amp;gt; module at the top of the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;quot;dojo/aspect&amp;quot;,&amp;lt;/span&amp;gt;                 //MUST BE IN THIRD POSITION&#039;&#039;&#039; (see [[#Including your own JavaScript module (II)|below]])&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
 ], function (dojo, declare, &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&#039;&#039;&#039;aspect&#039;&#039;&#039;&amp;lt;/span&amp;gt;) {&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
And you also need to add the following code in your &amp;lt;code&amp;gt;contructor&amp;lt;/code&amp;gt; method in the ggg.js:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         constructor: function(){&lt;br /&gt;
&lt;br /&gt;
             // ... skipped code ...&lt;br /&gt;
             let gameObject = this;            //Needed as the this object in aspect.before will not refer to the game object in which the formatting function resides&lt;br /&gt;
             aspect.before(dojo.string, &amp;quot;substitute&amp;quot;, function(template, map, transform) {      //This allows you to modify the arguments of the dojo.string.substitute method before they&#039;re actually passed to it&lt;br /&gt;
                 return [template, map, transform, gameObject];&lt;br /&gt;
             });&lt;br /&gt;
&lt;br /&gt;
Now you&#039;re all set to inject HTML in your logs. To actually achieve this, you must specify the function name with the key like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.game.php]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 $this-&amp;gt;notifyAllPlayers(&amp;quot;notificationName&amp;quot;, clienttranslate(&amp;quot;This log message contains ${plainTextArgument} and the following will receive HTML injection: ${html_injected_argument1:getTokenDiv}&amp;quot;), [&lt;br /&gt;
     &amp;quot;plainTextArgument&amp;quot; =&amp;gt; &amp;quot;some plain text here&amp;quot;,&lt;br /&gt;
     &amp;quot;html_injected_argument1&amp;quot; =&amp;gt; &amp;quot;some value used by getTokenDiv&amp;quot;,&lt;br /&gt;
 ]);&lt;br /&gt;
&lt;br /&gt;
You&#039;re not limited writing only one function, you can write as many functions as you like, and have them each inject a specific type of HTML. You just need to specify the relevant function name after the column in the substitution key.&lt;br /&gt;
&lt;br /&gt;
===== Use &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; argument of &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg_ggg.tpl, ggg.css&lt;br /&gt;
&lt;br /&gt;
This method is also relying on the use of &amp;lt;code&amp;gt;dojo.string.substitute&amp;lt;/code&amp;gt; by the framework, and will use the &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; argument, which, accordting to [https://github.com/dojo/dojo/blob/c3ceb017cfa25b703f5662dc83d1c8aae9bc5d81/string.js#L163 source code] and [https://dojotoolkit.org/reference-guide/1.7/dojo/string.html#substitute documentation] will be run on all the messages going through dojo.string.substitute.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING:&#039;&#039;&#039; This method will be applied to all strings that go through dojo.string.substitute. As such you must take extra care not to substitute keys that may be used by the framework (i.e. ${id}). In order to do so, a good practise would be to prefix all keys that need substitution with a trigram of the game name.&lt;br /&gt;
&lt;br /&gt;
Since all the keys will be fed to the tranform function, by default, it must return the value, substituted or not per your needs. You can define the function like this in the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         getTokenDiv : function(value, key) {&lt;br /&gt;
             //This is only an example implementation, you need to write your own.&lt;br /&gt;
             //The method should return HTML code&lt;br /&gt;
             switch (key) {&lt;br /&gt;
                 case &#039;html_injected_argument1&#039;:&lt;br /&gt;
                     return this.format_block(&#039;jstpl_HTMLLogElement1&#039;,{value: value});&lt;br /&gt;
                 case &#039;html_injected_argument2&#039;:&lt;br /&gt;
                     return this.format_block(&#039;jstpl_HTMLLogElement2&#039;,{value: value});&lt;br /&gt;
                 ...&lt;br /&gt;
                 default:&lt;br /&gt;
                     return value; //Needed otherwise regular strings won&#039;t appear since since the value isn&#039;t returned by the function&lt;br /&gt;
             }&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
The templates must be defined in the ggg_ggg.tpl file and the corresponding CSS classes in the ggg.css file.&lt;br /&gt;
&lt;br /&gt;
You need to add the following code at the beginning of the ggg.js file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;quot;dojo/aspect&amp;quot;,&amp;lt;/span&amp;gt;                 //MUST BE IN THIRD POSITION&#039;&#039;&#039; (see [[#Including your own JavaScript module (II)|below]])&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
 ], function (dojo, declare, &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&#039;&#039;&#039;aspect&#039;&#039;&#039;&amp;lt;/span&amp;gt;) {&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
And the following code to the &amp;lt;code&amp;gt;constructor&amp;lt;/code&amp;gt; method in ggg.js:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[ggg.js]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
         constructor: function(){&lt;br /&gt;
             // ... skipped code ...&lt;br /&gt;
             let transformFunction = dojo.hitch(this, &amp;quot;getTokenDiv&amp;quot;);          //Needed as the this object in aspect.before will not refer to the game object in which the formatting function resides&lt;br /&gt;
             aspect.before(dojo.string, &amp;quot;substitute&amp;quot;, function(template, map, transform) {&lt;br /&gt;
                 if (undefined === transform) {    //Check for a transform function presence, just in case&lt;br /&gt;
                     return [template, map, transformFunction];&lt;br /&gt;
                 }&lt;br /&gt;
             });&lt;br /&gt;
&lt;br /&gt;
Then you&#039;re all set for log injection, no need to change anything on the PHP side.&lt;br /&gt;
&lt;br /&gt;
==== Processing logs on re-loading ====&lt;br /&gt;
&lt;br /&gt;
You rarely need to process logs when reloading, but if you want to do something fancy you may have to do it after logs are loaded. &lt;br /&gt;
Logs are loaded asyncronously so you have to listen for logs to be fully loaded.&lt;br /&gt;
Unfortunately there is no direct way of doing it so this is the hack.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hack alert&#039;&#039;&#039; - this extends undocumented function and may be broken when framework is updated&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			/*&lt;br /&gt;
  			* [Undocumented] Override BGA framework functions to call onLoadingLogsComplete when loading is done&lt;br /&gt;
                        @Override&lt;br /&gt;
   			*/&lt;br /&gt;
			setLoader: function(image_progress, logs_progress) {&lt;br /&gt;
				this.inherited(arguments); // required, this is &amp;quot;super()&amp;quot; call, do not remove&lt;br /&gt;
				//console.log(&amp;quot;loader&amp;quot;, image_progress, logs_progress)&lt;br /&gt;
				if (!this.isLoadingLogsComplete &amp;amp;&amp;amp; logs_progress &amp;gt;= 100) {&lt;br /&gt;
					this.isLoadingLogsComplete = true; // this is to prevent from calling this more then once&lt;br /&gt;
					this.onLoadingLogsComplete();&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&lt;br /&gt;
			onLoadingLogsComplete: function() {&lt;br /&gt;
				console.log(&#039;Loading logs complete&#039;);&lt;br /&gt;
				// do something here&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Player Panel ===&lt;br /&gt;
&lt;br /&gt;
==== Inserting non-player panel ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg_ggg.tpl&lt;br /&gt;
&lt;br /&gt;
If you want to insert non-player panel on the right side (for example to hold extra preferences, zooming controls, etc)&lt;br /&gt;
&lt;br /&gt;
this can go pretty much anywhere in template it will be moved later&lt;br /&gt;
&lt;br /&gt;
ggg_ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&#039;player_board_config&#039; id=&amp;quot;player_board_config&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;!-- here is whatever you want, buttons just example --&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;zoom-out&amp;quot; class=&amp;quot; fa fa-search-minus fa-2x config-control&amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;zoom-in&amp;quot; class=&amp;quot; fa fa-search-plus fa-2x config-control&amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
		&amp;lt;button id=&amp;quot;show-settings&amp;quot; class=&amp;quot;fa fa-cog fa-2x config-control &amp;quot;&amp;gt;&amp;lt;/button&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
some hackery required in js&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* @Override */&lt;br /&gt;
	updatePlayerOrdering() {&lt;br /&gt;
		this.inherited(arguments);&lt;br /&gt;
		dojo.place(&#039;player_board_config&#039;, &#039;player_boards&#039;, &#039;first&#039;);&lt;br /&gt;
	},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Images and Icons ===&lt;br /&gt;
&lt;br /&gt;
==== Accessing images from js ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
     // your game resources&lt;br /&gt;
     &lt;br /&gt;
     var my_img = &#039;&amp;lt;img src=&amp;quot;&#039;+g_gamethemeurl+&#039;img/cards.jpg&amp;quot;/&amp;gt;&#039;;&lt;br /&gt;
     &lt;br /&gt;
     // shared resources&lt;br /&gt;
     var my_help_img = &amp;quot;&amp;lt;img class=&#039;imgtext&#039; src=&#039;&amp;quot; + g_themeurl + &amp;quot;img/layout/help_click.png&#039; alt=&#039;action&#039; /&amp;gt; &amp;lt;span class=&#039;tooltiptext&#039;&amp;gt;&amp;quot; +&lt;br /&gt;
                    text + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== High-Definition Graphics ====&lt;br /&gt;
&lt;br /&gt;
Some users will have screens which can display text and images at a greater resolution than the usual 72 dpi, e.g. the &amp;quot;Retina&amp;quot; screens on the 5k iMac, all iPads, and high-DPI screens on laptops from many manufacturers. If you can get art assets at this size, they will make your game look extra beautiful. You &#039;&#039;could&#039;&#039; just use large graphics and scale them down, but that would increase the download time and bandwidth for users who can&#039;t display them. Instead, a good way is to prepare a separate graphics file at exactly twice the size you would use otherwise, and add &amp;quot;@2x&amp;quot; at the end of the filename, e.g. if pieces.png is 240x320, then pieces@2x.png is 480x640.&lt;br /&gt;
&lt;br /&gt;
There are two changes required in order to use the separate graphics files. First in your css, where you use a file, add a media query which overrides the original definition and uses the bigger version on devices which can display them. Ensuring that the &amp;quot;background-size&amp;quot; attribute is set means that the size of the displayed object doesn&#039;t change, but only is drawn at the improved dot pitch.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.piece {&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/pieces.png&#039;);&lt;br /&gt;
    background-size:240px 320px;&lt;br /&gt;
    z-index: 10;&lt;br /&gt;
}&lt;br /&gt;
@media (-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 192dpi)&lt;br /&gt;
{&lt;br /&gt;
    .piece {&lt;br /&gt;
        background-image: url(&#039;img/pieces@2x.png&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Secondly, in your setup function in javascript, you must ensure than only the appropriate one version of the file gets pre-loaded (otherwise you more than waste the bandwidth saved by maintaining the standard-resolution file). Note that the media query is the same in both cases:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            var isRetina = &amp;quot;(-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 192dpi)&amp;quot;;&lt;br /&gt;
            if (window.matchMedia(isRetina).matches)&lt;br /&gt;
            {&lt;br /&gt;
                this.dontPreloadImage( &#039;pieces.png&#039; );&lt;br /&gt;
                this.dontPreloadImage( &#039;board.jpg&#039; );&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                this.dontPreloadImage( &#039;pieces@2x.png&#039; );&lt;br /&gt;
                this.dontPreloadImage( &#039;board@2x.jpg&#039; );&lt;br /&gt;
            }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using CSS to create different colors of game pieces if you have only white piece ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
background-color: #${color}; &lt;br /&gt;
background-blend-mode: multiply;&lt;br /&gt;
background-image: url( &#039;img/mypiece.png&#039;);&lt;br /&gt;
mask: url(&#039;img/mypiece.png&#039;);&lt;br /&gt;
-webkit-mask: url(&#039;img/mypiece.png&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ${color} - is color you want&lt;br /&gt;
&lt;br /&gt;
Note: piece has to be white (shades of gray). Sprite can be used too, just add add blackground-position as usual.&lt;br /&gt;
&lt;br /&gt;
==== Accessing player avatar URLs ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      getPlayerAvatar(playerId) {&lt;br /&gt;
         let avatarURL = &#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
         if (null != $(&#039;avatar_&#039; + playerId)) {&lt;br /&gt;
            let smallAvatarURL = dojo.attr(&#039;avatar_&#039; + playerId, &#039;src&#039;);&lt;br /&gt;
            avatarURL = smallAvatarURL.replace(&#039;_32.&#039;, &#039;_184.&#039;);&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
            avatarURL = &#039;https://x.boardgamearena.net/data/data/avatar/default_184.jpg&#039;;&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
         return avatarURL;&lt;br /&gt;
      },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note:  This gets avatar URLs at 184x184 resolution.  You can also use 92, 50, and 32 depending on which resolution you want.&lt;br /&gt;
&lt;br /&gt;
==== Adding Image buttons ====&lt;br /&gt;
&lt;br /&gt;
Its pretty trivial but just in case you need a working function:&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
                addImageActionButton: function (id, div_html, handler) { // div_html is string not node&lt;br /&gt;
                    this.addActionButton(id, div_html, handler, &#039;&#039;, false, &#039;gray&#039;); &lt;br /&gt;
                    dojo.style(id, &amp;quot;border&amp;quot;, &amp;quot;none&amp;quot;); // remove ugly border&lt;br /&gt;
                    dojo.addClass(id, &amp;quot;bgaimagebutton&amp;quot;); // add css class to do more styling&lt;br /&gt;
                    return $(id); // return node for chaining&lt;br /&gt;
                },&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    this.addImageActionButton(&#039;button_coin&#039;,&amp;quot;&amp;lt;div class=&#039;coin&#039;&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;, ()=&amp;gt;{ alert(&#039;Ha!&#039;); });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Other Fluff ===&lt;br /&gt;
&lt;br /&gt;
==== Use thematic fonts ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.css&lt;br /&gt;
&lt;br /&gt;
Sometime game elements use specific fonts of text, if you want to match it up you can load some specific font (IMPORTANT: from some &#039;&#039;&#039;free font&#039;&#039;&#039; source. See notes below).&lt;br /&gt;
&lt;br /&gt;
[[File:Dragonline_font.png]]&lt;br /&gt;
&lt;br /&gt;
.css&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* latin-ext */&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: 400;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(https://fonts.gstatic.com/s/qwigley/v6/2Dy1Unur1HJoklbsg4iPJ_Y6323mHUZFJMgTvxaG2iE.woff2) format(&#039;woff2&#039;);&lt;br /&gt;
  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;&lt;br /&gt;
}&lt;br /&gt;
/* latin */&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: normal;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(https://fonts.gstatic.com/s/qwigley/v6/gThgNuQB0o5ITpgpLi4Zpw.woff2) format(&#039;woff2&#039;);&lt;br /&gt;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;&lt;br /&gt;
}&lt;br /&gt;
@font-face {&lt;br /&gt;
  font-family: &#039;Qwigley&#039;;&lt;br /&gt;
  font-style: normal;&lt;br /&gt;
  font-weight: normal;&lt;br /&gt;
  src: local(&#039;Qwigley&#039;), local(&#039;Qwigley-Regular&#039;), url(http://ff.static.1001fonts.net/q/w/qwigley.regular.ttf) format(&#039;ttf&#039;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.zone_title {&lt;br /&gt;
	display: inline-block;&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	font: italic 32px/32px &amp;quot;Qwigley&amp;quot;, cursive;	   &lt;br /&gt;
	height: 32px;&lt;br /&gt;
	width: auto;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB:&#039;&#039;&#039; if you need to include a font that&#039;s not available online, an extra action will be needed from an admin. Please include the font file(s) in your img directory, and mention it to admins when requesting your game to be moved to alpha. &#039;&#039;&#039;Please remember that the font has to be free, and include a .txt with all appropriate license information about the font.&#039;&#039;&#039;&lt;br /&gt;
You can look for free fonts (for example) on https://fonts.google.com or https://www.fontsquirrel.com/)&lt;br /&gt;
&lt;br /&gt;
===== Content Security Policy =====&lt;br /&gt;
&lt;br /&gt;
BGA runs a Content Security Policy which will limit the origins from which you can load external fonts, in order to prevent license abuse.&lt;br /&gt;
&lt;br /&gt;
The CSP is a whitelist of allowed origins. To see the list, view the response headers of any page on Studio, and look for the &amp;quot;Content-Security-Policy&amp;quot; header.&lt;br /&gt;
&lt;br /&gt;
You will specifically want to check for the font-src token within these headers, and limit any external fonts to these sources.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This list is subject to change&#039;&#039;&#039; but as of the time of writing, the only acceptabled external sites are use.typekit.net and fonts.gstatic.com.&lt;br /&gt;
&lt;br /&gt;
=== Use player color in template ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.view.php&lt;br /&gt;
&lt;br /&gt;
.view.php:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function build_page($viewArgs) {&lt;br /&gt;
        // Get players &amp;amp; players number&lt;br /&gt;
        $players = $this-&amp;gt;game-&amp;gt;loadPlayersBasicInfos();&lt;br /&gt;
        $players_nbr = count($players);&lt;br /&gt;
        /**&lt;br /&gt;
         * ********* Place your code below: ***********&lt;br /&gt;
         */&lt;br /&gt;
        &lt;br /&gt;
        // Set PCOLOR to the current player color hex&lt;br /&gt;
        global $g_user;&lt;br /&gt;
        $cplayer = $g_user-&amp;gt;get_id();&lt;br /&gt;
        if (array_key_exists($cplayer, $players)) { // may be not set if spectator&lt;br /&gt;
            $player_color = $players [$cplayer] [&#039;player_color&#039;];&lt;br /&gt;
        } else {&lt;br /&gt;
            $player_color = &#039;ffffff&#039;; // spectator&lt;br /&gt;
        }&lt;br /&gt;
        $this-&amp;gt;tpl [&#039;PCOLOR&#039;] = $player_color;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scale to fit for big boards ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg_ggg.tpl, ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lets say you have huge game board, and lets say you want it to be 1400px wide. Besides the board there will be side bar which is 240 and trim. &lt;br /&gt;
My display is 1920 wide so it fits, but there is big chance other people won&#039;t have that width. What do you do?&lt;br /&gt;
&lt;br /&gt;
You have to decide:&lt;br /&gt;
* If board does not fit you want scale whole thing down, the best way is probably use viewport (see https://en.doc.boardgamearena.com/Your_game_mobile_version)&lt;br /&gt;
* You can leave the board as is and make sure it is scrollable horizonatally&lt;br /&gt;
* You add custom scale just for the board (can add user controls  - and hook to transform: scale())&lt;br /&gt;
&lt;br /&gt;
I tried to auto-scale but this just does work, too many variables - browser zoom, 3d mode, viewport, custom bga scaling, devicePixelRatio - all create some impossible coctail of zooming...&lt;br /&gt;
Here is scaling functing for custom user scaling&lt;br /&gt;
&lt;br /&gt;
ggg_ggg.tpl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;thething&amp;quot; class=&amp;quot;thething&amp;quot;&amp;gt;&lt;br /&gt;
            ... everything else you declare ...&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ggg.js:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    onZoomPlus: function() {&lt;br /&gt;
       this.setZoom(this.zoom + 0.1);&lt;br /&gt;
    },&lt;br /&gt;
    onZoomMinus: function() {&lt;br /&gt;
       this.setZoom(this.zoom - 0.1);&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    setZoom: function (zoom) {&lt;br /&gt;
      zoom = parseInt(zoom) || 0;&lt;br /&gt;
      if (zoom === 0 || zoom &amp;lt; 0.1 || zoom &amp;gt; 10) {&lt;br /&gt;
        zoom = 1;&lt;br /&gt;
      }&lt;br /&gt;
      this.zoom = zoom;&lt;br /&gt;
      var inner = document.getElementById(&amp;quot;thething&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
      if (zoom == 1) {&lt;br /&gt;
        inner.style.removeProperty(&amp;quot;transform&amp;quot;);&lt;br /&gt;
        inner.style.removeProperty(&amp;quot;width&amp;quot;);&lt;br /&gt;
      } else {&lt;br /&gt;
        inner.style.transform = &amp;quot;scale(&amp;quot; + zoom + &amp;quot;)&amp;quot;;&lt;br /&gt;
        inner.style.transformOrigin = &amp;quot;0 0&amp;quot;;&lt;br /&gt;
        inner.style.width = 100 / zoom + &amp;quot;%&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
      localStorage.setItem(`${this.game_name}_zoom`, &amp;quot;&amp;quot; + this.zoom);&lt;br /&gt;
      this.onScreenWidthChange();&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dynamic tooltips ===&lt;br /&gt;
&lt;br /&gt;
If you really need a dynamic tooltip you can use this technique. (Only use it if the static tooltips provided by the BGA framework are not sufficient.)&lt;br /&gt;
&lt;br /&gt;
            new dijit.Tooltip({&lt;br /&gt;
                connectId: [&amp;quot;divItemId&amp;quot;],&lt;br /&gt;
                getContent: function(matchedNode){&lt;br /&gt;
                    return &amp;quot;... calculated ...&amp;quot;; &lt;br /&gt;
                }&lt;br /&gt;
            });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is an out-of-the-box djit.Tooltip. It has a &#039;&#039;getContent&#039;&#039; method which is called dynamically.&lt;br /&gt;
&lt;br /&gt;
The string returned by getContent() becomes the innerHTML of the tooltip, so it can be anything. In this example matchedNode is a dojo node representing dom object with id of &amp;quot;divItemId&amp;quot; but there are more parameters which I am not posting here which allows more sophisticated subnode queries (i.e. you can attach tooltip to all nodes with class or whatever).&lt;br /&gt;
&lt;br /&gt;
[https://dojotoolkit.org/reference-guide/1.10/dijit/Tooltip.html dijit.Tooltip]&lt;br /&gt;
&lt;br /&gt;
It&#039;s not part of the BGA API so use at your own risk.&lt;br /&gt;
&lt;br /&gt;
=== Rendering text with players color and proper background ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        /* Implementation of proper colored You with background in case of white or light colors  */&lt;br /&gt;
 &lt;br /&gt;
        divYou: function() {&lt;br /&gt;
            var color = this.gamedatas.players[this.player_id].color;&lt;br /&gt;
            var color_bg = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.gamedatas.players[this.player_id] &amp;amp;&amp;amp; this.gamedatas.players[this.player_id].color_back) {&lt;br /&gt;
                color_bg = &amp;quot;background-color:#&amp;quot; + this.gamedatas.players[this.player_id].color_back + &amp;quot;;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            var you = &amp;quot;&amp;lt;span style=\&amp;quot;font-weight:bold;color:#&amp;quot; + color + &amp;quot;;&amp;quot; + color_bg + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + __(&amp;quot;lang_mainsite&amp;quot;, &amp;quot;You&amp;quot;) + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
            return you;&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        /* Implementation of proper colored player name with background in case of white or light colors  */&lt;br /&gt;
&lt;br /&gt;
        divColoredPlayer: function(player_id) {&lt;br /&gt;
            var color = this.gamedatas.players[player_id].color;&lt;br /&gt;
            var color_bg = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.gamedatas.players[player_id] &amp;amp;&amp;amp; this.gamedatas.players[player_id].color_back) {&lt;br /&gt;
                color_bg = &amp;quot;background-color:#&amp;quot; + this.gamedatas.players[player_id].color_back + &amp;quot;;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            var div = &amp;quot;&amp;lt;span style=\&amp;quot;color:#&amp;quot; + color + &amp;quot;;&amp;quot; + color_bg + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + this.gamedatas.players[player_id].name + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
            return div;&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cool realistic shadow effect with CSS ===&lt;br /&gt;
&lt;br /&gt;
==== Rectangles and circles ====&lt;br /&gt;
&lt;br /&gt;
It is often nice to have a drop shadow around tiles and tokens, to separate them from the table visually. It is very easy to add a shadow to rectangular elements, just add this to your css:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.xxx-tile {&lt;br /&gt;
    box-shadow: 3px 3px 3px #000000a0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
box-shadow obeys &#039;&#039;&#039;border-radius&#039;&#039;&#039; of the element, so it will look good for rounded rectangles, and hence also circles (if border-radius is set appropriately).&lt;br /&gt;
&lt;br /&gt;
box-shadow also supports various other parameters and can be used to achieve effects such as glowing, borders, inner shadows etc. If you need to animate a box-shadow, you may be able to get better performance (avoiding redraws) if you attach the shadow to another element (possibly an ::after pseudo-element) and change only the &#039;&#039;&#039;opacity&#039;&#039;&#039; of that element.&lt;br /&gt;
&lt;br /&gt;
==== Irregular Shapes ====&lt;br /&gt;
&lt;br /&gt;
If you wish to make a shadow effect for game pieces that are not a rectangle, but your game pieces are drawn from rectangles in a PNG image, you can apply the shadow to the piece using any art package and save it inside the image. This usually will yield the best performance. Remember to account for the size of the shadow when you lay out images in the sprite sheet.&lt;br /&gt;
&lt;br /&gt;
However that sometimes will not be an option, for example if the image needs to be rotated while the shadow remains offset in the same direction. In this case, one option is to not use box-shadow but use filter, which is supported by recent major browsers.  This way, you can use the alpha channel of your element to drop a shadow.  This even work for transparent backgrounds, so that if you are using the &amp;quot;CSS-sprite&amp;quot; method, it will work!&lt;br /&gt;
&lt;br /&gt;
For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.xxx-token {&lt;br /&gt;
    filter: drop-shadow(0px 0px 1px #000000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Beware that some browsers still do not always draw drop-shadow correctly. In particular, Safari frequently leaves bits of shadow behind when objects move around the screen. In Chrome, shadows sometimes flicker badly if another element is animating close by. Some of these correctness issues can be solved by adding &#039;&#039;&#039;isolation: isolate; will-change: filter;&#039;&#039;&#039; to affected elements, but this significantly affects redraw performance.&lt;br /&gt;
&lt;br /&gt;
Beware of performance issues - particularly on Safari (MacOS, iPhone and iPad). Keep in mind that drop-shadow are very GPU intensive. This becomes noticeable once you have about 40 components with drop-shadow filter. If that is your case, you can quite easily implement a user preference to disable shadows for users on slower machines:&lt;br /&gt;
&lt;br /&gt;
gameoptions.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
100 =&amp;gt; array(&lt;br /&gt;
			&#039;name&#039; =&amp;gt; totranslate(&#039;Shadows&#039;),&lt;br /&gt;
			&#039;needReload&#039; =&amp;gt; true, // after user changes this preference game interface would auto-reload&lt;br /&gt;
			&#039;values&#039; =&amp;gt; array(&lt;br /&gt;
					1 =&amp;gt; array( &#039;name&#039; =&amp;gt; totranslate( &#039;Enabled&#039; ), &#039;cssPref&#039; =&amp;gt; &#039;&#039; ),&lt;br /&gt;
					2 =&amp;gt; array( &#039;name&#039; =&amp;gt; totranslate( &#039;Disabled&#039; ), &#039;cssPref&#039; =&amp;gt; &#039;no-shadow&#039; )&lt;br /&gt;
			)&lt;br /&gt;
	),&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[game].css&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.no-shadow * {&lt;br /&gt;
	filter: none !important; &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;For Safari, it is usually better to simply disable drop-shadow completely: [[Game interface stylesheet: yourgamename.css#Warning: using drop-shadow]].&lt;br /&gt;
&lt;br /&gt;
==== Shadows with clip-path ====&lt;br /&gt;
&lt;br /&gt;
For some reason, a shadow will not work together with clip-path on one element. To use both clip-path (when for example using .svg to cut out cardboard components from your .jpg spritesheet) and drop-shadow, you need to wrap the element into another one, and apply drop-shadow to the outer one, and clip-path to the inner one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;my-token-wrap&#039;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&#039;my-token&#039;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.my-token-wrap {&lt;br /&gt;
    filter: drop-shadow(0px 0px 1px #000000);&lt;br /&gt;
}&lt;br /&gt;
.my-token-wrap .my-token {&lt;br /&gt;
    clip-path: url(#my-token-path);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using the CSS classes from the state machine ===&lt;br /&gt;
&lt;br /&gt;
If you need to hide or show stuff depending on the state of your game, you can of course use javascript, but CSS is hand enough for that.  The #overall-content element does change class depending on the game state.  For instance, if you are in state &#039;&#039;playerTurn&#039;&#039;, it will have the class &#039;&#039;gamestate_playerTurn&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now, if you want to show the discard pile only during player turns, you may use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#discard_pile { display: none }&lt;br /&gt;
.gamestate_playerTurn #discard_pile { display: block }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be used if you want to change sizing of elements, position, layout or visual appearance.&lt;br /&gt;
&lt;br /&gt;
== Game Model and Database design ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Database for The euro game ===&lt;br /&gt;
Lets say we have a game with workers, dice, tokens, board, resources, money and vp. Workers and dice can be placed in various zones on the board, and you can get resources, money, tokens and vp in your home zone. Also tokens can be flipped or not flipped.&lt;br /&gt;
&lt;br /&gt;
[[File:Madeira board.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets try to map it, we have&lt;br /&gt;
* (meeple,zone)&lt;br /&gt;
* (die, zone, sideup)&lt;br /&gt;
* (resource cube/money token/vp token,player home zone)&lt;br /&gt;
* (token, player home zone, flip state)&lt;br /&gt;
We can notice that resource and money are uncountable, and don&#039;t need to be track individually so we can replace our mapping to&lt;br /&gt;
* (resource type/money,player home zone, count)&lt;br /&gt;
And vp stored already for us in player table, so we can remove it from that list.&lt;br /&gt;
&lt;br /&gt;
Now when we get to encode it we can see that everything can be encoded as (object,zone,state) form, where object and zone is string and state is integer. The resource mapping is slightly different semantically so you can go with two table, or counting using same table with state been used as count for resources.&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based games can be in most case represented by (string: token_key, string: token_location, int: token_state), example of such database schema can be found here: [https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php table.game.php].&lt;br /&gt;
&lt;br /&gt;
Variant 1: Minimalistic&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|meeple_red_1&lt;br /&gt;
|home_red&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|dice_black_2&lt;br /&gt;
|board_guard&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|dice_green_1&lt;br /&gt;
|board_action_mayor&lt;br /&gt;
|3&lt;br /&gt;
|-&lt;br /&gt;
|bread&lt;br /&gt;
|home_red&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now how we represent resource counters such as bread?&lt;br /&gt;
Using same table from we simply add special counter token for bread and use state to indicate the count. Note to keep first column unique we have to add player identification for that counter, i.e. ff0000 is red player.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|bread_ff0000&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See php module for this table here https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php&lt;br /&gt;
&lt;br /&gt;
Variant 2: Additional resource table, resource count for each player id&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `resource` (&lt;br /&gt;
  `player_id` int(10) unsigned NOT NULL,&lt;br /&gt;
  `resource_key` varchar(32) NOT NULL,&lt;br /&gt;
  `resource_count` int(10) signed NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`player_id`,`resource_key`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE resource ADD CONSTRAINT fk_player_id FOREIGN KEY (player_id) REFERENCES player(player_id);&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+resource&lt;br /&gt;
! player_id&lt;br /&gt;
! resource_key&lt;br /&gt;
! resource_count&lt;br /&gt;
|-&lt;br /&gt;
|123456&lt;br /&gt;
|bread&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Variant 3: More normalised&lt;br /&gt;
&lt;br /&gt;
This version is similar to &amp;quot;card&amp;quot; table from hearts tutorial, you can also use exact cards database schema and Deck implementation for most purposes (even you not dealing with cards). &lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `token_type` varchar(16) NOT NULL,&lt;br /&gt;
  `token_arg` int(11) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_id`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_id&lt;br /&gt;
! token_type&lt;br /&gt;
! token_arg&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|22&lt;br /&gt;
|meeple&lt;br /&gt;
|123456&lt;br /&gt;
|home_123456&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|23&lt;br /&gt;
|dice&lt;br /&gt;
|2&lt;br /&gt;
|board_guard&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|26&lt;br /&gt;
|dice&lt;br /&gt;
|1&lt;br /&gt;
|board_action_mayor&lt;br /&gt;
|3&lt;br /&gt;
|-&lt;br /&gt;
|49&lt;br /&gt;
|bread&lt;br /&gt;
|0&lt;br /&gt;
|home_123456&lt;br /&gt;
|5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Advantages of this would be is a bit more straightforward to do some queries in db, disadvantage its hard to read (as you can compare with previous example, you&lt;br /&gt;
cannot just look at say, ah I know what it means). Another questionable advantage is it allows you to do id randomisation, so it hard to do crafted queries to &lt;br /&gt;
cheat, the down side of that you cannot understand it either, and handcraft db states for debugging or testing.&lt;br /&gt;
&lt;br /&gt;
=== Database for The card game ===&lt;br /&gt;
&lt;br /&gt;
Lets say you have a standard card game, player have hidden cards in hand, you can draw card from draw deck, play card on tableau and discard to discard pile.&lt;br /&gt;
We have to design database for such game.&lt;br /&gt;
&lt;br /&gt;
In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it.&lt;br /&gt;
&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in our database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
&lt;br /&gt;
Lets see what we have for that:&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real coordinates x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what information changes and what information is static, later is always candidate for material file&lt;br /&gt;
* For dynamic information we should try to reduce amount of fields we need&lt;br /&gt;
**  we need at least a field for card, so its one&lt;br /&gt;
**  we need to know what zone cards belong to, its 2&lt;br /&gt;
**  and we have possibly few other fields, if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
Variant 1: Minimalistic&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_key` varchar(32) unsigned NOT NULL,&lt;br /&gt;
  `card_location` varchar(32) NOT NULL,&lt;br /&gt;
  `card_state` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Variant 2: More normalised&lt;br /&gt;
&lt;br /&gt;
This version supported by Deck php class, so unless you want to rewrite db access layer go with this one&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you using this schema, some zones/locations have special semantic. The &#039;hand&#039; location is actually multiple locations - one per player, but player id is encoded as card_location_arg. If &#039;hand&#039; in your game is ordered, visible or can have some other card states, you cannot use hand location (replacement is hand_&amp;lt;player_id&amp;gt; or hand_&amp;lt;color_id&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== Code Organization ==&lt;br /&gt;
&lt;br /&gt;
=== Including your own JavaScript module ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, modules/ggg_other.js&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.js in modules/ folder and sync&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define([&lt;br /&gt;
    &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;&lt;br /&gt;
], function( dojo, declare )&lt;br /&gt;
{&lt;br /&gt;
return declare(&amp;quot;bgagame.other&amp;quot;, null, { // null here if we don&#039;t want to inherit from anything&lt;br /&gt;
        constructor: function(){},&lt;br /&gt;
        mystuff: function(){},&lt;br /&gt;
    });&lt;br /&gt;
        &lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Modify ggg.js to include it&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  define([ &amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;, &amp;quot;ebg/core/gamegui&amp;quot;, &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
    g_gamethemeurl + &amp;quot;modules/ggg_other.js&amp;quot;     // load my own module!!!&lt;br /&gt;
  ], function(dojo,&lt;br /&gt;
        declare) {&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
use it&lt;br /&gt;
&lt;br /&gt;
  foo = new bgagame.other();&lt;br /&gt;
&lt;br /&gt;
=== Including your own JavaScript module (II) ===&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.js in modules/ folder and sync&lt;br /&gt;
&lt;br /&gt;
  define([], function () {&lt;br /&gt;
    return &amp;quot;value&amp;quot;;&lt;br /&gt;
  });&lt;br /&gt;
&lt;br /&gt;
* Modify ggg.js to include it&lt;br /&gt;
&lt;br /&gt;
  define([ &lt;br /&gt;
    &amp;quot;dojo&amp;quot;, &lt;br /&gt;
    &amp;quot;dojo/_base/declare&amp;quot;, &lt;br /&gt;
    &amp;quot;bgagame/modules/ggg_other&amp;quot;, &lt;br /&gt;
    &amp;quot;ebg/core/gamegui&amp;quot;, &lt;br /&gt;
    &amp;quot;ebg/counter&amp;quot;&lt;br /&gt;
  ], function(dojo, declare, other) {&lt;br /&gt;
  &lt;br /&gt;
  });&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
This is maybe a little bit more the idea of the AMD Loader than the first option, although the first option should work as well.&lt;br /&gt;
&lt;br /&gt;
A little explanation to this:&lt;br /&gt;
The define function loads all the modules listed in the array and calls the following function with these loaded modules as parameters.&lt;br /&gt;
By putting your module at the third position in the array it is passed as the third parameter to the function. Be aware that the modules are resolved by position only, not by name. So you can load the module &#039;&#039;&#039;ggg_other&#039;&#039;&#039; and pass it as a parameter with the name &#039;&#039;&#039;other&#039;&#039;&#039;. &#039;&#039;&#039;gamegui&#039;&#039;&#039; and &#039;&#039;&#039;counter&#039;&#039;&#039; are passed in as well, but when the parameters are not defined they are just skipped. Because these modules put their content into the global scope it does not matter and you can use them from there.&lt;br /&gt;
&lt;br /&gt;
In the example above the string &amp;quot;value&amp;quot; is passed for the parameter &#039;&#039;&#039;other&#039;&#039;&#039;, but the function in your module can return whatever you want. It can be an object, an array, something you declared with dojo.declare, you can return even functions. &lt;br /&gt;
Your module can load other modules. Just put them in the array at the beginning and pass them as parameters to your function.&lt;br /&gt;
The advantage of passing the values as parameter is that you do not need to put these values in the global scope, so they can&#039;t be collisions with values defined in other scripts or the BGA Framework.&lt;br /&gt;
&lt;br /&gt;
The dojo toolkit provides good documentation to all of its components, the complete documentation for the AMD-Loader is here:&lt;br /&gt;
https://dojotoolkit.org/documentation/tutorials/1.10/modules/index.html It should be still correct, even as it seems to be only for version 1.10&lt;br /&gt;
&lt;br /&gt;
=== Including your own PHP module ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.game.php, modules/ggg_other.php&lt;br /&gt;
&lt;br /&gt;
* Create ggg_other.php in modules/ folder and sync&lt;br /&gt;
* Modify ggg.game.php to include it&lt;br /&gt;
&lt;br /&gt;
 require_once (&#039;modules/ggg_other.php&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Creating a test class to run PHP locally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.game.php, stubs&lt;br /&gt;
For this you need stubs of other method you can use this for example&lt;br /&gt;
https://github.com/elaskavaia/bga-sharedcode/raw/master/misc/module/table/table.game.php&lt;br /&gt;
&lt;br /&gt;
Create another php files, i.e ggg_test.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
define(&amp;quot;APP_GAMEMODULE_PATH&amp;quot;, &amp;quot;misc/&amp;quot;); // include path to stubs, which defines &amp;quot;table.game.php&amp;quot; and other classes&lt;br /&gt;
require_once (&#039;eminentdomaine.game.php&#039;);&lt;br /&gt;
&lt;br /&gt;
class MyGameTest1 extends MyGame { // this is your game class defined in ggg.game.php&lt;br /&gt;
    function __construct() {&lt;br /&gt;
        parent::__construct();&lt;br /&gt;
        include &#039;../material.inc.php&#039;;// this is how this normally included, from constructor&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // override/stub methods here that access db and stuff&lt;br /&gt;
    function getGameStateValue($var) {&lt;br /&gt;
        if ($var == &#039;round&#039;)&lt;br /&gt;
            return 3;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$x = new MyGameTest1(); // instantiate your class&lt;br /&gt;
$p = $x-&amp;gt;getGameProgression(); // call one of the methods to test&lt;br /&gt;
if ($p != 50)&lt;br /&gt;
    echo &amp;quot;Test1: FAILED&amp;quot;;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;Test1: PASSED&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run from command line like&lt;br /&gt;
 php7 ggg_test.php&lt;br /&gt;
&lt;br /&gt;
If you do it this way - you can also use local php debugger (i.e. integrated with IDE or command line).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Avoiding code in dojo declare style ===&lt;br /&gt;
Dojo class declarations are rather bizzare and do not work with most IDEs.&lt;br /&gt;
If you want to write in plain JS with classes, you can stub all the dojo define/declare stuff&lt;br /&gt;
and hook your class into that, so the classes are outside of this mess.&lt;br /&gt;
&lt;br /&gt;
NOTE: this technique is for experienced developers, do not try it if you do not understand&lt;br /&gt;
the consequences.&lt;br /&gt;
&lt;br /&gt;
This is complete example of game .js class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // Testla is game name is has to be changed&lt;br /&gt;
class Testla {&lt;br /&gt;
	constructor(game) {&lt;br /&gt;
		console.log(&#039;game constructor&#039;);&lt;br /&gt;
		this.game = game;&lt;br /&gt;
		this.varfoo = new MyFoo(); // this example of class from custom module&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	setup(gamedatas) {&lt;br /&gt;
		console.log(&amp;quot;Starting game setup&amp;quot;, this.varfoo);&lt;br /&gt;
		this.gamedatas = gamedatas;&lt;br /&gt;
		this.dojo.create(&amp;quot;div&amp;quot;, { class: &#039;whiteblock&#039;, innerHTML: _(&amp;quot;hello&amp;quot;) }, &#039;thething&#039;);&lt;br /&gt;
		console.log(&amp;quot;Ending game setup&amp;quot;);&lt;br /&gt;
	};&lt;br /&gt;
	onEnteringState(stateName, args) {&lt;br /&gt;
		console.log(&#039;onEnteringState : &#039; + stateName, args);&lt;br /&gt;
		this.game.addActionButton(&#039;b1&#039;,_(&#039;Click Me&#039;), (e)=&amp;gt;this.onButtonClick(e));&lt;br /&gt;
	};&lt;br /&gt;
	onLeavingState(stateName) {&lt;br /&gt;
		console.log(&#039;onLeavingState : &#039; + stateName, args);&lt;br /&gt;
	};&lt;br /&gt;
	onUpdateActionButtons(stateName, args) {&lt;br /&gt;
		console.log(&#039;onUpdateActionButtons : &#039; + stateName, args);&lt;br /&gt;
	};&lt;br /&gt;
	onButtonClick(event) {&lt;br /&gt;
		console.log(&#039;onButtonClick&#039;,event);&lt;br /&gt;
	};&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
define([&lt;br /&gt;
	&amp;quot;dojo&amp;quot;, &amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
	&amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
	&amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
	g_gamethemeurl + &#039;/modules/foo.js&#039; // custom module if needed&lt;br /&gt;
],&lt;br /&gt;
	function(dojo, declare) {&lt;br /&gt;
                // testla is game name is has to be changed&lt;br /&gt;
		return declare(&amp;quot;bgagame.testla&amp;quot;, ebg.core.gamegui, {&lt;br /&gt;
			constructor: function() {&lt;br /&gt;
				this.xapp = new Testla(this);&lt;br /&gt;
				this.xapp.dojo = dojo;&lt;br /&gt;
			},&lt;br /&gt;
			setup: function(gamedatas) {&lt;br /&gt;
				this.xapp.setup(gamedatas);&lt;br /&gt;
			},&lt;br /&gt;
			onEnteringState: function(stateName, args) {&lt;br /&gt;
				this.xapp.onEnteringState(stateName, args?.args);&lt;br /&gt;
			},&lt;br /&gt;
			onLeavingState: function(stateName) {&lt;br /&gt;
				this.xapp.onLeavingState(stateName, args);&lt;br /&gt;
			},&lt;br /&gt;
			onUpdateActionButtons: function(stateName, args) {&lt;br /&gt;
				this.xapp.onUpdateActionButtons(stateName, args);&lt;br /&gt;
			},&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== More readable JS: onEnteringState ===&lt;br /&gt;
&lt;br /&gt;
If you have a lot of states in onEnteringState or onUpdateActionButtons and friends - it becomes rather wild, you can do this trick to call some methods dynamically.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     onEnteringState: function(stateName, args) {&lt;br /&gt;
       console.log(&#039;Entering state: &#039; + stateName, args);&lt;br /&gt;
&lt;br /&gt;
       // Call appropriate method&lt;br /&gt;
       var methodName = &amp;quot;onEnteringState_&amp;quot; + stateName;&lt;br /&gt;
       if (this[methodName] !== undefined) {             &lt;br /&gt;
          console.log(&#039;Calling &#039; + methodName, args.args);&lt;br /&gt;
          this[methodName](args.args);&lt;br /&gt;
       }&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
     onEnteringState_playerTurn: function(args) { // this is args directly, not args.args &lt;br /&gt;
         // process&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
     onEnteringState_playerSomethingElse: function(args) { &lt;br /&gt;
         // process&lt;br /&gt;
     },&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: since its ignores the undefined functions you don&#039;t have define function for each state, but on the other hand you cannot make typos.&lt;br /&gt;
Same applies to onUpdateActionButtons except you pass &#039;args&#039; to method, not args.args, and for onLeavingState where you don&#039;t pass anything.&lt;br /&gt;
&lt;br /&gt;
=== Frameworks and Preprocessors ===&lt;br /&gt;
&lt;br /&gt;
* [[BGA-ts-template|BGA Type Safe Template]] - Setting up a fully typed project using typescript and more!&lt;br /&gt;
* [[Using Vue]] - work-in-progress guide on using the modern framework Vue.js to create a game&lt;br /&gt;
* [[Using Typescript and Scss]] - How to auto-build Typescript and SCSS files to make your code cleaner&lt;br /&gt;
&lt;br /&gt;
== Assorted Stuff ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Out-of-turn actions: Un-pass ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js, ggg.game.php, ggg.action.php, states.inc.php&lt;br /&gt;
&lt;br /&gt;
In multiplayer game sometimes players passes but than they think more and want to un-Pass and redo their choice. &lt;br /&gt;
To re-active a player who passes some trickery required.&lt;br /&gt;
&lt;br /&gt;
Define a special action that does that and hook it up.&lt;br /&gt;
&lt;br /&gt;
In states.inc.php add an action to mmultipleactiveplayer state to &amp;quot;unpass&amp;quot;, lets call it &amp;quot;actionCancel&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In ggg.action.php add action hook&lt;br /&gt;
    public function actionCancel() {&lt;br /&gt;
        $this-&amp;gt;setAjaxMode();&lt;br /&gt;
        $this-&amp;gt;game-&amp;gt;actionCancel();&lt;br /&gt;
        $this-&amp;gt;ajaxResponse();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
In ggg.game.php add action handler&lt;br /&gt;
    function actionCancel() {&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;checkPossibleAction(&#039;actionCancel&#039;);&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;setPlayersMultiactive(array ($this-&amp;gt;getCurrentPlayerId() ), &#039;error&#039;, false);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Finally to call this in client ggg.js you would do something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 onUpdateActionButtons:  function(stateName, args) {&lt;br /&gt;
   if (this.isCurrentPlayerActive()) { &lt;br /&gt;
     // ...&lt;br /&gt;
   } else if (!this.isSpectator) { // player is NOT active but not spectator&lt;br /&gt;
       switch (stateName) {&lt;br /&gt;
          case &#039;playerTurnMultiPlayerState&#039;:&lt;br /&gt;
		this.addActionButton(&#039;button_unpass&#039;, _(&#039;Oh no!&#039;), &#039;onUnpass&#039;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
				&lt;br /&gt;
 onUnpass: function(e) {&lt;br /&gt;
    this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; +  this.game_name + &amp;quot;/actionCancel.html&amp;quot;, {}, this); // no checkAction!&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although be careful that if the turn comes back to the player while he is about to click cancel, the action buttons will be updated and the player will misclick which can be quite frustrating. To avoid this, move the cancel button to another position, like to the left of pagemaintitletext:&lt;br /&gt;
  dojo.place(&#039;button_unpass&#039;, &#039;pagemaintitletext&#039;, &#039;before&#039;);&lt;br /&gt;
Being out of the generalactions div, it won&#039;t be automatically destroyed like normal buttons, so you&#039;ll have to handle that yourself in onLeavingState. You might also want to change the button color to red (blue buttons for active player only, red buttons also for inactive players?)&lt;br /&gt;
&lt;br /&gt;
Note: same technique can be used to do other out-of-turn actions, such as re-arranging cards in hand, exchanging resources, etc (i.e. if permitted by rules, such as &amp;quot;at any time player can...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
=== Multi Step Interactions: Select Worker/Place Worker - Using Selection ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
Simple way to implement something like that without extra states is to use &amp;quot;selection&amp;quot; mechanism. When user click on worker add some sort of class into that element i.e. &#039;selected&#039; (which also have to have some indication by css i.e. outline).&lt;br /&gt;
&lt;br /&gt;
Than user can click on placement zone, you can use dojo.query for &amp;quot;selected&amp;quot; element and use it along with zone id to send data to server. If proper worker is not selected yet can give a error message using this.showMessage(...) function.&lt;br /&gt;
&lt;br /&gt;
Extra code required to properly cleanup selection between states.&lt;br /&gt;
Also when you do that sometimes you want to change the state prompt, see below &#039;Change state prompt&#039;&lt;br /&gt;
&lt;br /&gt;
=== Multi Step Interactions: Select Worker/Place Worker - Using Client States ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
I don&#039;t think its documented feature but there is a way to do client-only states, which is absolutely wonderful for few reasons&lt;br /&gt;
* When player interaction is two step process, such as select worker, place worker, or place worker, pick one of two resources of your choice&lt;br /&gt;
* When multi-step process can result of impossible situation and has to be undone (by rules)&lt;br /&gt;
* When multi-step process is triggered from multiple states (such as you can do same thing as activated card action, pass action or main action)&lt;br /&gt;
&lt;br /&gt;
So lets do Select Worker/Place Worker&lt;br /&gt;
&lt;br /&gt;
Define your server state as usual, i.e. playerMainTurn -&amp;gt; &amp;quot;You must pick up a worker&amp;quot;.&lt;br /&gt;
Now define a client state, we only need &amp;quot;name&amp;quot; and &amp;quot;descriptionmyturn&amp;quot;, lets say &amp;quot;client_playerPicksLocation&amp;quot;. Always prefix names of client state with &amp;quot;client_&amp;quot; to avoid confusion. Now we have to do the following:&lt;br /&gt;
* Have a handler for onUpdateActionButtons for playerMainTurn to activate all possible workers he can pick&lt;br /&gt;
* When player clicks workers, remember the worker in one of the members of the main class, I usually use one called this.clientStateArgs.&lt;br /&gt;
* Transition to new client state&lt;br /&gt;
  onWorker: function(e) {&lt;br /&gt;
      var id = event.currentTarget.id;&lt;br /&gt;
      dojo.stopEvent(event);&lt;br /&gt;
      ... // do validity checks&lt;br /&gt;
      this.clientStateArgs.worker_id = id;&lt;br /&gt;
      this.setClientState(&amp;quot;client_playerPicksLocation&amp;quot;, {&lt;br /&gt;
                                descriptionmyturn : _(&amp;quot;${you} must select location&amp;quot;),&lt;br /&gt;
                            });&lt;br /&gt;
   }&lt;br /&gt;
* Have a handler for onUpdateActionButtons for client_playerPicksLocation to activate all possible locations this worker can go AND add Cancel button (see below)&lt;br /&gt;
* Have a location handler which will eventually send a server request, using stored this.clientStateArgs.worker_id as worker id&lt;br /&gt;
* The cancel button should call a method to restore server state, also if you doing it for more than one state you can add this universally using this.on_client_state check&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if (this.isCurrentPlayerActive()) {&lt;br /&gt;
          if (this.on_client_state &amp;amp;&amp;amp; !$(&#039;button_cancel&#039;)) {&lt;br /&gt;
               this.addActionButton(&#039;button_cancel&#039;, _(&#039;Cancel&#039;), dojo.hitch(this, function() {&lt;br /&gt;
                                             this.restoreServerGameState();&lt;br /&gt;
               }));&lt;br /&gt;
          }&lt;br /&gt;
        } &lt;br /&gt;
Note: usually I call my own function call this.cancelLocalStateEffects() which will do more stuff first then call restoreServerGameState(), same function is usually needs to be called when server request has failed (i.e. invalid move)&lt;br /&gt;
&lt;br /&gt;
Note: If you need more than 2 steps, you may have to do client side animation to reflect the new state, which gets trickier because you have to undo that also on cancellation.&lt;br /&gt;
&lt;br /&gt;
Code is available here [https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js sharedcode.js] (its using playerTurnPlayCubes and client_selectCubeLocation).&lt;br /&gt;
&lt;br /&gt;
=== Action Stack - Using Client States ===&lt;br /&gt;
&lt;br /&gt;
Action stack required where game is very complex and use triggered effects that can &amp;quot;stack&amp;quot;. It not always actual stack, it can be queue or random access&lt;br /&gt;
Examples:&lt;br /&gt;
* Magic the Gathering - classic card game where effects go on Stack, that allows to counter spell and counter spell of counter spell (not on bga - it just example of mechanics)&lt;br /&gt;
* Ultimate Railroads - action taking game where effects can be executed in any order&lt;br /&gt;
* Lewis and Clark - card game where actions executed as queue&lt;br /&gt;
&lt;br /&gt;
There is two ways of implementing it - on the server or the client.&lt;br /&gt;
For the server see article below.&lt;br /&gt;
The requirement for client side stack implementation is - all action can be undone, which means&lt;br /&gt;
* No dice rolls&lt;br /&gt;
* No card drawn&lt;br /&gt;
* No other players interaction&lt;br /&gt;
&lt;br /&gt;
No snippets are here, as this will be too complex but basically flow is:&lt;br /&gt;
* You have a action/effect stack (queue/list) as js object attached to &amp;quot;this&amp;quot;, i.e. this.unprocessed_actions&lt;br /&gt;
* When player plays a card, worker, etc, you read the effect of that card from the material file (client copy), and place into stack&lt;br /&gt;
* Then we call dispatch method which pulls the next action from the stack and change client state accordinly, i.e. this.setClientState(&amp;quot;client_playerGainsCubes&amp;quot;)&lt;br /&gt;
* When players acts on it - the action is removed from the stack and added to &amp;quot;server action arguments&amp;quot; list, this is another object which be used to send ajax call, i.e. this.clientStateArgs&lt;br /&gt;
* If nothing left in stack we can submit the ajax call assembling parameters from collected arguments (that can include action name)&lt;br /&gt;
* This method allows cheap undo - by restoring server state you will wipe out all user actions (but if you need intermediate aninmation you have to handle it yourself)&lt;br /&gt;
&lt;br /&gt;
Code can be found in Ultimate Railroads game (but it is random access list - so it a bit complex) and Lewis and Clark (complexity - user can always deny part of any effect)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Action Stack - Using Server States ===&lt;br /&gt;
&lt;br /&gt;
See definition of Action Stack above.&lt;br /&gt;
&lt;br /&gt;
To implement you usually need another db table that has the following fields: index of effect - which is used for sorted access, type - which is essense of the effect (i.e. collect resource), some extra arguments (i.e. resource type and resource count), and usually owner of the effect (i.e. player id)&lt;br /&gt;
The flow is:&lt;br /&gt;
* There is some initial player state, where player can play card for example&lt;br /&gt;
* Player main action - pushes the card effect on stack, which also can cause triggered effects which also go on stack&lt;br /&gt;
* After action processing is finished switch to game state which is &amp;quot;dispatcher&amp;quot;&lt;br /&gt;
* Dispatcher pulls the top effect (whatever definition of the top is), changes the active player and changes the state to appropriate player state to collect response&lt;br /&gt;
* Player state knows about the stack and pulls arguments (argX) from the effect arguments of the db&lt;br /&gt;
* Player action should clear up the top effect, and can possibly add more effects, then switch to &amp;quot;dispatcher&amp;quot; state again&lt;br /&gt;
* If stack is empty, dispatcher can either pick next player itself or use another game state which responsible for picking next player&lt;br /&gt;
&lt;br /&gt;
Code can be found in Tapestry.&lt;br /&gt;
&lt;br /&gt;
=== Changing state prompt ===&lt;br /&gt;
&lt;br /&gt;
State prompt is message displayed for player which usually comes from state description.&lt;br /&gt;
Sometimes you want to change it without changing state (one way is change state but locally, see client states above).&lt;br /&gt;
&lt;br /&gt;
Simple way just change the html&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        setMainTitle: function(text) {&lt;br /&gt;
            $(&#039;pagemaintitletext&#039;).innerHTML = text;&lt;br /&gt;
        },&lt;br /&gt;
         // usage&lt;br /&gt;
        onMeeple: function(event) {&lt;br /&gt;
              //... &lt;br /&gt;
              this.setMainTitle(_(&#039;You must select where meeple is going&#039;));&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This however will not work with parameters and will not draw You in color, if you want this its more sophisticated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        setDescriptionOnMyTurn : function(text) {&lt;br /&gt;
            this.gamedatas.gamestate.descriptionmyturn = text;&lt;br /&gt;
            var tpl = dojo.clone(this.gamedatas.gamestate.args);&lt;br /&gt;
            if (tpl === null) {&lt;br /&gt;
                tpl = {};&lt;br /&gt;
            }&lt;br /&gt;
            var title = &amp;quot;&amp;quot;;&lt;br /&gt;
            if (this.isCurrentPlayerActive() &amp;amp;&amp;amp; text !== null) {&lt;br /&gt;
                tpl.you = this.divYou(); &lt;br /&gt;
            }&lt;br /&gt;
            title = this.format_string_recursive(text, tpl);&lt;br /&gt;
&lt;br /&gt;
            if (!title) {&lt;br /&gt;
                this.setMainTitle(&amp;quot;&amp;amp;nbsp;&amp;quot;);&lt;br /&gt;
            } else {&lt;br /&gt;
                this.setMainTitle(title);&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this method uses &#039;&#039;&#039;setMainTitle&#039;&#039;&#039; defined above and &#039;&#039;&#039;divYou&#039;&#039;&#039; defined in another section of this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assigning Player Order ===&lt;br /&gt;
Normally when game starts there is &amp;quot;natural&amp;quot; player order assigned randomly.&lt;br /&gt;
&lt;br /&gt;
If you want to deliberatly assign player order at the start of the game (for example, in a game with teams options), you can do so by retrieving the initialization-only player attribute &#039;&#039;&#039;player_table_order&#039;&#039;&#039; and using it to assign values to &#039;&#039;&#039;player_no&#039;&#039;&#039; (which is normally assigned at the start of a game in the order in which players come to the table). (See [https://en.doc.boardgamearena.com/Game_database_model:_dbmodel.sql#The_player_table Game database model] for more details.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
                // Retrieve inital player order ([0=&amp;gt;playerId1, 1=&amp;gt;playerId2, ...])&lt;br /&gt;
		$playerInitialOrder = [];&lt;br /&gt;
		foreach ($players as $playerId =&amp;gt; $player) {&lt;br /&gt;
			$playerInitialOrder[$player[&#039;player_table_order&#039;]] = $playerId;&lt;br /&gt;
		}&lt;br /&gt;
		ksort($playerInitialOrder);&lt;br /&gt;
		$playerInitialOrder = array_flip(array_values($playerInitialOrder));&lt;br /&gt;
&lt;br /&gt;
		// Player order based on &#039;playerTeams&#039; option&lt;br /&gt;
		$playerOrder = [0, 1, 2, 3];&lt;br /&gt;
		switch ($this-&amp;gt;getGameStateValue(&#039;playerTeams&#039;)) {&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_2:&lt;br /&gt;
				$playerOrder = [0, 2, 1, 3];&lt;br /&gt;
				break;&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_4:&lt;br /&gt;
				$playerOrder = [0, 1, 3, 2];&lt;br /&gt;
				break;&lt;br /&gt;
			case $this-&amp;gt;TEAM_RANDOM:&lt;br /&gt;
				shuffle($playerOrder);&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
			case $this-&amp;gt;TEAM_1_3:&lt;br /&gt;
				// Default order&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
                // Create players&lt;br /&gt;
		// Note: if you added some extra field on &amp;quot;player&amp;quot; table in the database (dbmodel.sql), you can initialize it there.&lt;br /&gt;
		$sql =&lt;br /&gt;
			&#039;INSERT INTO player (player_id, player_color, player_canal, player_name, player_avatar, player_no) VALUES &#039;;&lt;br /&gt;
		$values = [];&lt;br /&gt;
&lt;br /&gt;
		foreach ($players as $playerId =&amp;gt; $player) {&lt;br /&gt;
			$color = array_shift($default_colors);&lt;br /&gt;
			$values[] =&lt;br /&gt;
				&amp;quot;(&#039;&amp;quot; .&lt;br /&gt;
				$playerId .&lt;br /&gt;
				&amp;quot;&#039;,&#039;$color&#039;,&#039;&amp;quot; .&lt;br /&gt;
				$player[&#039;player_canal&#039;] .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				addslashes($player[&#039;player_name&#039;]) .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				addslashes($player[&#039;player_avatar&#039;]) .&lt;br /&gt;
				&amp;quot;&#039;,&#039;&amp;quot; .&lt;br /&gt;
				$playerOrder[$playerInitialOrder[$playerId]] .&lt;br /&gt;
				&amp;quot;&#039;)&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
		$sql .= implode(&#039;,&#039;, $values);&lt;br /&gt;
		$this-&amp;gt;DbQuery($sql);&lt;br /&gt;
		$this-&amp;gt;reattributeColorsBasedOnPreferences(&lt;br /&gt;
			$players,&lt;br /&gt;
			$gameinfos[&#039;player_colors&#039;]&lt;br /&gt;
		);&lt;br /&gt;
		$this-&amp;gt;reloadPlayersBasicInfos();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send different notifications to active player vs everybody else ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
Hack alert. This is a hack. We were hoping for proper solution by bga framework.&lt;br /&gt;
&lt;br /&gt;
This will allow you to send notification with two message one for specific player and one for everybody else including spectators.&lt;br /&gt;
Note that this does not split the data - all data must be shared.&lt;br /&gt;
&lt;br /&gt;
Add this to .js file (if you already overriding it merge obviously)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/** @Override */&lt;br /&gt;
format_string_recursive: function(log, args) {&lt;br /&gt;
   if (typeof args.log_others != &#039;undefined&#039; &amp;amp;&amp;amp; typeof args.player_id != &#039;undefined&#039; &amp;amp;&amp;amp; this.player_id != args.player_id)&lt;br /&gt;
	log = args.log_others;&lt;br /&gt;
   return this.inherited(arguments); // you must call this to call super &lt;br /&gt;
},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of usage (from eminentdomain)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    $this-&amp;gt;notifyAllPlayers(&#039;tokenMoved&#039;, &lt;br /&gt;
             clienttranslate(&#039;${player_name} adds +2 Colonies to ${place_name}&#039;), // notification with show for player with player_id&lt;br /&gt;
             [&#039;player_id&#039;=&amp;gt;$player_id, // this is mandatory&lt;br /&gt;
             &#039;log_others&#039;=&amp;gt;clienttranslate(&#039;${player_name} adds +2 Colonies to an unknown planet&#039;), // notification will show for others&lt;br /&gt;
              ...&lt;br /&gt;
             ]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send transient notifications without incrementing move ID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.php&lt;br /&gt;
&lt;br /&gt;
Hack alert. This is a hack.&lt;br /&gt;
&lt;br /&gt;
Use this if you need to send some transient notification that should not create a new move ID. The notification should be idempotent -- it should have no practical effect on the game state and would be &#039;&#039;&#039;safe to drop&#039;&#039;&#039; (e.g., it would not matter if a player never received this notification). For example, in a co-op game you want all players to see a real-time preview of some action, before the active player commits their turn.&lt;br /&gt;
&lt;br /&gt;
Doing this mainly affects the instant replay &amp;amp; archive modes. During replay, the BGA framework automatically inserts a 1.5-second pause between each &amp;quot;move&amp;quot;. With this hack, your transient notifications are not considered to be a &amp;quot;move&amp;quot;, so no pause gets added.&lt;br /&gt;
&lt;br /&gt;
; In ggg.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;not_a_move_notification = true; // note: do not increase the move counter&lt;br /&gt;
$this-&amp;gt;notifyAllPlayers(&#039;cardsPreview&#039;, &#039;&#039;, $args);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: you cannot have code that send notification or even changes state after this, and you cannot reset this variable back either because it only takes effect when you exit action handling function&lt;br /&gt;
&lt;br /&gt;
=== Ajax Call wrapper ===&lt;br /&gt;
&#039;&#039;&#039;Ingredients:&#039;&#039;&#039; ggg.js&lt;br /&gt;
&lt;br /&gt;
The current ajaxcall is super vebose and prone to errors, I suggest using a helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
Most beginner mistakes come from missing part of this code (which is understandstandable - this is a huge snippet to clone every time).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
		if (!args) args = {}; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
			&lt;br /&gt;
		args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
		if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
			this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
				this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                               handler); // this is real result handler - it called both on success and error, it has optional param  &amp;quot;is_error&amp;quot; - you rarely need it&lt;br /&gt;
			}&lt;br /&gt;
		},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   this.ajaxcallwrapper(&#039;pass&#039;); // no args&lt;br /&gt;
   this.ajaxcallwrapper(&#039;playCard&#039;, {card: card_id}); // with args&lt;br /&gt;
   this.ajaxcallwrapper(&#039;playCard&#039;, {card: card_id}, (is_error)=&amp;gt;{if (!is_error) dojo.query(&amp;quot;.selected&amp;quot;).removeClass(&#039;selected&#039;);}) // with handler that cleans up &#039;selected&#039; class on success&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this always will lock interface and always check for action, you can modify this method to do it optionally, i.e replace &#039;args.lock = true;&#039; in the code above with this&lt;br /&gt;
  if (args.lock!==false) args.lock = true; else delete args.lock; // it does not work with false value - it has to be removed&lt;br /&gt;
&lt;br /&gt;
=== Custom error/exception handling in JavaScript ===&lt;br /&gt;
&lt;br /&gt;
; In ggg.php&lt;br /&gt;
Throw BgaUserException with some easy-to-identify prefix such as &amp;quot;!!!&amp;quot; and a custom error code. DO NOT TRANSLATE this message text. The exception will rollback database transaction and cancel all changes (including any notifications).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function foo(bool $didConfirm = false): void&lt;br /&gt;
    {&lt;br /&gt;
        // do processing for the user&#039;s move&lt;br /&gt;
        // afterwards, you determine this move will end the game&lt;br /&gt;
        // so you want to rollback the transaction and require the user to confirm the move first&lt;br /&gt;
&lt;br /&gt;
        if ($gameIsEnding &amp;amp;&amp;amp; !$didConfirm) {&lt;br /&gt;
            throw new BgaUserException(&#039;!!!endGameConfirm&#039;, 9001);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; In ggg.js&lt;br /&gt;
Override framework function showMessage to suppress the red banner message and gamelog message when you detect the &amp;quot;!!!&amp;quot; prefix&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    /* @Override */&lt;br /&gt;
    showMessage: function (msg, type) {&lt;br /&gt;
      if (type == &amp;quot;error&amp;quot; &amp;amp;&amp;amp; msg &amp;amp;&amp;amp; msg.startsWith(&amp;quot;!!!&amp;quot;)) {&lt;br /&gt;
        return; // suppress red banner and gamelog message&lt;br /&gt;
      }&lt;br /&gt;
      this.inherited(arguments);&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Deal with the error in your callback:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    fooAction: function (didConfirm) {&lt;br /&gt;
      var data = {&lt;br /&gt;
        foo: &amp;quot;bar&amp;quot;,&lt;br /&gt;
        didConfirm: !!didConfirm,&lt;br /&gt;
      };&lt;br /&gt;
      this.ajaxcallwrapper(&amp;quot;fooAction&amp;quot;, data, function (error, errorMsg) {&lt;br /&gt;
        if (error &amp;amp;&amp;amp; errorMsg == &amp;quot;!!!endGameConfirm&amp;quot;) {&lt;br /&gt;
          // your custom error handling goes here&lt;br /&gt;
          // for example, show a confirmation dialog and repeat the action with additional param&lt;br /&gt;
          this.confirmationDialog(&lt;br /&gt;
            _(&amp;quot;Doing the foo action now will end the game&amp;quot;),&lt;br /&gt;
            () =&amp;gt; {&lt;br /&gt;
              this.fooAction(true);&lt;br /&gt;
            }&lt;br /&gt;
          );&lt;br /&gt;
        }&lt;br /&gt;
      });&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For custom global error handling, you could modify ajaxcallwrapper:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  ajaxcallwrapper: function (action, args, handler) {&lt;br /&gt;
    if (!args) args = {};&lt;br /&gt;
    args.lock = true;&lt;br /&gt;
    args.version = this.gamedatas.version;&lt;br /&gt;
    if (this.checkAction(action)) {&lt;br /&gt;
      this.ajaxcall(&lt;br /&gt;
        &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;,&lt;br /&gt;
        args,&lt;br /&gt;
        this,&lt;br /&gt;
        (result) =&amp;gt; {},&lt;br /&gt;
        (error, errorMsg, errorCode) =&amp;gt; {&lt;br /&gt;
          if (error &amp;amp;&amp;amp; errorMsg == &amp;quot;!!!checkVersion&amp;quot;) {&lt;br /&gt;
            this.infoDialog(&lt;br /&gt;
              _(&amp;quot;A new version of this game is now available&amp;quot;),&lt;br /&gt;
              _(&amp;quot;Reload Required&amp;quot;),&lt;br /&gt;
              () =&amp;gt; {&lt;br /&gt;
                window.location.reload();&lt;br /&gt;
              },&lt;br /&gt;
              true&lt;br /&gt;
            );&lt;br /&gt;
          } else {&lt;br /&gt;
            if (handler) handler(error, errorMsg, errorCode);&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      );&lt;br /&gt;
    }&lt;br /&gt;
  },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force players to refresh after new deploy ===&lt;br /&gt;
&lt;br /&gt;
When you deploy a new version of your game, the PHP backend code is immediately updated but the JavaScript/HTML/CSS frontend code *does not update* for active players until they manually refresh the page (F5) in their browser. Obviously this is not ideal. In the best case, real-time tables don&#039;t see your shiny new enhancements. In the worst case, your old JS code isn&#039;t compatible with your new PHP code and the game breaks in strange ways (any bug reports filed will be false positives and unable to reproduce). To avoid any problems, you should force all players to immediately reload the page following a new deploy.&lt;br /&gt;
&lt;br /&gt;
By throwing a &amp;quot;visible&amp;quot; exception (simplest solution), you&#039;ll get something like this which instructs the user to reload:&lt;br /&gt;
&lt;br /&gt;
[[File:Force-refresh.png|950x950px]]&lt;br /&gt;
&lt;br /&gt;
Or, if you combine this technique with the above custom error handling technique, you could do something a bit nicer. You could show a dialog box and automatically refresh the page when the user clicks &amp;quot;OK&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
[[File:Reload-required.png|500x500px]]&lt;br /&gt;
; In ggg.php&lt;br /&gt;
Transmit the server version number in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    protected function getAllDatas(): array&lt;br /&gt;
    {&lt;br /&gt;
        $players = $this-&amp;gt;getCollectionFromDb(&amp;quot;SELECT player_id id, player_score score FROM player&amp;quot;);&lt;br /&gt;
        return [&lt;br /&gt;
            &#039;players&#039; =&amp;gt; $players,&lt;br /&gt;
            &#039;version&#039; =&amp;gt; intval($this-&amp;gt;gamestate-&amp;gt;table_globals[300]), // &amp;lt;-- ADD HERE&lt;br /&gt;
            ...&lt;br /&gt;
        ];&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a helper function to fail if the client and server versions mismatch. Note the version check uses &amp;lt;code&amp;gt;!=&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt; so it can support rollback to a previous deploy as well. ;-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    public function checkVersion(int $clientVersion): void&lt;br /&gt;
    {&lt;br /&gt;
        if ($clientVersion != intval($this-&amp;gt;gamestate-&amp;gt;table_globals[300])) {&lt;br /&gt;
            // Simplest way is to throw a &amp;quot;visible&amp;quot; exception&lt;br /&gt;
            // It&#039;s ugly but comes with a &amp;quot;click here&amp;quot; link to refresh&lt;br /&gt;
            throw new BgaVisibleSystemException($this-&amp;gt;_(&amp;quot;A new version of this game is now available. Please reload the page (F5).&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
            // For something prettier, throw a &amp;quot;user&amp;quot; exception and handle in JS&lt;br /&gt;
            // (see BGA cookbook section above on custom error handling)&lt;br /&gt;
            throw new BgaUserException(&#039;!!!checkVersion&#039;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
; In ggg.action.php&lt;br /&gt;
Create a helper function for actions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  private function checkVersion()&lt;br /&gt;
  {&lt;br /&gt;
    $clientVersion = (int) $this-&amp;gt;getArg(&#039;version&#039;, AT_int, false);&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;checkVersion($clientVersion);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Call &amp;lt;code&amp;gt;$this-&amp;gt;checkVersion()&amp;lt;/code&amp;gt; at the top of &amp;lt;b&amp;gt;every action function&amp;lt;/b&amp;gt;, immediately after &amp;lt;code&amp;gt;$this-&amp;gt;setAjaxMode()&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  public function move()&lt;br /&gt;
  {&lt;br /&gt;
    $this-&amp;gt;setAjaxMode();&lt;br /&gt;
    $this-&amp;gt;checkVersion(); // &amp;lt;-- ADD HERE&lt;br /&gt;
    ...&lt;br /&gt;
    $this-&amp;gt;ajaxResponse();&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; In ggg.js&lt;br /&gt;
Transmit the version (from gamedatas) as a parameter with every ajax call. For example, if you&#039;re already using a wrapper function for every ajax call, add it like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  ajaxcallwrapper: function (action, args, handler) {&lt;br /&gt;
    if (!args) args = {};&lt;br /&gt;
    args.lock = true;&lt;br /&gt;
    args.version = this.gamedatas.version; // &amp;lt;-- ADD HERE&lt;br /&gt;
    if (this.checkAction(action)) {&lt;br /&gt;
      this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, this, () =&amp;gt; {}, handler);&lt;br /&gt;
    }&lt;br /&gt;
  },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable / lock table creation for new deploy ===&lt;br /&gt;
&lt;br /&gt;
If you are deploying a major new game version, especially if it involves upgrading production game databases, you may have a lot of angry players if you break their tables.  Depending on your changes, you may be able to restore the previous version and fix the tables easily.&lt;br /&gt;
&lt;br /&gt;
However, if a new deploy turns out bad and players created turn-based tables while it was live, it may be quite difficult to fix those tables, since they were created from a bad deploy.&lt;br /&gt;
&lt;br /&gt;
The solution?  You can announce in your game group that you are locking table creation, and then in your new version, add an impossible startcondition to an existing option.  &lt;br /&gt;
Note: This only makes sense if you have a few games running in real time mode in the time of deployment, otherwise it won&#039;t achieve much, unless you wait at least a day for other turn based games to break (or not)&lt;br /&gt;
&lt;br /&gt;
Here is an example of an option with only 2 values (if you don&#039;t have options at all you have to create a fake option to use this method, if you have more values - you have to list them all):&lt;br /&gt;
&lt;br /&gt;
; In gameoptions.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// TODO NEXT remove after testing deploy to upgrade, here 0 and 1 - replace with values of your option!&lt;br /&gt;
&#039;startcondition&#039; =&amp;gt; [&lt;br /&gt;
   0 =&amp;gt; [ [ &#039;type&#039; =&amp;gt; &#039;minplayers&#039;, &#039;value&#039; =&amp;gt; 32, &#039;message&#039; =&amp;gt; totranslate(&#039;Maintenance in progress.  Table creation disabled.&#039;) ] ],&lt;br /&gt;
   1 =&amp;gt; [ [ &#039;type&#039; =&amp;gt; &#039;minplayers&#039;, &#039;value&#039; =&amp;gt; 32, &#039;message&#039; =&amp;gt; totranslate(&#039;Maintenance in progress.  Table creation disabled.&#039;) ] ],&lt;br /&gt;
],&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Be sure to click &amp;quot;Reload game options configuration&amp;quot; after making this change, then test in studio (test that you cannot create any table)&lt;br /&gt;
* Deploy to production&lt;br /&gt;
* Now, when a player attempts to create a new table, they will see a red error bar with your &amp;quot;Maintenance in progress&amp;quot; message.  &lt;br /&gt;
* Wait for screaming (if you have real times games in progress waiting 15 min probably ok, if you have only turn based games, probably a day)&lt;br /&gt;
* Once you confirm the new deploy looks good, you can revert the change in gameoptions.inc.php and do another deploy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Local Storage ===&lt;br /&gt;
&lt;br /&gt;
There is not much you can store in localStorage (https://developer.mozilla.org/docs/Web/API/Window/localStorage), since most stuff should be stored either in game db or in user prefrences,&lt;br /&gt;
but some stuff makes sense to store there, for example &amp;quot;zoom&amp;quot; level (if you use custom zooming). This setting really affect this specific host and specific browser, setting it localStorage makes most sense.&lt;br /&gt;
&lt;br /&gt;
game.js&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   setup: function (gamedatas) {&lt;br /&gt;
        let zoom = localStorage.getItem(`${this.game_name}_zoom`);&lt;br /&gt;
        this.setZoom(zoom);&lt;br /&gt;
...&lt;br /&gt;
   },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this case setZoom is custom function to actually set it.&lt;br /&gt;
When zoom changed, for example when some buttons pressed, store current value (but sanitize it so it never so bad that game cannot be viewed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    setZoom: function (zoom) {&lt;br /&gt;
      zoom = parseInt(zoom) || 0;&lt;br /&gt;
      if (zoom === 0 || zoom &amp;lt; 0.1 || zoom &amp;gt; 10) {&lt;br /&gt;
        zoom = 1;&lt;br /&gt;
      }&lt;br /&gt;
      this.zoom = zoom;&lt;br /&gt;
      localStorage.setItem(`${this.game_name}_zoom`, &amp;quot;&amp;quot; + this.zoom);&lt;br /&gt;
... do actual zooming stuff&lt;br /&gt;
    },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Algorithms ==&lt;br /&gt;
&lt;br /&gt;
=== Generate permutations in lexicographic order ===&lt;br /&gt;
&lt;br /&gt;
Use this when you have an array like [1, 2, 3, 4] and need to loop over some/all 24 permutations of possible ordering. This type of [https://www.php.net/manual/en/language.generators.syntax.php generator function] computes each possibility one at a time, making it vastly more efficient than either a normal iteration or recursive function that produce all possibilities up front.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function generatePermutations(array $array): Generator&lt;br /&gt;
{&lt;br /&gt;
    // https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order&lt;br /&gt;
    // Sort the array and this is the first permutation&lt;br /&gt;
    sort($array);&lt;br /&gt;
    yield $array;&lt;br /&gt;
&lt;br /&gt;
    $count = count($array);&lt;br /&gt;
    do {&lt;br /&gt;
        // Find the largest index k where a[k] &amp;lt; a[k + 1]&lt;br /&gt;
        // End when no such index exists&lt;br /&gt;
        $found = false;&lt;br /&gt;
        for ($k = $count - 2; $k &amp;gt;= 0; $k--) {&lt;br /&gt;
            $kvalue = $array[$k];&lt;br /&gt;
            $knext = $array[$k + 1];&lt;br /&gt;
            if ($kvalue &amp;lt; $knext) {&lt;br /&gt;
                // Find the largest index l greater than k where a[k] &amp;lt; a[l]&lt;br /&gt;
                for ($l = $count - 1; $l &amp;gt; $k; $l--) {&lt;br /&gt;
                    $lvalue = $array[$l];&lt;br /&gt;
                    if ($kvalue &amp;lt; $lvalue) {&lt;br /&gt;
                        // Swap a[k] and a[l]&lt;br /&gt;
                        [$array[$k], $array[$l]] = [$array[$l], $array[$k]];&lt;br /&gt;
&lt;br /&gt;
                        // Reverse the sequence from a[k + 1] up to and including the final element&lt;br /&gt;
                        $reverse = array_reverse(array_slice($array, $k + 1));&lt;br /&gt;
                        array_splice($array, $k + 1, $count, $reverse);&lt;br /&gt;
                        yield $array;&lt;br /&gt;
&lt;br /&gt;
                        // Restart with the new array to find the next permutation&lt;br /&gt;
                        $found = true;&lt;br /&gt;
                        break 2;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    } while ($found);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$cash = [4, 1, 2, 3, 4];&lt;br /&gt;
foreach ($this-&amp;gt;generatePermutations($cash) as $p) {&lt;br /&gt;
    // your code here to evaluate permutation $p&lt;br /&gt;
    // first iteration: $p = [1, 2, 3, 4, 4]&lt;br /&gt;
    // last (60th) iteration: $p = [4, 4, 3, 2, 1]&lt;br /&gt;
    // break from loop once you achieve your goal&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Studio&amp;diff=20752</id>
		<title>Studio</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Studio&amp;diff=20752"/>
		<updated>2024-04-11T20:49:41Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added the BGA Type safe template to the tips/tools&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[File:Bga_studio_small.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note: Please DO NOT translate Studio Documentation, so that there can be one place where you can find the latest information available.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== What is Board Game Arena Studio? ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Board Game Arena Studio&#039;&#039;&#039; is a platform to build online board game adaptations using the Board Game Arena platform.&lt;br /&gt;
&lt;br /&gt;
It is open to any gamer with software development skills :)&lt;br /&gt;
&lt;br /&gt;
BGA Studio website: https://studio.boardgamearena.com&lt;br /&gt;
&lt;br /&gt;
Original announcement on BGA forum: https://forum.boardgamearena.com/viewtopic.php?f=10&amp;amp;t=1973&lt;br /&gt;
&lt;br /&gt;
== Discover BGA Studio in 5 presentations ==&lt;br /&gt;
&lt;br /&gt;
Why, how, what... to start discovering BGA Studio, we prepared 5 &amp;quot;powerpoint&amp;quot; presentations for you:&lt;br /&gt;
&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/5-reasons-why-you-should-use-bga-studio-for-your-online-board-game 5 reasons why you should use BGA Studio for your online board game] (or [http://en.doc.boardgamearena.com/images/5/58/1-why-developing.pdf ‎Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/the-8-steps-to-create-a-board-game-on-board-game-arena The 8 steps to create a board game on Board Game Arena] (or [http://en.doc.boardgamearena.com/images/1/1e/2-8-steps-to-realize.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/the-bga-framework-at-a-glance The BGA Framework at a glance] (or [http://en.doc.boardgamearena.com/images/7/79/3-thebgaframework.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine] (or [http://en.doc.boardgamearena.com/images/9/98/4-gamestates.pdf Download as PDF])&lt;br /&gt;
* [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] (or [http://en.doc.boardgamearena.com/images/7/76/5-guidelines.pdf ‎Download as PDF])&lt;br /&gt;
&lt;br /&gt;
== How to join the BGA developer team? ==&lt;br /&gt;
&lt;br /&gt;
Please see this page: [[How to join BGA developer team?]]&lt;br /&gt;
&lt;br /&gt;
== Great, I&#039;m in! ... How should I start? ==&lt;br /&gt;
&lt;br /&gt;
If you didn&#039;t already, check the presentations at the top of this page to get the basics.&lt;br /&gt;
&lt;br /&gt;
Then, you should checkout the [[First steps with BGA Studio]] to make sure that runs fine.&lt;br /&gt;
&lt;br /&gt;
After that, we strongly advise you to take one of these game creation tutorials:&lt;br /&gt;
* [[Tutorial reversi]] - an abstract strategy game played on an 8×8 uncheckered board for 2 players&lt;br /&gt;
* [[Tutorial gomoku]] - an abstract strategy game tic-tac-toe style for 2 players&lt;br /&gt;
* [[Tutorial hearts]] - a card game for 4 players&lt;br /&gt;
&lt;br /&gt;
Then start editing files and see what happens! ;)&lt;br /&gt;
&lt;br /&gt;
Once you&#039;re done with tutorials, you can start a real game (or join existing project)&lt;br /&gt;
* [[Create a game in BGA Studio: Complete Walkthrough]] &lt;br /&gt;
&lt;br /&gt;
If you have any questions, please check out the [[Studio FAQ]] or [[Contact BGA Studio]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To search wiki pages on studio enter this text in search bar: &lt;br /&gt;
  &amp;quot;Category:Studio&amp;quot; white rabbit &lt;br /&gt;
That is if you want to search for white rabbit&lt;br /&gt;
&lt;br /&gt;
== BGA Studio documentation ==&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio Framework reference ===&lt;br /&gt;
&lt;br /&gt;
This part of the documentation focuses on the development framework itself: functions and methods available to build your game.&lt;br /&gt;
&lt;br /&gt;
[[Studio file reference|File structure of a BGA game]]&lt;br /&gt;
&lt;br /&gt;
==== Game logic (Server side) ====&lt;br /&gt;
&lt;br /&gt;
* [[Main game logic: yourgamename.game.php]]&lt;br /&gt;
* [[Your game state machine: states.inc.php]]&lt;br /&gt;
* [[Game database model: dbmodel.sql]]&lt;br /&gt;
* [[Players actions: yourgamename.action.php]]&lt;br /&gt;
* [[Game material description: material.inc.php]]&lt;br /&gt;
* [[Game statistics: stats.inc.php]]&lt;br /&gt;
&lt;br /&gt;
==== Game interface (Client side) ====&lt;br /&gt;
&lt;br /&gt;
* [[Game interface logic: yourgamename.js]]&lt;br /&gt;
* [[Game art: img directory]]&lt;br /&gt;
* [[Game interface stylesheet: yourgamename.css]]&lt;br /&gt;
* [[Game layout: view and template: yourgamename.view.php and yourgamename_yourgamename.tpl]]&lt;br /&gt;
* [[Your game mobile version]]&lt;br /&gt;
&lt;br /&gt;
==== Other components ====&lt;br /&gt;
&lt;br /&gt;
* [[Translations]] (how to make your game translatable)&lt;br /&gt;
* [[Game options and preferences: gameoptions.inc.php]]&lt;br /&gt;
* [[Game meta-information: gameinfos.inc.php]]&lt;br /&gt;
* [[Game replay]]&lt;br /&gt;
* [[3D]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio game components reference ===&lt;br /&gt;
&lt;br /&gt;
Game components are useful tools you can use in your game adaptations.&lt;br /&gt;
&lt;br /&gt;
JS:&lt;br /&gt;
&lt;br /&gt;
* [[Counter]]: a JS component to manage a counter that can increase/decrease (ex: player&#039;s score).&lt;br /&gt;
* [[Scrollmap]]: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples:  Saboteur or Takenoko games).&lt;br /&gt;
* [[Stock]]: a JS component to manage and display a set of game elements displayed at a position.&lt;br /&gt;
* [[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&#039;s places at Can&#039;t Stop).&lt;br /&gt;
* [[Draggable]]: a JS component to manage drag&#039;n&#039;drop actions.&lt;br /&gt;
* [[ExpandableSection]]: a JS component to manage a rectangular block of HTML than can be displayed/hidden.&lt;br /&gt;
* [[Anti-Stock]]:Code snippets in ValinaJS/HTML5 to do what stock does (that is if you cannot beat Stock into submission)&lt;br /&gt;
&lt;br /&gt;
PHP:&lt;br /&gt;
* [[Deck]]: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).&lt;br /&gt;
&lt;br /&gt;
Reference for classes in game class hierarchy&lt;br /&gt;
&lt;br /&gt;
* [[Table]]: a PHP class that you inherit from for the game php&lt;br /&gt;
&lt;br /&gt;
=== BGA Studio user guide ===&lt;br /&gt;
&lt;br /&gt;
This part of the documentation is a user guide for the BGA Studio online development environment.&lt;br /&gt;
&lt;br /&gt;
Lifecycle&lt;br /&gt;
&lt;br /&gt;
* [[BGA game Lifecycle]]&lt;br /&gt;
* [[Create a game in BGA Studio: Complete Walkthrough]]&lt;br /&gt;
* [[Pre-release checklist]] - Go throught this list if you think you done development&lt;br /&gt;
* [[Post-release phase]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools and Advice&lt;br /&gt;
* [[BGA Studio Guidelines]]&lt;br /&gt;
* [[Tutorials checklist]]&lt;br /&gt;
* [[I wish I knew this when I started]] - one liners on most common missed features, mistakes, etc with further doc references&lt;br /&gt;
* [[Tools and tips of BGA Studio]] - Tips and instructions on setting up development environment&lt;br /&gt;
** [[Setting up BGA Development environment using VSCode]]&lt;br /&gt;
** [[Practical debugging]] - Tips focused on debugging&lt;br /&gt;
** [[Testing by developer]]&lt;br /&gt;
** [[Studio logs]] - Instructions for log access&lt;br /&gt;
** [[Troubleshooting]] - Most common &amp;quot;I am really stuck&amp;quot; situations&lt;br /&gt;
* [[BGA Studio Cookbook]] - Tips and instructions on using API&#039;s, libraries and frameworks&lt;br /&gt;
** [[BGA-ts-template|BGA Type Safe Template]] - Setting up a fully typed project using typescript and more!&lt;br /&gt;
** [[Using Vue]] - work-in-progress guide on using the modern framework Vue.js to create a game&lt;br /&gt;
** [[Using Typescript and Scss]] - How to auto-build Typescript and SCSS files to make your code cleaner&lt;br /&gt;
** [[Bots and Artificial Intelligence]] - How to add AI/Bots to the game&lt;br /&gt;
* [[Studio FAQ]]&lt;br /&gt;
&lt;br /&gt;
Sharing&lt;br /&gt;
* [[Common board game elements image resources]] - Dice, meeples, cubes, etc&lt;br /&gt;
* [[BGA Code Sharing]] - Shared resources, projects on git hub, common code, other links&lt;br /&gt;
&lt;br /&gt;
== Software Versions ==&lt;br /&gt;
&lt;br /&gt;
Versions currently used by BGA framework:&lt;br /&gt;
&lt;br /&gt;
* Dojo Toolkit 1.15&lt;br /&gt;
* PHP: 7.4 (8.2 on studio - choice in control panel, also see announcement on forum)&lt;br /&gt;
* SQL: MySQL 5.7&lt;br /&gt;
* JS/CSS/HTML: limited by what minimization tools support [[Game_interface_logic:_yourgamename.js#Javascript_minimization_.28after_July_2020.29]]&lt;br /&gt;
* Font Awesome: 4.7 https://fontawesome.com/v4.7/icons/ (available as &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;i class=&amp;quot;fa fa-clock&amp;quot; /&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;)&lt;br /&gt;
* Font Awesome: 6.4.0 https://fontawesome.com/v6/search?o=r&amp;amp;m=free (available as &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;i class=&amp;quot;fa6 fa6-clock&amp;quot; /&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
=== PHP Extensions Used ===&lt;br /&gt;
&lt;br /&gt;
The following PHP extensions are - as of May 8th, 2022 - in use in BGA Studio and available:&lt;br /&gt;
&lt;br /&gt;
date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, sodium, apache2handler, mysqlnd, PDO, xml, apcu, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, gmp, iconv, igbinary, json, exif, msgpack, mysqli, pdo_mysql, apc, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, v8js, xmlreader, xmlwriter, xsl, zip, Phar, memcached, Zend OPcache&lt;br /&gt;
&lt;br /&gt;
== Other resources ==&lt;br /&gt;
&lt;br /&gt;
[http://forum.boardgamearena.com/viewforum.php?f=12 Development forum]&lt;br /&gt;
&lt;br /&gt;
[https://studio.boardgamearena.com/bugs Bug tracking system FOR STUDIO issues and APIs]&lt;br /&gt;
&lt;br /&gt;
DISCORD chat server/room invite link https://discord.gg/YxEUacY if it does not work check this topic https://forum.boardgamearena.com/viewtopic.php?f=12&amp;amp;t=17403&amp;amp;hilit=discord&lt;br /&gt;
&lt;br /&gt;
Developer BLOGS https://bga-devs.github.io/blog/&lt;br /&gt;
&lt;br /&gt;
[[Contact BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=20751</id>
		<title>Tutorial reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=20751"/>
		<updated>2024-04-11T20:43:27Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added a redirect note to the top of the page leading to the type-safe template tutorial for reversi&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Check out an update version&#039;&#039;&#039; of the Reversi Tutorial: [[BGA-ts-template Reversi]] which uses the [[BGA-ts-template|BGA Type Safe Template]]. {{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Using this tutorial, you can build a complete working game on the BGA environment: Reversi.&lt;br /&gt;
&lt;br /&gt;
Before you read this tutorial, you must:&lt;br /&gt;
* Read the overall presentations of the BGA Framework ([[Studio|see here]]).&lt;br /&gt;
* Know the [http://en.wikipedia.org/wiki/Reversi#Rules rules of Reversi].&lt;br /&gt;
* Know the languages used on BGA: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* &#039;&#039;&#039;Setup your development environment&#039;&#039;&#039; [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
&lt;br /&gt;
== Create your first game ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: you should already have created a project following instructions in [[First_steps_with_BGA_Studio#Create_a_new_game_project|Create a new game project]]. While you will find a &#039;&#039;&#039;reversi&#039;&#039;&#039; directory in your SFTP folder, do not use it for this tutorial. Instead, use the project you have created as an (empty) starting point.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
With the initial skeleton of code provided in your project, you can already start a game from the BGA Studio:&lt;br /&gt;
* Go to your [https://studio.boardgamearena.com/controlpanel studio Control panel], then Manage games and select your initial project. &#039;&#039;Note: there are warnings displayed about a missing BGG_ID and presentation text. You can ignore that for now.&#039;&#039;&lt;br /&gt;
* Click the Play link next to your project name. This will open the Play page and offer to create a new table for your project. &#039;&#039;Optional: click the Heart icon to add your project to your favorite games list.&#039;&#039;&lt;br /&gt;
* On the Play page, on the top of the page, make sure that your settings are &amp;quot;Simple game&amp;quot;, &amp;quot;Real time&amp;quot; and &amp;quot;Manual&amp;quot;.&lt;br /&gt;
* Click &amp;quot;Create table&amp;quot; to create a table of your project. &lt;br /&gt;
* For now, we are going to work with one player only, so use the (-) button to set the number of players to 1. Most of the time it is simpler to proceed with only one player during the early phase of development of your game, as it&#039;s easy and fast to start/stop games. If you choose to start with 2 players, you should see two names on the right: testdude0 and testdude1. To switch between them, press the red arrow button near their names; it will open another tab. This way you don&#039;t need to login and logout from multiple accounts.) &lt;br /&gt;
* Reminder: Always use the &amp;quot;Express Start&amp;quot; button to start the game.&lt;br /&gt;
&lt;br /&gt;
Thus, you can start a &amp;quot;Reversi&amp;quot; game, and arrive on a void, empty game. Yeah.&lt;br /&gt;
&lt;br /&gt;
End the game by clicking on the game options icon on the top right, and then on &amp;quot;Express Stop&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Editing the game information (Optional) ==&lt;br /&gt;
&lt;br /&gt;
This step is optional and will fix the warnings on the project page (missing BGG_ID and presentation).&lt;br /&gt;
&lt;br /&gt;
==== Edits to fix Errors ====&lt;br /&gt;
* Edit your local copy of the gameinfos.inc.php file:&lt;br /&gt;
** Change the &amp;lt;code&amp;gt;bgg_id&amp;lt;/code&amp;gt; value from &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;2389&amp;lt;/code&amp;gt; - that&#039;s around line 37.&lt;br /&gt;
** Add &amp;lt;code&amp;gt;1,&amp;lt;/code&amp;gt; to the players array - that&#039;s around line 41.&lt;br /&gt;
** Change the presentation array content - that&#039;s around line 134. Uncomment one line and change the text. Remove the final comma if you keep only one line!&lt;br /&gt;
* Upload the &amp;lt;code&amp;gt;gameinfos.inc.php&amp;lt;/code&amp;gt; file to the SFTP server (see [[First_steps_with_BGA_Studio#Connect_to_your_SFTP_folder|Connect to your SFTP folder]]).&lt;br /&gt;
&lt;br /&gt;
==== Test your Edits ====&lt;br /&gt;
* Go back to your project page, and in the &amp;quot;Game Information&amp;quot; section, click &amp;quot;Reload game informations&amp;quot;.&lt;br /&gt;
* Finally, refresh the project page in your browser (usually CTRL-F5).&lt;br /&gt;
&lt;br /&gt;
===== Not working? =====&lt;br /&gt;
Some changes will require bypassing the cache. It is often worth doing a hard refresh to make sure the&lt;br /&gt;
&lt;br /&gt;
Sometimes the cache will keep your changes from showing. Since this is a possibility, it will be useful to know how to bypass the cache. To do so you may manually clear cache or use a shortcut to refresh and ignore the cached version of the page. Here&#039;s how&lt;br /&gt;
&lt;br /&gt;
====== Windows ======&lt;br /&gt;
Chrome, Firefox, or Edge: Press &amp;lt;code&amp;gt;Ctrl+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Shift+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Ctrl+Shift+R&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Mac ======&lt;br /&gt;
Chrome or Firefox: Press &amp;lt;code&amp;gt;Shift+Command+R&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Safari for Mac: Press &amp;lt;code&amp;gt;Command+Option+E&amp;lt;/code&amp;gt; to empty the cache, then hold down Shift and click Reload in the toolbar&lt;br /&gt;
&lt;br /&gt;
== Make it look like Reversi ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start with the board. This will give you a good idea of how things will look and where tokens should go.&lt;br /&gt;
&lt;br /&gt;
Be careful designing the layout of your game: you must always keep in mind that players with a 1024px screen width must be able to play. Usually, it means that the width of the play area can be 750px (in the worst case).&lt;br /&gt;
&lt;br /&gt;
For Reversi, it&#039;s useless to have a 750x750px board - much too big, so we chose this one which fit perfectly (536x528):&lt;br /&gt;
&lt;br /&gt;
[[File:Board.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note that we are using a jpg file. Jpg filesare lighter than png, so they are faster to load. Later, we are going to use PNGs for tokens because they allow for transparency.&lt;br /&gt;
&lt;br /&gt;
==== Add the board ====&lt;br /&gt;
use lowercase file names&lt;br /&gt;
* upload &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;img/&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
* edit &amp;lt;code&amp;gt;reversi_reversi.tpl&amp;lt;/code&amp;gt; to add a &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; for your board.&lt;br /&gt;
&lt;br /&gt;
Note: If you are building this game by following the tutorial, you will have a different project name than &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; (i.e. &amp;lt;code&amp;gt;mygame_mygame.tpl&amp;lt;/code&amp;gt;). The file names in your project will be different than shown in this tutorial, replacing &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; with your project name. Be sure that any code (other than comments) that references &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; is changed to your actual project name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* edit your &amp;lt;code&amp;gt;reversi.css&amp;lt;/code&amp;gt; file to transform it into a visible board:&lt;br /&gt;
&lt;br /&gt;
 #board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: refresh your page.&#039;&#039;&#039; Here&#039;s your board:[[File:reversi1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If the board does not appear, refresh the page (always do this when you update the CSS file), and check the image filename. Remember file names are case sensitive!&lt;br /&gt;
&lt;br /&gt;
==== Code the Grid ====&lt;br /&gt;
Now, we need to create some invisible HTML elements where squares are. These elements will be used as position references for the white and black tokens. &lt;br /&gt;
&lt;br /&gt;
===== Make a Square Template =====&lt;br /&gt;
The board is 8 squares by 8 squares. This means we need 64 squares. To avoid writing 64 individual &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; elements on our template, we are going to use the &amp;quot;block&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s modify our template (the &amp;lt;code&amp;gt;.tpl&amp;lt;/code&amp;gt; file) like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- BEGIN square --&amp;gt;&lt;br /&gt;
        &amp;lt;div id=&amp;quot;square_{X}_{Y}&amp;quot; class=&amp;quot;square&amp;quot; style=&amp;quot;left: {LEFT}px; top: {TOP}px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we created a &amp;quot;square&amp;quot; block, with 4 variable elements: &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LEFT&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;TOP&amp;lt;/code&amp;gt;. We are going to use this block 64 times during page load.&lt;br /&gt;
&lt;br /&gt;
===== Use Square Template to Build Grid =====&lt;br /&gt;
Let&#039;s do it in our &amp;lt;code&amp;gt;reversi.view.php&amp;lt;/code&amp;gt; file, inside the &amp;lt;code&amp;gt;build_page&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
Note that &amp;quot;reversi_reversi&amp;quot; is the name of the game and if you named your differently you will have to change that when you copy and paste. Example &amp;quot;testreversi_testreversi&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $this-&amp;gt;page-&amp;gt;begin_block( &amp;quot;reversi_reversi&amp;quot;, &amp;quot;square&amp;quot; );&lt;br /&gt;
        &lt;br /&gt;
        $hor_scale = 64.8;&lt;br /&gt;
        $ver_scale = 64.4;&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $this-&amp;gt;page-&amp;gt;insert_block( &amp;quot;square&amp;quot;, array(&lt;br /&gt;
                    &#039;X&#039; =&amp;gt; $x,&lt;br /&gt;
                    &#039;Y&#039; =&amp;gt; $y,&lt;br /&gt;
                    &#039;LEFT&#039; =&amp;gt; round( ($x-1)*$hor_scale+10 ),&lt;br /&gt;
                    &#039;TOP&#039; =&amp;gt; round( ($y-1)*$ver_scale+7 )&lt;br /&gt;
                ) );&lt;br /&gt;
            }        &lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: as you can see, squares in our &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; files do not have an exact width/height in pixels, and that&#039;s the reason we are using floating point numbers here.&lt;br /&gt;
&lt;br /&gt;
===== Style Those Squares =====&lt;br /&gt;
Now, to finish our work and check if everything works fine, we are going to style our square a little bit in our CSS stylesheet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
    position: relative;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.square {&lt;br /&gt;
    width: 62px;&lt;br /&gt;
    height: 62px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-color: red;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explanations:&lt;br /&gt;
* With &amp;quot;position: relative&amp;quot; on board, we ensure square elements are positioned relatively to board.&lt;br /&gt;
* &amp;lt;code&amp;gt;background-color: red;&amp;lt;/code&amp;gt; is used for testing. This allows us to see the invisible elements. (You could instead do something like &amp;lt;code&amp;gt;border: 1px solid orange;&amp;lt;/code&amp;gt;. have fun and be creative)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s refresh and check our (beautiful) squares:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now that you know the squares are there, you can remove the test line &amp;lt;code&amp;gt;background-color: red;&amp;lt;/code&amp;gt;  from your &amp;lt;code&amp;gt;.square&amp;lt;/code&amp;gt; class in the CSS stylesheet.&lt;br /&gt;
&lt;br /&gt;
===== Not Working? =====&lt;br /&gt;
If the styled squares do not appear, inspect and check your css (Chrome DevTools: Application &amp;gt; Frames &amp;gt; top &amp;gt; Stylesheets &amp;gt; reversi.css). &lt;br /&gt;
&lt;br /&gt;
If your changes are not there try clearing your cache. Remember, you can bybass cache&lt;br /&gt;
&lt;br /&gt;
== The Tokens ==&lt;br /&gt;
&lt;br /&gt;
Now, our board is ready for some tokens!&lt;br /&gt;
&lt;br /&gt;
[Note: Throughout this tutorial, sometimes &amp;quot;tokens&amp;quot; is used, and sometimes &amp;quot;discs&amp;quot; is used. They are often swapped if you&#039;re looking at code in the reversi example project.]&lt;br /&gt;
&lt;br /&gt;
=== Build the Token ===&lt;br /&gt;
There are quite a few steps before the tokens will appear. You may be used to testing after every change, but that won&#039;t work well here. The token will &#039;&#039;&#039;not&#039;&#039;&#039; show until you have add a div to the tpl, styles to the css, js template to the tpl, utility method in the js,  adjusted the php file, and added the token to the board in the js file.&lt;br /&gt;
&lt;br /&gt;
==== HTML in the .tpl file ====&lt;br /&gt;
At first, we introduce a new &#039;div&#039; element as a child of &amp;quot;board&amp;quot; to host all these tokens (in our template):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;div id=&amp;quot;tokens&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt; is plural. This div will be used to hold the token divs. Shortly, we will use javascript to add individual tokens to the board.&lt;br /&gt;
&lt;br /&gt;
==== Add Token to img directory ====&lt;br /&gt;
Here&#039;s a new piece of art with the tokens. We need transparency here so we are using a png file:&lt;br /&gt;
&lt;br /&gt;
[[File:tokens.png]]&lt;br /&gt;
&lt;br /&gt;
Upload this image file &amp;lt;code&amp;gt;tokens.png&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;img/&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
Important Fun Fact: we are using ONE file for both tokens. It is really important to use a minimum number of graphic files for your game. This is called the &amp;quot;CSS sprite&amp;quot; technique, because it makes the game load faster and more reliable. [http://www.w3schools.com/css/css_image_sprites.asp Read more about CSS sprites].&lt;br /&gt;
&lt;br /&gt;
==== Style the Tokens in .css file ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.token {&lt;br /&gt;
    width: 56px;&lt;br /&gt;
    height: 56px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/tokens.png&#039;);&lt;br /&gt;
}&lt;br /&gt;
.tokencolor_ffffff { background-position: 0px 0px;   }&lt;br /&gt;
.tokencolor_000000 { background-position: -56px 0px;   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this CSS code, we could apply the classes &amp;quot;token&amp;quot; and &amp;quot;tokencolor_ffffff&amp;quot; to a div element and we&#039;d got a white token.&lt;br /&gt;
&lt;br /&gt;
Note the &amp;quot;position: absolute&amp;quot; which allows us to position tokens on the board and make them &amp;quot;slide&amp;quot; to their positions.&lt;br /&gt;
&lt;br /&gt;
==== Build Token JS Template in .tpl file ====&lt;br /&gt;
Now, let&#039;s make the first token appear on our board. Tokens are not visible at the beginning of the game: they appear dynamically during the game. For this reason, we are going to make them appear from our Javascript code, with a BGA Framework technique called &amp;quot;JS template&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In our template file (&amp;lt;code&amp;gt;reversi_reversi.tpl&amp;lt;/code&amp;gt;), let&#039;s create the piece of HTML needed to display our token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Templates&lt;br /&gt;
&lt;br /&gt;
var jstpl_token=&#039;&amp;lt;div class=&amp;quot;token tokencolor_${color}&amp;quot; id=&amp;quot;token_${x_y}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: we already created the &amp;quot;templates&amp;quot; section for you in the game skeleton.&lt;br /&gt;
&lt;br /&gt;
As you can see, we defined a JS template named &amp;lt;code&amp;gt;jstpl_token&amp;lt;/code&amp;gt; with a piece of HTML and two variables: the color of the token and its x/y coordinates. Note that the syntax of the argument is different for template block variables (braces &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;) and JS template variables (dollar and braces &amp;lt;code&amp;gt;${}&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Add Token Utility Method in .js file ====&lt;br /&gt;
Now, let&#039;s create a method in our Javascript code (in the &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt; file) that will make a token appear on the board, using this template. Add under the section //// Utility methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        addTokenOnBoard: function( x, y, player )&lt;br /&gt;
        {&lt;br /&gt;
            dojo.place( this.format_block( &#039;jstpl_token&#039;, {&lt;br /&gt;
                x_y: x+&#039;_&#039;+y,&lt;br /&gt;
                color: this.gamedatas.players[ player ].color&lt;br /&gt;
            } ) , &#039;tokens&#039; );&lt;br /&gt;
            &lt;br /&gt;
            this.placeOnObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;overall_player_board_&#039;+player );&lt;br /&gt;
            this.slideToObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;square_&#039;+x+&#039;_&#039;+y ).play();&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Utility Method Explanation =====&lt;br /&gt;
* with &amp;lt;code&amp;gt;dojo.place&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;this.format_block&amp;lt;/code&amp;gt; methods, we create a HTML piece of code and insert it as a new child of &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt; div element.&lt;br /&gt;
* with BGA &amp;lt;code&amp;gt;this.placeOnObject&amp;lt;/code&amp;gt; method, we place this element over the panel of some player. &lt;br /&gt;
* Immediately after, using BGA &amp;lt;code&amp;gt;this.slideToObject&amp;lt;/code&amp;gt; method, we make the token slide to the &amp;lt;code&amp;gt;square&amp;lt;/code&amp;gt; element, its final destination.&lt;br /&gt;
* &amp;lt;code&amp;gt;&#039;overall_player_board_&#039;+player&amp;lt;/code&amp;gt; refers to the div element that contains each player&#039;s information and avatar. By initially placing the token here, it gives the effect that the player&#039;s avatar is throwing the token onto the board.&lt;br /&gt;
&lt;br /&gt;
Note: don&#039;t forget to call the &amp;lt;code&amp;gt;play()&amp;lt;/code&amp;gt;, otherwise the token will remain at its original location.&lt;br /&gt;
&lt;br /&gt;
Note: during this process, the parent of the new token HTML element will stay &amp;lt;code&amp;gt;tokens&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;placeOnObject&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;slideToObject&amp;lt;/code&amp;gt; methods are &#039;&#039;only&#039;&#039; moving the position of elements on screen, and they are &#039;&#039;not&#039;&#039; modifying the HTML tree.&lt;br /&gt;
&lt;br /&gt;
==== Set Token Colors in setupNewGame in .game.php file ====&lt;br /&gt;
Before we can show a token, we need to set the player colors in the setupNewGame function in reversi.game.php:&lt;br /&gt;
&lt;br /&gt;
Replace &amp;lt;code&amp;gt;$default_colors = $gameinfos[&#039;player_colors&#039;];&amp;lt;/code&amp;gt; with the following line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $default_colors = array( &amp;quot;ffffff&amp;quot;, &amp;quot;000000&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: A few lines below, you may have to remove the line &amp;lt;code&amp;gt;self::reattributeColorsBasedOnPreferences( $players, $gameinfos[&#039;player_colors&#039;] );&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test the Token ===&lt;br /&gt;
Now, to test if everything works fine&lt;br /&gt;
&lt;br /&gt;
==== addTokenOnBoard() in .js file to Test ====&lt;br /&gt;
In &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt;, in &amp;lt;code&amp;gt;setup: function&amp;lt;/code&amp;gt;, under &amp;lt;code&amp;gt;// TODO: Set up your game interface here&amp;lt;/code&amp;gt; add &lt;br /&gt;
 this.addTokenOnBoard( 2, 2, this.player_id );&lt;br /&gt;
Now restart the game.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: if the page fails to load with a &amp;lt;code&amp;gt;Javascript error: n is null&amp;lt;/code&amp;gt; message, make sure you have added the &amp;quot;tokens&amp;quot; div in your template as instructed above.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A token should appear and slide immediately to its position, like this:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi3.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The database ==&lt;br /&gt;
&lt;br /&gt;
We did most of the client-side programming, so let&#039;s have a look on the other side now. To design the database model of our game, you will need to access the database. You won&#039;t need to do anything in database UI, yet.&lt;br /&gt;
&lt;br /&gt;
=== Accessing the Database ===&lt;br /&gt;
To access the database, start a game, then click &amp;quot;Go to game database&amp;quot; link at the bottom of our game, to access the database directly with a PhpMyAdmin instance.&lt;br /&gt;
&lt;br /&gt;
After the first time you&#039;ve acess the database, you could skip opening a game and instead, go to https://studio.boardgamearena.com/db/ . Your PhpMyAdmin username/password is in your welcome email.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: do not remove existing tables&lt;br /&gt;
&lt;br /&gt;
=== Create Table in .sql file ===&lt;br /&gt;
Now, you are able to create the table(s) you need for your game, and report every SQL command used in your &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
The database model of Reversi is short: just one table with the squares of the board. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `board` (&lt;br /&gt;
  `board_x` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_y` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_player` int(10) unsigned DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`board_x`,`board_y`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the above SQL to &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt;. Pay special attention to the backtick &amp;lt;code&amp;gt;`&amp;lt;/code&amp;gt; character vs. the single quote &amp;lt;code&amp;gt;&#039;&amp;lt;/code&amp;gt; when working with SQL. &lt;br /&gt;
&lt;br /&gt;
=== Test the Table ===&lt;br /&gt;
Now, a new database with a &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt; table will be created each time we start a Reversi game. This is why after modifying our &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; it&#039;s a good time to stop your current game &amp;amp; start a new game.&lt;br /&gt;
&lt;br /&gt;
Start a new game and verify a table is created.&lt;br /&gt;
&lt;br /&gt;
== Setup the initial game position ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: From now on, you must launch the game with &#039;&#039;&#039;two players&#039;&#039;&#039; to get two &amp;lt;code&amp;gt;player_id&amp;lt;/code&amp;gt;s within the database. Otherwise, the game will crash.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;setupNewGame&amp;lt;/code&amp;gt; method of our &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; is called during initial setup. This initializes our data and places the starting tokens on the board. At the beginning of the game, there should be 4 tokens on the board.&lt;br /&gt;
&lt;br /&gt;
=== Initialize the Board in .game.php file ===&lt;br /&gt;
Under &amp;lt;code&amp;gt;// TODO: setup the initial game situation here&amp;lt;/code&amp;gt;, initialize the board&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Init the board&lt;br /&gt;
        $sql = &amp;quot;INSERT INTO board (board_x,board_y,board_player) VALUES &amp;quot;;&lt;br /&gt;
        $sql_values = array();&lt;br /&gt;
        list( $blackplayer_id, $whiteplayer_id ) = array_keys( $players );&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $token_value = &amp;quot;NULL&amp;quot;;&lt;br /&gt;
                if( ($x==4 &amp;amp;&amp;amp; $y==4) || ($x==5 &amp;amp;&amp;amp; $y==5) )  // Initial positions of white player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$whiteplayer_id&#039;&amp;quot;;&lt;br /&gt;
                else if( ($x==4 &amp;amp;&amp;amp; $y==5) || ($x==5 &amp;amp;&amp;amp; $y==4) )  // Initial positions of black player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$blackplayer_id&#039;&amp;quot;;&lt;br /&gt;
                    &lt;br /&gt;
                $sql_values[] = &amp;quot;(&#039;$x&#039;,&#039;$y&#039;,$token_value)&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        $sql .= implode( &#039;,&#039;, $sql_values );&lt;br /&gt;
        self::DbQuery( $sql );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Board Initialization Explanation ====&lt;br /&gt;
&lt;br /&gt;
* We create one table entry for each square, with a &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; value which means &amp;quot;empty square&amp;quot;&lt;br /&gt;
* On 4 of the squares, we place an initial token.&lt;br /&gt;
&lt;br /&gt;
After this, we set &amp;lt;code&amp;gt;activeNextPlayer&amp;lt;/code&amp;gt; to make the first player active at the beginning of the game (this line is already present in the default code template).&lt;br /&gt;
&lt;br /&gt;
If you didn&#039;t do it earlier, you need to remove the call to &amp;lt;code&amp;gt;self::reattributeColorsBasedOnPreferences()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;SetupNewGame()&amp;lt;/code&amp;gt;. If you don&#039;t, player color preferences will try (and fail) to override the two colors supported here.&lt;br /&gt;
&lt;br /&gt;
=== Show the Initial Token Setup ===&lt;br /&gt;
Now, we need to make these tokens appear on the client side. The first step is to return the token positions with our &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; PHP method. &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; is called during each page reload.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; method, after &amp;lt;code&amp;gt;// TODO: Gather all information about current game situation (visible by player $current_player_id)&amp;lt;/code&amp;gt;, add the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Get reversi board token&lt;br /&gt;
        $result[&#039;board&#039;] = self::getObjectListFromDB( &amp;quot;SELECT board_x x, board_y y, board_player player&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       WHERE board_player IS NOT NULL&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you may need to modify the query that gets player information to also get the player&#039;s colors. This is in the variable &amp;lt;code&amp;gt;$sql&amp;lt;/code&amp;gt;, above the lines you just inserted in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt;. Below is what the line will look like. Notice how we&#039;ve added &amp;lt;code&amp;gt;player_color color&amp;lt;/code&amp;gt; to the sql query.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$sql = &amp;quot;SELECT player_id id, player_score score, player_color color FROM player &amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are using the BGA framework&#039;s &amp;lt;code&amp;gt;getObjectListFromDB()&amp;lt;/code&amp;gt; that formats the result of this SQL query in a PHP array with x, y and player attributes. We add it to the result associative array with the key &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Last, we process this array client side. Let&#039;s place a token on the board for each array item. We&#039;ll do this in our Javascript &amp;lt;code&amp;gt;setup&amp;lt;/code&amp;gt; method under &amp;lt;code&amp;gt;// TODO: Set up your game interface here, according to &amp;quot;gamedatas&amp;quot;&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This will result in a removal or edit of the previously added line &amp;lt;code&amp;gt;this.addTokenOnBoard(2, 2, this.player_id);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            for( var i in gamedatas.board )&lt;br /&gt;
            {&lt;br /&gt;
                var square = gamedatas.board[i];&lt;br /&gt;
                &lt;br /&gt;
                if( square.player !== null )&lt;br /&gt;
                {&lt;br /&gt;
                    this.addTokenOnBoard( square.x, square.y, square.player );&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;board&amp;lt;/code&amp;gt; entry created in &amp;lt;code&amp;gt;getAllDatas()&amp;lt;/code&amp;gt; is used here as &amp;lt;code&amp;gt;gamedatas.board&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test the Game Start ===&lt;br /&gt;
Reload... and here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi5.jpg]]&lt;br /&gt;
&lt;br /&gt;
It starts to feel like Reversi here...&lt;br /&gt;
&lt;br /&gt;
== The game state machine ==&lt;br /&gt;
&lt;br /&gt;
Stop your game, again. You&#039;re about to start the core game logic.&lt;br /&gt;
&lt;br /&gt;
You already read [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine], so you know that this is the heart of your game logic. For reversi, it&#039;s relatively simple. Here&#039;s a diagram of our game state machine:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi6.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Build your States ===&lt;br /&gt;
And here&#039;s our &amp;lt;code&amp;gt;states.inc.php&amp;lt;/code&amp;gt;, according to this diagram:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$machinestates = array(&lt;br /&gt;
&lt;br /&gt;
    1 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;Game setup&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;&amp;quot; =&amp;gt; 10 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    10 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;playerTurn&amp;quot;,&lt;br /&gt;
		&amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&#039;${actplayer} must play a disc&#039;),&lt;br /&gt;
		&amp;quot;descriptionmyturn&amp;quot; =&amp;gt; clienttranslate(&#039;${you} must play a disc&#039;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;activeplayer&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argPlayerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;possibleactions&amp;quot; =&amp;gt; array( &#039;playDisc&#039; ),&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;playDisc&amp;quot; =&amp;gt; 11, &amp;quot;zombiePass&amp;quot; =&amp;gt; 11 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    11 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;nextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;game&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stNextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;updateGameProgression&amp;quot; =&amp;gt; true,        &lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;nextTurn&amp;quot; =&amp;gt; 10, &amp;quot;cantPlay&amp;quot; =&amp;gt; 11, &amp;quot;endGame&amp;quot; =&amp;gt; 99 )&lt;br /&gt;
    ),&lt;br /&gt;
   &lt;br /&gt;
    99 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;End of game&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argGameEnd&amp;quot;&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; let&#039;s create the methods that are declared in this game states description file:&lt;br /&gt;
* &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt;: referenced in the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; property of the &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; state; this is the name of the method to call to retrieve arguments for this gamestate. Arguments are sent to the client side to be used on &amp;lt;code&amp;gt;onEnteringState&amp;lt;/code&amp;gt; or to set arguments in the gamestate description.&lt;br /&gt;
* &amp;lt;code&amp;gt;stNextPlayer&amp;lt;/code&amp;gt;: referenced in the &amp;lt;code&amp;gt;action&amp;lt;/code&amp;gt; property of the &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt; state; this is the name of the method to call when this game state become the current game state. &lt;br /&gt;
&lt;br /&gt;
=== Test Your States ===&lt;br /&gt;
... and start a new Reversi game.&lt;br /&gt;
&lt;br /&gt;
As you can see on the screen capture below, the BGA framework makes the game jump to our first game state &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; right after the initial setup. That&#039;s why the status bar contains the description of &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; state (&amp;quot;XXXX must play a disc&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
[[File:reversi7.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The rules ==&lt;br /&gt;
&lt;br /&gt;
We will use the &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt; PHP method to:&lt;br /&gt;
* Indicate to the current player where she is allowed to play by returning a list of coordinates&lt;br /&gt;
* Check if the player has the right to play in the spot they choose&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Example of getPossibleMoves here https://gist.github.com/leocaseiro/a8bc2851bd0caddd06685b5035937d15&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is pure PHP programming here, and there are no special things from the BGA framework that can be used. This is why we won&#039;t go into details here. The overall idea is:&lt;br /&gt;
* Create a &amp;lt;code&amp;gt;getTurnedOverDiscs(x,y)&amp;lt;/code&amp;gt; method that returns coordinates of discs that would be turned over if a token would be played at &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;,&amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Loop through all free squares of the board and call the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; method on each of them. If at least 1 token is turned over, this is a valid move.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: Making a database query is slow! Please don&#039;t load the entire game board with a SQL query multiple times. In our implementation, we load the entire board once at the beginning of &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt;, and then pass the board as an argument to all methods.&lt;br /&gt;
&lt;br /&gt;
If you want to look into details, please look at the &amp;quot;utility method&amp;quot; sections of &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;. If building the tutorial yourself, copy the functions under &amp;quot;Utility functions&amp;quot; comment from the Reversi tutorial.&lt;br /&gt;
&lt;br /&gt;
== Display allowed moves ==&lt;br /&gt;
&lt;br /&gt;
Now we want to highlight the squares where the player can place a disc.&lt;br /&gt;
&lt;br /&gt;
To do this, we add a &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;. This method is called on the server each time we enter into &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state, and its result is transferred automatically to the client-side:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function argPlayerTurn()&lt;br /&gt;
    {&lt;br /&gt;
        return array(&lt;br /&gt;
            &#039;possibleMoves&#039; =&amp;gt; self::getPossibleMoves( self::getActivePlayerId() )&lt;br /&gt;
        );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;getPossibleMoves&amp;lt;/code&amp;gt; method we just developed.&lt;br /&gt;
&lt;br /&gt;
Each time we enter into a new game state, we use the &amp;lt;code&amp;gt;onEnteringState&amp;lt;/code&amp;gt; Javascript method (in the &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt; file, under &amp;quot;Game &amp;amp; client states&amp;quot;). This lets us use the data returned by the method above on the client side.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onEnteringState: function( stateName, args )&lt;br /&gt;
        {&lt;br /&gt;
           console.log( &#039;Entering state: &#039;+stateName );&lt;br /&gt;
            &lt;br /&gt;
            switch( stateName )&lt;br /&gt;
            {&lt;br /&gt;
            case &#039;playerTurn&#039;:&lt;br /&gt;
                this.updatePossibleMoves( args.args.possibleMoves );&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, when we enter into &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state, we call our &amp;lt;code&amp;gt;updatePossibleMoves&amp;lt;/code&amp;gt; method (under the &amp;quot;Utility methods&amp;quot; section). This method looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        updatePossibleMoves: function( possibleMoves )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );&lt;br /&gt;
&lt;br /&gt;
            for( var x in possibleMoves )&lt;br /&gt;
            {&lt;br /&gt;
                for( var y in possibleMoves[ x ] )&lt;br /&gt;
                {&lt;br /&gt;
                    // x,y is a possible move&lt;br /&gt;
                    dojo.addClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; );&lt;br /&gt;
                }            &lt;br /&gt;
            }&lt;br /&gt;
                        &lt;br /&gt;
            this.addTooltipToClass( &#039;possibleMove&#039;, &#039;&#039;, _(&#039;Place a disc here&#039;) );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here&#039;s what this does. At first, it removes all &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; classes currently applied with the very useful combination of &amp;lt;code&amp;gt;dojo.query&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;removeClass&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
Then it loops through all possible moves our PHP &amp;lt;code&amp;gt;updatePossibleMoves&amp;lt;/code&amp;gt; function created for us, and adds the &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; class to each corresponding square.&lt;br /&gt;
&lt;br /&gt;
Finally, it uses the BGA framework &amp;lt;code&amp;gt;addTooltipToClass&amp;lt;/code&amp;gt; method to associate a tooltip to all those highlighted squares so that players can understand their meaning.&lt;br /&gt;
&lt;br /&gt;
To see the possible moves we need to create a CSS class (&amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt;) that can be applied to a &amp;lt;code&amp;gt;square&amp;lt;/code&amp;gt; element to highlight it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.possibleMove {&lt;br /&gt;
    background-color: white;&lt;br /&gt;
    opacity: 0.2;&lt;br /&gt;
    filter:alpha(opacity=20); /* For IE8 and earlier */  &lt;br /&gt;
    cursor: pointer;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi8.jpg.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s play ==&lt;br /&gt;
&lt;br /&gt;
From now, it&#039;s better to restart a game with 2 players, because we are going to implement a complete Reversi turn. The summary of what we are going to do is:&lt;br /&gt;
* When we click on a &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; square, send the move to the server.&lt;br /&gt;
* Server side, check the move is correct, apply Reversi rules and jump to next player.&lt;br /&gt;
* Client side, change the token position to reflect the move.&lt;br /&gt;
&lt;br /&gt;
First we associate each click on a square to one of our methods using our Javascript &amp;lt;code&amp;gt;setup&amp;lt;/code&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.query( &#039;.square&#039; ).connect( &#039;onclick&#039;, this, &#039;onPlayDisc&#039; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the &amp;quot;dojo.query&amp;quot; method to get all HTML elements with &amp;quot;square&amp;quot; class in just one function call. Now, our &amp;quot;onPlayDisc&amp;quot; method is called each time someone clicks on a square.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s our &amp;quot;onPlayDisc&amp;quot; method below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onPlayDisc: function( evt )&lt;br /&gt;
        {&lt;br /&gt;
            // Stop this event propagation&lt;br /&gt;
            dojo.stopEvent( evt );&lt;br /&gt;
&lt;br /&gt;
            // Get the clicked square x and y&lt;br /&gt;
            // Note: square id format is &amp;quot;square_X_Y&amp;quot;&lt;br /&gt;
            var coords = evt.currentTarget.id.split(&#039;_&#039;);&lt;br /&gt;
            var x = coords[1];&lt;br /&gt;
            var y = coords[2];&lt;br /&gt;
&lt;br /&gt;
            if( ! dojo.hasClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; ) )&lt;br /&gt;
            {&lt;br /&gt;
                // This is not a possible move =&amp;gt; the click does nothing&lt;br /&gt;
                return ;&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            if( this.checkAction( &#039;playDisc&#039; ) )    // Check that this action is possible at this moment&lt;br /&gt;
            {            &lt;br /&gt;
                this.ajaxcall( &amp;quot;/reversi/reversi/playDisc.html&amp;quot;, {&lt;br /&gt;
                    x:x,&lt;br /&gt;
                    y:y&lt;br /&gt;
                }, this, function( result ) {} );&lt;br /&gt;
            }            &lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Warning: Make sure to replace &amp;lt;code&amp;gt;reversi&amp;lt;/code&amp;gt; in line &amp;lt;code&amp;gt;this.ajaxcall( &amp;quot;/reversi/reversi/playDisc.html&amp;quot;, {&amp;lt;/code&amp;gt; with the name of your project. E.g. &amp;lt;code&amp;gt;&amp;quot;/yourgamename/yourgamename/playDisc.html&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What we do here is:&lt;br /&gt;
* We stop the propagation of the Javascript &amp;lt;code&amp;gt;onclick&amp;lt;/code&amp;gt; event. Otherwise, it can lead to random behavior so it&#039;s always a good idea.&lt;br /&gt;
* We get the x/y coordinates of the square by using &amp;lt;code&amp;gt;evt.currentTarget.id&amp;lt;/code&amp;gt;&lt;br /&gt;
* We check that clicked square has the &amp;lt;code&amp;gt;possibleMove&amp;lt;/code&amp;gt; class, otherwise we know for sure that we can&#039;t play there.&lt;br /&gt;
* We check that &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; action is possible, according to current game state (see &amp;lt;code&amp;gt;possibleactions&amp;lt;/code&amp;gt; entry in our &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state defined above). This check is important to avoid issues if a player double clicks on a square.&lt;br /&gt;
* Finally, we make a call to the server using BGA &amp;lt;code&amp;gt;ajaxcall&amp;lt;/code&amp;gt; method with argument x and y.&lt;br /&gt;
&lt;br /&gt;
Now, we have to manage this &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; action on the server side. At first, we introduce a &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; entry point in our &amp;lt;code&amp;gt;reversi.action.php&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    public function playDisc()&lt;br /&gt;
    {&lt;br /&gt;
        self::setAjaxMode();     &lt;br /&gt;
        $x = self::getArg( &amp;quot;x&amp;quot;, AT_posint, true );&lt;br /&gt;
        $y = self::getArg( &amp;quot;y&amp;quot;, AT_posint, true );&lt;br /&gt;
        $result = $this-&amp;gt;game-&amp;gt;playDisc( $x, $y );&lt;br /&gt;
        self::ajaxResponse( );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we get the 2 arguments x and y from the javascript call, and call a corresponding &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; method in our game logic (&amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s have a look of this &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function playDisc( $x, $y )&lt;br /&gt;
    {&lt;br /&gt;
        // Check that this player is active and that this action is possible at this moment&lt;br /&gt;
        self::checkAction( &#039;playDisc&#039; );  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... at first, we check that this action is possible according to current game state (see &amp;quot;possible action&amp;quot;). We already did it on client side, but it&#039;s important to do it on server side too (otherwise it would be possible to cheat).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Now, check if this is a possible move&lt;br /&gt;
        $board = self::getBoard();&lt;br /&gt;
        $player_id = self::getActivePlayerId();&lt;br /&gt;
        $turnedOverDiscs = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
        &lt;br /&gt;
        if( count( $turnedOverDiscs ) &amp;gt; 0 )&lt;br /&gt;
        {&lt;br /&gt;
            // This move is possible!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...now, we are using the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; method again to check that this move is possible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
            &lt;br /&gt;
            $sql = &amp;quot;UPDATE board SET board_player=&#039;$player_id&#039;&lt;br /&gt;
                    WHERE ( board_x, board_y) IN ( &amp;quot;;&lt;br /&gt;
            &lt;br /&gt;
            foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                $sql .= &amp;quot;(&#039;&amp;quot;.$turnedOver[&#039;x&#039;].&amp;quot;&#039;,&#039;&amp;quot;.$turnedOver[&#039;y&#039;].&amp;quot;&#039;),&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            $sql .= &amp;quot;(&#039;$x&#039;,&#039;$y&#039;) ) &amp;quot;;&lt;br /&gt;
                       &lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... we update the database to change the color of all turned over disc + the disc we just placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Update scores according to the number of disc on board&lt;br /&gt;
            $sql = &amp;quot;UPDATE player&lt;br /&gt;
                    SET player_score = (&lt;br /&gt;
                    SELECT COUNT( board_x ) FROM board WHERE board_player=player_id&lt;br /&gt;
                    )&amp;quot;;&lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
            &lt;br /&gt;
            // Statistics&lt;br /&gt;
            self::incStat( count( $turnedOverDiscs ), &amp;quot;turnedOver&amp;quot;, $player_id );&lt;br /&gt;
            if( ($x==1 &amp;amp;&amp;amp; $y==1) || ($x==8 &amp;amp;&amp;amp; $y==1) || ($x==1 &amp;amp;&amp;amp; $y==8) || ($x==8 &amp;amp;&amp;amp; $y==8) )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCorner&#039;, $player_id );&lt;br /&gt;
            else if( $x==1 || $x==8 || $y==1 || $y==8 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnBorder&#039;, $player_id );&lt;br /&gt;
            else if( $x&amp;gt;=3 &amp;amp;&amp;amp; $x&amp;lt;=6 &amp;amp;&amp;amp; $y&amp;gt;=3 &amp;amp;&amp;amp; $y&amp;lt;=6 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCenter&#039;, $player_id );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... now, we update both player score by counting all disc, and we manage game statistics.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Notify&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;playDisc&amp;quot;, clienttranslate( &#039;${player_name} plays a disc and turns over ${returned_nbr} disc(s)&#039; ), array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;player_name&#039; =&amp;gt; self::getActivePlayerName(),&lt;br /&gt;
                &#039;returned_nbr&#039; =&amp;gt; count( $turnedOverDiscs ),&lt;br /&gt;
                &#039;x&#039; =&amp;gt; $x,&lt;br /&gt;
                &#039;y&#039; =&amp;gt; $y&lt;br /&gt;
            ) );&lt;br /&gt;
&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;turnOverDiscs&amp;quot;, &#039;&#039;, array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;turnedOver&#039; =&amp;gt; $turnedOverDiscs&lt;br /&gt;
            ) );&lt;br /&gt;
            &lt;br /&gt;
            $newScores = self::getCollectionFromDb( &amp;quot;SELECT player_id, player_score FROM player&amp;quot;, true );&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;newScores&amp;quot;, &amp;quot;&amp;quot;, array(&lt;br /&gt;
                &amp;quot;scores&amp;quot; =&amp;gt; $newScores&lt;br /&gt;
            ) );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... then we notify about all these changes. We are using for that 3 notifications (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;newScores&amp;lt;/code&amp;gt; that we are going to implement on client side later). Note that the description of the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; notification will be logged in the game log.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Then, go to the next state&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
            throw new BgaSystemException( &amp;quot;Impossible move&amp;quot; );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... finally, we jump to the next game state if everything goes fine (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; is the name of a transition in the &amp;lt;code&amp;gt;playerTurn&amp;lt;/code&amp;gt; game state description above which leads to state 11 which is &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
To make the statistics work, we have to initialize them in &amp;lt;code&amp;gt;stats.json&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;player&amp;quot;: {&lt;br /&gt;
    &amp;quot;discPlayedOnCorner&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 10,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on a corner&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;discPlayedOnBorder&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 11,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on a border&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;discPlayedOnCenter&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 12,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Discs played on board center part&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;turnedOver&amp;quot;: {&lt;br /&gt;
      &amp;quot;id&amp;quot;: 13,&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;Number of discs turned over&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A last thing to do on the server side is to activate the next player when we enter the &amp;lt;code&amp;gt;nextPlayer&amp;lt;/code&amp;gt; game state (in the &amp;lt;code&amp;gt;reversi.game.php&amp;lt;/code&amp;gt; file, under &amp;quot;Game state reactions&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function stNextPlayer()&lt;br /&gt;
    {&lt;br /&gt;
        // Active next player&lt;br /&gt;
        $player_id = self::activeNextPlayer();&lt;br /&gt;
&lt;br /&gt;
        // Check if both player has at least 1 discs, and if there are free squares to play&lt;br /&gt;
        $player_to_discs = self::getCollectionFromDb( &amp;quot;SELECT board_player, COUNT( board_x )&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       GROUP BY board_player&amp;quot;, true );&lt;br /&gt;
&lt;br /&gt;
        if( ! isset( $player_to_discs[ null ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Index 0 has not been set =&amp;gt; there&#039;s no more free place on the board !&lt;br /&gt;
            // =&amp;gt; end of the game&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        else if( ! isset( $player_to_discs[ $player_id ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Active player has no more disc on the board =&amp;gt; he looses immediately&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Can this player play?&lt;br /&gt;
&lt;br /&gt;
        $possibleMoves = self::getPossibleMoves( $player_id );&lt;br /&gt;
        if( count( $possibleMoves ) == 0 )&lt;br /&gt;
        {&lt;br /&gt;
&lt;br /&gt;
            // This player can&#039;t play&lt;br /&gt;
            // Can his opponent play ?&lt;br /&gt;
            $opponent_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039; &amp;quot; );&lt;br /&gt;
            if( count( self::getPossibleMoves( $opponent_id ) ) == 0 )&lt;br /&gt;
            {&lt;br /&gt;
                // Nobody can move =&amp;gt; end of the game&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {            &lt;br /&gt;
                // =&amp;gt; pass his turn&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;cantPlay&#039; );&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            // This player can play. Give him some extra time&lt;br /&gt;
            self::giveExtraTime( $player_id );&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;nextTurn&#039; );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, when we play a token, the rules are checked and the token appears in the database.&lt;br /&gt;
&lt;br /&gt;
[[File:reversi9.jpg]]&lt;br /&gt;
&lt;br /&gt;
Of course, as we don&#039;t manage notifications on client side, we need to press F5 after each move to see the changes on the board.&lt;br /&gt;
&lt;br /&gt;
== Make the move appear automatically ==&lt;br /&gt;
&lt;br /&gt;
Now, what we have to do is process the notifications sent by the server and make the move appear on the interface.&lt;br /&gt;
&lt;br /&gt;
In our &amp;lt;code&amp;gt;setupNotifications&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;reversi.js&amp;lt;/code&amp;gt;, we register 2 methods for the 2 notifications we created at the previous step (&amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.subscribe( &#039;playDisc&#039;, this, &amp;quot;notif_playDisc&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;playDisc&#039;, 500 );&lt;br /&gt;
            dojo.subscribe( &#039;turnOverDiscs&#039;, this, &amp;quot;notif_turnOverDiscs&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;turnOverDiscs&#039;, 1500 );&lt;br /&gt;
            dojo.subscribe( &#039;newScores&#039;, this, &amp;quot;notif_newScores&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;newScores&#039;, 500 );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we associate each of our 3 notifications with a method prefixed with &amp;lt;code&amp;gt;notif_&amp;lt;/code&amp;gt;. We also define these notifications as &amp;quot;synchronous&amp;quot;, with a duration in millisecond. It tells the user interface to wait some time after executing the notification, to let the animation end before starting the next notification. In our specific case, the animation will be the following:&lt;br /&gt;
* Make a disc slide from the player panel to its place on the board&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
* Make all turned over discs blink (and of course turned them over)&lt;br /&gt;
* (wait 1500ms)&lt;br /&gt;
* Update the player scores&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
&lt;br /&gt;
The 2nd parameter in &amp;lt;code&amp;gt;dojo.subscribe&amp;lt;/code&amp;gt; call (this) is the &amp;lt;code&amp;gt;context&amp;lt;/code&amp;gt;, and will be passed in as a parameter to the specified method.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s have a look now on the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; notification handler method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_playDisc: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves (makes the board more clear)&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );        &lt;br /&gt;
        &lt;br /&gt;
            this.addTokenOnBoard( notif.args.x, notif.args.y, notif.args.player_id );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No surprise here, we re-used some existing stuff to:&lt;br /&gt;
* Remove the highlighted squares.&lt;br /&gt;
* Add a new disc on board, coming from player panel.&lt;br /&gt;
&lt;br /&gt;
Now, here&#039;s the method that handles the &amp;lt;code&amp;gt;turnOverDiscs&amp;lt;/code&amp;gt; notification:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_turnOverDiscs: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Get the color of the player who is returning the discs&lt;br /&gt;
            var targetColor = this.gamedatas.players[ notif.args.player_id ].color;&lt;br /&gt;
&lt;br /&gt;
            // Make these discs blink and set them to the specified color&lt;br /&gt;
            for( var i in notif.args.turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                var token = notif.args.turnedOver[ i ];&lt;br /&gt;
                &lt;br /&gt;
                // Make the token blink 2 times&lt;br /&gt;
                var anim = dojo.fx.chain( [&lt;br /&gt;
                    dojo.fadeOut( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeOut( { &lt;br /&gt;
                                    node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y,&lt;br /&gt;
                                    onEnd: function( node ) {&lt;br /&gt;
&lt;br /&gt;
                                        // Remove any color class&lt;br /&gt;
                                        dojo.removeClass( node, [ &#039;tokencolor_000000&#039;, &#039;tokencolor_ffffff&#039; ] );&lt;br /&gt;
                                        // ... and add the good one&lt;br /&gt;
                                        dojo.addClass( node, &#039;tokencolor_&#039;+targetColor );&lt;br /&gt;
                                                             &lt;br /&gt;
                                    } &lt;br /&gt;
                                  } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y  } )&lt;br /&gt;
                                 &lt;br /&gt;
                ] ); // end of dojo.fx.chain&lt;br /&gt;
&lt;br /&gt;
                // ... and launch the animation&lt;br /&gt;
                anim.play();                &lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The list of the discs to be turned over has been made available by our server side code in &amp;lt;code&amp;gt;notif.args.turnedOver&amp;lt;/code&amp;gt; (see previous paragraph). We loop through all these discs, and create a complex animation using &amp;lt;code&amp;gt;dojo.Animation&amp;lt;/code&amp;gt; for each of them. The complete documentation on dojo animations [http://dojotoolkit.org/documentation/tutorials/1.6/animation/ can be found here].&lt;br /&gt;
&lt;br /&gt;
In few words: we create a chain of 4 animations to make the disc fade out, fade in, fade out again, and fade in again. At the end of the second fade out, we change the color of the disc. Finally, we launch the animation with &amp;lt;code&amp;gt;play()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And Also the notification to update the scores:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
notif_newScores: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            for( var player_id in notif.args.scores )&lt;br /&gt;
            {&lt;br /&gt;
                var newScore = notif.args.scores[ player_id ];&lt;br /&gt;
                this.scoreCtrl[ player_id ].toValue( newScore );&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20750</id>
		<title>Setting up BGA Development environment using VSCode</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20750"/>
		<updated>2024-04-11T20:38:22Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added the BGA-ts-template to the JS Intellisense section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Microsoft Visual Studio Code is light weight IDE/Editor. All desktops.&lt;br /&gt;
&lt;br /&gt;
== Downloads ==&lt;br /&gt;
&lt;br /&gt;
* Download and install vscode from https://code.visualstudio.com&lt;br /&gt;
* Download and install php (7.4) command line interface (for local tests and debugging)&lt;br /&gt;
&lt;br /&gt;
== Extensions ==&lt;br /&gt;
Use [https://marketplace.visualstudio.com/items?itemName=NevinFoster.bga-extension-pack&amp;amp;ssr=false#overview BGA Extension Pack] to download all of the recommended extensions with one click.&lt;br /&gt;
* PHP Intelephense - https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client&lt;br /&gt;
* Or PHP IntelliSense - https://marketplace.visualstudio.com/items?itemName=zobo.php-intellisense&lt;br /&gt;
* PHP Debug - https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug&lt;br /&gt;
* SQLTools - https://marketplace.visualstudio.com/items?itemName=mtxr.sqltools&lt;br /&gt;
* Prettier - code formatter - https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&lt;br /&gt;
* SFTP (by Natizyskunk) -  https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp&lt;br /&gt;
&lt;br /&gt;
== Intellisense - Navigation/Auto-complete ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Intellisense ===&lt;br /&gt;
The intellisense for JavaScript code is to &#039;&#039;&#039;use the [[BGA-ts-template]]&#039;&#039;&#039;. It offers a much cleaner initial file, clearer workflow, and nearly complete type and autofill support for whatever you may need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:Stripped base Typescript file.png|alt=Starting TS file with comments/template code removed|thumb|696x696px|Starting TS file with comments/template code removed]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:Typescript autofill.gif|alt=Typescript Autocomplete using BGA Type Safe Template|thumb|542x542px|Typescript Autocomplete using BGA Type Safe Template]] &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this does not interest you, you can also revert to the old ways of getting better intellisense:&lt;br /&gt;
&lt;br /&gt;
- Because of dojo style class/method declarations most IDE won&#039;t be able to index main JavaScript file properly (i.e. go to definition of function and such).&lt;br /&gt;
If you manage to get it working in VS code, let us know how.&lt;br /&gt;
&lt;br /&gt;
- There is a way to re-structure code to avoid using this style, but this is not for beginners. Do not use this on your first game!&lt;br /&gt;
https://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Avoiding_code_in_dojo_declare_style&lt;br /&gt;
&lt;br /&gt;
- There is also a complete example of a &amp;quot;dojo-less&amp;quot; project, it also includes a (incomplete) typescript definition file (.d.ts) for auto-completion of js BGA interfaces&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===PHP Intellisense===&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t do anything PHP will complain about undefined symbols from BGA framework (as well as from the material file).&lt;br /&gt;
To solve the warning about framework issues, you need a stubs for the BGA APIs:&lt;br /&gt;
&lt;br /&gt;
*git clone git@github.com:elaskavaia/bga-sharedcode.git (you can also get and unzip it from the GitHub page) &lt;br /&gt;
** if that doesn&#039;t work, try git clone &amp;lt;nowiki&amp;gt;https://github.com/elaskavaia/bga-sharedcode.git&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
**you can do this in a terminal from VS Code - Terminal menu -&amp;gt; New Terminal&lt;br /&gt;
*add reference (include path) to bga-sharedcode/misc using settings of PHP extension, see example below&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using the Intelephense plugin, add this to global user settings (modify the path obviously)&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;intelephense.environment.includePaths&amp;quot;: [&lt;br /&gt;
        &amp;quot;/home/victoria/git/bga-sharedcode/misc/&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To solve the warning about the material file class members&lt;br /&gt;
&lt;br /&gt;
Option 1)&lt;br /&gt;
If you don&#039;t have too many class members you can define them, for example if I have $this-&amp;gt;token_types = [...] in the material file I can define them in in the class of game.php&lt;br /&gt;
&lt;br /&gt;
    private $token_types;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Option 2) &lt;br /&gt;
&lt;br /&gt;
Put this line in the settings.json if you using Intelliphense extension to ignore them:&lt;br /&gt;
&lt;br /&gt;
   &amp;quot;intelephense.diagnostics.undefinedProperties&amp;quot;: false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
If using phpunit, install it via composer somewhere in home directory, i.e.&lt;br /&gt;
   cd /home/victoria/php-composer&lt;br /&gt;
   composer require --dev phpunit/phpunit ^9&lt;br /&gt;
&lt;br /&gt;
Then add this path (e.x.  /home/victoria/php-composer) to include paths as above&lt;br /&gt;
&lt;br /&gt;
See more about unit testing in [[Testing by developer]]&lt;br /&gt;
&lt;br /&gt;
== File Sync==&lt;br /&gt;
You can set up your sync using other methods, not related to vscode (such as rsync), if you want to do that see [[Tools_and_tips_of_BGA_Studio#File_Sync]] otherwise see below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You might rely on your IDE to sync the files with the SFTP server. Each time you &amp;quot;save&amp;quot; a file with your modifications, the IDE will also submit it to the sFTP server. These are instructions for VS Code&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Install this extension&#039;&#039;&#039; https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp (File-&amp;gt;Preferences-&amp;gt;Extensions ... type SFTP and make sure its by Natizyskunk)&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Open VSCode on an empty folder&#039;&#039;&#039; that will be the local root of your project.&lt;br /&gt;
&lt;br /&gt;
*Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: config&amp;quot;&#039;&#039;&#039; - the edit will open with json config &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Update the json&#039;&#039;&#039; as below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;your SFTP username&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;password&amp;quot;: &amp;quot;&amp;lt;your SFTP password&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;your project name&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.vscode&amp;quot;,&lt;br /&gt;
        &amp;quot;.git&amp;quot;,&lt;br /&gt;
        &amp;quot;.DS_Store&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, # syncs new files&lt;br /&gt;
        &amp;quot;delete&amp;quot;: true # syncs deleted files&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===One time only - first sync ===&lt;br /&gt;
&lt;br /&gt;
- Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: Download Project&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This will download all the files locally. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Daily use===&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to do anything else! Each time you modify/save a file in VSCode, it will upload it to the SFTP Server.&lt;br /&gt;
&lt;br /&gt;
To force upload to a server, execute Ctrl+Shift+P -&amp;gt; &#039;&#039;&#039;&amp;quot;SFTP: Sync Local -&amp;gt; Remote&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note: the SFTP sync may fail with a permissions error when create or delete nested folders. To fix this, execute `chmod -R 755 &amp;lt;your directory name&amp;gt;` in your terminal, then force sync to remote.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Split settings for version control===&lt;br /&gt;
If you want to commit this file to version control, use private key (upload ssh key https://studio.boardgamearena.com/controlpanel) instead and move user/password settings into vscode user settings&lt;br /&gt;
&lt;br /&gt;
I.e. in user setting add this (have to edit settings.js manually, google for location its os specific)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;quot;remotefs.remote&amp;quot;: {&lt;br /&gt;
        &amp;quot;bgadev&amp;quot;: {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
            &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
            &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
            &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
            &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;yourdevusername&amp;gt;&amp;quot;,&lt;br /&gt;
            &amp;quot;privateKeyPath&amp;quot;: &amp;quot;~/.ssh/id_rsa&amp;quot;,&lt;br /&gt;
        },&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in project folder sftp.json (replace &amp;lt;yourproject&amp;gt; with project name)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;remote&amp;quot;: &amp;quot;bgadev&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;yourproject&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.git&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, &lt;br /&gt;
        &amp;quot;delete&amp;quot;: true &lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;watcher&amp;quot;: {&lt;br /&gt;
        &amp;quot;files&amp;quot;: &amp;quot;**/*.{js,css}&amp;quot;,&lt;br /&gt;
        &amp;quot;autoUpload&amp;quot;: true,&lt;br /&gt;
        &amp;quot;autoDelete&amp;quot;: true&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: you don&#039;t need watcher section if you don&#039;t use code generators, but its needed if you use typescript, scss or similar code generator tools.&lt;br /&gt;
&lt;br /&gt;
==Code Formatter==&lt;br /&gt;
I think Prettier has better format, you can install Prettier plugin to do the formatting, for PHP add the following in package.json&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
    &amp;quot;@prettier/plugin-php&amp;quot;: &amp;quot;^0.19.1&amp;quot;,&lt;br /&gt;
    &amp;quot;prettier&amp;quot;: &amp;quot;^2.7.1&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;prettier&amp;quot;: {&lt;br /&gt;
    &amp;quot;braceStyle&amp;quot;: &amp;quot;1tbs&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== Code generators==&lt;br /&gt;
If you want to run code generators for example for typescript or scss you can install this extension:&lt;br /&gt;
*https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave&lt;br /&gt;
&lt;br /&gt;
In settings.json add these (example only):&lt;br /&gt;
    &amp;quot;emeraldwalk.runonsave&amp;quot;: {&lt;br /&gt;
        &amp;quot;commands&amp;quot;: [&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.ts$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:ts&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.scss$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:scss&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        ]&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
In this example &amp;lt;code&amp;gt;build:ts&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;build:scss&amp;lt;/code&amp;gt; are scripts configured via package.json&lt;br /&gt;
&lt;br /&gt;
Another example - you can run php script that will generate material.inc.php from misc/xxx_material.csv&lt;br /&gt;
      {&lt;br /&gt;
        &amp;quot;match&amp;quot;: &amp;quot;misc/.*material\\.csv$&amp;quot;,&lt;br /&gt;
        &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
        &amp;quot;cmd&amp;quot;: &amp;quot;php7.4 ${env.HOME}/git/bga-sharedcode/misc/genmat.php ${file}&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
== User templates==&lt;br /&gt;
&lt;br /&gt;
You can define user template to avoid writing boilerplate code, here is example of php template for states&lt;br /&gt;
(it is placed in global location php.json - you can open it from the gui File-&amp;gt;Preferences-&amp;gt;Configure User Snippets and type php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Single player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;state&amp;quot;, &amp;quot;playerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT playerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;\\${actplayer} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;activeplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;st_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_PLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create single player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Multiple player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;mstate&amp;quot;, &amp;quot;multiplayerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT mplayerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;Other players must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;multipleactiveplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;stMakeEveryoneActive&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_MPLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create multi player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Action in action.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;action&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;public function ${1:actionName}() {&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::setAjaxMode();&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$${2:arg} = self::getArg(&#039;${2:arg}&#039;, AT_posint, false, 0);&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$this-&amp;gt;game-&amp;gt;action_${1:actionName}(\\$${2:arg});&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::ajaxResponse();&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Player loop in game.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;players&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;\\$players = \\$this-&amp;gt;loadPlayersBasicInfos();&amp;quot;,&lt;br /&gt;
      &amp;quot;foreach (\\$players as \\$player_id =&amp;gt; \\$player_info) {&amp;quot;,&lt;br /&gt;
      &amp;quot;${1}&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=File:Stripped_base_Typescript_file.png&amp;diff=20749</id>
		<title>File:Stripped base Typescript file.png</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=File:Stripped_base_Typescript_file.png&amp;diff=20749"/>
		<updated>2024-04-11T20:27:37Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The main typescript file for the BGA Type Safe Template, with comments and noop code removed.&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Code_Sharing&amp;diff=20747</id>
		<title>BGA Code Sharing</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Code_Sharing&amp;diff=20747"/>
		<updated>2024-04-11T20:08:06Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added the BGA Type safe template to this page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
This page is for listing of externally hosted bga projects, tools and resources, as well as internal project&lt;br /&gt;
intended for sharing&lt;br /&gt;
&lt;br /&gt;
== Community shared components, pens, etc ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! NAME&lt;br /&gt;
! CODE LINK&lt;br /&gt;
! DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Dice models and animation&lt;br /&gt;
|-&lt;br /&gt;
| Die: 4 sided &lt;br /&gt;
| https://codepen.io/mrkiffie/pen/doVZgW  ; https://codepen.io/VictoriaLa/pen/JjZNezr&lt;br /&gt;
| code pen&lt;br /&gt;
|-&lt;br /&gt;
| Die: 6 sided &lt;br /&gt;
| https://github.com/elaskavaia/bga-sharedcode ; https://codepen.io/VictoriaLa/pen/QWBBbwz&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Die: 8 sided &lt;br /&gt;
| https://codepen.io/VictoriaLa/pen/YzMPeGq&lt;br /&gt;
| code pen&lt;br /&gt;
|-&lt;br /&gt;
| Die: 12 sided (dodecahedron) &lt;br /&gt;
| https://codepen.io/VictoriaLa/pen/xxLLxOP &amp;lt;nowiki/&amp;gt;  https://codepen.io/hoursgoby/pen/GRwQzxo&lt;br /&gt;
| Code pen&lt;br /&gt;
|- &lt;br /&gt;
| Die: 20 sided &lt;br /&gt;
| https://codepen.io/vicentemundim/details/cenIh&lt;br /&gt;
| Code pen&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Moving object using CSS animation (mostly)&lt;br /&gt;
|-&lt;br /&gt;
| Phantom object move on oversurface &lt;br /&gt;
| https://codepen.io/VictoriaLa/pen/gORvdJo&lt;br /&gt;
| This technique creates clone of the object it moves it on another surface. It works well when parents that css transform applies such as scale and rotate&lt;br /&gt;
|-&lt;br /&gt;
| Move object directly using positioning &lt;br /&gt;
| https://codepen.io/VictoriaLa/pen/dyzgKVX&lt;br /&gt;
| This technique is modification of BGA framework method to allow mobile object not to have absolute position before or after the move (and uses css animation not dojo). Methods slideToObjectRelative, attachToNewObjectNoDestroy&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Responsive layout for game boards&lt;br /&gt;
|-&lt;br /&gt;
|Flex Layout&lt;br /&gt;
|https://codepen.io/VictoriaLa/pen/XWjJJgG&lt;br /&gt;
|Example on how to create flexible layout just by using css&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Algorithms&lt;br /&gt;
|-&lt;br /&gt;
|Hex grid&lt;br /&gt;
|tapestry,Tumbleweed,gaia project,Gold West&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Shortest path on hex grid&lt;br /&gt;
|memoir 44&lt;br /&gt;
| Dijkstra&lt;br /&gt;
|-&lt;br /&gt;
|Largest area on hex grid&lt;br /&gt;
|tapestry, ...&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Largest area on square grid&lt;br /&gt;
|king domino, ...&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Tetris pieces&lt;br /&gt;
|patchwork, ...&lt;br /&gt;
|Matrix manupations to rotate, flip and fit tetris pieces&lt;br /&gt;
|-&lt;br /&gt;
|Line of sights on hex grid&lt;br /&gt;
|memoir 44&lt;br /&gt;
|Find intersecting hexes on a line between two cells&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Alternative implementations of BGA modules&lt;br /&gt;
|-&lt;br /&gt;
|Scrollmap with zoom&lt;br /&gt;
|https://github.com/yansnow78/bga_scrollmap&lt;br /&gt;
|you can find it in cacao an implementation in cacao (currently only changed in studio) . &amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; improvements compare to scrollmap:&lt;br /&gt;
- add zoom capabilities &lt;br /&gt;
&lt;br /&gt;
- add possibility to adjust pan delta to tile size when clicking on arrows&lt;br /&gt;
&lt;br /&gt;
- allow zoom with scroll wheel. only allow zoom with wheel if alt or ctrl or shift are pressed by default.  add possibility to select which key need to be pressed when zooming with wheel&lt;br /&gt;
&lt;br /&gt;
- allow pan/scroll and pinch zoom on smartphone. only allow 2 fingers to start scrolling by default, one finger is for page scrolling&lt;br /&gt;
&lt;br /&gt;
- make clickable area of buttons a bit bigger on smartphone&lt;br /&gt;
&lt;br /&gt;
- improve animation between game board and player bards thanks to an animation_div&lt;br /&gt;
&lt;br /&gt;
- add support to long click on buttons (continuous scroll or zoom or enlarge/reduce until button released)&lt;br /&gt;
|-&lt;br /&gt;
|Scrollmap Plus &lt;br /&gt;
|patchwork&lt;br /&gt;
|Implementation with some bugs fixed, improved drag support and ability to use only one direction (i.e. only horizontal like carousel). Found in modules/extscrollmap.js&lt;br /&gt;
|-&lt;br /&gt;
|Zoom&lt;br /&gt;
|[https://github.com/thoun/bga-zoom/ Repo]&amp;lt;nowiki&amp;gt; | &amp;lt;/nowiki&amp;gt;[https://thoun.github.io/bga-zoom/demo/index.html Demo] (visible on Knarr, Azul, Abyss, ...)&lt;br /&gt;
|Allow the user to zoom on the game board. Include the controls to zoom, and handle the scale applied to the HTML element.&lt;br /&gt;
|-&lt;br /&gt;
|Cards&lt;br /&gt;
|[https://github.com/thoun/bga-cards/ Repo]&amp;lt;nowiki&amp;gt; | &amp;lt;/nowiki&amp;gt;[https://thoun.github.io/bga-cards/demo/index.html Demo] (visible on Knarr, King of Tokyo, Abyss, ...)&lt;br /&gt;
|Alternative to BGA Stock component, using CSS transitions instead of dojo animations.&lt;br /&gt;
|-&lt;br /&gt;
|Jump to&lt;br /&gt;
|[https://github.com/thoun/bga-jump-to/ Repo]&amp;lt;nowiki&amp;gt; | &amp;lt;/nowiki&amp;gt;[https://thoun.github.io/bga-jump-to/demo/index.html Demo] (visible on Knarr, Elawa)&lt;br /&gt;
|Add floating controls to quickly jump to a player&#039;s table&lt;br /&gt;
|-&lt;br /&gt;
|Help&lt;br /&gt;
|[https://github.com/thoun/bga-help/ Repo]&amp;lt;nowiki&amp;gt; | &amp;lt;/nowiki&amp;gt;[https://thoun.github.io/bga-help/demo/index.html Demo] (visible on Knarr)&lt;br /&gt;
|Add floating help buttons at the bottom left corner of the screen&lt;br /&gt;
|-&lt;br /&gt;
|Dice&lt;br /&gt;
|[https://github.com/thoun/bga-dice/ Repo]&amp;lt;nowiki&amp;gt; | &amp;lt;/nowiki&amp;gt;[https://thoun.github.io/bga-dice/demo/index.html Demo] (not used yet)&lt;br /&gt;
|Handle dice display and animation &#039;&#039;&#039;WORK IN PROGRESS&#039;&#039;&#039; Only d6 is started&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Projects ==&lt;br /&gt;
&lt;br /&gt;
Add the game name, a link to repository and nickname of the developer on bga (same as used for dev forum), and short description. See [[Tools_and_tips_of_BGA_Studio#Version_Control]] for some suggestions on how and where to publish your code externally. Also see the [https://github.com/topics/boardgamearena boardgamearena] topic on github.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important notice about artwork on BGA Open Source projects: original hi-resolution images from publishers must not be published on the repositories. In addition, it is better to specify that the images derivated from publishers artwork are copyrighted and cannot be licensed under a free license like Creative Commons.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! NON-GAME PROJECTS&lt;br /&gt;
! CODE LINK&lt;br /&gt;
! DEVELOPER&lt;br /&gt;
! COMMENT&lt;br /&gt;
|-&lt;br /&gt;
| Shared Code (not a game)&lt;br /&gt;
| https://github.com/elaskavaia/bga-sharedcode&lt;br /&gt;
| Victoria_La&lt;br /&gt;
| Examples of various game components and PHP stubs of framework code to make IDE happy&lt;br /&gt;
|-&lt;br /&gt;
| Vanilla Typescipt template (not a game)&lt;br /&gt;
| https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
| Victoria_La&lt;br /&gt;
| Project template for typescript and using minimal dojo, good for vscode - type checking, auto-complete, navigation&lt;br /&gt;
|-&lt;br /&gt;
| BoardGameArena Workbench (not a game)&lt;br /&gt;
| https://github.com/danielholmes/bga-workbench&lt;br /&gt;
| Daniel Holmes (dhau)&lt;br /&gt;
|-&lt;br /&gt;
|BGA-boilerplate&lt;br /&gt;
|https://github.com/bga-devs/tisaac-boilerplate/&lt;br /&gt;
|Tisaac (and Vincentt ?)&lt;br /&gt;
|Main boilerplate with extended &amp;quot;basic&amp;quot; function and code structure&lt;br /&gt;
|-&lt;br /&gt;
|BGA Type Safe Template&lt;br /&gt;
|https://github.com/NevinAF/bga-ts-template&lt;br /&gt;
|NevinAF&lt;br /&gt;
|Full typing of all BGA Framework components.&lt;br /&gt;
|-&lt;br /&gt;
! GAME&lt;br /&gt;
! CODE LINK&lt;br /&gt;
! DEVELOPER&lt;br /&gt;
! COMMENT&lt;br /&gt;
|-&lt;br /&gt;
| 99 (Trick-taking Card Game)&lt;br /&gt;
| https://github.com/ekelly/bga-ninetynine&lt;br /&gt;
| QuasarDukeDev&lt;br /&gt;
|-&lt;br /&gt;
| Abandon All Artichokes&lt;br /&gt;
| https://github.com/0-wiz-0/bga-abandonallartichokes&lt;br /&gt;
| __wiz__, rojomojo&lt;br /&gt;
|-&lt;br /&gt;
| Assyria &lt;br /&gt;
| https://github.com/sebastien-prudhomme/bga-assyria&lt;br /&gt;
| daikinee &lt;br /&gt;
|-&lt;br /&gt;
| Aura&lt;br /&gt;
| https://github.com/micahstairs/bga-aura&lt;br /&gt;
| Micah Stairs (micahstairs)&lt;br /&gt;
|-&lt;br /&gt;
| Bandido &lt;br /&gt;
| https://github.com/opheliehb/BandidoBGA&lt;br /&gt;
| ophelopede &amp;amp; Harkle &lt;br /&gt;
|-&lt;br /&gt;
| The Battle for Hill 218&lt;br /&gt;
| https://github.com/danielholmes/battle-for-hill-218&lt;br /&gt;
| Daniel Holmes (dhau)&lt;br /&gt;
|-&lt;br /&gt;
| Bonbons&lt;br /&gt;
| https://github.com/AntonioSoler/bga-bonbons&lt;br /&gt;
| Morgalad &lt;br /&gt;
|-&lt;br /&gt;
|Big Monster&lt;br /&gt;
|https://github.com/nmatton/bigmonster&lt;br /&gt;
|nicotacotac&lt;br /&gt;
|-&lt;br /&gt;
| Canosa&lt;br /&gt;
| https://codeberg.org/halibut/Canosa&lt;br /&gt;
| junibegood&lt;br /&gt;
|-&lt;br /&gt;
| Coinche&lt;br /&gt;
| https://github.com/drasill/bga-coinche&lt;br /&gt;
| Draasill&lt;br /&gt;
|-&lt;br /&gt;
|Copenhagen&lt;br /&gt;
|https://github.com/JoeProgram/bga-copenhagen&lt;br /&gt;
|JoeProgram&lt;br /&gt;
|-&lt;br /&gt;
| Coup: City State&lt;br /&gt;
| https://github.com/quietmint/bga-coupcitystate&lt;br /&gt;
| quietmint&lt;br /&gt;
|-&lt;br /&gt;
| Dice Summoners&lt;br /&gt;
| https://github.com/eoincos/bga-dicesummoners&lt;br /&gt;
| eoincos&lt;br /&gt;
|-&lt;br /&gt;
| Dungeon Roll&lt;br /&gt;
| https://github.com/MartinGoulet/bga-dungeonroll&lt;br /&gt;
| MGoulet&lt;br /&gt;
|-&lt;br /&gt;
| Egyptian Ratscrew&lt;br /&gt;
| https://github.com/0BuRner/bga-egyptianratscrew&lt;br /&gt;
| 0BuRner&lt;br /&gt;
|-&lt;br /&gt;
| Eruption&lt;br /&gt;
| https://github.com/AndyKerrison/bga-eruption&lt;br /&gt;
| Andy_K&lt;br /&gt;
|-&lt;br /&gt;
| A Fistful Of Gold&lt;br /&gt;
| https://bitbucket.org/Joel_L/fistfulofgold&lt;br /&gt;
| Brainchild&lt;br /&gt;
|-&lt;br /&gt;
|Flip Freighters&lt;br /&gt;
|https://github.com/joesimpson/bga-flipfreighters&lt;br /&gt;
|joesimpson&lt;br /&gt;
|-&lt;br /&gt;
| Florenza: The Card Game&lt;br /&gt;
| https://github.com/alberto-bottarini/bga-florenza&lt;br /&gt;
| tarini &lt;br /&gt;
|-&lt;br /&gt;
| For-Ex&lt;br /&gt;
| https://github.com/Fnordistan/forex&lt;br /&gt;
| AmadanNaBriona&lt;br /&gt;
|-&lt;br /&gt;
| Get the MacGuffin&lt;br /&gt;
| https://github.com/mizutismask/bga-get-the-MacGuffin&lt;br /&gt;
| mizutismask&lt;br /&gt;
|-&lt;br /&gt;
| Hardback&lt;br /&gt;
| https://github.com/quietmint/bga-hardback&lt;br /&gt;
| quietmint&lt;br /&gt;
|-&lt;br /&gt;
| Hearts &#039;&#039;&#039;(Tutorial)&#039;&#039;&#039;&lt;br /&gt;
| https://github.com/elaskavaia/bga-heartsla&lt;br /&gt;
| Victoria_La&lt;br /&gt;
|-&lt;br /&gt;
| Homesteaders&lt;br /&gt;
| https://github.com/npatron/bga-homesteaders&lt;br /&gt;
| TheBoot&lt;br /&gt;
|-&lt;br /&gt;
| Incan Gold&lt;br /&gt;
| https://github.com/AntonioSoler/bga-incangold&lt;br /&gt;
| Morgalad &lt;br /&gt;
|-&lt;br /&gt;
| In the Year of the Dragon (10th Anniversary Edition)&lt;br /&gt;
| https://github.com/Fnordistan/ityotd&lt;br /&gt;
| AmadanNaBriona&lt;br /&gt;
|-&lt;br /&gt;
| Just Desserts&lt;br /&gt;
| https://github.com/mizutismask/bga-just-desserts&lt;br /&gt;
| mizutismask&lt;br /&gt;
|-&lt;br /&gt;
| The King&#039;s Guild&lt;br /&gt;
| https://github.com/AdamNovotny/BGG-KingsGuild&lt;br /&gt;
| A-dam&lt;br /&gt;
|-&lt;br /&gt;
| The Lady and the Tiger (Doors)&lt;br /&gt;
| https://github.com/Fnordistan/ladyandthetiger&lt;br /&gt;
| AmadanNaBriona&lt;br /&gt;
|-&lt;br /&gt;
| Mapmaker: The Gerrymandering Game&lt;br /&gt;
| https://github.com/gzhang01/bga-mapmaker&lt;br /&gt;
| gkz&lt;br /&gt;
|-&lt;br /&gt;
| Marco Polo&lt;br /&gt;
| https://github.com/rcitaliano/MarcoPolo&lt;br /&gt;
| rcitaliano&lt;br /&gt;
|-&lt;br /&gt;
| Nile&lt;br /&gt;
| https://github.com/AndyKerrison/bga-nile&lt;br /&gt;
| Andy_K&lt;br /&gt;
|-&lt;br /&gt;
| Noir: Killer vs Inspector&lt;br /&gt;
| https://bitbucket.org/chhuang76/bga_noirkvi&lt;br /&gt;
| ch huang&lt;br /&gt;
|-&lt;br /&gt;
| Penny Press&lt;br /&gt;
| https://github.com/AdamNovotny/bga-blooms&lt;br /&gt;
| A-dam&lt;br /&gt;
|-&lt;br /&gt;
| Perikles&lt;br /&gt;
| https://github.com/Fnordistan/perikles&lt;br /&gt;
| AmadanNaBriona&lt;br /&gt;
|-&lt;br /&gt;
| P.I.&lt;br /&gt;
| https://gitlab.com/fa81/bga-pi, https://github.com/hellp/bga-pi (mirror)&lt;br /&gt;
| Fabian Neumann (fa81)&lt;br /&gt;
|-&lt;br /&gt;
| President&lt;br /&gt;
| https://github.com/quaresma95/president&lt;br /&gt;
| quaresma95&lt;br /&gt;
|-&lt;br /&gt;
| Santorini&lt;br /&gt;
| https://github.com/AntonioSoler/bga-santorini&lt;br /&gt;
| Morgalad, quietmint, Tisaac&lt;br /&gt;
|-&lt;br /&gt;
| Tablut&lt;br /&gt;
| https://github.com/Lucas-C/tablut&lt;br /&gt;
| Lucas-C &amp;amp; ntaffore&lt;br /&gt;
|-&lt;br /&gt;
| Takara Island&lt;br /&gt;
| https://github.com/AntonioSoler/bga-takaraisland&lt;br /&gt;
| Morgalad&lt;br /&gt;
|-&lt;br /&gt;
| Taluva&lt;br /&gt;
| https://github.com/quietmint/bga-taluva&lt;br /&gt;
| Morgalad &amp;amp; quietmint&lt;br /&gt;
|-&lt;br /&gt;
| Teotihuacan: City of Gods&lt;br /&gt;
| https://github.com/Trompetenhut/bga-teotihuacan&lt;br /&gt;
| Trompetenhut&lt;br /&gt;
|-&lt;br /&gt;
| Texas 42 (domino game, still under development)&lt;br /&gt;
| https://github.com/ishermandom/bga-42&lt;br /&gt;
| Stardust Spikes, Jason Turner-Maier, Ilya Sherman&lt;br /&gt;
|-&lt;br /&gt;
| Tic Tac Match&lt;br /&gt;
| https://github.com/leocaseiro/bga-tictacmatch&lt;br /&gt;
| Leo Caseiro&lt;br /&gt;
|-&lt;br /&gt;
| Trick of the Rails&lt;br /&gt;
| https://github.com/Fnordistan/trickoftherails&lt;br /&gt;
| AmadanNaBriona&lt;br /&gt;
|-&lt;br /&gt;
| Uptown&lt;br /&gt;
| https://github.com/elliotkendall/bga-uptown&lt;br /&gt;
| SpottedShroom&lt;br /&gt;
|-&lt;br /&gt;
| Via Magica&lt;br /&gt;
| https://github.com/christopherburke/bga_viamagica&lt;br /&gt;
| CuriousTerran&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Projects on studio ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Any developer can add themselves to a project as read-only from https://studio.boardgamearena.com/#!projects page (almost any project).&lt;br /&gt;
&lt;br /&gt;
If it is not visible: a) it has no bgg id b) it is already published (use radio button to switch) c) it is an old game not developed on studio.&lt;br /&gt;
&lt;br /&gt;
== Other useful resources ==&lt;br /&gt;
&lt;br /&gt;
Moved to [[Tools_and_tips_of_BGA_Studio]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20746</id>
		<title>Using Typescript and Scss</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20746"/>
		<updated>2024-04-11T20:04:17Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Make the sections purpose a bit more clear&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will help you set up your project to use Typescript client file and Scss style files, and automatically build Javascript (in ES5) files and CSS files so your project stay compatible to BGA framework requirements.&lt;br /&gt;
You can use only TS or only SCSS part if you want, they are not linked.&lt;br /&gt;
&lt;br /&gt;
== BGA Type Safe Template ==&lt;br /&gt;
If you are interested in all of the BGA Framework being typed for you, &#039;&#039;&#039;check out the [[BGA-ts-template]]&#039;&#039;&#039;. It will let you set up full typescript support and more with the fewest, easy to follow steps.&lt;br /&gt;
[[File:Typescript autofill.gif|alt=Typescript Autocomplete|center|thumb|734x734px|Typescript Autocomplete using BGA Type Safe Template]]&#039;&#039;&#039;The following document is geared towards setting up a custom project where you will be in charge of typing all components that you want to use.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Install and configure ==&lt;br /&gt;
&lt;br /&gt;
=== Install dev stack  ===&lt;br /&gt;
Install node/npm.  Here is an example to activate auto-build in Visual Studio Code, if you use another tool I strongly recommend to find an equivalent so you don&#039;t have to launch build manually after each modification.&lt;br /&gt;
&lt;br /&gt;
=== Configure package.json and tsconfig.json ===&lt;br /&gt;
&lt;br /&gt;
Create a file named &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; on the root folder, not on the src folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;package.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
   &amp;quot;name&amp;quot;: &amp;quot;yourgamename&amp;quot;,&lt;br /&gt;
   &amp;quot;version&amp;quot;: &amp;quot;1.0.0&amp;quot;,&lt;br /&gt;
   &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
   &amp;quot;main&amp;quot;: &amp;quot;YourGameName.js&amp;quot;,&lt;br /&gt;
   &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
     &amp;quot;build:ts&amp;quot;: &amp;quot;tsc&amp;quot;,&lt;br /&gt;
     &amp;quot;build:scss&amp;quot;: &amp;quot;sass --no-source-map src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:ts&amp;quot;: &amp;quot;tsc --watch&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:scss&amp;quot;: &amp;quot;sass --watch src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch&amp;quot;: &amp;quot;npm run watch:ts &amp;amp;&amp;amp; npm run watch:scss&amp;quot;,&lt;br /&gt;
     &amp;quot;build&amp;quot;: &amp;quot;npm run build:ts &amp;amp;&amp;amp; npm run build:scss&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;author&amp;quot;: &amp;quot;yourname&amp;quot;,&lt;br /&gt;
   &amp;quot;license&amp;quot;: &amp;quot;MIT&amp;quot;,&lt;br /&gt;
   &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
     &amp;quot;sass&amp;quot;: &amp;quot;^1.32.6&amp;quot;,&lt;br /&gt;
     &amp;quot;typescript&amp;quot;: &amp;quot;^4.1.3&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: if you not using scss - remove corresponding scripts and deps.&lt;br /&gt;
&lt;br /&gt;
When package.json is created, run &amp;lt;code&amp;gt;npm i&amp;lt;/code&amp;gt; on the root folder to install builders (will generate a node_modules folder).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For Typescript compilation we also need to set up a &amp;lt;code&amp;gt;tsconfig.json&amp;lt;/code&amp;gt; on the root folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tsconfig.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;rootDir&amp;quot;: &amp;quot;.&amp;quot;, &lt;br /&gt;
     &amp;quot;compilerOptions&amp;quot;: {&lt;br /&gt;
       &amp;quot;target&amp;quot;: &amp;quot;es5&amp;quot;,&lt;br /&gt;
       &amp;quot;module&amp;quot;: &amp;quot;none&amp;quot;,&lt;br /&gt;
       &amp;quot;lib&amp;quot;: [&amp;quot;dom&amp;quot;, &amp;quot;esnext&amp;quot;],  &lt;br /&gt;
       &amp;quot;sourceMap&amp;quot;: false,&lt;br /&gt;
       &amp;quot;typeRoots&amp;quot;: [&amp;quot;src/types&amp;quot;, &amp;quot;./types&amp;quot;, &amp;quot;./node_modules/@types&amp;quot;],&lt;br /&gt;
       &amp;quot;outFile&amp;quot;: &amp;quot;YourGameName.js&amp;quot;&lt;br /&gt;
     },&lt;br /&gt;
     &amp;quot;files&amp;quot;: [&lt;br /&gt;
         &amp;quot;src/GameBody.ts&amp;quot;,&lt;br /&gt;
         &amp;quot;src/define.ts&amp;quot;&lt;br /&gt;
     ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: it only works now with es5&lt;br /&gt;
&lt;br /&gt;
If you want to split your code onto multiple files, just add them in the file list (order is important for dependencies, new subpart should go on top of the list). No need to import classes or types from one file to another. In fact, you can&#039;t with this configuration. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create skeleton ==&lt;br /&gt;
When you create your game in BGA Studio, a JS and CSS file are generated. As we will overwrite them with autobuild. You can put the TS/SCSS files on a &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; folder to separate them from built files, but that&#039;s not mandatory.&lt;br /&gt;
Note to myself: check if &#039;src&#039; dir will be svn version control, if not cannot really use it (even if duplicated in git).&lt;br /&gt;
&lt;br /&gt;
=== Typescript file skeleton ===&lt;br /&gt;
Typescript example here have been stripped down of all comments for clarity. &lt;br /&gt;
Your TS code can be splitted in multiple files, you can have a look [https://github.com/thoun/bga-ts-example here] for inspiration.&lt;br /&gt;
To make this page concise, I removed comments and code samples. If it&#039;s your first game, well - don&#039;t do it if your first game - you won&#039;t be able to apply other code samples from docs, they all using dojo style and have to completely rewritten.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/GameBody.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// @ts-ignore&lt;br /&gt;
GameGui = (function () { // this hack required so we fake extend GameGui&lt;br /&gt;
  function GameGui() {}&lt;br /&gt;
  return GameGui;&lt;br /&gt;
})();&lt;br /&gt;
&lt;br /&gt;
// Note: it does not really extend it in es6 way, you cannot call super you have to use dojo way &lt;br /&gt;
class GameBody extends GameGui { &lt;br /&gt;
     constructor() {}&lt;br /&gt;
     &lt;br /&gt;
     public setup(gamedatas: any) {&lt;br /&gt;
         this.setupNotifications();&lt;br /&gt;
     } &lt;br /&gt;
     public onEnteringState(stateName: string, args: any) {}&lt;br /&gt;
     public onLeavingState(stateName: string) {}&lt;br /&gt;
     public onUpdateActionButtons(stateName: string, args: any) {} &lt;br /&gt;
     public setupNotifications() {}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To plug the class with BGA framework, we&#039;ll also create another file:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/define.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;,&amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/stock&amp;quot;&lt;br /&gt;
 ],&lt;br /&gt;
 function (dojo, declare) {&lt;br /&gt;
     return declare(&amp;quot;bgagame.yourgamename&amp;quot;, ebg.core.gamegui, new GameBody());             &lt;br /&gt;
 });&lt;br /&gt;
Copy &amp;lt;code&amp;gt;bgagame.yourgamename&amp;lt;/code&amp;gt; from original JS to avoid name mistakes with letter case.&lt;br /&gt;
&lt;br /&gt;
If you try to compile it you will be missing definitions of bunch of methods and variables for that we will add special ts type definition file .d.ts, this is not a complete version but you can get more complete from git projects below&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/types/bga-framework.d.ts&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare var gameui: GameGui;&lt;br /&gt;
declare var g_replayFrom: number | undefined;&lt;br /&gt;
declare var g_gamethemeurl: string;&lt;br /&gt;
declare var g_themeurl: string;&lt;br /&gt;
declare var g_archive_mode: string;&lt;br /&gt;
declare function _(str: string): string;&lt;br /&gt;
&lt;br /&gt;
declare const define;&lt;br /&gt;
declare const ebg;&lt;br /&gt;
&lt;br /&gt;
declare class GameGui {&lt;br /&gt;
    page_is_unloading: any;&lt;br /&gt;
    game_name: string;&lt;br /&gt;
    instantaneousMode: any;&lt;br /&gt;
    player_id: string;&lt;br /&gt;
    interface_min_width: number;&lt;br /&gt;
    gamedatas: any;&lt;br /&gt;
    &lt;br /&gt;
  &lt;br /&gt;
    isCurrentPlayerActive(): boolean;&lt;br /&gt;
    addActionButton(id: string, label: string, callback: (event?: any) =&amp;gt; void);&lt;br /&gt;
    checkAction(action: any);&lt;br /&gt;
    ajaxcall(url: string, args: object, bind: GameGui, resultHandler: (result: any) =&amp;gt; void, allHandler: any);&lt;br /&gt;
    &lt;br /&gt;
    setup(gamedatas: any): void;&lt;br /&gt;
    onEnteringState(stateName: string, args: any): void;&lt;br /&gt;
    onLeavingState(stateName: string ): void;&lt;br /&gt;
    onUpdateActionButtons(stateName: string, args: any): void;&lt;br /&gt;
    setupNotifications(): void;&lt;br /&gt;
&lt;br /&gt;
    onScriptError(msg: string, url?: string, linenumber?:number);&lt;br /&gt;
    inherited(args: any);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Above is barebone definition of gameui interface,  you can find more complete one here&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless/blob/main/src/types/bga-framework.d.ts&lt;br /&gt;
&lt;br /&gt;
=== SCSS file ===&lt;br /&gt;
Nothing special here, just write classic SCSS (will be compiled by Dart scss) and name it &#039;&#039;&#039;src/yourgamename.scss&#039;&#039;&#039;.&lt;br /&gt;
Original content same as original .css, i.e&lt;br /&gt;
&lt;br /&gt;
  @import url(../../../css/csslayer.css);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your SCSS code can be splitted in multiple files, for example :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;yourgamename.scss&#039;&#039;&#039;&lt;br /&gt;
  @import &#039;gametable&#039;;&lt;br /&gt;
 &lt;br /&gt;
  /* some classes */&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;_gametable.scss&#039;&#039;&#039;&lt;br /&gt;
  /* _gametable related classes */&lt;br /&gt;
&lt;br /&gt;
== Auto build and auto upload ==&lt;br /&gt;
&lt;br /&gt;
=== Auto build JS and CSS files ===&lt;br /&gt;
&lt;br /&gt;
To build and watch (i.e. re-build continiously changed files) run in terminal:&lt;br /&gt;
  npm run watch&lt;br /&gt;
&lt;br /&gt;
Alternately you can make vscode to do it for you by installing Run on Save extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
Note: to build without watch&lt;br /&gt;
  npm run build&lt;br /&gt;
&lt;br /&gt;
=== Auto-upload generated files ===&lt;br /&gt;
You can setup stanard file sync or use vscode SFTP extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hint ===&lt;br /&gt;
Make sure &amp;lt;code&amp;gt;.vscode&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;node_modules&amp;lt;/code&amp;gt; are in &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; if you commit your project somewhere.&lt;br /&gt;
&lt;br /&gt;
=== Code completion ===&lt;br /&gt;
To add code completion on framework, dojo, stock, ... you&#039;ll need more type definition files. Feel free to copy them from [https://github.com/thoun/bga-ts-example this repo] and reference them at the top of files array, even before your subpart files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Referenced Projects ==&lt;br /&gt;
&lt;br /&gt;
* https://github.com/thoun/bga-ts-example&lt;br /&gt;
* https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
* https://github.com/NevinAF/bga-ts-template&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20745</id>
		<title>Using Typescript and Scss</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20745"/>
		<updated>2024-04-11T20:02:44Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added the BGA Type Safe template redirect to the top of the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will help you set up your project to use Typescript client file and Scss style files, and automatically build Javascript (in ES5) files and CSS files so your project stay compatible to BGA framework requirements.&lt;br /&gt;
You can use only TS or only SCSS part if you want, they are not linked.&lt;br /&gt;
&lt;br /&gt;
== BGA Type Safe Template ==&lt;br /&gt;
If you are interested in all of the BGA Framework being typed for you, check out the [[BGA-ts-template]]. It will let you set up full typescript support and more with the fewest, easy to follow steps. The following document is geared towards setting up a custom project where you will be in charge of typing all components that you want to use.&lt;br /&gt;
[[File:Typescript autofill.gif|alt=Typescript Autocomplete|center|thumb|734x734px|Typescript Autocomplete]]&lt;br /&gt;
&lt;br /&gt;
== Install and configure ==&lt;br /&gt;
&lt;br /&gt;
=== Install dev stack  ===&lt;br /&gt;
Install node/npm.  Here is an example to activate auto-build in Visual Studio Code, if you use another tool I strongly recommend to find an equivalent so you don&#039;t have to launch build manually after each modification.&lt;br /&gt;
&lt;br /&gt;
=== Configure package.json and tsconfig.json ===&lt;br /&gt;
&lt;br /&gt;
Create a file named &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; on the root folder, not on the src folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;package.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
   &amp;quot;name&amp;quot;: &amp;quot;yourgamename&amp;quot;,&lt;br /&gt;
   &amp;quot;version&amp;quot;: &amp;quot;1.0.0&amp;quot;,&lt;br /&gt;
   &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
   &amp;quot;main&amp;quot;: &amp;quot;YourGameName.js&amp;quot;,&lt;br /&gt;
   &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
     &amp;quot;build:ts&amp;quot;: &amp;quot;tsc&amp;quot;,&lt;br /&gt;
     &amp;quot;build:scss&amp;quot;: &amp;quot;sass --no-source-map src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:ts&amp;quot;: &amp;quot;tsc --watch&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:scss&amp;quot;: &amp;quot;sass --watch src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch&amp;quot;: &amp;quot;npm run watch:ts &amp;amp;&amp;amp; npm run watch:scss&amp;quot;,&lt;br /&gt;
     &amp;quot;build&amp;quot;: &amp;quot;npm run build:ts &amp;amp;&amp;amp; npm run build:scss&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;author&amp;quot;: &amp;quot;yourname&amp;quot;,&lt;br /&gt;
   &amp;quot;license&amp;quot;: &amp;quot;MIT&amp;quot;,&lt;br /&gt;
   &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
     &amp;quot;sass&amp;quot;: &amp;quot;^1.32.6&amp;quot;,&lt;br /&gt;
     &amp;quot;typescript&amp;quot;: &amp;quot;^4.1.3&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: if you not using scss - remove corresponding scripts and deps.&lt;br /&gt;
&lt;br /&gt;
When package.json is created, run &amp;lt;code&amp;gt;npm i&amp;lt;/code&amp;gt; on the root folder to install builders (will generate a node_modules folder).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For Typescript compilation we also need to set up a &amp;lt;code&amp;gt;tsconfig.json&amp;lt;/code&amp;gt; on the root folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tsconfig.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;rootDir&amp;quot;: &amp;quot;.&amp;quot;, &lt;br /&gt;
     &amp;quot;compilerOptions&amp;quot;: {&lt;br /&gt;
       &amp;quot;target&amp;quot;: &amp;quot;es5&amp;quot;,&lt;br /&gt;
       &amp;quot;module&amp;quot;: &amp;quot;none&amp;quot;,&lt;br /&gt;
       &amp;quot;lib&amp;quot;: [&amp;quot;dom&amp;quot;, &amp;quot;esnext&amp;quot;],  &lt;br /&gt;
       &amp;quot;sourceMap&amp;quot;: false,&lt;br /&gt;
       &amp;quot;typeRoots&amp;quot;: [&amp;quot;src/types&amp;quot;, &amp;quot;./types&amp;quot;, &amp;quot;./node_modules/@types&amp;quot;],&lt;br /&gt;
       &amp;quot;outFile&amp;quot;: &amp;quot;YourGameName.js&amp;quot;&lt;br /&gt;
     },&lt;br /&gt;
     &amp;quot;files&amp;quot;: [&lt;br /&gt;
         &amp;quot;src/GameBody.ts&amp;quot;,&lt;br /&gt;
         &amp;quot;src/define.ts&amp;quot;&lt;br /&gt;
     ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: it only works now with es5&lt;br /&gt;
&lt;br /&gt;
If you want to split your code onto multiple files, just add them in the file list (order is important for dependencies, new subpart should go on top of the list). No need to import classes or types from one file to another. In fact, you can&#039;t with this configuration. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create skeleton ==&lt;br /&gt;
When you create your game in BGA Studio, a JS and CSS file are generated. As we will overwrite them with autobuild. You can put the TS/SCSS files on a &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; folder to separate them from built files, but that&#039;s not mandatory.&lt;br /&gt;
Note to myself: check if &#039;src&#039; dir will be svn version control, if not cannot really use it (even if duplicated in git).&lt;br /&gt;
&lt;br /&gt;
=== Typescript file skeleton ===&lt;br /&gt;
Typescript example here have been stripped down of all comments for clarity. &lt;br /&gt;
Your TS code can be splitted in multiple files, you can have a look [https://github.com/thoun/bga-ts-example here] for inspiration.&lt;br /&gt;
To make this page concise, I removed comments and code samples. If it&#039;s your first game, well - don&#039;t do it if your first game - you won&#039;t be able to apply other code samples from docs, they all using dojo style and have to completely rewritten.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/GameBody.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// @ts-ignore&lt;br /&gt;
GameGui = (function () { // this hack required so we fake extend GameGui&lt;br /&gt;
  function GameGui() {}&lt;br /&gt;
  return GameGui;&lt;br /&gt;
})();&lt;br /&gt;
&lt;br /&gt;
// Note: it does not really extend it in es6 way, you cannot call super you have to use dojo way &lt;br /&gt;
class GameBody extends GameGui { &lt;br /&gt;
     constructor() {}&lt;br /&gt;
     &lt;br /&gt;
     public setup(gamedatas: any) {&lt;br /&gt;
         this.setupNotifications();&lt;br /&gt;
     } &lt;br /&gt;
     public onEnteringState(stateName: string, args: any) {}&lt;br /&gt;
     public onLeavingState(stateName: string) {}&lt;br /&gt;
     public onUpdateActionButtons(stateName: string, args: any) {} &lt;br /&gt;
     public setupNotifications() {}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To plug the class with BGA framework, we&#039;ll also create another file:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/define.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;,&amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/stock&amp;quot;&lt;br /&gt;
 ],&lt;br /&gt;
 function (dojo, declare) {&lt;br /&gt;
     return declare(&amp;quot;bgagame.yourgamename&amp;quot;, ebg.core.gamegui, new GameBody());             &lt;br /&gt;
 });&lt;br /&gt;
Copy &amp;lt;code&amp;gt;bgagame.yourgamename&amp;lt;/code&amp;gt; from original JS to avoid name mistakes with letter case.&lt;br /&gt;
&lt;br /&gt;
If you try to compile it you will be missing definitions of bunch of methods and variables for that we will add special ts type definition file .d.ts, this is not a complete version but you can get more complete from git projects below&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/types/bga-framework.d.ts&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare var gameui: GameGui;&lt;br /&gt;
declare var g_replayFrom: number | undefined;&lt;br /&gt;
declare var g_gamethemeurl: string;&lt;br /&gt;
declare var g_themeurl: string;&lt;br /&gt;
declare var g_archive_mode: string;&lt;br /&gt;
declare function _(str: string): string;&lt;br /&gt;
&lt;br /&gt;
declare const define;&lt;br /&gt;
declare const ebg;&lt;br /&gt;
&lt;br /&gt;
declare class GameGui {&lt;br /&gt;
    page_is_unloading: any;&lt;br /&gt;
    game_name: string;&lt;br /&gt;
    instantaneousMode: any;&lt;br /&gt;
    player_id: string;&lt;br /&gt;
    interface_min_width: number;&lt;br /&gt;
    gamedatas: any;&lt;br /&gt;
    &lt;br /&gt;
  &lt;br /&gt;
    isCurrentPlayerActive(): boolean;&lt;br /&gt;
    addActionButton(id: string, label: string, callback: (event?: any) =&amp;gt; void);&lt;br /&gt;
    checkAction(action: any);&lt;br /&gt;
    ajaxcall(url: string, args: object, bind: GameGui, resultHandler: (result: any) =&amp;gt; void, allHandler: any);&lt;br /&gt;
    &lt;br /&gt;
    setup(gamedatas: any): void;&lt;br /&gt;
    onEnteringState(stateName: string, args: any): void;&lt;br /&gt;
    onLeavingState(stateName: string ): void;&lt;br /&gt;
    onUpdateActionButtons(stateName: string, args: any): void;&lt;br /&gt;
    setupNotifications(): void;&lt;br /&gt;
&lt;br /&gt;
    onScriptError(msg: string, url?: string, linenumber?:number);&lt;br /&gt;
    inherited(args: any);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Above is barebone definition of gameui interface,  you can find more complete one here&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless/blob/main/src/types/bga-framework.d.ts&lt;br /&gt;
&lt;br /&gt;
=== SCSS file ===&lt;br /&gt;
Nothing special here, just write classic SCSS (will be compiled by Dart scss) and name it &#039;&#039;&#039;src/yourgamename.scss&#039;&#039;&#039;.&lt;br /&gt;
Original content same as original .css, i.e&lt;br /&gt;
&lt;br /&gt;
  @import url(../../../css/csslayer.css);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your SCSS code can be splitted in multiple files, for example :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;yourgamename.scss&#039;&#039;&#039;&lt;br /&gt;
  @import &#039;gametable&#039;;&lt;br /&gt;
 &lt;br /&gt;
  /* some classes */&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;_gametable.scss&#039;&#039;&#039;&lt;br /&gt;
  /* _gametable related classes */&lt;br /&gt;
&lt;br /&gt;
== Auto build and auto upload ==&lt;br /&gt;
&lt;br /&gt;
=== Auto build JS and CSS files ===&lt;br /&gt;
&lt;br /&gt;
To build and watch (i.e. re-build continiously changed files) run in terminal:&lt;br /&gt;
  npm run watch&lt;br /&gt;
&lt;br /&gt;
Alternately you can make vscode to do it for you by installing Run on Save extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
Note: to build without watch&lt;br /&gt;
  npm run build&lt;br /&gt;
&lt;br /&gt;
=== Auto-upload generated files ===&lt;br /&gt;
You can setup stanard file sync or use vscode SFTP extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hint ===&lt;br /&gt;
Make sure &amp;lt;code&amp;gt;.vscode&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;node_modules&amp;lt;/code&amp;gt; are in &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; if you commit your project somewhere.&lt;br /&gt;
&lt;br /&gt;
=== Code completion ===&lt;br /&gt;
To add code completion on framework, dojo, stock, ... you&#039;ll need more type definition files. Feel free to copy them from [https://github.com/thoun/bga-ts-example this repo] and reference them at the top of files array, even before your subpart files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Referenced Projects ==&lt;br /&gt;
&lt;br /&gt;
* https://github.com/thoun/bga-ts-example&lt;br /&gt;
* https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
* https://github.com/NevinAF/bga-ts-template&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=File:Typescript_autofill.gif&amp;diff=20744</id>
		<title>File:Typescript autofill.gif</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=File:Typescript_autofill.gif&amp;diff=20744"/>
		<updated>2024-04-11T19:59:14Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A gif showing the bga type-safe template autofill in typescript&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Reversi&amp;diff=20742</id>
		<title>BGA Type Safe Template: Reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Reversi&amp;diff=20742"/>
		<updated>2024-04-11T19:21:02Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Converted this page from the github using a slightly modified version of Pandoc.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;This page was generated from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/reversi.md BGA TS Template: Reversi.md]. It is recommended to view this document from the source file. All links will redirect to source documentation, and images will only be included via link.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;ts-template-reversi-tutorial&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= TS Template: Reversi Tutorial =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#board-game-arena-type-safe-template &#039;&#039;BGA Type Safe Template&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Project Files:&#039;&#039;&#039; [[BGA-TS-Template-Reversi]]&lt;br /&gt;
&lt;br /&gt;
This page is a beginner friendly tutorial which mimics the official [https://en.doc.boardgamearena.com/Tutorial_reversi Tutorial Reversi] page, but is more approachable and uses the BGA Type Safe Template. If you are not a new Board Game Arena developer, you may want to follow along with the [https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#getting-started BGA Type Safe Template: Getting Started] guide for a more concise overview of the template.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;All steps are recorded as a git branch so you can track the exact changes that were made, and view the project files from any point in the tutorial.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/reversi_steps_branches.gif&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;steps-0-1-2-3&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Steps 0, 1, 2, 3 ==&lt;br /&gt;
&lt;br /&gt;
Go to [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md TS Template: Tutorial] for the first four steps of the tutorial. The first four steps for any project are the same. To avoid redundancy, they are not repeated here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-3.5---from-here-on-out&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 3.5 - From here on out ==&lt;br /&gt;
&lt;br /&gt;
At this point, your are ready to start developing your game. You can choose to follow any of the tutorials or guides on the [https://en.doc.boardgamearena.com/Main_Page BGA Studio Documentation] to continue.&lt;br /&gt;
&lt;br /&gt;
From this point in the tutorial and on:&lt;br /&gt;
&lt;br /&gt;
* It will be assumed that files are built and synced before running the game in the BGA studio.&lt;br /&gt;
* It will be assumed that you do a hard refresh of the client page after making changes.&lt;br /&gt;
* It will be assumed that you are using all of the default settings for initializing the typescript template. Adjustments can be made as needed and all sections have links to original file documentation for reference.&lt;br /&gt;
* Most steps will have specific instructions, but you can always adjust at your own discretion.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Make sure the following game information is set for Reversi:&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;// gameinfos.jsonc&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;players&amp;quot;: [ 2 ],&lt;br /&gt;
    &amp;quot;bgg_id&amp;quot;: 2389,&lt;br /&gt;
    &amp;quot;player_colors&amp;quot;: [ &amp;quot;cbcbcb&amp;quot;, &amp;quot;363636&amp;quot; ],&lt;br /&gt;
    &amp;quot;favorite_colors_support&amp;quot;: false&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-4---game-board&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 4 - Game Board ==&lt;br /&gt;
&lt;br /&gt;
# Download the following board image for Reversi, and place it in the &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder of your project. It should be named &amp;lt;code&amp;gt;board.jpg&amp;lt;/code&amp;gt; to match the SCSS background-image in the next step.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/board.jpg&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the board to the DOM by adding the following Smarty template code to the &amp;lt;code&amp;gt;yourgamename_yourgamename.tpl&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- BEGIN square --&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;square_{X}_{Y}&amp;quot; class=&amp;quot;square&amp;quot; style=&amp;quot;left: {LEFT}px; top: {TOP}px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;The &amp;lt;code&amp;gt;&amp;amp;lt;!-- BEGIN &amp;amp;lt;block&amp;amp;gt; --&amp;amp;gt;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;amp;lt;!-- END &amp;amp;lt;block&amp;amp;gt; --&amp;amp;gt;&amp;lt;/code&amp;gt; are Smarty template tags that let you programmatically generate HTML as you will use in a following step. See [https://en.doc.boardgamearena.com/Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl X_X.tpl] for more information about the template file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following SCSS to the &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to style the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;#board {&lt;br /&gt;
    // Setup Image&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
    // Center the board&lt;br /&gt;
    margin: auto;&lt;br /&gt;
    left: 0; top: 0; right: 0; bottom: 0;&lt;br /&gt;
    // Tokens and squares are absolutely placed relative to the board&lt;br /&gt;
    position: relative;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.square {&lt;br /&gt;
    // Size of a square&lt;br /&gt;
    width: 62px;&lt;br /&gt;
    height: 62px;&lt;br /&gt;
    // Position relative to the board, not affected by other elements.&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    // Placeholder for validating the positions.&lt;br /&gt;
    background-color: red;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_interface_stylesheet:_yourgamename.css X.css] for more information about the style sheet for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step4-3.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following code to the &amp;lt;code&amp;gt;yourgamename.view.php&amp;lt;/code&amp;gt; file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// function build_page( $viewArgs ) {&lt;br /&gt;
// ...&lt;br /&gt;
/*********** Place your code below:  ************/&lt;br /&gt;
&lt;br /&gt;
// States that we should start inserting at the &#039;square&#039; block&lt;br /&gt;
// &amp;lt;yourgamename&amp;gt;_&amp;lt;yourgamename&amp;gt; should be replaced with your game name: tstemplatereversi_tstemplatereversi&lt;br /&gt;
$this-&amp;gt;page-&amp;gt;begin_block( &amp;quot;&amp;lt;yourgamename&amp;gt;_&amp;lt;yourgamename&amp;gt;&amp;quot;, &amp;quot;square&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
$hor_scale = 64.8; // Constant for square width&lt;br /&gt;
$ver_scale = 64.4; // Constant for square height&lt;br /&gt;
for( $x=1; $x&amp;lt;=8; $x++ ) // Loop the 8 columns..&lt;br /&gt;
{&lt;br /&gt;
    for( $y=1; $y&amp;lt;=8; $y++ ) // Loop the 8 rows..&lt;br /&gt;
    {&lt;br /&gt;
        // Inserts the code found at the square block based on the variables.&lt;br /&gt;
        $this-&amp;gt;page-&amp;gt;insert_block( &amp;quot;square&amp;quot;, array(&lt;br /&gt;
            &#039;X&#039; =&amp;gt; $x,&lt;br /&gt;
            &#039;Y&#039; =&amp;gt; $y,&lt;br /&gt;
            &#039;LEFT&#039; =&amp;gt; round( ($x-1)*$hor_scale+10 ),&lt;br /&gt;
            &#039;TOP&#039; =&amp;gt; round( ($y-1)*$ver_scale+7 )&lt;br /&gt;
        ) );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl X.view.php] for more information about the view file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step4-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-5---the-tokens&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 5 - The Tokens ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following token image to the &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder of your project. It should be named &amp;lt;code&amp;gt;tokens.png&amp;lt;/code&amp;gt; to match the SCSS background-image in the next step.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/tokens.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a template variable to the &amp;lt;code&amp;gt;yourgamename_yourgamename.tpl&amp;lt;/code&amp;gt; file to represent the tokens:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var jstpl_token=&#039;&amp;lt;div class=&amp;quot;token tokencolor_${color}&amp;quot; id=&amp;quot;token_${x_y}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;Note that this does not have any information that needs to be populated by the server, so this could be directly defined in the TypeScript file.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following SCSS to the &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to style the tokens:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;// Same as square, but matching the token size/image.&lt;br /&gt;
.token {&lt;br /&gt;
    width: 56px;&lt;br /&gt;
    height: 56px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/tokens.png&#039;);&lt;br /&gt;
}&lt;br /&gt;
// For clarity, but doesn&#039;t actually do anything.&lt;br /&gt;
.tokencolor_cbcbcb { background-position: 0px 0px; }&lt;br /&gt;
// Translate the background the exact size of the white token, so the black one shows instead.&lt;br /&gt;
.tokencolor_363636 { background-position: -56px 0px; }&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a TypeScript function to the &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file to place the tokens on the board. You can hover over any function/property in the TypeScript file to see the documentation and usage.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;///////////////////////////////////////////////////&lt;br /&gt;
//// Utility methods&lt;br /&gt;
&lt;br /&gt;
/** Adds a token matching the given player to the board at the specified location. */&lt;br /&gt;
addTokenOnBoard( x: number, y: number, player_id: number )&lt;br /&gt;
{&lt;br /&gt;
    let player = this.gamedatas.players[ player_id ];&lt;br /&gt;
    if (!player)&lt;br /&gt;
        throw new Error( &#039;Unknown player id: &#039; + player_id );&lt;br /&gt;
&lt;br /&gt;
    dojo.place( this.format_block( &#039;jstpl_token&#039;, {&lt;br /&gt;
        x_y: `${x}_${y}`,&lt;br /&gt;
        color: player.color&lt;br /&gt;
    } ) , &#039;board&#039; );&lt;br /&gt;
&lt;br /&gt;
    this.placeOnObject( `token_${x}_${y}`, `overall_player_board_${player_id}` );&lt;br /&gt;
    this.slideToObject( `token_${x}_${y}`, `square_${x}_${y}` ).play();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js X.js] for more information about the script file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For a placeholder, test your tokens by manually placing some in the setup function. you can also remove the boilerplate code.:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;///////////////////////////////////////////////////&lt;br /&gt;
//// Game setup&lt;br /&gt;
&lt;br /&gt;
setup(gamedatas: Gamedatas): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &amp;quot;Starting game setup&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    this.addTokenOnBoard( 2, 2, this.player_id );&lt;br /&gt;
    this.addTokenOnBoard( 6, 3, this.player_id );&lt;br /&gt;
&lt;br /&gt;
    this.setupNotifications(); // &amp;lt;-- Keep this line&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step5-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-6---the-database-and-initial-setup&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 6 - The Database and Initial Setup ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Create a database for your board in the &amp;lt;code&amp;gt;dbmodel.sql&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;sql&amp;quot;&amp;gt;CREATE TABLE IF NOT EXISTS `board` (&lt;br /&gt;
    `board_x` smallint(5) unsigned NOT NULL,&lt;br /&gt;
    `board_y` smallint(5) unsigned NOT NULL,&lt;br /&gt;
    `board_player` int(10) unsigned DEFAULT NULL,&lt;br /&gt;
    PRIMARY KEY (`board_x`,`board_y`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Pay special attention to the backtick &amp;lt;code&amp;gt;`&amp;lt;/code&amp;gt; character vs. the single quote &amp;lt;code&amp;gt;&#039;&amp;lt;/code&amp;gt; when working with SQL. You can quit and restart your game to see if the file is correct.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_database_model:_dbmodel.sql dbmodel.sql] for more information about the database file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Setup the board in your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file. This is initializing the data in the database and setting the four discs in the center of the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;protected function setupNewGame( $players, $options = array() )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    $sql .= implode( &#039;,&#039;, $values );&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
    // self::reattributeColorsBasedOnPreferences( $players, $gameinfos[&#039;player_colors&#039;] );&lt;br /&gt;
    self::reloadPlayersBasicInfos();&lt;br /&gt;
&lt;br /&gt;
    /************ Start the game initialization *****/&lt;br /&gt;
    $sql = &amp;quot;INSERT INTO board (board_x,board_y,board_player) VALUES &amp;quot;;&lt;br /&gt;
    $sql_values = array();&lt;br /&gt;
    list( $whiteplayer_id, $blackplayer_id ) = array_keys( $players );&lt;br /&gt;
    for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
    {&lt;br /&gt;
        for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
        {&lt;br /&gt;
            // Initial positions of white player&lt;br /&gt;
            if( ($x==4 &amp;amp;&amp;amp; $y==4) || ($x==5 &amp;amp;&amp;amp; $y==5) )&lt;br /&gt;
                $token_value = &amp;quot;&#039;$whiteplayer_id&#039;&amp;quot;;&lt;br /&gt;
            // Initial positions of black player&lt;br /&gt;
            else if( ($x==4 &amp;amp;&amp;amp; $y==5) || ($x==5 &amp;amp;&amp;amp; $y==4) )&lt;br /&gt;
                $token_value = &amp;quot;&#039;$blackplayer_id&#039;&amp;quot;;&lt;br /&gt;
            // Not a starting position&lt;br /&gt;
            else&lt;br /&gt;
                $token_value = &amp;quot;NULL&amp;quot;;&lt;br /&gt;
            $sql_values[] = &amp;quot;(&#039;$x&#039;,&#039;$y&#039;,$token_value)&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    $sql .= implode( &#039;,&#039;, $sql_values );&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Now we need to send the board information to the client whenever the page is reloaded. In your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file, add the following code to the &amp;lt;code&amp;gt;getAllDatas&amp;lt;/code&amp;gt; function:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;protected function getAllDatas()&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    $sql = &amp;quot;SELECT board_x x, board_y y, board_player player&lt;br /&gt;
            FROM board WHERE board_player IS NOT NULL&amp;quot;;&lt;br /&gt;
    $result[&#039;board&#039;] = self::getObjectListFromDB( $sql );&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the board data to the &amp;lt;code&amp;gt;Gamedatas&amp;lt;/code&amp;gt; interface in the &amp;lt;code&amp;gt;yourgamename.d.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;interface Gamedatas {&lt;br /&gt;
    board: { x: number, y: number, player: number }[];&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file place the discs at the start of a page load:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;setup(gamedatas: Gamedatas): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &amp;quot;Starting game setup&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    // Place the tokens on the board&lt;br /&gt;
    for( let i in gamedatas.board )&lt;br /&gt;
    {&lt;br /&gt;
        let square = gamedatas.board[i];&lt;br /&gt;
&lt;br /&gt;
        if( square?.player ) // If square is defined and has a player&lt;br /&gt;
            this.addTokenOnBoard( square.x, square.y, square.player );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    this.setupNotifications(); // &amp;lt;-- Keep this line&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step6-5.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-7---game-states&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 7 - Game States ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the gamestates.jsonc file with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gamestates.schema.json&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    // The initial state. Please do not modify.&lt;br /&gt;
    &amp;quot;1&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;gameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stGameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: { &amp;quot;&amp;quot;: 10 }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;10&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;playerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;${actplayer} must play a disc&amp;quot;,&lt;br /&gt;
        &amp;quot;descriptionmyturn&amp;quot;: &amp;quot;${you} must play a disc&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;activeplayer&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot;: &amp;quot;argPlayerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;argsType&amp;quot;: {&lt;br /&gt;
            &amp;quot;possibleMoves&amp;quot;: &amp;quot;boolean[][]&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;possibleactions&amp;quot;: {&lt;br /&gt;
            &amp;quot;playDisc&amp;quot;: [&lt;br /&gt;
                { &amp;quot;name&amp;quot;: &amp;quot;x&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;AT_int&amp;quot; },&lt;br /&gt;
                { &amp;quot;name&amp;quot;: &amp;quot;y&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;AT_int&amp;quot; }&lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: {&lt;br /&gt;
            &amp;quot;playDisc&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;zombiePass&amp;quot;: 11&lt;br /&gt;
        }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;11&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;nextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;game&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stNextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;updateGameProgression&amp;quot;: true,&lt;br /&gt;
        &amp;quot;transitions&amp;quot;: {&lt;br /&gt;
            &amp;quot;nextTurn&amp;quot;: 10,&lt;br /&gt;
            &amp;quot;cantPlay&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;endGame&amp;quot;: 99&lt;br /&gt;
        }&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    // Final state.&lt;br /&gt;
    // Please do not modify (and do not overload action/args methods}.&lt;br /&gt;
    &amp;quot;99&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;gameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot;: &amp;quot;End of game&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot;: &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot;: &amp;quot;stGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot;: &amp;quot;argGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;argsType&amp;quot;: &amp;quot;object&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;There is a lot of information in this file. Most information can be found in the hover-over tooltips, but the [https://en.doc.boardgamearena.com/Your_game_state_machine:_states.inc.php Game States] page has more information about the concepts.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;This will automatically be converted to &amp;lt;code&amp;gt;gamestates.inc.php&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;build/gamestates.d.ts&amp;lt;/code&amp;gt; when you run &amp;lt;code&amp;gt;npm run build&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add placeholder functions to remove &amp;lt;code&amp;gt;Undefined method&amp;lt;/code&amp;gt; errors. Add the following to your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file. Note that this replaces the large section of comments in the file describing the player actions, state arguments, and state actions.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Player actions&lt;br /&gt;
function playDisc( int $x, int $y ) {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game state arguments&lt;br /&gt;
function argPlayerTurn() {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game state actions&lt;br /&gt;
function stNextPlayer() {&lt;br /&gt;
    /* TODO */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fix the &amp;lt;code&amp;gt;dummmy&amp;lt;/code&amp;gt; state errors in your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file. These are added as a placeholder and now cause issues because there is no gamestate with the name &amp;lt;code&amp;gt;dummmy&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;onEnteringState(stateName: GameStateName, args: CurrentStateArgs): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Entering state: &#039; + stateName );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
onLeavingState(stateName: GameStateName): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Leaving state: &#039; + stateName );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
onUpdateActionButtons(stateName: GameStateName, args: AnyGameStateArgs | null): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;onUpdateActionButtons: &#039; + stateName, args );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You should no longer have any type issues in any of your files.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
When you reload your game (this will cause current games to fail), your should see the banner change to &amp;lt;code&amp;gt;{actplayer} must play a disc&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;You must play a disc&amp;lt;/code&amp;gt;. This will be the only visible change in the game at this point.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step7-3.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-8---game-rules-and-possible-moves&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 8 - Game Rules and Possible Moves ==&lt;br /&gt;
&lt;br /&gt;
There are a couple of variations on the rules for Reversi, but the most common is with &amp;lt;code&amp;gt;outflanking rules&amp;lt;/code&amp;gt;. You can see the official rules at [https://www.worldothello.org/about/about-othello/othello-rules/official-rules/ World Othello]. There rules have been implemented with the following utility functions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Copy these functions into your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Get the complete board with a double associative array&lt;br /&gt;
function getBoard()&lt;br /&gt;
{&lt;br /&gt;
    $sql = &amp;quot;SELECT board_x x, board_y y, board_player player FROM board&amp;quot;;&lt;br /&gt;
    return self::getDoubleKeyCollectionFromDB( $sql, true );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the list of possible moves (x =&amp;gt; y =&amp;gt; true)&lt;br /&gt;
function getPossibleMoves( $player_id )&lt;br /&gt;
{&lt;br /&gt;
    $result = array();&lt;br /&gt;
&lt;br /&gt;
    $board = self::getBoard();&lt;br /&gt;
&lt;br /&gt;
    for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
    {&lt;br /&gt;
        for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
        {&lt;br /&gt;
            $returned = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
            if( count( $returned ) == 0 )&lt;br /&gt;
            {&lt;br /&gt;
                // No discs returned =&amp;gt; not a possible move&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // Okay =&amp;gt; set this coordinate to &amp;quot;true&amp;quot;&lt;br /&gt;
                if( ! isset( $result[$x] ) )&lt;br /&gt;
                    $result[$x] = array();&lt;br /&gt;
&lt;br /&gt;
                $result[$x][$y] = true;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return $result;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the list of returned disc when &amp;quot;player&amp;quot; we play at this place (&amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;),&lt;br /&gt;
//  or a void array if no disc is returned (invalid move)&lt;br /&gt;
function getTurnedOverDiscs( $x, $y, $player, $board )&lt;br /&gt;
{&lt;br /&gt;
    $turnedOverDiscs = array();&lt;br /&gt;
&lt;br /&gt;
    if( $board[ $x ][ $y ] === null ) // If there is already a disc on this place, this can&#039;t be a valid move&lt;br /&gt;
    {&lt;br /&gt;
        // For each directions...&lt;br /&gt;
        $directions = array(&lt;br /&gt;
            array( -1,-1 ), array( -1,0 ), array( -1, 1 ), array( 0, -1),&lt;br /&gt;
            array( 0,1 ), array( 1,-1), array( 1,0 ), array( 1, 1 )&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        foreach( $directions as $direction )&lt;br /&gt;
        {&lt;br /&gt;
            // Starting from the square we want to place a disc...&lt;br /&gt;
            $current_x = $x;&lt;br /&gt;
            $current_y = $y;&lt;br /&gt;
            $bContinue = true;&lt;br /&gt;
            $mayBeTurnedOver = array();&lt;br /&gt;
&lt;br /&gt;
            while( $bContinue )&lt;br /&gt;
            {&lt;br /&gt;
                // Go to the next square in this direction&lt;br /&gt;
                $current_x += $direction[0];&lt;br /&gt;
                $current_y += $direction[1];&lt;br /&gt;
&lt;br /&gt;
                if( $current_x&amp;lt;1 || $current_x&amp;gt;8 || $current_y&amp;lt;1 || $current_y&amp;gt;8 )&lt;br /&gt;
                    $bContinue = false; // Out of the board =&amp;gt; stop here for this direction&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] === null )&lt;br /&gt;
                    $bContinue = false; // An empty square =&amp;gt; stop here for this direction&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] != $player )&lt;br /&gt;
                {&lt;br /&gt;
                    // There is a disc from our opponent on this square&lt;br /&gt;
                    // =&amp;gt; add it to the list of the &amp;quot;may be turned over&amp;quot;, and continue on this direction&lt;br /&gt;
                    $mayBeTurnedOver[] = array( &#039;x&#039; =&amp;gt; $current_x, &#039;y&#039; =&amp;gt; $current_y );&lt;br /&gt;
                }&lt;br /&gt;
                else if( $board[ $current_x ][ $current_y ] == $player )&lt;br /&gt;
                {&lt;br /&gt;
                    // This is one of our disc&lt;br /&gt;
&lt;br /&gt;
                    if( count( $mayBeTurnedOver ) == 0 )&lt;br /&gt;
                    {&lt;br /&gt;
                        // There is no disc to be turned over between our 2 discs =&amp;gt; stop here for this direction&lt;br /&gt;
                        $bContinue = false;&lt;br /&gt;
                    }&lt;br /&gt;
                    else&lt;br /&gt;
                    {&lt;br /&gt;
                        // We found some disc to be turned over between our 2 discs&lt;br /&gt;
                        // =&amp;gt; add them to the result and stop here for this direction&lt;br /&gt;
                        $turnedOverDiscs = array_merge( $turnedOverDiscs, $mayBeTurnedOver );&lt;br /&gt;
                        $bContinue = false;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return $turnedOverDiscs;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the list of possible moves to the &amp;lt;code&amp;gt;argPlayerTurn&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function argPlayerTurn()&lt;br /&gt;
{&lt;br /&gt;
    $possibleMoves = self::getPossibleMoves( self::getActivePlayerId() );&lt;br /&gt;
    return array(&lt;br /&gt;
        &#039;possibleMoves&#039; =&amp;gt; $possibleMoves&lt;br /&gt;
    );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a css class to represent the possible moves in your &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;.possibleMove {&lt;br /&gt;
    background-color: rgba(255, 255, 255, 0.15);&lt;br /&gt;
    cursor: pointer;&lt;br /&gt;
    transition: 100ms;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.possibleMove:hover {&lt;br /&gt;
    background-color: rgba(255, 255, 255, 0.3);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the possible moves to the board when entering a new state by adding the following to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;// Utility methods&lt;br /&gt;
&lt;br /&gt;
/** Removes the &#039;possibleMove&#039; class from all elements. */&lt;br /&gt;
clearPossibleMoves() {&lt;br /&gt;
    document.querySelectorAll(&#039;.possibleMove&#039;).forEach(element =&amp;gt; {&lt;br /&gt;
        element.classList.remove(&#039;possibleMove&#039;);&lt;br /&gt;
    });&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/** Updates the squares on the board matching the possible moves. */&lt;br /&gt;
updatePossibleMoves( possibleMoves: boolean[][] )&lt;br /&gt;
{&lt;br /&gt;
    this.clearPossibleMoves();&lt;br /&gt;
&lt;br /&gt;
    for( var x in possibleMoves )&lt;br /&gt;
    {&lt;br /&gt;
        for( var y in possibleMoves[ x ] )&lt;br /&gt;
        {&lt;br /&gt;
            let square = $(`square_${x}_${y}`);&lt;br /&gt;
            if( !square )&lt;br /&gt;
                throw new Error( `Unknown square element: ${x}_${y}. Make sure the board grid was set up correctly in the tpl file.` );&lt;br /&gt;
            square.classList.add(&#039;possibleMove&#039;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    this.addTooltipToClass( &#039;possibleMove&#039;, &#039;&#039;, _(&#039;Place a disc here&#039;) );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Game &amp;amp; client states&lt;br /&gt;
&lt;br /&gt;
onEnteringState(stateName: GameStateName, args: CurrentStateArgs): void&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;Entering state: &#039;+stateName );&lt;br /&gt;
&lt;br /&gt;
    switch( stateName )&lt;br /&gt;
    {&lt;br /&gt;
        case &#039;playerTurn&#039;:&lt;br /&gt;
            this.updatePossibleMoves( args.args!.possibleMoves );&lt;br /&gt;
            break;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step8-4.png&amp;lt;br&amp;gt; &amp;lt;i&amp;gt;Reloading the game (with a hard refresh).&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The game is still not playable, but you can now see the possible moves for the first turn.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-9---player-actions&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 9 - Player Actions ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fill in the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    // Check that this player is active and that this action is possible at this moment&lt;br /&gt;
    self::checkAction( &#039;playDisc&#039; );&lt;br /&gt;
&lt;br /&gt;
    // Now, check if this is a possible move&lt;br /&gt;
    $board = self::getBoard();&lt;br /&gt;
    $player_id = self::getActivePlayerId();&lt;br /&gt;
    $turnedOverDiscs = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
&lt;br /&gt;
    if( count( $turnedOverDiscs ) &amp;lt;= 0 )&lt;br /&gt;
        throw new BgaSystemException( &amp;quot;Impossible move&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    // This move is possible!&lt;br /&gt;
&lt;br /&gt;
    // Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
    $sql = &amp;quot;UPDATE board SET board_player=&#039;$player_id&#039;&lt;br /&gt;
            WHERE ( board_x, board_y) IN ( &amp;quot;;&lt;br /&gt;
    foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
        $sql .= &amp;quot;(&#039;&amp;quot;.$turnedOver[&#039;x&#039;].&amp;quot;&#039;,&#039;&amp;quot;.$turnedOver[&#039;y&#039;].&amp;quot;&#039;),&amp;quot;;&lt;br /&gt;
    $sql .= &amp;quot;(&#039;$x&#039;,&#039;$y&#039;) ) &amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
    // Update scores according to the number of disc on board&lt;br /&gt;
    $sql = &amp;quot;UPDATE player&lt;br /&gt;
            SET player_score = (&lt;br /&gt;
            SELECT COUNT( board_x ) FROM board WHERE board_player=player_id&lt;br /&gt;
            )&amp;quot;;&lt;br /&gt;
    self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
    // Then, go to the next state&lt;br /&gt;
    $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fill in the &amp;lt;code&amp;gt;stNextPlayer&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function stNextPlayer()&lt;br /&gt;
{&lt;br /&gt;
    // Active next player&lt;br /&gt;
    $player_id = self::activeNextPlayer();&lt;br /&gt;
&lt;br /&gt;
    // Check if both player has at least 1 discs, and if there are free squares to play&lt;br /&gt;
    $sql = &amp;quot;SELECT board_player, COUNT( board_x ) FROM board&lt;br /&gt;
            GROUP BY board_player&amp;quot;;&lt;br /&gt;
    $player_to_discs = self::getCollectionFromDb( $sql, true );&lt;br /&gt;
&lt;br /&gt;
    if( ! isset( $player_to_discs[ null ] ) )&lt;br /&gt;
    {&lt;br /&gt;
        // Index 0 has not been set =&amp;gt; there&#039;s no more free place on the board !&lt;br /&gt;
        // =&amp;gt; end of the game&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        return ;&lt;br /&gt;
    }&lt;br /&gt;
    else if( ! isset( $player_to_discs[ $player_id ] ) )&lt;br /&gt;
    {&lt;br /&gt;
        // Active player has no more disc on the board =&amp;gt; he looses immediately&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        return ;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Can this player play?&lt;br /&gt;
&lt;br /&gt;
    $possibleMoves = self::getPossibleMoves( $player_id );&lt;br /&gt;
    if( count( $possibleMoves ) == 0 )&lt;br /&gt;
    {&lt;br /&gt;
        // This player can&#039;t play&lt;br /&gt;
        // Can his opponent play ?&lt;br /&gt;
        $opponent_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039; &amp;quot; );&lt;br /&gt;
        if( count( self::getPossibleMoves( $opponent_id ) ) == 0 )&lt;br /&gt;
        {&lt;br /&gt;
            // Nobody can move =&amp;gt; end of the game&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {            &lt;br /&gt;
            // =&amp;gt; pass his turn&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;cantPlay&#039; );&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
        // This player can play. Give him some extra time&lt;br /&gt;
        self::giveExtraTime( $player_id );&lt;br /&gt;
        $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;nextTurn&#039; );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Connect an &amp;lt;code&amp;gt;onclick&amp;lt;/code&amp;gt; function to all of the squares on the board:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;```typescript setup(gamedatas: Gamedatas): void { // … dojo.query( ‘.square’ ).connect( ‘onclick’, this, ‘onPlayDisc’ ); // … }&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the &amp;lt;code&amp;gt;onPlayDisc&amp;lt;/code&amp;gt; function to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;// Player&#039;s action&lt;br /&gt;
&lt;br /&gt;
/** Called when a square is clicked, check if it is a possible move and send the action to the server. */&lt;br /&gt;
onPlayDisc( evt: Event )&lt;br /&gt;
{&lt;br /&gt;
    // Stop this event propagation&lt;br /&gt;
    evt.preventDefault();&lt;br /&gt;
&lt;br /&gt;
    if (!(evt.currentTarget instanceof HTMLElement))&lt;br /&gt;
        throw new Error(&#039;evt.currentTarget is null! Make sure that this function is being connected to a DOM HTMLElement.&#039;);&lt;br /&gt;
&lt;br /&gt;
    // Check if this is a possible move&lt;br /&gt;
    if( !evt.currentTarget.classList.contains(&#039;possibleMove&#039;) )&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // Check that this action is possible at this moment (shows error dialog if not possible)&lt;br /&gt;
    if( !this.checkAction( &#039;playDisc&#039; ) )&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // Get the clicked square x and y&lt;br /&gt;
    // Note: square id format is &amp;quot;square_X_Y&amp;quot;&lt;br /&gt;
    let [_square_, x, y] = evt.currentTarget.id.split(&#039;_&#039;);&lt;br /&gt;
&lt;br /&gt;
    this.ajaxcall( `/${this.game_name}/${this.game_name}/playDisc.html`, {&lt;br /&gt;
        x, y, lock: true&lt;br /&gt;
    }, this, function() {} );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you should be able to play the game! However, you will need to reload the game after every move to force the board to update.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-10---notifications&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 10 - Notifications ==&lt;br /&gt;
&lt;br /&gt;
Notifications are used to inform players when something happens in the game. In our case, we only need to send one notification stating when the player has played a disc; however, it is often much more useful to send the notifications as a sequence of events so they can be automatically sequenced in the client. In this case, we will send three notifications:=, all of which can be sent from the player action function: - When a player plays a disc - When discs are converted because of a move - When the scores&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    // ...&lt;br /&gt;
&lt;br /&gt;
    // Notify&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;playDisc&amp;quot;, clienttranslate( &#039;${player_name} plays a disc and turns over ${returned_nbr} disc(s)&#039; ), array(&lt;br /&gt;
        &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
        &#039;player_name&#039; =&amp;gt; self::getActivePlayerName(),&lt;br /&gt;
        &#039;returned_nbr&#039; =&amp;gt; count( $turnedOverDiscs ),&lt;br /&gt;
        &#039;x&#039; =&amp;gt; $x,&lt;br /&gt;
        &#039;y&#039; =&amp;gt; $y&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;turnOverDiscs&amp;quot;, &#039;&#039;, array(&lt;br /&gt;
        &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
        &#039;turnedOver&#039; =&amp;gt; $turnedOverDiscs&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    $newScores = self::getCollectionFromDb( &amp;quot;SELECT player_id, player_score FROM player&amp;quot;, true );&lt;br /&gt;
    self::notifyAllPlayers( &amp;quot;newScores&amp;quot;, &amp;quot;&amp;quot;, array(&lt;br /&gt;
        &amp;quot;scores&amp;quot; =&amp;gt; $newScores&lt;br /&gt;
    ) );&lt;br /&gt;
&lt;br /&gt;
    // Then, go to the next state&lt;br /&gt;
    $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the notifications to your &amp;lt;code&amp;gt;NotifTypes&amp;lt;/code&amp;gt; interface in the &amp;lt;code&amp;gt;yourgamename.d.ts&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;interface NotifTypes {&lt;br /&gt;
    &#039;playDisc&#039;: { x: number, y: number, player_id: number };&lt;br /&gt;
    &#039;turnOverDiscs&#039;: {&lt;br /&gt;
        player_id: number,&lt;br /&gt;
        turnedOver: { x: number, y: number }[]&lt;br /&gt;
    },&lt;br /&gt;
    &#039;newScores&#039;: { scores: Record&amp;lt;number, number&amp;gt; };&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to your &amp;lt;code&amp;gt;yourgamename.ts&amp;lt;/code&amp;gt; file to listen and handle the notifications:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;typescript&amp;quot;&amp;gt;setupNotifications()&lt;br /&gt;
{&lt;br /&gt;
    console.log( &#039;notifications subscriptions setup&#039; );&lt;br /&gt;
&lt;br /&gt;
    dojo.subscribe( &#039;playDisc&#039;, this, &amp;quot;notif_playDisc&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;playDisc&#039;, 500 );&lt;br /&gt;
    dojo.subscribe( &#039;turnOverDiscs&#039;, this, &amp;quot;notif_turnOverDiscs&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;turnOverDiscs&#039;, 1000 );&lt;br /&gt;
    dojo.subscribe( &#039;newScores&#039;, this, &amp;quot;notif_newScores&amp;quot; );&lt;br /&gt;
    this.notifqueue.setSynchronous( &#039;newScores&#039;, 500 );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_playDisc( notif: NotifAs&amp;lt;&#039;playDisc&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    this.clearPossibleMoves();&lt;br /&gt;
    this.addTokenOnBoard( notif.args.x, notif.args.y, notif.args.player_id );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_turnOverDiscs( notif: NotifAs&amp;lt;&#039;turnOverDiscs&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    // Change the color of the turned over discs&lt;br /&gt;
    for( var i in notif.args.turnedOver )&lt;br /&gt;
    {&lt;br /&gt;
        let token_data = notif.args.turnedOver[ i ]!;&lt;br /&gt;
        let token = $&amp;lt;HTMLElement&amp;gt;( `token_${token_data.x}_${token_data.y}` );&lt;br /&gt;
&lt;br /&gt;
        if (!token)&lt;br /&gt;
            throw new Error( `Unknown token element: ${token_data.x}_${token_data.y}. Make sure the board grid was set up correctly in the tpl file.` );&lt;br /&gt;
&lt;br /&gt;
        token.classList.toggle(&#039;tokencolor_cbcbcb&#039;);&lt;br /&gt;
        token.classList.toggle(&#039;tokencolor_363636&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
notif_newScores( notif: NotifAs&amp;lt;&#039;newScores&#039;&amp;gt; )&lt;br /&gt;
{&lt;br /&gt;
    for( var player_id in notif.args.scores )&lt;br /&gt;
    {&lt;br /&gt;
        let counter = this.scoreCtrl[ player_id ];&lt;br /&gt;
        let newScore = notif.args.scores[ player_id ];&lt;br /&gt;
        if (counter &amp;amp;&amp;amp; newScore)&lt;br /&gt;
            counter.toValue( newScore );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;(optional) Add a flipping animation to the token when the classes:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;yourgamename_yourgamename.tpl&#039;&#039; &amp;lt;code&amp;gt;html  // Updated token template  var jstpl_token = &#039;&amp;amp;lt;div class=&amp;amp;quot;token-container tokencolor_${color}&amp;amp;quot; id=&amp;amp;quot;token_${x_y}&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-flip&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-white&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;div class=&amp;amp;quot;token-black&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&#039;;&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;yourgamename.scss&#039;&#039; ```scss .token-container { background-color: transparent; width: 56px; height: 56px; perspective: 250px; position: absolute; }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-flip { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 1.2s; transform-style: preserve-3d; border-radius:50%; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.25); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.tokencolor_363636 &amp;amp;gt; .token-flip { transform: rotateY(180deg); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-white, .token-black { position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; background-image: url(“img/tokens.png”); }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-white { background-position: 0px 0px; }&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;.token-black { background-position: -56px 0px; transform: rotateY(180deg); } ```&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step10-4.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, you now have a fully functional game that can be played on BGA. The following steps are to add flurishes and additional features to the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;optional-step-11---statistics&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== (optional) Step 11 - Statistics ==&lt;br /&gt;
&lt;br /&gt;
Statistics are mostly optional and are a fun way to compare player strategies or how much they have played the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the contents of &amp;lt;code&amp;gt;shared/stats.jsonc&amp;lt;/code&amp;gt; with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/stats.schema.json&amp;quot;,&lt;br /&gt;
    // All of these stats are tracked per player&lt;br /&gt;
    &amp;quot;player&amp;quot;: {&lt;br /&gt;
        &amp;quot;discPlayedOnCorner&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 10,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on a corner&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;discPlayedOnBorder&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 11,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on a border&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;discPlayedOnCenter&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 12,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Discs played on board center part&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;turnedOver&amp;quot;: {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 13,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Number of discs turned over&amp;quot;,&lt;br /&gt;
            &amp;quot;type&amp;quot;: &amp;quot;int&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Game_statistics:_stats.json stats.json] for more information about the stats file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function playDisc( int $x, int $y )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
    // Update scores...&lt;br /&gt;
&lt;br /&gt;
    // Statistics&lt;br /&gt;
    self::incStat( count( $turnedOverDiscs ), &amp;quot;turnedOver&amp;quot;, $player_id );&lt;br /&gt;
    if( ($x==1 &amp;amp;&amp;amp; $y==1) || ($x==8 &amp;amp;&amp;amp; $y==1) || ($x==1 &amp;amp;&amp;amp; $y==8) || ($x==8 &amp;amp;&amp;amp; $y==8) )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnCorner&#039;, $player_id );&lt;br /&gt;
    else if( $x==1 || $x==8 || $y==1 || $y==8 )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnBorder&#039;, $player_id );&lt;br /&gt;
    else if( $x&amp;gt;=3 &amp;amp;&amp;amp; $x&amp;lt;=6 &amp;amp;&amp;amp; $y&amp;gt;=3 &amp;amp;&amp;amp; $y&amp;lt;=6 )&lt;br /&gt;
        self::incStat( 1, &#039;discPlayedOnCenter&#039;, $player_id );&lt;br /&gt;
&lt;br /&gt;
    // Notify...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the statistics configuration on the manage game page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Play a game and verify that your new statistics are visible at the end of the game:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step11-3.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;optional-step-12---game-options&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== (Optional) Step 12 - Game Options ==&lt;br /&gt;
&lt;br /&gt;
Game options are a way for users to change game behavior or rules. As an example, we will be adding another rule variant called “Reversi Bombs” that flips all 8 adjacent discs when a disc is played.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/reversi_bombs_rules.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace your gameoptions with the following in the &amp;lt;code&amp;gt;shared/gameoptions.jsonc&amp;lt;/code&amp;gt; file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gameoptions.schema.json&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;100&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;Variant&amp;quot;,&lt;br /&gt;
        &amp;quot;values&amp;quot;: {&lt;br /&gt;
            // This is the current rule set we have implemented&lt;br /&gt;
            &amp;quot;1&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Standard&amp;quot;,&lt;br /&gt;
                &amp;quot;description&amp;quot;: &amp;quot;Flip all outflanked discs.&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;2&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Reversi Bombs&amp;quot;,&lt;br /&gt;
                &amp;quot;description&amp;quot;: &amp;quot;Flip all 8 adjacent discs.&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json gameoptions.json] for more information about the options file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Modify the &amp;lt;code&amp;gt;getTurnedOverDiscs&amp;lt;/code&amp;gt; function in your &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file to handle the new game option:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;function getTurnedOverDiscs( $x, $y, $player, $board )&lt;br /&gt;
{&lt;br /&gt;
    //...&lt;br /&gt;
&lt;br /&gt;
    foreach( $directions as $direction )&lt;br /&gt;
    {&lt;br /&gt;
        // If game option &#039;100&#039; is set to 2 (reversi bombs)&lt;br /&gt;
        if ($this-&amp;gt;gamestate-&amp;gt;table_globals[100] == 2)&lt;br /&gt;
        {&lt;br /&gt;
            $current_x = $x + $direction[0];&lt;br /&gt;
            $current_y = $y + $direction[1];&lt;br /&gt;
            if( $current_x&amp;lt;1 || $current_x&amp;gt;8 || $current_y&amp;lt;1 || $current_y&amp;gt;8 )&lt;br /&gt;
                continue; // Out of the board =&amp;gt; stop here for this direction&lt;br /&gt;
&lt;br /&gt;
            if ($board[ $current_x ][ $current_y ] !== null)&lt;br /&gt;
                // push the disc to be turned over&lt;br /&gt;
                $turnedOverDiscs[] = array( &#039;x&#039; =&amp;gt; $current_x, &#039;y&#039; =&amp;gt; $current_y );&lt;br /&gt;
&lt;br /&gt;
            continue; // Don&#039;t do standard game logic&lt;br /&gt;
        }&lt;br /&gt;
        // Standard...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //...&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Fix the &amp;lt;code&amp;gt;playDisc&amp;lt;/code&amp;gt; function to flip all turned disc instead of setting them to the active player:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
$other_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039;&amp;quot; );&lt;br /&gt;
$sql = &amp;quot;UPDATE board SET board_player = CASE WHEN board_player = &#039;$player_id&#039; THEN &#039;$other_id&#039; ELSE &#039;$player_id&#039; END WHERE (board_x, board_y) IN (&amp;quot;;&lt;br /&gt;
foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
    //...&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the game options from within the game manager page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step12-4.gif&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;user-preferences&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== User Preferences ==&lt;br /&gt;
&lt;br /&gt;
User preferences is something cosmetic about the game interface which you want users to be able to controll. Reversi has a classic athstetic, but in this example, we will add a user preference to change the color of the board. This is not a great use case for user preferences, but it is a simple example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace the contents of &amp;lt;code&amp;gt;shared/gamepreferences.jsonc&amp;lt;/code&amp;gt; with the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;$schema&amp;quot;: &amp;quot;../../node_modules/bga-ts-template/schema/gamepreferences.schema.json&amp;quot;,&lt;br /&gt;
    &amp;quot;101&amp;quot;: {&lt;br /&gt;
        &amp;quot;name&amp;quot;: &amp;quot;Game Style&amp;quot;,&lt;br /&gt;
        &amp;quot;needReload&amp;quot;: true,&lt;br /&gt;
        &amp;quot;values&amp;quot;: {&lt;br /&gt;
            &amp;quot;1&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Classic&amp;quot;,&lt;br /&gt;
                &amp;quot;cssPref&amp;quot;: &amp;quot;game_style_classic&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;2&amp;quot;: {&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Wooden&amp;quot;,&lt;br /&gt;
                // Then this is added to the page, we will override the image urls in the css.&lt;br /&gt;
                &amp;quot;cssPref&amp;quot;: &amp;quot;game_style_wooden&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
        &amp;quot;default&amp;quot;: 1&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;See [https://en.doc.boardgamearena.com/Options_and_preferences:_gameoptions.json,_gamepreferences.json gamepreferences.json] for more information about the options file for BGA games.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Download the following images and add them to your &amp;lt;code&amp;gt;img&amp;lt;/code&amp;gt; folder. They should be named ‘wooden_board.jpg’ and ‘wooden_tokens.png’.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot; width=&amp;quot;50%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/wooden_board.jpg&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/assets/wooden_tokens.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add the following to your &amp;lt;code&amp;gt;yourgamename.scss&amp;lt;/code&amp;gt; file to change the board and token images:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;scss&amp;quot;&amp;gt;// This overrides the #board + .token- images when the .game_style_wooden is automatically added to the page (by the user preference).&lt;br /&gt;
.game_style_wooden {&lt;br /&gt;
    #board {&lt;br /&gt;
        background-image: url(&#039;img/wooden_board.jpg&#039;);&lt;br /&gt;
    }&lt;br /&gt;
    .token-white, .token-black {&lt;br /&gt;
        background-image: url(&#039;img/wooden_tokens.png&#039;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Refresh the game options in the game manager page. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-3---game-information--metadata Step 3.3] for more information.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/game_configuration.png&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reload the game and change the user preference to see the new board and token images:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/reversi/step13-5.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Tutorials&amp;diff=20741</id>
		<title>BGA Type Safe Template: Tutorials</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=BGA_Type_Safe_Template:_Tutorials&amp;diff=20741"/>
		<updated>2024-04-11T19:16:55Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Converted this page from the github using a slightly modified version of Pandoc.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;This page was generated from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md BGA TS Template: README.md]. It is recommended to view this document from the source file. All links will redirect to source documentation, and images will only be included via link.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;ts-template-tutorials&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= TS Template: Tutorials =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NevinAF/bga-ts-template?tab=readme-ov-file#board-game-arena-type-safe-template &#039;&#039;BGA Type Safe Template&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
All tutorials are beginner friendly and are designed to help you get started with the BGA Type Safe Template. Each tutorial will link to this page for the first four steps which are shared for any project you are working.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;tutorial-list&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Tutorial List ==&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/reversi.md Reversi]: A two player turn-based, perfect knowledge strategy game. Great starting point, meant for learning the purpose of each file and quickly getting a game up and running. Less good for learning internal components and framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-0---development-environment-setup&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 0 - Development Environment Setup ==&lt;br /&gt;
&lt;br /&gt;
No matter what you are doing, the first step is to always prepare your development tools. There are many different ways to set up your development environment, and many different tools to choose from.&lt;br /&gt;
&lt;br /&gt;
Board Game Arena requires some sort of [https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol SFTP client], but that’s about it. Adding on to that, the Type Safe Template requires [https://nodejs.org/en/ Node.js] to initialize and build the project. Everything else is up to the developer or team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&#039;&#039;&#039;S&#039;&#039;&#039;ecure &#039;&#039;&#039;F&#039;&#039;&#039;ile &#039;&#039;&#039;T&#039;&#039;&#039;ransfer &#039;&#039;&#039;P&#039;&#039;&#039;rotocol (SFTP) essentially describes how to upload and download files from a network drive, not that different from Google Drive or Dropbox.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The official BGA team recommends [https://code.visualstudio.com/ Visual Studio Code] and a specific set of extensions for development. Based on this, the following steps are a quick guide for anyone who is starting from scratch or unsure of what to do.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;This is labeled as step 0 because it only ever needs to be down once. If you already have these tools installed and set up, you can skip this step.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;recommended-tools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Recommended Tools ===&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;[https://code.visualstudio.com/ Visual Studio Code]&#039;&#039;&#039;: A code editor with a wide range of extensions and features. Using VS Code will provide automatic code completion, syntax highlighting, and many other features that make development easier. Download [https://code.visualstudio.com/download VS Code here.]&lt;br /&gt;
# &#039;&#039;&#039;[https://nodejs.org/en/download/ Node.js]&#039;&#039;&#039;: A JavaScript runtime which is used to initialize and build source files to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;A node version manager is also recommended for managing multiple versions of node.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;[https://docs.npmjs.com/about-npm Node Package Manager (npm)]&#039;&#039;&#039;: A package manager for JavaScript. This will be used to automatically install and manage the dependencies,including the BGA Type Safe Template.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Once you have node.js installed, you can install npm by simply running the following in the terminal:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;bash&amp;quot;&amp;gt;npm install -g npm&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;[https://marketplace.visualstudio.com/items?itemName=nevinfoster.bga-extension-pack BGA Extension Pack]&#039;&#039;&#039;: A collection of VS Code extensions that are useful for BGA development. This includes syntax highlighting for BGA files, a BGA icon theme, and more.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;(optional) &#039;&#039;&#039;[https://git-scm.com/downloads Git]&#039;&#039;&#039;: One of the most populate version control systems. This is used to track changes to your code and collaborate easily with others. Nearly all BGA developers use [https://github.com GitHub] to share their code, which is built on top of Git.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_vscode.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_nodejs.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_npm.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/download_git.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-1---create-a-new-project&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 1 - Create a New Project ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Go to [https://studio.boardgamearena.com studio.boardgamearena.com] and login. Then navigate to your [https://studio.boardgamearena.com/studio manage games] page:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on your profile icon on the top right of any page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the Control Panel button on the top right. This is only visible if you are on a developer account.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the Manage Games button on the left side of the page.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_create_new_project.gif&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Create new project&#039;&#039;&#039;. You only need to fill out the name of the game, usually something like &amp;lt;code&amp;gt;&amp;amp;lt;UserName&amp;amp;gt;Tutorial&amp;amp;lt;Game&amp;amp;gt;&amp;lt;/code&amp;gt; for a first project.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;This should always be in upper camel case (Pascal Case) with no spaces or special characters. This is because the project name is used in the URL of the game, and the URL is case sensitive.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Create a local folder&#039;&#039;&#039; for the project files. Something like &amp;lt;code&amp;gt;C:\Users\&amp;amp;lt;UserName&amp;amp;gt;\Documents\BGA\&amp;amp;lt;project-name&amp;amp;gt;&amp;lt;/code&amp;gt; is a good place to start.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Use SFTP client to download the project files&#039;&#039;&#039; to the folder you just created. If you are using the recommended tools for development, you can do the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: lower-alpha;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Open the new folder in VS Code&#039;&#039;&#039;. You can open VS Code and use the &amp;lt;code&amp;gt;File &amp;amp;gt; Open Folder&amp;lt;/code&amp;gt; to open the specific folder you created.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the [[command:sftp.config|SFTP: Config]] command&#039;&#039;&#039;. You can do this by pressing &amp;lt;code&amp;gt;Ctrl+Shift+P&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;F1&amp;lt;/code&amp;gt;) to open the command palette, then typing &amp;lt;code&amp;gt;SFTP: Config&amp;lt;/code&amp;gt; and pressing enter.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Paste the following&#039;&#039;&#039; into the created &amp;lt;code&amp;gt;.vscode/sftp.json&amp;lt;/code&amp;gt; file, then update the username, password, and remotePath fields with your own information. The username and password will have been emailed when signing up for a developer account::&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;___YourUsername___&amp;quot;,&lt;br /&gt;
    &amp;quot;password&amp;quot;: &amp;quot;___yourpassword_hexstring___&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/___lowercaseprojectname___/&amp;quot;,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.vscode&amp;quot;,&lt;br /&gt;
        &amp;quot;.git&amp;quot;,&lt;br /&gt;
        &amp;quot;.idea&amp;quot;,&lt;br /&gt;
        &amp;quot;.gitignore&amp;quot;,&lt;br /&gt;
        &amp;quot;.DS_Store&amp;quot;,&lt;br /&gt;
        &amp;quot;node_modules&amp;quot;,&lt;br /&gt;
        &amp;quot;package-lock.json&amp;quot;,&lt;br /&gt;
        &amp;quot;yarn.lock&amp;quot;,&lt;br /&gt;
        &amp;quot;nmp-debug.log&amp;quot;,&lt;br /&gt;
        &amp;quot;yarn-error.log&amp;quot;,&lt;br /&gt;
        &amp;quot;source/client/build&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: lower-alpha;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;&#039;Run the [[command:sftp.sync.remoteToLocal|SFTP: Sync Remote -&amp;amp;gt; Local]]&#039;&#039;&#039; command. This will download all initial files from the BGA server to your local folder.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot; width=&amp;quot;50%&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_starting_files.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;When viewing files in VS Code, the php files will have errors because the shared codes in not yet linked. This will be resolved in the next step.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;5&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the game&#039;&#039;&#039; to make sure everything is working correctly. You can run tests filled with your developer accounts by using &amp;lt;code&amp;gt;Express Start&amp;lt;/code&amp;gt; when setting up to play a game.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Navigate to the &amp;lt;code&amp;gt;Manage Games&amp;lt;/code&amp;gt; page as described in step 1.1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on any games in your list of games.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Play&amp;lt;/code&amp;gt; from within the list of options on one of your game’s versions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Create A Table&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;lt;code&amp;gt;Express Start&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_test_game.gif&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/bga_open_dev_player.png&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You can play as any of the connected developer accounts by clicking on the red &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt; next to any of the players’ names.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-2---initialize-the-bga-type-safe-template&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 2 - Initialize the BGA Type Safe Template ==&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;Create a &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; file&#039;&#039;&#039;, and fill it with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;json&amp;quot;&amp;gt;{&lt;br /&gt;
    &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
        &amp;quot;init&amp;quot;: &amp;quot;npm install bga-ts-template &amp;amp;&amp;amp; npx bga-init YourGameName \&amp;quot;developers\&amp;quot; source --typescript --scss --vscode-extension-pack --php-8.2 --gameinfos.jsonc --gameoptions.jsonc --gamepreferences.jsonc --stats.jsonc --gamestates.jsonc&amp;quot;,&lt;br /&gt;
        &amp;quot;build&amp;quot;: &amp;quot;npx bga-build&amp;quot;,&lt;br /&gt;
        &amp;quot;watch&amp;quot;: &amp;quot;npx bga-build --watch&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Change the &amp;lt;code&amp;gt;YourGameName&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;developers&amp;lt;/code&amp;gt; arguments&#039;&#039;&#039; to fit your project. You can also change any of the other arguments to fit your needs. See the [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#configurations BGA Type Safe Template: Configurations] for more information.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt; script&#039;&#039;&#039;. This can be done using a terminal on the project directory, or in VS Code by hovering over the &amp;lt;code&amp;gt;scripts: &amp;amp;quot;init&amp;amp;quot;&amp;lt;/code&amp;gt; line in the &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; file. You can see more information about the package.json scripts at [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#package-scripts BGA Type Safe Template: Package Scripts].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/package_json_run_script.gif&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;View your files.&#039;&#039;&#039; You should now only have a trhee error among all of your files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;One issue in &amp;lt;code&amp;gt;yourgamename.game.php&amp;lt;/code&amp;gt; file, usually on line 75, and is a syntax error caused by a minor bug in the starting files.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Error: Expected type &#039;null|array&#039;. Found &#039;string&#039;&lt;br /&gt;
$sql .= implode( $values, &#039;,&#039; ); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;// Fixed!&lt;br /&gt;
$sql .= implode( &#039;,&#039;, $values ); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Two issues in &amp;lt;code&amp;gt;yourgamename.action.php&amp;lt;/code&amp;gt;, one for each player action. This is a type error stating that your main game code does not have the player action functions defined (which is true!). This will be fixed later when adding player actions.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;public function playCard()&lt;br /&gt;
{&lt;br /&gt;
    self::setAjaxMode();&lt;br /&gt;
&lt;br /&gt;
    /** @var int $card_id */&lt;br /&gt;
    $card_id = self::getArg(&#039;card_id&#039;, AT_int, true);&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;playCard( $card_id ); // Error: Undefined method&lt;br /&gt;
    self::ajaxResponse();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;php&amp;quot;&amp;gt;public function pass()&lt;br /&gt;
{&lt;br /&gt;
    self::setAjaxMode();&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;game-&amp;gt;pass(  ); // Error: Undefined method&lt;br /&gt;
    self::ajaxResponse();&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Sync your local files to the BGA server. When using VS Code SFTP extension, &#039;&#039;&#039;run the [[command:sftp.sync.localToRemote|SFTP: Sync Local -&amp;amp;gt; Remote]] command&#039;&#039;&#039;. &#039;&#039;This is only needed the first time you upload, or if you change files when VS code is not running (ie, the extension is not active).&#039;&#039;&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Run the game in the BGA studio&#039;&#039;&#039;. See [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-1---create-a-new-project step 1.5] for more information on how to do this.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&#039;&#039;&#039;Hard Refresh the client page&#039;&#039;&#039;. You should ALWAYS do a hard refresh when making changes, otherwise you will likely be using old cached files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;Windows&#039;&#039;: Chrome, Firefox, or Edge =&amp;amp;gt; Press &amp;lt;code&amp;gt;Ctrl+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Shift+F5&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Ctrl+Shift+R&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;Mac&#039;&#039;: Chrome or Firefox =&amp;amp;gt; Press &amp;lt;code&amp;gt;Cmd+Shift+R&amp;lt;/code&amp;gt;. Safari =&amp;amp;gt; Press &amp;lt;code&amp;gt;Cmd+Option+E&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;There are no differences, but running the game makes sure that everything is working correctly.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;step-3---game-information-metadata&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Step 3 - Game Information + Metadata ==&lt;br /&gt;
&lt;br /&gt;
A good portion of this information is optional, but it is always good practice to fill out as much as possible for all projects.&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;Update &amp;lt;code&amp;gt;shared/gameinfos.jsonc&amp;lt;/code&amp;gt;&#039;&#039;&#039;. The [https://en.doc.boardgamearena.com/Game_meta-information:_gameinfos.inc.php Game Infos] contains all meta-information for the game such as the full name and number of players. Each value in the file has hover-able tooltips for more information and will show error if there are any validation issues.&lt;br /&gt;
# &#039;&#039;&#039;Run &amp;lt;code&amp;gt;npm run build&amp;lt;/code&amp;gt;&#039;&#039;&#039;. This will convert your json to the &amp;lt;code&amp;gt;gameinfos.inc.php&amp;lt;/code&amp;gt; file which is used by the BGA server. See the [https://github.com/NevinAF/bga-ts-template/blob/main/README.md#package-scripts BGA Type Safe Template: Package Scripts] for more information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You can also run &amp;lt;code&amp;gt;npm run watch&amp;lt;/code&amp;gt; to automatically build any files whenever they are changed.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;3&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go to the manage game page for your game and &#039;&#039;&#039;select Reload game informations&#039;&#039;&#039;. This must be clicked whenever the &amp;lt;code&amp;gt;gameinfos&amp;lt;/code&amp;gt; file is updated.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;The manage game page for a game can always be found by going to the &amp;lt;code&amp;gt;Manage Games&amp;lt;/code&amp;gt; page from [https://github.com/NevinAF/bga-ts-template/blob/main/docs/tutorials/index.md#step-1---create-a-new-project Step 1.1], then clicking on the game you want to manage.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/NevinAF/bga-ts-template/tree/main/docs/tutorials/img/game_configuration.png&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;From the same location in step 3.3, click on &amp;lt;code&amp;gt;Manage metadata images&amp;lt;/code&amp;gt; to edit all visual/informational metadata of the game. See the [https://en.doc.boardgamearena.com/Game_metadata_manager Game Metadata Manager] wiki page for more information.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After steps 3.3 and 3.4, your can view your game’s &amp;lt;code&amp;gt;game page&amp;lt;/code&amp;gt; verify that you see the corrected information.&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20646</id>
		<title>Setting up BGA Development environment using VSCode</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Setting_up_BGA_Development_environment_using_VSCode&amp;diff=20646"/>
		<updated>2024-04-04T00:33:41Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: /* Extensions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Microsoft Visual Studio Code is light weight IDE/Editor. All desktops.&lt;br /&gt;
&lt;br /&gt;
== Downloads ==&lt;br /&gt;
&lt;br /&gt;
* Download and install vscode from https://code.visualstudio.com&lt;br /&gt;
* Download and install php (7.4) command line interface (for local tests and debugging)&lt;br /&gt;
&lt;br /&gt;
== Extensions ==&lt;br /&gt;
Use [https://marketplace.visualstudio.com/items?itemName=NevinFoster.bga-extension-pack&amp;amp;ssr=false#overview BGA Extension Pack] to download all of the recommended extensions with one click.&lt;br /&gt;
* PHP Intelephense - https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client&lt;br /&gt;
* Or PHP IntelliSense - https://marketplace.visualstudio.com/items?itemName=zobo.php-intellisense&lt;br /&gt;
* PHP Debug - https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug&lt;br /&gt;
* SQLTools - https://marketplace.visualstudio.com/items?itemName=mtxr.sqltools&lt;br /&gt;
* Prettier - code formatter - https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&lt;br /&gt;
* SFTP (by Natizyskunk) -  https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp&lt;br /&gt;
&lt;br /&gt;
== Intellisense - Navigation/Auto-complete ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Intellisense ===&lt;br /&gt;
&lt;br /&gt;
Because of dojo style class/method declarations most IDE won&#039;t be able to index main JavaScript file properly (i.e. go to definition of function and such).&lt;br /&gt;
If you manage to get it working in VS code, let us know how.&lt;br /&gt;
&lt;br /&gt;
There is a way to re-structure code to avoid using this style, but this is not for beginners. Do not use this on your first game!&lt;br /&gt;
https://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Avoiding_code_in_dojo_declare_style&lt;br /&gt;
&lt;br /&gt;
There is also a complete example of a &amp;quot;dojo-less&amp;quot; project, it also includes a (incomplete) typescript definition file (.d.ts) for auto-completion of js BGA interfaces&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== PHP Intellisense ===&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t do anything PHP will complain about undefined symbols from BGA framework (as well as from the material file).&lt;br /&gt;
To solve the warning about framework issues, you need a stubs for the BGA APIs:&lt;br /&gt;
&lt;br /&gt;
* git clone git@github.com:elaskavaia/bga-sharedcode.git (you can also get and unzip it from the GitHub page) &lt;br /&gt;
** if that doesn&#039;t work, try git clone &amp;lt;nowiki&amp;gt;https://github.com/elaskavaia/bga-sharedcode.git&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
** you can do this in a terminal from VS Code - Terminal menu -&amp;gt; New Terminal&lt;br /&gt;
* add reference (include path) to bga-sharedcode/misc using settings of PHP extension, see example below&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using the Intelephense plugin, add this to global user settings (modify the path obviously)&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;intelephense.environment.includePaths&amp;quot;: [&lt;br /&gt;
        &amp;quot;/home/victoria/git/bga-sharedcode/misc/&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To solve the warning about the material file class members&lt;br /&gt;
&lt;br /&gt;
Option 1)&lt;br /&gt;
If you don&#039;t have too many class members you can define them, for example if I have $this-&amp;gt;token_types = [...] in the material file I can define them in in the class of game.php&lt;br /&gt;
&lt;br /&gt;
    private $token_types;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Option 2) &lt;br /&gt;
&lt;br /&gt;
Put this line in the settings.json if you using Intelliphense extension to ignore them:&lt;br /&gt;
&lt;br /&gt;
   &amp;quot;intelephense.diagnostics.undefinedProperties&amp;quot;: false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Unit testing ===&lt;br /&gt;
&lt;br /&gt;
If using phpunit, install it via composer somewhere in home directory, i.e.&lt;br /&gt;
   cd /home/victoria/php-composer&lt;br /&gt;
   composer require --dev phpunit/phpunit ^9&lt;br /&gt;
&lt;br /&gt;
Then add this path (e.x.  /home/victoria/php-composer) to include paths as above&lt;br /&gt;
&lt;br /&gt;
See more about unit testing in [[Testing by developer]]&lt;br /&gt;
&lt;br /&gt;
== File Sync ==&lt;br /&gt;
You can set up your sync using other methods, not related to vscode (such as rsync), if you want to do that see [[Tools_and_tips_of_BGA_Studio#File_Sync]] otherwise see below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You might rely on your IDE to sync the files with the SFTP server. Each time you &amp;quot;save&amp;quot; a file with your modifications, the IDE will also submit it to the sFTP server. These are instructions for VS Code&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Install this extension&#039;&#039;&#039; https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp (File-&amp;gt;Preferences-&amp;gt;Extensions ... type SFTP and make sure its by Natizyskunk)&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Open VSCode on an empty folder&#039;&#039;&#039; that will be the local root of your project.&lt;br /&gt;
&lt;br /&gt;
* Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: config&amp;quot;&#039;&#039;&#039; - the edit will open with json config&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Update the json&#039;&#039;&#039; as below: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;your SFTP username&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;password&amp;quot;: &amp;quot;&amp;lt;your SFTP password&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;your project name&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.vscode&amp;quot;,&lt;br /&gt;
        &amp;quot;.git&amp;quot;,&lt;br /&gt;
        &amp;quot;.DS_Store&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, # syncs new files&lt;br /&gt;
        &amp;quot;delete&amp;quot;: true # syncs deleted files&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== One time only - first sync ===&lt;br /&gt;
&lt;br /&gt;
- Execute Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac to open the command palette, and the type/run : &#039;&#039;&#039;&amp;quot;SFTP: Download Project&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This will download all the files locally. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Daily use ===&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to do anything else! Each time you modify/save a file in VSCode, it will upload it to the SFTP Server.&lt;br /&gt;
&lt;br /&gt;
To force upload to a server, execute Ctrl+Shift+P -&amp;gt; &#039;&#039;&#039;&amp;quot;SFTP: Sync Local -&amp;gt; Remote&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note: the SFTP sync may fail with a permissions error when create or delete nested folders. To fix this, execute `chmod -R 755 &amp;lt;your directory name&amp;gt;` in your terminal, then force sync to remote.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Split settings for version control ===&lt;br /&gt;
If you want to commit this file to version control, use private key (upload ssh key https://studio.boardgamearena.com/controlpanel) instead and move user/password settings into vscode user settings&lt;br /&gt;
&lt;br /&gt;
I.e. in user setting add this (have to edit settings.js manually, google for location its os specific)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;quot;remotefs.remote&amp;quot;: {&lt;br /&gt;
        &amp;quot;bgadev&amp;quot;: {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;BGA&amp;quot;,&lt;br /&gt;
            &amp;quot;host&amp;quot;: &amp;quot;1.studio.boardgamearena.com&amp;quot;,&lt;br /&gt;
            &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
            &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
            &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;yourdevusername&amp;gt;&amp;quot;,&lt;br /&gt;
            &amp;quot;privateKeyPath&amp;quot;: &amp;quot;~/.ssh/id_rsa&amp;quot;,&lt;br /&gt;
        },&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in project folder sftp.json (replace &amp;lt;yourproject&amp;gt; with project name)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;remote&amp;quot;: &amp;quot;bgadev&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/&amp;lt;yourproject&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;ignore&amp;quot;: [&lt;br /&gt;
        &amp;quot;.git&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;syncOption&amp;quot;: {&lt;br /&gt;
        &amp;quot;skipCreate&amp;quot;: false, &lt;br /&gt;
        &amp;quot;delete&amp;quot;: true &lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;watcher&amp;quot;: {&lt;br /&gt;
        &amp;quot;files&amp;quot;: &amp;quot;**/*.{js,css}&amp;quot;,&lt;br /&gt;
        &amp;quot;autoUpload&amp;quot;: true,&lt;br /&gt;
        &amp;quot;autoDelete&amp;quot;: true&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: you don&#039;t need watcher section if you don&#039;t use code generators, but its needed if you use typescript, scss or similar code generator tools.&lt;br /&gt;
&lt;br /&gt;
== Code Formatter ==&lt;br /&gt;
I think Prettier has better format, you can install Prettier plugin to do the formatting, for PHP add the following in package.json&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
    &amp;quot;@prettier/plugin-php&amp;quot;: &amp;quot;^0.19.1&amp;quot;,&lt;br /&gt;
    &amp;quot;prettier&amp;quot;: &amp;quot;^2.7.1&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;prettier&amp;quot;: {&lt;br /&gt;
    &amp;quot;braceStyle&amp;quot;: &amp;quot;1tbs&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== Code generators ==&lt;br /&gt;
If you want to run code generators for example for typescript or scss you can install this extension:&lt;br /&gt;
* https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave &lt;br /&gt;
&lt;br /&gt;
In settings.json add these (example only):&lt;br /&gt;
    &amp;quot;emeraldwalk.runonsave&amp;quot;: {&lt;br /&gt;
        &amp;quot;commands&amp;quot;: [&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.ts$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:ts&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;match&amp;quot;: &amp;quot;.*\\.scss$&amp;quot;,&lt;br /&gt;
                &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
                &amp;quot;cmd&amp;quot;: &amp;quot;npm run build:scss&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        ]&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
In this example &amp;lt;code&amp;gt;build:ts&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;build:scss&amp;lt;/code&amp;gt; are scripts configured via package.json&lt;br /&gt;
&lt;br /&gt;
Another example - you can run php script that will generate material.inc.php from misc/xxx_material.csv&lt;br /&gt;
      {&lt;br /&gt;
        &amp;quot;match&amp;quot;: &amp;quot;misc/.*material\\.csv$&amp;quot;,&lt;br /&gt;
        &amp;quot;isAsync&amp;quot;: true,&lt;br /&gt;
        &amp;quot;cmd&amp;quot;: &amp;quot;php7.4 ${env.HOME}/git/bga-sharedcode/misc/genmat.php ${file}&amp;quot;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
== User templates ==&lt;br /&gt;
&lt;br /&gt;
You can define user template to avoid writing boilerplate code, here is example of php template for states&lt;br /&gt;
(it is placed in global location php.json - you can open it from the gui File-&amp;gt;Preferences-&amp;gt;Configure User Snippets and type php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Single player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;state&amp;quot;, &amp;quot;playerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT playerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;\\${actplayer} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;activeplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;st_playerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_PLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_PLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create single player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Multiple player state&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;mstate&amp;quot;, &amp;quot;multiplayerstate&amp;quot;],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;$LINE_COMMENT mplayerTurn${1:something}&amp;quot;,&lt;br /&gt;
      &amp;quot;${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;name&#039; =&amp;gt; &#039;mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;description&#039; =&amp;gt; clienttranslate(&#039;Other players must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;descriptionmyturn&#039; =&amp;gt; clienttranslate(&#039;\\${you} must ${1:something}&#039;),&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;type&#039; =&amp;gt; &#039;multipleactiveplayer&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;args&#039;=&amp;gt;&#039;arg_mplayerTurn${1:something}&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;action&#039;=&amp;gt;&#039;stMakeEveryoneActive&#039;,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;possibleactions&#039; =&amp;gt; [ &#039;playCard&#039;, &#039;pass&#039; ],&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;transitions&#039; =&amp;gt; [&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;next&#039; =&amp;gt; STATE_GAME_TURN_NEXT_MPLAYER,&amp;quot;,&lt;br /&gt;
      &amp;quot;&#039;loopback&#039; =&amp;gt; ${1/(.*)/STATE_MPLAYER_TURN_${1:/upcase}/} ]&amp;quot;,&lt;br /&gt;
      &amp;quot;],&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;description&amp;quot;: &amp;quot;Create multi player state defition, use tab to fill template parameters&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Action in action.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;action&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;public function ${1:actionName}() {&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::setAjaxMode();&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$${2:arg} = self::getArg(&#039;${2:arg}&#039;, AT_posint, false, 0);&amp;quot;,&lt;br /&gt;
      &amp;quot;\t\\$this-&amp;gt;game-&amp;gt;action_${1:actionName}(\\$${2:arg});&amp;quot;,&lt;br /&gt;
      &amp;quot;\tself::ajaxResponse();&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  },&lt;br /&gt;
  &amp;quot;Player loop in game.php&amp;quot;: {&lt;br /&gt;
    &amp;quot;prefix&amp;quot;: [&amp;quot;players&amp;quot;],&lt;br /&gt;
    &amp;quot;body&amp;quot;: [&lt;br /&gt;
      &amp;quot;\\$players = \\$this-&amp;gt;loadPlayersBasicInfos();&amp;quot;,&lt;br /&gt;
      &amp;quot;foreach (\\$players as \\$player_id =&amp;gt; \\$player_info) {&amp;quot;,&lt;br /&gt;
      &amp;quot;${1}&amp;quot;,&lt;br /&gt;
      &amp;quot;}&amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20509</id>
		<title>Using Typescript and Scss</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Using_Typescript_and_Scss&amp;diff=20509"/>
		<updated>2024-03-18T23:03:47Z</updated>

		<summary type="html">&lt;p&gt;NevinAF: Added NevinAF ts template to the Referenced Projects&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will help you set up your project to use Typescript client file and Scss style files, and automatically build Javascript (in ES5) files and CSS files so your project stay compatible to BGA framework requirements.&lt;br /&gt;
You can use only TS or only SCSS part if you want, they are not linked.&lt;br /&gt;
&lt;br /&gt;
== Install and configure ==&lt;br /&gt;
&lt;br /&gt;
=== Install dev stack  ===&lt;br /&gt;
Install node/npm.  Here is an example to activate auto-build in Visual Studio Code, if you use another tool I strongly recommend to find an equivalent so you don&#039;t have to launch build manually after each modification.&lt;br /&gt;
&lt;br /&gt;
=== Configure package.json and tsconfig.json ===&lt;br /&gt;
&lt;br /&gt;
Create a file named &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt; on the root folder, not on the src folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;package.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
   &amp;quot;name&amp;quot;: &amp;quot;yourgamename&amp;quot;,&lt;br /&gt;
   &amp;quot;version&amp;quot;: &amp;quot;1.0.0&amp;quot;,&lt;br /&gt;
   &amp;quot;description&amp;quot;: &amp;quot;&amp;quot;,&lt;br /&gt;
   &amp;quot;main&amp;quot;: &amp;quot;YourGameName.js&amp;quot;,&lt;br /&gt;
   &amp;quot;scripts&amp;quot;: {&lt;br /&gt;
     &amp;quot;build:ts&amp;quot;: &amp;quot;tsc&amp;quot;,&lt;br /&gt;
     &amp;quot;build:scss&amp;quot;: &amp;quot;sass --no-source-map src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:ts&amp;quot;: &amp;quot;tsc --watch&amp;quot;,&lt;br /&gt;
     &amp;quot;watch:scss&amp;quot;: &amp;quot;sass --watch src/yourgamename.scss yourgamename.css&amp;quot;,&lt;br /&gt;
     &amp;quot;watch&amp;quot;: &amp;quot;npm run watch:ts &amp;amp;&amp;amp; npm run watch:scss&amp;quot;,&lt;br /&gt;
     &amp;quot;build&amp;quot;: &amp;quot;npm run build:ts &amp;amp;&amp;amp; npm run build:scss&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;author&amp;quot;: &amp;quot;yourname&amp;quot;,&lt;br /&gt;
   &amp;quot;license&amp;quot;: &amp;quot;MIT&amp;quot;,&lt;br /&gt;
   &amp;quot;devDependencies&amp;quot;: {&lt;br /&gt;
     &amp;quot;sass&amp;quot;: &amp;quot;^1.32.6&amp;quot;,&lt;br /&gt;
     &amp;quot;typescript&amp;quot;: &amp;quot;^4.1.3&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: if you not using scss - remove corresponding scripts and deps.&lt;br /&gt;
&lt;br /&gt;
When package.json is created, run &amp;lt;code&amp;gt;npm i&amp;lt;/code&amp;gt; on the root folder to install builders (will generate a node_modules folder).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For Typescript compilation we also need to set up a &amp;lt;code&amp;gt;tsconfig.json&amp;lt;/code&amp;gt; on the root folder.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tsconfig.json&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;rootDir&amp;quot;: &amp;quot;.&amp;quot;, &lt;br /&gt;
     &amp;quot;compilerOptions&amp;quot;: {&lt;br /&gt;
       &amp;quot;target&amp;quot;: &amp;quot;es5&amp;quot;,&lt;br /&gt;
       &amp;quot;module&amp;quot;: &amp;quot;none&amp;quot;,&lt;br /&gt;
       &amp;quot;lib&amp;quot;: [&amp;quot;dom&amp;quot;, &amp;quot;esnext&amp;quot;],  &lt;br /&gt;
       &amp;quot;sourceMap&amp;quot;: false,&lt;br /&gt;
       &amp;quot;typeRoots&amp;quot;: [&amp;quot;src/types&amp;quot;, &amp;quot;./types&amp;quot;, &amp;quot;./node_modules/@types&amp;quot;],&lt;br /&gt;
       &amp;quot;outFile&amp;quot;: &amp;quot;YourGameName.js&amp;quot;&lt;br /&gt;
     },&lt;br /&gt;
     &amp;quot;files&amp;quot;: [&lt;br /&gt;
         &amp;quot;src/GameBody.ts&amp;quot;,&lt;br /&gt;
         &amp;quot;src/define.ts&amp;quot;&lt;br /&gt;
     ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: it only works now with es5&lt;br /&gt;
&lt;br /&gt;
If you want to split your code onto multiple files, just add them in the file list (order is important for dependencies, new subpart should go on top of the list). No need to import classes or types from one file to another. In fact, you can&#039;t with this configuration. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create skeleton ==&lt;br /&gt;
When you create your game in BGA Studio, a JS and CSS file are generated. As we will overwrite them with autobuild. You can put the TS/SCSS files on a &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; folder to separate them from built files, but that&#039;s not mandatory.&lt;br /&gt;
Note to myself: check if &#039;src&#039; dir will be svn version control, if not cannot really use it (even if duplicated in git).&lt;br /&gt;
&lt;br /&gt;
=== Typescript file skeleton ===&lt;br /&gt;
Typescript example here have been stripped down of all comments for clarity. &lt;br /&gt;
Your TS code can be splitted in multiple files, you can have a look [https://github.com/thoun/bga-ts-example here] for inspiration.&lt;br /&gt;
To make this page concise, I removed comments and code samples. If it&#039;s your first game, well - don&#039;t do it if your first game - you won&#039;t be able to apply other code samples from docs, they all using dojo style and have to completely rewritten.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/GameBody.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// @ts-ignore&lt;br /&gt;
GameGui = (function () { // this hack required so we fake extend GameGui&lt;br /&gt;
  function GameGui() {}&lt;br /&gt;
  return GameGui;&lt;br /&gt;
})();&lt;br /&gt;
&lt;br /&gt;
// Note: it does not really extend it in es6 way, you cannot call super you have to use dojo way &lt;br /&gt;
class GameBody extends GameGui { &lt;br /&gt;
     constructor() {}&lt;br /&gt;
     &lt;br /&gt;
     public setup(gamedatas: any) {&lt;br /&gt;
         this.setupNotifications();&lt;br /&gt;
     } &lt;br /&gt;
     public onEnteringState(stateName: string, args: any) {}&lt;br /&gt;
     public onLeavingState(stateName: string) {}&lt;br /&gt;
     public onUpdateActionButtons(stateName: string, args: any) {} &lt;br /&gt;
     public setupNotifications() {}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To plug the class with BGA framework, we&#039;ll also create another file:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/define.ts&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 define([&lt;br /&gt;
     &amp;quot;dojo&amp;quot;,&amp;quot;dojo/_base/declare&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/core/gamegui&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/counter&amp;quot;,&lt;br /&gt;
     &amp;quot;ebg/stock&amp;quot;&lt;br /&gt;
 ],&lt;br /&gt;
 function (dojo, declare) {&lt;br /&gt;
     return declare(&amp;quot;bgagame.yourgamename&amp;quot;, ebg.core.gamegui, new GameBody());             &lt;br /&gt;
 });&lt;br /&gt;
Copy &amp;lt;code&amp;gt;bgagame.yourgamename&amp;lt;/code&amp;gt; from original JS to avoid name mistakes with letter case.&lt;br /&gt;
&lt;br /&gt;
If you try to compile it you will be missing definitions of bunch of methods and variables for that we will add special ts type definition file .d.ts, this is not a complete version but you can get more complete from git projects below&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;src/types/bga-framework.d.ts&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare var gameui: GameGui;&lt;br /&gt;
declare var g_replayFrom: number | undefined;&lt;br /&gt;
declare var g_gamethemeurl: string;&lt;br /&gt;
declare var g_themeurl: string;&lt;br /&gt;
declare var g_archive_mode: string;&lt;br /&gt;
declare function _(str: string): string;&lt;br /&gt;
&lt;br /&gt;
declare const define;&lt;br /&gt;
declare const ebg;&lt;br /&gt;
&lt;br /&gt;
declare class GameGui {&lt;br /&gt;
    page_is_unloading: any;&lt;br /&gt;
    game_name: string;&lt;br /&gt;
    instantaneousMode: any;&lt;br /&gt;
    player_id: string;&lt;br /&gt;
    interface_min_width: number;&lt;br /&gt;
    gamedatas: any;&lt;br /&gt;
    &lt;br /&gt;
  &lt;br /&gt;
    isCurrentPlayerActive(): boolean;&lt;br /&gt;
    addActionButton(id: string, label: string, callback: (event?: any) =&amp;gt; void);&lt;br /&gt;
    checkAction(action: any);&lt;br /&gt;
    ajaxcall(url: string, args: object, bind: GameGui, resultHandler: (result: any) =&amp;gt; void, allHandler: any);&lt;br /&gt;
    &lt;br /&gt;
    setup(gamedatas: any): void;&lt;br /&gt;
    onEnteringState(stateName: string, args: any): void;&lt;br /&gt;
    onLeavingState(stateName: string ): void;&lt;br /&gt;
    onUpdateActionButtons(stateName: string, args: any): void;&lt;br /&gt;
    setupNotifications(): void;&lt;br /&gt;
&lt;br /&gt;
    onScriptError(msg: string, url?: string, linenumber?:number);&lt;br /&gt;
    inherited(args: any);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Above is barebone definition of gameui interface,  you can find more complete one here&lt;br /&gt;
https://github.com/elaskavaia/bga-dojoless/blob/main/src/types/bga-framework.d.ts&lt;br /&gt;
&lt;br /&gt;
=== SCSS file ===&lt;br /&gt;
Nothing special here, just write classic SCSS (will be compiled by Dart scss) and name it &#039;&#039;&#039;src/yourgamename.scss&#039;&#039;&#039;.&lt;br /&gt;
Original content same as original .css, i.e&lt;br /&gt;
&lt;br /&gt;
  @import url(../../../css/csslayer.css);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your SCSS code can be splitted in multiple files, for example :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;yourgamename.scss&#039;&#039;&#039;&lt;br /&gt;
  @import &#039;gametable&#039;;&lt;br /&gt;
 &lt;br /&gt;
  /* some classes */&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;_gametable.scss&#039;&#039;&#039;&lt;br /&gt;
  /* _gametable related classes */&lt;br /&gt;
&lt;br /&gt;
== Auto build and auto upload ==&lt;br /&gt;
&lt;br /&gt;
=== Auto build JS and CSS files ===&lt;br /&gt;
&lt;br /&gt;
To build and watch (i.e. re-build continiously changed files) run in terminal:&lt;br /&gt;
  npm run watch&lt;br /&gt;
&lt;br /&gt;
Alternately you can make vscode to do it for you by installing Run on Save extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
Note: to build without watch&lt;br /&gt;
  npm run build&lt;br /&gt;
&lt;br /&gt;
=== Auto-upload generated files ===&lt;br /&gt;
You can setup stanard file sync or use vscode SFTP extension, see details in [[Setting_up_BGA_Development_environment_using_VSCode]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hint ===&lt;br /&gt;
Make sure &amp;lt;code&amp;gt;.vscode&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;node_modules&amp;lt;/code&amp;gt; are in &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; if you commit your project somewhere.&lt;br /&gt;
&lt;br /&gt;
=== Code completion ===&lt;br /&gt;
To add code completion on framework, dojo, stock, ... you&#039;ll need more type definition files. Feel free to copy them from [https://github.com/thoun/bga-ts-example this repo] and reference them at the top of files array, even before your subpart files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Referenced Projects ==&lt;br /&gt;
&lt;br /&gt;
* https://github.com/thoun/bga-ts-example&lt;br /&gt;
* https://github.com/NevinAF/bga-ts-template&lt;br /&gt;
* https://github.com/elaskavaia/bga-dojoless&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Studio]]&lt;/div&gt;</summary>
		<author><name>NevinAF</name></author>
	</entry>
</feed>