board-game-engine 0.0.7 → 0.0.9

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 {
@@ -16405,40 +16407,43 @@ class Client {
16405
16407
  this.client.start();
16406
16408
  return this;
16407
16409
  } catch (error) {
16408
- console.error('Failed to join game:', error);
16410
+ console.error('Failed to join game:', error?.message ?? error);
16411
+ if (error?.stack) console.error(error.stack);
16409
16412
  }
16410
16413
  }
16411
16414
  update() {
16412
16415
  this.options.onClientUpdate?.();
16413
16416
  }
16414
16417
  getState() {
16415
- let state;
16416
- let moves;
16417
- let gameover;
16418
16418
  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
16419
+ if (!clientState) return {};
16420
+ if (this.options.boardgameIOGame) {
16421
+ return {
16422
+ state: clientState,
16423
+ gameover: clientState?.ctx?.gameover,
16424
+ moves: this.client.moves
16424
16425
  };
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
16426
  }
16438
- const {
16439
- allClickable,
16440
- possibleMoveMeta
16441
- } = getPossibleMoves(state, moves, this.moveBuilder);
16427
+ const state = {
16428
+ ...clientState,
16429
+ G: (0, _wackson.deserialize)(JSON.stringify(clientState.G), _registry.registry),
16430
+ originalG: clientState.G
16431
+ };
16432
+ const gameover = state?.ctx?.gameover;
16433
+ const moves = !gameover ? Object.entries((0, _getCurrentMoves.default)(state, this.client)).reduce((acc, _ref) => {
16434
+ let [moveName, rawMove] = _ref;
16435
+ const move = payload => {
16436
+ this.client.moves[moveName]((0, _preparePayload.default)(payload));
16437
+ };
16438
+ move.moveInstance = rawMove.moveInstance;
16439
+ return {
16440
+ ...acc,
16441
+ [moveName]: move
16442
+ };
16443
+ }, {}) : [];
16444
+ const possibleMoves = getPossibleMoves(state, moves, this.moveBuilder);
16445
+ const allClickable = possibleMoves.allClickable;
16446
+ const possibleMoveMeta = possibleMoves.possibleMoveMeta;
16442
16447
  return {
16443
16448
  state,
16444
16449
  gameover,
@@ -16448,6 +16453,7 @@ class Client {
16448
16453
  };
16449
16454
  }
16450
16455
  doStep(_target) {
16456
+ if (this.options.boardgameIOGame) return;
16451
16457
  const {
16452
16458
  state,
16453
16459
  moves,
@@ -16492,6 +16498,7 @@ class Client {
16492
16498
  this.update();
16493
16499
  }
16494
16500
  reset() {
16501
+ if (this.options.boardgameIOGame) return;
16495
16502
  this.moveBuilder = {
16496
16503
  targets: [],
16497
16504
  stepIndex: 0,
@@ -16501,6 +16508,7 @@ class Client {
16501
16508
  this.update();
16502
16509
  }
16503
16510
  undoStep() {
16511
+ if (this.options.boardgameIOGame) return;
16504
16512
  if (this.moveBuilder.targets.length) {
16505
16513
  this.moveBuilder = {
16506
16514
  targets: this.moveBuilder.targets.slice(0, -1),
@@ -16669,7 +16677,7 @@ class Bank {
16669
16677
  createEntity() {
16670
16678
  let definition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16671
16679
  let options = arguments.length > 1 ? arguments[1] : undefined;
16672
- const entity = new _registry.registry[definition.type || 'Entity']({
16680
+ const entity = new _registry.registry[definition.entityType || 'Entity']({
16673
16681
  bank: this,
16674
16682
  fromBank: true,
16675
16683
  ...options
@@ -17151,7 +17159,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
17151
17159
  class IsFull extends _condition.default {
17152
17160
  checkCondition(bgioArguments, rule, payload, context) {
17153
17161
  return {
17154
- conditionIsMet: payload.target.spaces.every(space => space.entities.length)
17162
+ conditionIsMet: payload.target.spaces.every(space => space?.entities.length)
17155
17163
  };
17156
17164
  }
17157
17165
  }
@@ -17338,7 +17346,7 @@ class WouldCondition extends _condition.default {
17338
17346
  const payload = {
17339
17347
  arguments: targets.reduce((acc, target, i) => ({
17340
17348
  ...acc,
17341
- [argNameMap[context.moveInstance.rule.type][i]]: target
17349
+ [argNameMap[context.moveInstance.rule.moveType][i]]: target
17342
17350
  }), {})
17343
17351
  };
17344
17352
  const simulatedG = (0, _simulateMove.default)(bgioArguments, payload, context);
@@ -17470,10 +17478,10 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
17470
17478
  // Things we always want, don't need to configure, and
17471
17479
  // want to treat as first-class citizens
17472
17480
  const invariantEntities = [{
17473
- type: "Space",
17481
+ entityType: "Space",
17474
17482
  count: "Infinity"
17475
17483
  }, {
17476
- type: "Board",
17484
+ entityType: "Board",
17477
17485
  name: 'sharedBoard'
17478
17486
  }, {
17479
17487
  name: "playerMarker",
@@ -17496,7 +17504,7 @@ function expandInitialPlacements(rules, entities) {
17496
17504
  }
17497
17505
  if (rules.personalBoard) {
17498
17506
  entities.push({
17499
- type: "Board",
17507
+ entityType: "Board",
17500
17508
  name: 'personalBoard',
17501
17509
  perPlayer: true
17502
17510
  });
@@ -17520,7 +17528,7 @@ function expandInitialPlacements(rules, entities) {
17520
17528
  const entityDefinition = (0, _find.default)(entities, matcher);
17521
17529
  if (placement.destination.name === 'personalBoard') {
17522
17530
  return {
17523
- type: 'ForEach',
17531
+ moveType: 'ForEach',
17524
17532
  arguments: {
17525
17533
  targets: {
17526
17534
  type: 'ctxPath',
@@ -17528,7 +17536,7 @@ function expandInitialPlacements(rules, entities) {
17528
17536
  }
17529
17537
  },
17530
17538
  move: {
17531
- type: 'PlaceNew',
17539
+ moveType: 'PlaceNew',
17532
17540
  entity: {
17533
17541
  state,
17534
17542
  conditions: [{
@@ -17562,7 +17570,7 @@ function expandInitialPlacements(rules, entities) {
17562
17570
  };
17563
17571
  } else {
17564
17572
  return {
17565
- type: 'PlaceNew',
17573
+ moveType: 'PlaceNew',
17566
17574
  entity: {
17567
17575
  state,
17568
17576
  conditions: [{
@@ -17586,7 +17594,7 @@ function expandInitialPlacements(rules, entities) {
17586
17594
  delete rules.initialPlacements;
17587
17595
  }
17588
17596
  }
17589
- const keyMappings = [['thatMatches', 'conditions'], ['entityType', 'type'], ['moveType', 'type'], ['endConditions', 'endIf']];
17597
+ const keyMappings = [];
17590
17598
  const simpleReplacements = [['isCurrentPlayer', {
17591
17599
  conditionType: 'Is',
17592
17600
  matcher: {
@@ -18098,7 +18106,7 @@ function revivePayload(serializablePayload, G) {
18098
18106
  }
18099
18107
  }
18100
18108
  function getMoveInstance(moveRule) {
18101
- switch (moveRule.type) {
18109
+ switch (moveRule.moveType) {
18102
18110
  case 'MoveEntity':
18103
18111
  return new _moveEntity.default(moveRule);
18104
18112
  case 'PlaceNew':
@@ -18556,7 +18564,7 @@ class SpaceGroup extends _entity.default {
18556
18564
  }
18557
18565
  makeSpaces(bank) {
18558
18566
  return Array(this.getSpacesCount()).fill().map((_, i) => bank.createEntity({
18559
- type: 'Space',
18567
+ entityType: 'Space',
18560
18568
  index: i
18561
18569
  }));
18562
18570
  }
@@ -19064,7 +19072,7 @@ const argNamesMap = {
19064
19072
 
19065
19073
  // this might not be where special handling for setstate wants to live
19066
19074
  function getSteps(bgioState, moveRule) {
19067
- return argNamesMap[moveRule.type].filter(argName => moveRule.arguments[argName].playerChoice).map(argName => ({
19075
+ return argNamesMap[moveRule.moveType].filter(argName => moveRule.arguments[argName].playerChoice).map(argName => ({
19068
19076
  argName,
19069
19077
  getClickable: argName === 'state' ? () => moveRule.arguments[argName].possibleValues.map(value => ({
19070
19078
  abstract: true,
@@ -20411,7 +20419,7 @@ module.exports = ListCache;
20411
20419
 
20412
20420
  /***/ },
20413
20421
 
20414
- /***/ 604
20422
+ /***/ 8223
20415
20423
  (module, __unused_webpack_exports, __webpack_require__) {
20416
20424
 
20417
20425
  var getNative = __webpack_require__(6110),
@@ -23461,7 +23469,7 @@ module.exports = getSymbolsIn;
23461
23469
  (module, __unused_webpack_exports, __webpack_require__) {
23462
23470
 
23463
23471
  var DataView = __webpack_require__(5580),
23464
- Map = __webpack_require__(604),
23472
+ Map = __webpack_require__(8223),
23465
23473
  Promise = __webpack_require__(2804),
23466
23474
  Set = __webpack_require__(6545),
23467
23475
  WeakMap = __webpack_require__(8303),
@@ -24250,7 +24258,7 @@ module.exports = listCacheSet;
24250
24258
 
24251
24259
  var Hash = __webpack_require__(1549),
24252
24260
  ListCache = __webpack_require__(79),
24253
- Map = __webpack_require__(604);
24261
+ Map = __webpack_require__(8223);
24254
24262
 
24255
24263
  /**
24256
24264
  * Removes all key-value entries from the map.
@@ -24889,7 +24897,7 @@ module.exports = stackHas;
24889
24897
  (module, __unused_webpack_exports, __webpack_require__) {
24890
24898
 
24891
24899
  var ListCache = __webpack_require__(79),
24892
- Map = __webpack_require__(604),
24900
+ Map = __webpack_require__(8223),
24893
24901
  MapCache = __webpack_require__(3661);
24894
24902
 
24895
24903
  /** Used as the size to enable large array optimizations. */
@@ -28811,9 +28819,9 @@ function createCookieJar() { }
28811
28819
 
28812
28820
  Object.defineProperty(exports, "__esModule", ({ value: true }));
28813
28821
  exports.WebTransport = exports.WebSocket = exports.NodeWebSocket = exports.XHR = exports.NodeXHR = exports.Fetch = exports.nextTick = exports.parse = exports.installTimerFunctions = exports.transports = exports.TransportError = exports.Transport = exports.protocol = exports.SocketWithUpgrade = exports.SocketWithoutUpgrade = exports.Socket = void 0;
28814
- const socket_js_1 = __webpack_require__(8223);
28822
+ const socket_js_1 = __webpack_require__(604);
28815
28823
  Object.defineProperty(exports, "Socket", ({ enumerable: true, get: function () { return socket_js_1.Socket; } }));
28816
- var socket_js_2 = __webpack_require__(8223);
28824
+ var socket_js_2 = __webpack_require__(604);
28817
28825
  Object.defineProperty(exports, "SocketWithoutUpgrade", ({ enumerable: true, get: function () { return socket_js_2.SocketWithoutUpgrade; } }));
28818
28826
  Object.defineProperty(exports, "SocketWithUpgrade", ({ enumerable: true, get: function () { return socket_js_2.SocketWithUpgrade; } }));
28819
28827
  exports.protocol = socket_js_1.Socket.protocol;
@@ -28844,7 +28852,7 @@ Object.defineProperty(exports, "WebTransport", ({ enumerable: true, get: functio
28844
28852
 
28845
28853
  /***/ },
28846
28854
 
28847
- /***/ 8223
28855
+ /***/ 604
28848
28856
  (__unused_webpack_module, exports, __webpack_require__) {
28849
28857
 
28850
28858
  "use strict";
@@ -35606,8 +35614,8 @@ Object.defineProperty(exports, "gameFactory", ({
35606
35614
  return _gameFactory.default;
35607
35615
  }
35608
35616
  }));
35609
- var _client = __webpack_require__(4245);
35610
35617
  var _gameFactory = _interopRequireDefault(__webpack_require__(4913));
35618
+ var _client = __webpack_require__(4245);
35611
35619
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
35612
35620
  })();
35613
35621