File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99import { Events } from './events/events' ;
1010
11+ export interface EventsAPI {
12+ endGame ?( ...args : any [ ] ) : void ;
13+ endPhase ?( ...args : any [ ] ) : void ;
14+ endStage ?( ...args : any [ ] ) : void ;
15+ endTurn ?( ...args : any [ ] ) : void ;
16+ pass ?( ...args : any [ ] ) : void ;
17+ setActivePlayers ?( ...args : any [ ] ) : void ;
18+ setPhase ?( ...args : any [ ] ) : void ;
19+ setStage ?( ...args : any [ ] ) : void ;
20+ }
21+
1122export default {
1223 name : 'events' ,
1324
Original file line number Diff line number Diff line change 66 * https://opensource.org/licenses/MIT.
77 */
88
9+ export interface PlayerAPI {
10+ state : {
11+ [ playerId : string ] : object ;
12+ } ;
13+ get ( ) : any ;
14+ set ( value : any ) : any ;
15+ opponent ?: {
16+ get ( ) : any ;
17+ set ( value : any ) : any ;
18+ } ;
19+ }
20+
921/**
1022 * Plugin that maintains state for each player in G.players.
1123 * During a turn, G.player will contain the object for the current player.
@@ -20,19 +32,18 @@ export default {
2032 return { players : api . state } ;
2133 } ,
2234
23- api : ( { ctx, data } ) => {
35+ api : ( { ctx, data } ) : PlayerAPI => {
2436 let state = data . players ;
25- let result = { state } ;
2637
2738 const get = ( ) => {
2839 return data . players [ ctx . currentPlayer ] ;
2940 } ;
30- result . get = get ;
3141
3242 const set = value => {
3343 return ( state [ ctx . currentPlayer ] = value ) ;
3444 } ;
35- result . set = set ;
45+
46+ let result : PlayerAPI = { state, get, set } ;
3647
3748 if ( ctx . numPlayers === 2 ) {
3849 const other = ctx . currentPlayer === '0' ? '1' : '0' ;
Original file line number Diff line number Diff line change 88
99import { Random } from './random/random' ;
1010
11+ export interface RandomAPI {
12+ D4 ( ) : number ;
13+ D4 ( diceCount : number ) : number [ ] ;
14+ D6 ( ) : number ;
15+ D6 ( diceCount : number ) : number [ ] ;
16+ D10 ( ) : number ;
17+ D10 ( diceCount : number ) : number [ ] ;
18+ D12 ( ) : number ;
19+ D12 ( diceCount : number ) : number [ ] ;
20+ D20 ( ) : number ;
21+ D20 ( diceCount : number ) : number [ ] ;
22+ Die ( spotvalue ?: number ) : number ;
23+ Die ( spotvalue : number , diceCount : number ) : number [ ] ;
24+ Number ( ) : number ;
25+ Shuffle < T > ( deck : T [ ] ) : T [ ] ;
26+ }
27+
1128export default {
1229 name : 'random' ,
1330
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import { Object } from 'ts-toolbelt';
22import * as ActionCreators from './core/action-creators' ;
33import { Flow } from './core/flow' ;
44import * as StorageAPI from './server/db/base' ;
5+ import { EventsAPI } from './plugins/plugin-events' ;
6+ import { PlayerAPI } from './plugins/plugin-player' ;
7+ import { RandomAPI } from './plugins/plugin-random' ;
58
69export { StorageAPI } ;
710
@@ -42,6 +45,12 @@ export interface Ctx {
4245 _random ?: {
4346 seed : string | number ;
4447 } ;
48+ // enhanced by events plugin
49+ events ?: EventsAPI ;
50+ // enhanced by player plugin
51+ player ?: PlayerAPI ;
52+ // enhanced by random plugin
53+ random ?: RandomAPI ;
4554}
4655
4756export interface PluginState {
You can’t perform that action at this time.
0 commit comments