Git Product home page Git Product logo

bga-workbench's Introduction

BoardGameArena Workbench

Build Status Latest Stable Version

A set of tools to work with BoardGameArena projects.

Installation

Via composer:

composer require --dev dholmes/bga-workbench

To set up your project to work with BGA Workbench you need to have a bgaproject.yml file in the root. To generate one see the bgawb init command.

Initialise BGA Project

Once you've installed bgawb you can run the below command to interactively create a bgaproject.yml file in your current directory.

bgawb init

Deploying to BGA Studio

bgawb build --deploy

Continuous Deployment to Studio

Watches development files and deploys them as they change.

bgawb build --deploy --watch

Compiling composer projects

The Board Game Arena production framework/environment doesn't natively support a Composer project setup. By having useComposer: true set in your bgaproject.yml file, the [bgawb build](Deploying to BGA Studio) command will merge all non-dev composer dependencies inline into your .game.php file before deploying.

Testing Utilities

Some testing utilities are provided to help test various parts of a standard BGA project game.

The Validate Command

Will run some basic checks on your project setup. e.g. whether you have the required files to function on the BGA platform (.game.php, .action.php, etc), whether your states.inc.php file is valid, etc.

bgawb validate

PHPUnit TestHelp trait

Including this trait and implementing the createGameTableInstanceBuilder method will set up and tear down a game table instance for each test that is run. Note that this makes use of the setUp and tearDown PHPUnit hooks

<?php

namespace Game\Tests;

use PHPUnit\Framework\TestCase;
use BGAWorkbench\Test\TestHelp;
use Doctrine\DBAL\Connection;
use BGAWorkbench\Utils;

class ChooseAttackTest extends TestCase
{
    use TestHelp;
    
    protected function createGameTableInstanceBuilder() : TableInstanceBuilder
    {
        return $this->gameTableInstanceBuilder()
            ->setPlayersWithIds([66, 77])
            ->overridePlayersPostSetup([
                66 => ['player_color' => 'ff0000'],
                77 => ['player_color' => '00ff00']
            ]);
    }
    
    public function testAction()
    {
        $action = $this->table
            ->setupNewGame()
            ->withDbConnection(function (Connection $db) {
                $db->exec('INSERT battlefield_card (player_id, type, x, y) VALUES (' .
                    join('), (', [
                        [77, '"infantry"', 0, -1],  
                        [66, '"infantry"', 0, 1],  
                        [66, '"artillery"', 6, 1],  
                    ])
                . ')');
            })
            ->createActionInstanceForCurrentPlayer(66)
            ->stubActivePlayerId(66)
            ->stubArgs(['x' => 5, 'y' => 5]);

        $action->chooseAttack();
        
        // TODO: Run some asserts on the db
    }
    
    public function testStateFunc()
    {
        $game = $this->table
            ->setupNewGame()
            ->createGameInstanceWithNoBoundedPlayer()
            ->stubActivePlayerId(66);
        
        $game->stNextPlayer();
    }
    
    public function testGetAllDatas()
    {
        $game = $this->table
            ->setupNewGame()
            ->withDbConnection(function (Connection $db) {
                $db->exec('DELETE FROM deck_card');
                $db->exec('DELETE FROM playable_card');
                $db->exec('INSERT INTO battlefield_card (player_id, type, x, y) VALUES (66, "tank", 0, 2)');
                $db->executeUpdate('UPDATE player SET player_score_aux = 1 WHERE player_id = 66');
            })
            ->createGameInstanceForCurrentPlayer(66);

        $datas = Utils::callProtectedMethod($game, 'getAllDatas');
        
        // TODO: Some asserts on $datas
    }
}

Projects Using BGA Workbench

Development

i.e. if you want to make some changes to the BGA Workbench project. This is not required for using the library in your own project.

Requirements

Setting up Developer Machine

vagrant up

Running Tests

vagrant ssh
composer test

bga-workbench's People

Contributors

danielholmes avatar ghunti avatar jmichaelward avatar kutagh avatar lucas-c avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.