Skip to content

BGA Studio Guidelines (Code)

Make your code as easy to read and understand as possible: clearly named functions and variables, comments when necessary, ...

Everything should be in english in your code.

In case you drop the support for a project, another developer should be able to follow up on your code and understand it easily.

Front-end (JS)

Generated code

Generated code (SCSS, Typescript) is tolerated, as long as you provide both source files (in src folder) and built files, ideally with build tools. The build file should not be minimized, as someone taking over your project might not know the source language, and will the work on the built file ignoring the source file. Build tools are useful if he wants to continue the project with your source files.

JS and CSS files remains the used file in the end, BGA does not handle natively other languages.

Templates

Use of .tpl file and view.php is deprecated and forbidden for new projects.

Back-end (PHP)

Game name and option names should be Capitalized.

Framework functions

Undocumented functions

Do not use undocumented functions. They may change or be deleted without warning, and your game will not work anymore. Any change on documented function will be avoided as much as possible, and will be notified.

Function override

Do not override framework functions. Use a wrapper instead.

Bad :

same name as the framework function = override
public function getPlayerNameById($player_id) { // 
  if ($player_id == 0) {
    return 'Automata';
  } else {
    return parent::getPlayerNameById($player_id);
  } 
}

Better :

different name = wrapper
public function myGameGetPlayerNameById($player_id) {
  if ($player_id == 0) {
    return 'Automata';
  } else {
    return $this->getPlayerNameById($player_id);
  } 
}

Namespacing

The classes should be namespaced following the PSR-4 norm. That means you won't need to require the classes, as BGA will be able to autoload them.

So a class named PowerCardManager on a PowerCard folder should have the filename <mygame>/PowerCard/PowerCardManager.php and start like this :

<?php
declare(strict_types=1);
namespace Bga\Games\<mygame>\PowerCard;
class PowerCardManager {

Other

.action.php shouldn’t be used anymore, auto-wiring should be used instead.

The actions function must check any input. To avoid code duplication, they can use the arg function.

Example :  

public function actPlayCard(int $cardId, int $activePlayer, array $args) {
if (!in_array($cardId, $args['selectableCardsIds'])) { throw new \BgaUserException(...); }

Don’t use `@` to ignore the errors of a function call.