boardgame.io
Version:
library for turn-based games
52 lines (48 loc) • 1.57 kB
JavaScript
;
var turnOrder = require('./turn-order-d6c2e620.js');
var reducer = require('./reducer-76d3a4df.js');
/*
* Copyright 2020 The boardgame.io Authors
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
/**
* Creates the initial game state.
*/
function InitializeGame({ game, numPlayers, setupData, }) {
game = reducer.ProcessGameConfig(game);
if (!numPlayers) {
numPlayers = 2;
}
let ctx = game.flow.ctx(numPlayers);
let state = {
// User managed state.
G: {},
// Framework managed state.
ctx,
// Plugin related state.
plugins: {},
};
// Run plugins over initial state.
state = turnOrder.Setup(state, { game });
state = turnOrder.Enhance(state, { game, playerID: undefined });
const enhancedCtx = turnOrder.EnhanceCtx(state);
state.G = game.setup(enhancedCtx, setupData);
let initial = {
...state,
// List of {G, ctx} pairs that can be undone.
_undo: [],
// List of {G, ctx} pairs that can be redone.
_redo: [],
// A monotonically non-decreasing ID to ensure that
// state updates are only allowed from clients that
// are at the same version that the server.
_stateID: 0,
};
initial = game.flow.init(initial);
initial = turnOrder.Flush(initial, { game });
return initial;
}
exports.InitializeGame = InitializeGame;