Giter Club home page Giter Club logo

boardgame.io-angular's Introduction

Boardgame.io Angular Client

npm version

Angular client for Boardgame.io.

Checkout the demo application

Current version (>=0.25) was built using Angular 9.

Installation

$ npm install --save boardgame.io-angular [email protected]

Usage

  1. Define your boardgame.io's framework independent Game.
  2. Define your board component that inherits BoardBase - the available properties are described at the Client's documentation under board component:
    @Component({  
      template: 'do something like {{G | json}}',  
    })  
    export class MyBoardComponent extends BoardBase {  
       // unfortunately, 
       // the following boilerplate is currently required:
       constructor(@Inject(OBSERVABLE_BOARD_CONFIG) 
                   observableBoardConfig: Observable<BoardConfig>) {  
         super(observableBoardConfig);  
       }  
     }
  • This board component is loaded dynamaically, so it shouldn't indirectly depend on other parts of your application. In order to define its module dependencies you need to add a module:

    @NgModule({
      declarations: [MyBoardComponent],
      imports: [CommonModule, /* other dependencies */],  
    }) export class StupidButNeededModule {}

    (It would have been nice to be able to just specify imports on the board component; this feature is tracked by Angular issue#33507).

  1. import the module in you main app:

    import { NgModule } from '@angular/core';  
    import { BoardgameIoModule } from 'boardgame.io-angular';  
      
    @NgModule({  
      declarations: [  
        MyBoardComponent  
      ],  
      imports: [  
        // ...  
        BoardgameIoModule, // import for using bio-client  
    ]}) // Angular 9+ does not require entryComponent!
    export class MyModule {}  
  2. Use bioGameConfig attribute directive to setup game scope. It uses the same config as boardgame.io's client factory. Use bio-client component to setup a client instance:

    import { MyGame } from '.';  
    import { MyBoardComponent } from '.';  
     
    @Component({  
      template: `
        <bio-client
          [bioGameConfig]="config" gameID="single">
        </bio-client>`
    })  
    export class MyExampleComponent {
      config = {game: MyGame, board: MyBoardComponent};
    }
  • bioGameConfig can also be used setup a game scope for more than one client (useful for a multiview game and examples):
    <ng-container [bioGameConfig]="config">
      <bio-client gameID="multi" playerID="0"></bio-client>`
      <bio-client gameID="multi" playerID="1"></bio-client>`
    </ng-container>
  • bioGameConfig just assigns a config to a GameScope injectable. You can also directly make a GameScope available to bio-client using the providers property of an available module, a parent component, or a directive.
  1. See the examples.

Development

Running examples in this repository

$ git clone https://github.com/turn-based/boardgame.io-angular.git  
$ cd boardgame.io-angular  
$ npm i  
$ npm run build   
$ npm run start  

For Running the multiplayer examples you'll also need to have the server running running on port 8000:

$ cd server  
$ npm i  
$ npm run start:dev   

This project was generated with Angular CLI version 9 using the follwing commands :

  1. npx @angular/cli@9 new boardgame.io-angular --create-application false --prefix bio --style scss --strict --skip-tests -s -t
  2. cd boardgame.io-angular
  3. npx @angular/cli@9 g application demo --prefix bio --style scss --skip-tests -s -t
  4. npx @angular/cli@9 g library bio-angular --prefix bio

boardgame.io-angular's People

Contributors

amitport avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boardgame.io-angular's Issues

Can't install dependencies for demo

Edwards-MacBook-Pro:boardgame.io-angular edward$ npm i --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'i', '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session c50ae775510ca0a1
npm info lifecycle @~preinstall: @
npm timing stage:loadCurrentTree Completed in 12ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 287ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 157ms
npm timing stage:loadIdealTree Completed in 465ms
npm timing stage:generateActionsToTake Completed in 483ms
npm verb correctMkdir /Users/edward/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/edward/.npm/_locks/staging-acd918ac543db2b2.lock for /Users/edward/boardgame.io-angular/node_modules/.staging
npm timing audit submit Completed in 1673ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 1674ms
npm timing audit body Completed in 11ms
npm timing action:extract Completed in 14700ms
npm verb unlock done using /Users/edward/.npm/_locks/staging-acd918ac543db2b2.lock for /Users/edward/boardgame.io-angular/node_modules/.staging
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 19227ms
npm verb stack Error: Command failed: git checkout a98b46d0c5fc434d37600f53f9eaaaaef4b2b490
npm verb stack fatal: reference is not a tree: a98b46d0c5fc434d37600f53f9eaaaaef4b2b490
npm verb stack 
npm verb stack     at ChildProcess.exithandler (child_process.js:294:12)
npm verb stack     at ChildProcess.emit (events.js:198:13)
npm verb stack     at maybeClose (internal/child_process.js:982:16)
npm verb stack     at Socket.stream.socket.on (internal/child_process.js:389:11)
npm verb stack     at Socket.emit (events.js:198:13)
npm verb stack     at Pipe._handle.close (net.js:606:12)
npm verb cwd /Users/edward/boardgame.io-angular
npm verb Darwin 19.2.0
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "--verbose"
npm verb node v10.16.3
npm verb npm  v6.13.4
npm ERR! code 128
npm ERR! Command failed: git checkout a98b46d0c5fc434d37600f53f9eaaaaef4b2b490
npm ERR! fatal: reference is not a tree: a98b46d0c5fc434d37600f53f9eaaaaef4b2b490
npm ERR! 
npm verb exit [ 1, true ]
npm timing npm Completed in 19779ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/edward/.npm/_logs/2019-12-27T07_04_41_089Z-debug.log

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.