board-game-engine 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16361,13 +16361,15 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
16361
16361
  class Client {
16362
16362
  constructor(options) {
16363
16363
  this.options = options;
16364
- this.moveBuilder = {
16365
- targets: [],
16366
- stepIndex: 0,
16367
- eliminatedMoves: []
16368
- };
16369
- this.optimisticWinner = null;
16370
- this.game = options.game || (0, _gameFactory.default)(JSON.parse(options.gameRules), options.gameName);
16364
+ this.game = options.boardgameIOGame || (0, _gameFactory.default)(JSON.parse(options.gameRules), options.gameName);
16365
+ if (!options.boardgameIOGame) {
16366
+ this.moveBuilder = {
16367
+ targets: [],
16368
+ stepIndex: 0,
16369
+ eliminatedMoves: []
16370
+ };
16371
+ this.optimisticWinner = null;
16372
+ }
16371
16373
  }
16372
16374
  connect() {
16373
16375
  const {
@@ -16412,33 +16414,35 @@ class Client {
16412
16414
  this.options.onClientUpdate?.();
16413
16415
  }
16414
16416
  getState() {
16415
- let state;
16416
- let moves;
16417
- let gameover;
16418
16417
  const clientState = this.client?.getState();
16419
- if (clientState) {
16420
- state = {
16421
- ...clientState,
16422
- G: (0, _wackson.deserialize)(JSON.stringify(clientState.G), _registry.registry),
16423
- originalG: clientState.G
16418
+ if (!clientState) return {};
16419
+ if (this.options.boardgameIOGame) {
16420
+ return {
16421
+ state: clientState,
16422
+ gameover: clientState?.ctx?.gameover,
16423
+ moves: this.client.moves
16424
16424
  };
16425
- gameover = state?.ctx?.gameover;
16426
- moves = !gameover ? Object.entries((0, _getCurrentMoves.default)(state, this.client)).reduce((acc, _ref) => {
16427
- let [moveName, rawMove] = _ref;
16428
- const move = payload => {
16429
- this.client.moves[moveName]((0, _preparePayload.default)(payload));
16430
- };
16431
- move.moveInstance = rawMove.moveInstance;
16432
- return {
16433
- ...acc,
16434
- [moveName]: move
16435
- };
16436
- }, {}) : [];
16437
16425
  }
16438
- const {
16439
- allClickable,
16440
- possibleMoveMeta
16441
- } = getPossibleMoves(state, moves, this.moveBuilder);
16426
+ const state = {
16427
+ ...clientState,
16428
+ G: (0, _wackson.deserialize)(JSON.stringify(clientState.G), _registry.registry),
16429
+ originalG: clientState.G
16430
+ };
16431
+ const gameover = state?.ctx?.gameover;
16432
+ const moves = !gameover ? Object.entries((0, _getCurrentMoves.default)(state, this.client)).reduce((acc, _ref) => {
16433
+ let [moveName, rawMove] = _ref;
16434
+ const move = payload => {
16435
+ this.client.moves[moveName]((0, _preparePayload.default)(payload));
16436
+ };
16437
+ move.moveInstance = rawMove.moveInstance;
16438
+ return {
16439
+ ...acc,
16440
+ [moveName]: move
16441
+ };
16442
+ }, {}) : [];
16443
+ const possibleMoves = getPossibleMoves(state, moves, this.moveBuilder);
16444
+ const allClickable = possibleMoves.allClickable;
16445
+ const possibleMoveMeta = possibleMoves.possibleMoveMeta;
16442
16446
  return {
16443
16447
  state,
16444
16448
  gameover,
@@ -16448,6 +16452,7 @@ class Client {
16448
16452
  };
16449
16453
  }
16450
16454
  doStep(_target) {
16455
+ if (this.options.boardgameIOGame) return;
16451
16456
  const {
16452
16457
  state,
16453
16458
  moves,
@@ -16492,6 +16497,7 @@ class Client {
16492
16497
  this.update();
16493
16498
  }
16494
16499
  reset() {
16500
+ if (this.options.boardgameIOGame) return;
16495
16501
  this.moveBuilder = {
16496
16502
  targets: [],
16497
16503
  stepIndex: 0,
@@ -16501,6 +16507,7 @@ class Client {
16501
16507
  this.update();
16502
16508
  }
16503
16509
  undoStep() {
16510
+ if (this.options.boardgameIOGame) return;
16504
16511
  if (this.moveBuilder.targets.length) {
16505
16512
  this.moveBuilder = {
16506
16513
  targets: this.moveBuilder.targets.slice(0, -1),