board-game-engine 0.0.8 → 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.
@@ -0,0 +1,23 @@
1
+ const { devices } = require('@playwright/test')
2
+
3
+ const PORT = 5174
4
+
5
+ module.exports = {
6
+ testDir: 'e2e',
7
+ fullyParallel: false,
8
+ forbidOnly: !!process.env.CI,
9
+ retries: process.env.CI ? 2 : 0,
10
+ workers: 1,
11
+ reporter: 'html',
12
+ use: {
13
+ baseURL: `http://localhost:${PORT}`,
14
+ trace: 'on-first-retry',
15
+ viewport: { width: 800, height: 600 },
16
+ },
17
+ projects: [{ name: 'firefox', use: { ...devices['Desktop Firefox'] } }],
18
+ webServer: {
19
+ command: `npx http-server . -p ${PORT} -c-1`,
20
+ url: `http://localhost:${PORT}`,
21
+ reuseExistingServer: !process.env.CI,
22
+ },
23
+ }
@@ -55,7 +55,8 @@ export class Client {
55
55
  this.client.start()
56
56
  return this
57
57
  } catch (error) {
58
- console.error('Failed to join game:', error)
58
+ console.error('Failed to join game:', error?.message ?? error)
59
+ if (error?.stack) console.error(error.stack)
59
60
  }
60
61
  }
61
62
 
@@ -12,7 +12,7 @@ class Bank {
12
12
  }
13
13
 
14
14
  createEntity (definition = {}, options) {
15
- const entity = new (registry[definition.type || 'Entity'])(
15
+ const entity = new (registry[definition.entityType || 'Entity'])(
16
16
  {
17
17
  bank: this,
18
18
  fromBank: true,
@@ -3,7 +3,7 @@ import Condition from "./condition.js";
3
3
  export default class IsFull extends Condition {
4
4
  checkCondition(bgioArguments, rule, payload, context) {
5
5
  return {
6
- conditionIsMet: payload.target.spaces.every(space => space.entities.length)
6
+ conditionIsMet: payload.target.spaces.every(space => space?.entities.length)
7
7
  };
8
8
  }
9
9
  }
@@ -17,7 +17,7 @@ export default class WouldCondition extends Condition {
17
17
  const payload = {
18
18
  arguments: targets.reduce((acc, target, i) => ({
19
19
  ...acc,
20
- [argNameMap[context.moveInstance.rule.type][i]]: target
20
+ [argNameMap[context.moveInstance.rule.moveType][i]]: target
21
21
  }), {})
22
22
  }
23
23
 
@@ -21,11 +21,11 @@ import transformJSON from "../utils/json-transformer.js";
21
21
  // want to treat as first-class citizens
22
22
  const invariantEntities = [
23
23
  {
24
- type: "Space",
24
+ entityType: "Space",
25
25
  count: "Infinity",
26
26
  },
27
27
  {
28
- type: "Board",
28
+ entityType: "Board",
29
29
  name: 'sharedBoard'
30
30
  },
31
31
  {
@@ -51,7 +51,7 @@ function expandInitialPlacements (rules, entities) {
51
51
 
52
52
  if (rules.personalBoard) {
53
53
  entities.push({
54
- type: "Board",
54
+ entityType: "Board",
55
55
  name: 'personalBoard',
56
56
  perPlayer: true
57
57
  })
@@ -75,7 +75,7 @@ function expandInitialPlacements (rules, entities) {
75
75
 
76
76
  if (placement.destination.name === 'personalBoard') {
77
77
  return {
78
- type: 'ForEach',
78
+ moveType: 'ForEach',
79
79
  arguments: {
80
80
  targets: {
81
81
  type: 'ctxPath',
@@ -83,7 +83,7 @@ function expandInitialPlacements (rules, entities) {
83
83
  }
84
84
  },
85
85
  move: {
86
- type: 'PlaceNew',
86
+ moveType: 'PlaceNew',
87
87
  entity: {
88
88
  state,
89
89
  conditions: [{
@@ -120,7 +120,7 @@ function expandInitialPlacements (rules, entities) {
120
120
  }
121
121
  } else {
122
122
  return {
123
- type: 'PlaceNew',
123
+ moveType: 'PlaceNew',
124
124
  entity: {
125
125
  state,
126
126
  conditions: [{
@@ -145,12 +145,7 @@ function expandInitialPlacements (rules, entities) {
145
145
  }
146
146
  }
147
147
 
148
- const keyMappings = [
149
- ['thatMatches', 'conditions'],
150
- ['entityType', 'type'],
151
- ['moveType', 'type'],
152
- ['endConditions', 'endIf'],
153
- ]
148
+ const keyMappings = []
154
149
 
155
150
  const simpleReplacements = [
156
151
  [
@@ -62,7 +62,7 @@ function revivePayload (serializablePayload, G) {
62
62
  }
63
63
 
64
64
  export function getMoveInstance (moveRule) {
65
- switch (moveRule.type) {
65
+ switch (moveRule.moveType) {
66
66
  case 'MoveEntity':
67
67
  return new MoveEntity(moveRule);
68
68
  case 'PlaceNew':
@@ -8,7 +8,7 @@ export default class SpaceGroup extends Entity {
8
8
 
9
9
  makeSpaces (bank) {
10
10
  return Array(this.getSpacesCount()).fill()
11
- .map((_, i) => bank.createEntity({ type: 'Space', index: i }))
11
+ .map((_, i) => bank.createEntity({ entityType: 'Space', index: i }))
12
12
  }
13
13
 
14
14
  getEmptySpaces() {
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { Client } from './client/client'
2
1
  export { default as gameFactory } from './game-factory/game-factory'
2
+ export { Client } from './client/client'
@@ -9,7 +9,7 @@ const argNamesMap = {
9
9
 
10
10
  // this might not be where special handling for setstate wants to live
11
11
  export default function getSteps (bgioState, moveRule) {
12
- return argNamesMap[moveRule.type]
12
+ return argNamesMap[moveRule.moveType]
13
13
  .filter(argName => moveRule.arguments[argName].playerChoice)
14
14
  .map(argName => ({
15
15
  argName,
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "passed",
3
+ "failedTests": []
4
+ }
package/babel.config.js DELETED
@@ -1,6 +0,0 @@
1
- // only used for jest
2
- module.exports = {
3
- presets: [
4
- ['@babel/preset-env', { targets: { node: 'current' } }]
5
- ]
6
- }
@@ -1,7 +0,0 @@
1
- /* eslint-env jest */
2
-
3
- describe('functional test', () => {
4
- test('should have a test', () => {
5
- expect(true).toBe(true)
6
- })
7
- })
package/jest.config.js DELETED
@@ -1,21 +0,0 @@
1
- module.exports = {
2
- testEnvironment: 'node',
3
- transform: {
4
- '^.+\\.(js|ts)$': ['babel-jest', {
5
- presets: [
6
- '@babel/preset-typescript',
7
- ['@babel/preset-env', {
8
- modules: 'cjs',
9
- targets: { node: 'current' }
10
- }]
11
- ],
12
- plugins: ['add-module-exports']
13
- }]
14
- },
15
- clearMocks: true,
16
- moduleFileExtensions: ['js', 'ts', 'json'],
17
- testMatch: [
18
- '**/__tests__/**/*.(js|ts)',
19
- '**/*.(test|spec).(js|ts)'
20
- ]
21
- }
@@ -1,54 +0,0 @@
1
- {
2
- "playerCountRange": [2, 2],
3
- "sharedBoard": {
4
- "grid": {
5
- "type": "grid",
6
- "width": 3,
7
- "height": 3
8
- }
9
- },
10
- "pieces": [
11
- {
12
- "name": "playerMarker",
13
- "perPlayer": true
14
- }
15
- ],
16
- "winCondition": {
17
- "type": "bingo",
18
- "boardPath": ["sharedBoard", "grid"],
19
- "piece": {
20
- "name": "playerMarker"
21
- }
22
- },
23
- "round": {
24
- "loopUntil": false,
25
- "phases": [
26
- {
27
- "type": "sequentialPlayerTurn",
28
- "actions": [
29
- {
30
- "type": "movePiece",
31
- "piece": {
32
- "name": "playerMarker"
33
- },
34
- "from": "player",
35
- "to": ["sharedBoard", "grid"],
36
- "conditions": [
37
- {
38
- "type": "doesNotContain",
39
- "piece": "any"
40
- }
41
- ]
42
- }
43
- ]
44
- }
45
- ]
46
- },
47
- "drawCondition": {
48
- "type": "blackout",
49
- "boardPath": ["sharedBoard", "grid"],
50
- "piece": {
51
- "name": "playerMarker"
52
- }
53
- }
54
- }