board-game-engine 2.0.0 → 2.1.0
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.
- package/.github/workflows/ci.yml +33 -0
- package/README.md +2 -2
- package/dist/board-game-engine.cjs +463 -349
- package/dist/board-game-engine.js +463 -349
- package/dist/board-game-engine.min.js +22 -22
- package/dist/board-game-engine.mjs +461 -348
- package/dist/client/client.d.ts +76 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/game-factory/bank/bank-slot.d.ts +30 -0
- package/dist/game-factory/bank/bank-slot.d.ts.map +1 -0
- package/dist/game-factory/bank/bank.d.ts +34 -0
- package/dist/game-factory/bank/bank.d.ts.map +1 -0
- package/dist/game-factory/board.d.ts +4 -0
- package/dist/game-factory/board.d.ts.map +1 -0
- package/dist/game-factory/condition/condition-factory.d.ts +4 -0
- package/dist/game-factory/condition/condition-factory.d.ts.map +1 -0
- package/dist/game-factory/condition/condition.d.ts +13 -0
- package/dist/game-factory/condition/condition.d.ts.map +1 -0
- package/dist/game-factory/condition/contains-condition.d.ts +8 -0
- package/dist/game-factory/condition/contains-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/contains-same-condition.d.ts +7 -0
- package/dist/game-factory/condition/contains-same-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/evaluate-condition.d.ts +8 -0
- package/dist/game-factory/condition/evaluate-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/every-condition.d.ts +12 -0
- package/dist/game-factory/condition/every-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/has-line-condition.d.ts +8 -0
- package/dist/game-factory/condition/has-line-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/in-line-condition.d.ts +8 -0
- package/dist/game-factory/condition/in-line-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/is-condition.d.ts +8 -0
- package/dist/game-factory/condition/is-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/is-full-condition.d.ts +7 -0
- package/dist/game-factory/condition/is-full-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/no-possible-moves-condition.d.ts +7 -0
- package/dist/game-factory/condition/no-possible-moves-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/not-condition.d.ts +7 -0
- package/dist/game-factory/condition/not-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/or-condition.d.ts +7 -0
- package/dist/game-factory/condition/or-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/position-condition.d.ts +7 -0
- package/dist/game-factory/condition/position-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/some-condition.d.ts +8 -0
- package/dist/game-factory/condition/some-condition.d.ts.map +1 -0
- package/dist/game-factory/condition/would-condition.d.ts +8 -0
- package/dist/game-factory/condition/would-condition.d.ts.map +1 -0
- package/dist/game-factory/entity.d.ts +13 -0
- package/dist/game-factory/entity.d.ts.map +1 -0
- package/dist/game-factory/expand-game-rules.d.ts +3 -0
- package/dist/game-factory/expand-game-rules.d.ts.map +1 -0
- package/dist/game-factory/game-factory.d.ts +10 -0
- package/dist/game-factory/game-factory.d.ts.map +1 -0
- package/{src/game-factory/move/end-turn.js → dist/game-factory/move/end-turn.d.ts} +2 -4
- package/dist/game-factory/move/end-turn.d.ts.map +1 -0
- package/dist/game-factory/move/for-each.d.ts +5 -0
- package/dist/game-factory/move/for-each.d.ts.map +1 -0
- package/dist/game-factory/move/index.d.ts +6 -0
- package/dist/game-factory/move/index.d.ts.map +1 -0
- package/dist/game-factory/move/move-entity.d.ts +7 -0
- package/dist/game-factory/move/move-entity.d.ts.map +1 -0
- package/dist/game-factory/move/move-factory.d.ts +18 -0
- package/dist/game-factory/move/move-factory.d.ts.map +1 -0
- package/dist/game-factory/move/move.d.ts +54 -0
- package/dist/game-factory/move/move.d.ts.map +1 -0
- package/dist/game-factory/move/pass-turn.d.ts +5 -0
- package/dist/game-factory/move/pass-turn.d.ts.map +1 -0
- package/{src/game-factory/move/pass.js → dist/game-factory/move/pass.d.ts} +2 -4
- package/dist/game-factory/move/pass.d.ts.map +1 -0
- package/dist/game-factory/move/place-new.d.ts +5 -0
- package/dist/game-factory/move/place-new.d.ts.map +1 -0
- package/dist/game-factory/move/remove-entity.d.ts +5 -0
- package/dist/game-factory/move/remove-entity.d.ts.map +1 -0
- package/dist/game-factory/move/set-active-players.d.ts +5 -0
- package/dist/game-factory/move/set-active-players.d.ts.map +1 -0
- package/dist/game-factory/move/set-state.d.ts +5 -0
- package/dist/game-factory/move/set-state.d.ts.map +1 -0
- package/dist/game-factory/move/shuffle.d.ts +5 -0
- package/dist/game-factory/move/shuffle.d.ts.map +1 -0
- package/dist/game-factory/move/take-from.d.ts +11 -0
- package/dist/game-factory/move/take-from.d.ts.map +1 -0
- package/dist/game-factory/space/space.d.ts +10 -0
- package/dist/game-factory/space/space.d.ts.map +1 -0
- package/dist/game-factory/space-group/grid.d.ts +15 -0
- package/dist/game-factory/space-group/grid.d.ts.map +1 -0
- package/dist/game-factory/space-group/space-group.d.ts +20 -0
- package/dist/game-factory/space-group/space-group.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/registry.d.ts +17 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/types/bagel-types.d.ts +339 -0
- package/dist/types/bagel-types.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/rule-with-conditions.d.ts +9 -0
- package/dist/types/rule-with-conditions.d.ts.map +1 -0
- package/dist/utils/any-valid-moves.d.ts +2 -0
- package/dist/utils/any-valid-moves.d.ts.map +1 -0
- package/dist/utils/bgio-resolve-types.d.ts +25 -0
- package/dist/utils/bgio-resolve-types.d.ts.map +1 -0
- package/dist/utils/check-conditions.d.ts +7 -0
- package/dist/utils/check-conditions.d.ts.map +1 -0
- package/dist/utils/create-payload.d.ts +5 -0
- package/dist/utils/create-payload.d.ts.map +1 -0
- package/dist/utils/deserialize-bgio-arguments.d.ts +3 -0
- package/dist/utils/deserialize-bgio-arguments.d.ts.map +1 -0
- package/dist/utils/do-moves.d.ts +8 -0
- package/dist/utils/do-moves.d.ts.map +1 -0
- package/dist/utils/entity-matches.d.ts +6 -0
- package/dist/utils/entity-matches.d.ts.map +1 -0
- package/dist/utils/find-met-condition.d.ts +6 -0
- package/dist/utils/find-met-condition.d.ts.map +1 -0
- package/dist/utils/get-current-moves.d.ts +24 -0
- package/dist/utils/get-current-moves.d.ts.map +1 -0
- package/dist/utils/get-scenario-results.d.ts +3 -0
- package/dist/utils/get-scenario-results.d.ts.map +1 -0
- package/dist/utils/get-steps.d.ts +13 -0
- package/dist/utils/get-steps.d.ts.map +1 -0
- package/dist/utils/get.d.ts +7 -0
- package/dist/utils/get.d.ts.map +1 -0
- package/dist/utils/grid-contains-sequence.d.ts +27 -0
- package/dist/utils/grid-contains-sequence.d.ts.map +1 -0
- package/dist/utils/json-transformer.d.ts +8 -0
- package/dist/utils/json-transformer.d.ts.map +1 -0
- package/dist/utils/prepare-payload.d.ts +2 -0
- package/dist/utils/prepare-payload.d.ts.map +1 -0
- package/dist/utils/resolve-entity.d.ts +3 -0
- package/dist/utils/resolve-entity.d.ts.map +1 -0
- package/dist/utils/resolve-expression.d.ts +6 -0
- package/dist/utils/resolve-expression.d.ts.map +1 -0
- package/dist/utils/resolve-properties.d.ts +4 -0
- package/dist/utils/resolve-properties.d.ts.map +1 -0
- package/dist/utils/simulate-move.d.ts +16 -0
- package/dist/utils/simulate-move.d.ts.map +1 -0
- package/e2e/fixtures/bge-checkers.html +1 -2
- package/e2e/fixtures/bge-minimal.html +1 -2
- package/e2e/fixtures/bge-ttt.html +1 -2
- package/examples/index.html +1 -1
- package/package.json +9 -3
- package/playwright-report/index.html +1 -1
- package/scripts/build.mjs +2 -2
- package/src/client/client.ts +305 -0
- package/src/game-factory/bank/bank-slot.ts +81 -0
- package/src/game-factory/bank/bank.ts +125 -0
- package/src/game-factory/{board.js → board.ts} +1 -1
- package/src/game-factory/condition/condition-factory.ts +59 -0
- package/src/game-factory/condition/condition.ts +50 -0
- package/src/game-factory/condition/{contains-condition.js → contains-condition.ts} +5 -4
- package/src/game-factory/condition/{contains-same-condition.js → contains-same-condition.ts} +8 -5
- package/src/game-factory/condition/{evaluate-condition.js → evaluate-condition.ts} +4 -3
- package/src/game-factory/condition/every-condition.ts +27 -0
- package/src/game-factory/condition/has-line-condition.ts +15 -0
- package/src/game-factory/condition/in-line-condition.ts +25 -0
- package/src/game-factory/condition/is-condition.ts +24 -0
- package/src/game-factory/condition/is-full-condition.ts +10 -0
- package/src/game-factory/condition/{no-possible-moves-condition.js → no-possible-moves-condition.ts} +3 -2
- package/src/game-factory/condition/{not-condition.js → not-condition.ts} +3 -2
- package/src/game-factory/condition/{or-condition.js → or-condition.ts} +3 -2
- package/src/game-factory/condition/position-condition.ts +13 -0
- package/src/game-factory/condition/{some-condition.js → some-condition.ts} +5 -3
- package/src/game-factory/condition/would-condition.ts +104 -0
- package/src/game-factory/entity.ts +37 -0
- package/src/game-factory/expand-game-rules.ts +263 -0
- package/src/game-factory/game-factory.ts +263 -0
- package/src/game-factory/move/end-turn.ts +7 -0
- package/src/game-factory/move/for-each.ts +20 -0
- package/src/game-factory/move/move-entity.ts +18 -0
- package/src/game-factory/move/move-factory.ts +107 -0
- package/src/game-factory/move/move.ts +147 -0
- package/src/game-factory/move/pass-turn.ts +15 -0
- package/src/game-factory/move/pass.ts +7 -0
- package/src/game-factory/move/place-new.ts +42 -0
- package/src/game-factory/move/remove-entity.ts +11 -0
- package/src/game-factory/move/set-active-players.ts +26 -0
- package/src/game-factory/move/set-state.ts +14 -0
- package/src/game-factory/move/shuffle.ts +9 -0
- package/src/game-factory/move/take-from.ts +12 -0
- package/src/game-factory/space/space.ts +36 -0
- package/src/game-factory/space-group/grid.ts +48 -0
- package/src/game-factory/space-group/space-group.ts +44 -0
- package/src/index.ts +5 -0
- package/src/types/bagel-types.ts +449 -0
- package/src/types/boardgame-io-core.d.ts +7 -0
- package/src/types/index.ts +70 -0
- package/src/types/rule-with-conditions.ts +9 -0
- package/src/utils/{any-valid-moves.js → any-valid-moves.ts} +54 -49
- package/src/utils/bgio-resolve-types.ts +27 -0
- package/src/utils/check-conditions.ts +28 -0
- package/src/utils/create-payload.ts +19 -0
- package/src/utils/deserialize-bgio-arguments.ts +10 -0
- package/src/utils/do-moves.ts +22 -0
- package/src/utils/entity-matches.ts +30 -0
- package/src/utils/expr-eval.d.ts +6 -0
- package/src/utils/find-met-condition.ts +23 -0
- package/src/utils/get-current-moves.ts +39 -0
- package/src/utils/get-scenario-results.ts +30 -0
- package/src/utils/get-steps.ts +38 -0
- package/src/utils/get.ts +28 -0
- package/src/utils/{grid-contains-sequence.js → grid-contains-sequence.ts} +71 -33
- package/src/utils/json-transformer.ts +17 -0
- package/src/utils/prepare-payload.ts +20 -0
- package/src/utils/resolve-entity.ts +15 -0
- package/src/utils/resolve-expression.ts +16 -0
- package/src/utils/resolve-properties.ts +172 -0
- package/src/utils/simulate-move.ts +32 -0
- package/src/wackson.d.ts +4 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +21 -0
- package/src/client/client.js +0 -224
- package/src/game-factory/bank/bank-slot.js +0 -69
- package/src/game-factory/bank/bank.js +0 -114
- package/src/game-factory/condition/condition-factory.js +0 -52
- package/src/game-factory/condition/condition.js +0 -39
- package/src/game-factory/condition/every-condition.js +0 -25
- package/src/game-factory/condition/has-line-condition.js +0 -14
- package/src/game-factory/condition/in-line-condition.js +0 -19
- package/src/game-factory/condition/is-condition.js +0 -23
- package/src/game-factory/condition/is-full-condition.js +0 -9
- package/src/game-factory/condition/position-condition.js +0 -12
- package/src/game-factory/condition/would-condition.js +0 -94
- package/src/game-factory/entity.js +0 -29
- package/src/game-factory/expand-game-rules.js +0 -271
- package/src/game-factory/game-factory.js +0 -239
- package/src/game-factory/move/for-each.js +0 -18
- package/src/game-factory/move/move-entity.js +0 -16
- package/src/game-factory/move/move-factory.js +0 -89
- package/src/game-factory/move/move.js +0 -131
- package/src/game-factory/move/pass-turn.js +0 -10
- package/src/game-factory/move/place-new.js +0 -33
- package/src/game-factory/move/remove-entity.js +0 -7
- package/src/game-factory/move/set-active-players.js +0 -23
- package/src/game-factory/move/set-state.js +0 -11
- package/src/game-factory/move/shuffle.js +0 -7
- package/src/game-factory/move/take-from.js +0 -7
- package/src/game-factory/space/space.js +0 -30
- package/src/game-factory/space-group/grid.js +0 -43
- package/src/game-factory/space-group/space-group.js +0 -29
- package/src/index.js +0 -2
- package/src/utils/check-conditions.js +0 -28
- package/src/utils/create-payload.js +0 -16
- package/src/utils/deserialize-bgio-arguments.js +0 -8
- package/src/utils/do-moves.js +0 -18
- package/src/utils/entity-matches.js +0 -20
- package/src/utils/find-met-condition.js +0 -22
- package/src/utils/get-current-moves.js +0 -12
- package/src/utils/get-scenario-results.js +0 -23
- package/src/utils/get-steps.js +0 -29
- package/src/utils/get.js +0 -25
- package/src/utils/json-transformer.js +0 -12
- package/src/utils/prepare-payload.js +0 -16
- package/src/utils/resolve-entity.js +0 -9
- package/src/utils/resolve-expression.js +0 -10
- package/src/utils/resolve-properties.js +0 -149
- package/src/utils/simulate-move.js +0 -25
- /package/src/game-factory/move/{index.js → index.ts} +0 -0
- /package/src/{registry.js → registry.ts} +0 -0
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { serialize, deserialize } from 'wackson'
|
|
2
|
-
import { INVALID_MOVE } from '@mnbroatch/boardgame.io/dist/cjs/core.js';
|
|
3
|
-
import { registry } from '../../registry.js'
|
|
4
|
-
import deserializeBgioArguments from '../../utils/deserialize-bgio-arguments.js'
|
|
5
|
-
import MoveEntity from "./move-entity.js";
|
|
6
|
-
import RemoveEntity from "./remove-entity.js";
|
|
7
|
-
import PlaceNew from "./place-new.js";
|
|
8
|
-
import TakeFrom from "./take-from.js";
|
|
9
|
-
import SetState from "./set-state.js";
|
|
10
|
-
import SetActivePlayers from "./set-active-players.js";
|
|
11
|
-
import EndTurn from "./end-turn.js";
|
|
12
|
-
import PassTurn from "./pass-turn.js";
|
|
13
|
-
import ForEach from "./for-each.js";
|
|
14
|
-
import Pass from "./pass.js";
|
|
15
|
-
import Shuffle from "./shuffle.js";
|
|
16
|
-
|
|
17
|
-
export default function moveFactory(moveRule, game) {
|
|
18
|
-
const moveInstance = getMoveInstance(moveRule)
|
|
19
|
-
|
|
20
|
-
// accepts serialized G and payload, returns serialized
|
|
21
|
-
const compatibleMove = function (
|
|
22
|
-
bgioArguments,
|
|
23
|
-
serializablePayload
|
|
24
|
-
) {
|
|
25
|
-
const newBgioArguments = deserializeBgioArguments(bgioArguments)
|
|
26
|
-
const { G } = newBgioArguments
|
|
27
|
-
const payload = revivePayload(serializablePayload, G)
|
|
28
|
-
const context = { moveInstance, game }
|
|
29
|
-
const moveConditionResults = moveInstance.doMove(newBgioArguments, payload, context)
|
|
30
|
-
|
|
31
|
-
context.moveConditionResults = [moveConditionResults]
|
|
32
|
-
|
|
33
|
-
if (moveConditionResults !== INVALID_MOVE && moveRule.then) {
|
|
34
|
-
for (let automaticMoveRule of moveRule.then) {
|
|
35
|
-
const result = getMoveInstance(automaticMoveRule).doMove(
|
|
36
|
-
newBgioArguments,
|
|
37
|
-
{},
|
|
38
|
-
{...context} // spread here so prevArguments doesn't change for sibling
|
|
39
|
-
)
|
|
40
|
-
context.moveConditionResults.push(result)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return JSON.parse(serialize(G))
|
|
45
|
-
}
|
|
46
|
-
compatibleMove.moveInstance = moveInstance
|
|
47
|
-
return compatibleMove
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function revivePayload (serializablePayload, G) {
|
|
51
|
-
if (serializablePayload) {
|
|
52
|
-
const payload = deserialize(JSON.stringify(serializablePayload), registry)
|
|
53
|
-
payload.arguments =
|
|
54
|
-
Object.entries(payload.arguments).reduce((acc, [key, argOrEntityId]) => ({
|
|
55
|
-
...acc,
|
|
56
|
-
[key]: typeof argOrEntityId === 'number' ? G.bank.locate(argOrEntityId) : argOrEntityId
|
|
57
|
-
}), {})
|
|
58
|
-
return payload
|
|
59
|
-
} else {
|
|
60
|
-
return serializablePayload
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getMoveInstance (moveRule) {
|
|
65
|
-
switch (moveRule.moveType) {
|
|
66
|
-
case 'MoveEntity':
|
|
67
|
-
return new MoveEntity(moveRule);
|
|
68
|
-
case 'PlaceNew':
|
|
69
|
-
return new PlaceNew(moveRule);
|
|
70
|
-
case 'RemoveEntity':
|
|
71
|
-
return new RemoveEntity(moveRule);
|
|
72
|
-
case 'TakeFrom':
|
|
73
|
-
return new TakeFrom(moveRule);
|
|
74
|
-
case 'SetState':
|
|
75
|
-
return new SetState(moveRule);
|
|
76
|
-
case 'ForEach':
|
|
77
|
-
return new ForEach(moveRule);
|
|
78
|
-
case 'Pass':
|
|
79
|
-
return new Pass(moveRule);
|
|
80
|
-
case 'Shuffle':
|
|
81
|
-
return new Shuffle(moveRule);
|
|
82
|
-
case 'SetActivePlayers':
|
|
83
|
-
return new SetActivePlayers(moveRule);
|
|
84
|
-
case 'EndTurn':
|
|
85
|
-
return new EndTurn(moveRule);
|
|
86
|
-
case 'PassTurn':
|
|
87
|
-
return new PassTurn(moveRule);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { INVALID_MOVE } from '@mnbroatch/boardgame.io/dist/cjs/core.js';
|
|
2
|
-
import checkConditions from "../../utils/check-conditions.js";
|
|
3
|
-
import resolveProperties from "../../utils/resolve-properties.js";
|
|
4
|
-
|
|
5
|
-
export default class Move {
|
|
6
|
-
constructor (rule) {
|
|
7
|
-
this.rule = this.transformRule(rule)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
checkValidity (bgioArguments, payload, context) {
|
|
11
|
-
const argRuleEntries = Object.entries(this.rule.arguments ?? {})
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
!argRuleEntries.every(([argName]) => {
|
|
15
|
-
const arg = payload.arguments[argName]
|
|
16
|
-
return arg !== undefined && (!Array.isArray(arg) || arg.length)
|
|
17
|
-
})
|
|
18
|
-
) {
|
|
19
|
-
// not the best return value but we don't want to do expensive checks
|
|
20
|
-
// when we know the operation is doomed. At least for now.
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const argumentResults = {}
|
|
25
|
-
|
|
26
|
-
for (let i = 0, len = argRuleEntries.length; i < len; i++) {
|
|
27
|
-
const [argName, argRule] = argRuleEntries[i]
|
|
28
|
-
const payloadArg = payload.arguments[argName]
|
|
29
|
-
const args = Array.isArray(payloadArg)
|
|
30
|
-
? payloadArg
|
|
31
|
-
: [payloadArg]
|
|
32
|
-
|
|
33
|
-
const argResults = []
|
|
34
|
-
for (let j = 0, len = args.length; j < len; j++) {
|
|
35
|
-
const arg = args[j]
|
|
36
|
-
const result = checkConditions(
|
|
37
|
-
bgioArguments,
|
|
38
|
-
argRule,
|
|
39
|
-
{ target: arg },
|
|
40
|
-
{ ...context, moveArguments: payload.arguments }
|
|
41
|
-
)
|
|
42
|
-
argResults.push(result)
|
|
43
|
-
if (!result.conditionsAreMet) {
|
|
44
|
-
break
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const argConditionsAreMet = argResults.at(-1).conditionsAreMet
|
|
49
|
-
argumentResults[argName] = {
|
|
50
|
-
results: argResults,
|
|
51
|
-
conditionsAreMet: argConditionsAreMet
|
|
52
|
-
}
|
|
53
|
-
if (!argConditionsAreMet) {
|
|
54
|
-
break
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const moveResults = checkConditions(
|
|
59
|
-
bgioArguments,
|
|
60
|
-
{ conditions: this.rule.conditions },
|
|
61
|
-
undefined,
|
|
62
|
-
{ ...context, moveArguments: payload.arguments }
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
argumentResults,
|
|
67
|
-
moveResults,
|
|
68
|
-
conditionsAreMet: moveResults.conditionsAreMet
|
|
69
|
-
&& Object.values(argumentResults).every(a => a.conditionsAreMet)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
isValid (bgioArguments, payload, context) {
|
|
74
|
-
const conditionResults = this.checkValidity(
|
|
75
|
-
bgioArguments,
|
|
76
|
-
payload,
|
|
77
|
-
context
|
|
78
|
-
)
|
|
79
|
-
return conditionResults.conditionsAreMet
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
doMove (bgioArguments, payload, context, { skipCheck = false } = {}) {
|
|
83
|
-
const rule = resolveProperties(
|
|
84
|
-
bgioArguments,
|
|
85
|
-
this.rule,
|
|
86
|
-
context
|
|
87
|
-
)
|
|
88
|
-
const resolvedPayload = {
|
|
89
|
-
...payload,
|
|
90
|
-
arguments: Object.entries(rule.arguments ?? {})
|
|
91
|
-
.reduce((acc, [argName, arg]) => {
|
|
92
|
-
return {
|
|
93
|
-
...acc,
|
|
94
|
-
[argName]: payload?.arguments?.[argName] ?? arg
|
|
95
|
-
};
|
|
96
|
-
}, {})
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// does not store automatic moves, do we need that?
|
|
100
|
-
if (rule.name) {
|
|
101
|
-
bgioArguments.G._meta.previousPayloads[rule.name] = resolvedPayload
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let conditionResults
|
|
105
|
-
if (!skipCheck) {
|
|
106
|
-
conditionResults = this.checkValidity(bgioArguments, resolvedPayload, context)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!skipCheck && !conditionResults.conditionsAreMet) {
|
|
110
|
-
return INVALID_MOVE
|
|
111
|
-
} else {
|
|
112
|
-
this.do(bgioArguments, rule, resolvedPayload, context)
|
|
113
|
-
if (context) {
|
|
114
|
-
context.previousArguments = resolvedPayload.arguments
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return { conditionResults }
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
transformRule (rule) {
|
|
122
|
-
const args = rule.arguments
|
|
123
|
-
for (let key in args) {
|
|
124
|
-
const arg = args[key]
|
|
125
|
-
if (!arg.playerChoice) {
|
|
126
|
-
arg.resolveAsEntity = true
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return rule
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import Move from "./move.js";
|
|
2
|
-
|
|
3
|
-
export default class PassTurn extends Move {
|
|
4
|
-
do(bgioArguments) {
|
|
5
|
-
if (bgioArguments.G._meta.passedPlayers.length < bgioArguments.ctx.numPlayers) {
|
|
6
|
-
bgioArguments.G._meta.passedPlayers.push(bgioArguments.ctx.currentPlayer)
|
|
7
|
-
bgioArguments.events.pass()
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import Move from "./move.js";
|
|
2
|
-
|
|
3
|
-
export default class PlaceNew extends Move {
|
|
4
|
-
do(bgioArguments, rule, { arguments: { destination } }, context) {
|
|
5
|
-
const entities = rule.matchMultiple
|
|
6
|
-
? bgioArguments.G.bank.getMultiple(
|
|
7
|
-
bgioArguments,
|
|
8
|
-
{
|
|
9
|
-
...rule.entity,
|
|
10
|
-
conditions: [
|
|
11
|
-
...(rule.entity?.conditions || []),
|
|
12
|
-
...(rule.conditions || []),
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
rule.count,
|
|
16
|
-
context
|
|
17
|
-
)
|
|
18
|
-
: [bgioArguments.G.bank.getOne(
|
|
19
|
-
bgioArguments,
|
|
20
|
-
{
|
|
21
|
-
...rule.entity,
|
|
22
|
-
conditions: [
|
|
23
|
-
...(rule.entity?.conditions || []),
|
|
24
|
-
...(rule.conditions || []),
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
context
|
|
28
|
-
)]
|
|
29
|
-
entities.forEach((entity) => {
|
|
30
|
-
destination.placeEntity(entity, rule.position)
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Move from "./move.js";
|
|
2
|
-
import doMoves from '../../utils/do-moves.js'
|
|
3
|
-
|
|
4
|
-
export default class SetActivePlayers extends Move {
|
|
5
|
-
do(bgioArguments, rule, _, context) {
|
|
6
|
-
bgioArguments.events.setActivePlayers(rule.options)
|
|
7
|
-
|
|
8
|
-
// this is going to need to be expanded to handle more complex things
|
|
9
|
-
// than "move current player to new stage"
|
|
10
|
-
const phaseName = bgioArguments.ctx.phase
|
|
11
|
-
const stageName = rule.options.currentPlayer?.stage
|
|
12
|
-
const phaseOrRoot = context.game.phases?.[phaseName] ?? context.game
|
|
13
|
-
const stage = phaseOrRoot?.turn?.stages?.[stageName]
|
|
14
|
-
doMoves(
|
|
15
|
-
bgioArguments,
|
|
16
|
-
stage?.initialMoves,
|
|
17
|
-
{
|
|
18
|
-
...context,
|
|
19
|
-
stageName,
|
|
20
|
-
}
|
|
21
|
-
)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Move from "./move.js";
|
|
2
|
-
|
|
3
|
-
// todo: invariant conditions like "is one of the allowed values"
|
|
4
|
-
export default class SetState extends Move {
|
|
5
|
-
do(_, __, { arguments: { entity, state } }) {
|
|
6
|
-
entity.state = {
|
|
7
|
-
...entity.state,
|
|
8
|
-
[state.property]: state.value,
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import Entity from "../entity.js";
|
|
2
|
-
|
|
3
|
-
export default class Space extends Entity {
|
|
4
|
-
constructor (...args) {
|
|
5
|
-
super(...args)
|
|
6
|
-
this.entities = []
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
placeEntity (entity, position = 'Last') {
|
|
10
|
-
if (position === 'Last') {
|
|
11
|
-
this.entities.push(entity);
|
|
12
|
-
} else if (position === 'First') {
|
|
13
|
-
this.entities.unshift(entity);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
remove (entity) {
|
|
18
|
-
this.entities.splice(this.entities.indexOf(entity), 1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
takeOne (position = 'First') {
|
|
22
|
-
if (position === 'First') {
|
|
23
|
-
return this.entities.splice(0, 1)[0];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
isEmpty() {
|
|
28
|
-
return this.entities.length === 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import chunk from "lodash/chunk.js";
|
|
2
|
-
import SpaceGroup from "../space-group/space-group.js";
|
|
3
|
-
|
|
4
|
-
export default class Grid extends SpaceGroup {
|
|
5
|
-
getSpacesCount () {
|
|
6
|
-
return this.rule.width * this.rule.height
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
getRows () {
|
|
10
|
-
return chunk(this.spaces, this.rule.width)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getCoordinates (index) {
|
|
14
|
-
const { width } = this.rule
|
|
15
|
-
return [
|
|
16
|
-
index % width,
|
|
17
|
-
Math.floor(index/width)
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getIndex ([ x, y ]) {
|
|
22
|
-
const { width } = this.rule
|
|
23
|
-
return y * width + x
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getSpace (coordinates) {
|
|
27
|
-
return this.spaces[this.getIndex(coordinates)]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getRelativeCoordinates ([oldX, oldY], [relativeX, relativeY]) {
|
|
31
|
-
const newCoordinates = [oldX + relativeX, oldY + relativeY]
|
|
32
|
-
return this.areCoordinatesValid(newCoordinates)
|
|
33
|
-
? newCoordinates
|
|
34
|
-
: null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
areCoordinatesValid([x, y]) {
|
|
38
|
-
return x >= 0
|
|
39
|
-
&& y >= 0
|
|
40
|
-
&& x < this.rule.width
|
|
41
|
-
&& y < this.rule.height
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Entity from "../entity.js";
|
|
2
|
-
|
|
3
|
-
export default class SpaceGroup extends Entity {
|
|
4
|
-
constructor (options, ...rest) {
|
|
5
|
-
super(options, ...rest)
|
|
6
|
-
this.spaces = this.makeSpaces(options.bank);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
makeSpaces (bank) {
|
|
10
|
-
return Array(this.getSpacesCount()).fill()
|
|
11
|
-
.map((_, i) => bank.createEntity({ entityType: 'Space', index: i }))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getEmptySpaces() {
|
|
15
|
-
return this.spaces.filter(space => space.isEmpty())
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getSpace(index) {
|
|
19
|
-
return this.spaces[index]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getEntities(index) {
|
|
23
|
-
return this.getSpace(index).entities;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
placeEntity(index, entity) {
|
|
27
|
-
this.getSpace(index).placeEntity(entity);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import conditionFactory from '../game-factory/condition/condition-factory.js';
|
|
2
|
-
|
|
3
|
-
export default function checkConditions (
|
|
4
|
-
bgioArguments,
|
|
5
|
-
rule,
|
|
6
|
-
payload,
|
|
7
|
-
context
|
|
8
|
-
) {
|
|
9
|
-
const { conditions = [] } = rule
|
|
10
|
-
const results = [];
|
|
11
|
-
let failedAt
|
|
12
|
-
for (const conditionRule of conditions) {
|
|
13
|
-
const result = conditionFactory(conditionRule)
|
|
14
|
-
.check(bgioArguments, payload, context);
|
|
15
|
-
if (!result.conditionIsMet) {
|
|
16
|
-
failedAt = conditionRule
|
|
17
|
-
break
|
|
18
|
-
} else {
|
|
19
|
-
results.push(result);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
results,
|
|
25
|
-
failedAt,
|
|
26
|
-
conditionsAreMet: results.length === conditions.length
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import getSteps from './get-steps.js';
|
|
2
|
-
|
|
3
|
-
export default function createPayload (bgioState, moveRule, targets, context) {
|
|
4
|
-
const argNames = getSteps(
|
|
5
|
-
bgioState,
|
|
6
|
-
moveRule,
|
|
7
|
-
context
|
|
8
|
-
).map(s => s.argName)
|
|
9
|
-
return {
|
|
10
|
-
arguments: targets.reduce((acc, target, i) => ({
|
|
11
|
-
...acc,
|
|
12
|
-
[argNames[i]]: target
|
|
13
|
-
}), {})
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
package/src/utils/do-moves.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import moveFactory from "../game-factory/move/move-factory.js";
|
|
2
|
-
|
|
3
|
-
export default function doMoves (bgioArguments, moves = [], context) {
|
|
4
|
-
if (!moves?.length) {
|
|
5
|
-
return bgioArguments.G
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
moves.forEach((moveRule) => {
|
|
9
|
-
moveFactory(moveRule, context.game).moveInstance.doMove(
|
|
10
|
-
bgioArguments,
|
|
11
|
-
undefined,
|
|
12
|
-
context
|
|
13
|
-
);
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
return bgioArguments.G
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import matches from 'lodash/matches.js'
|
|
2
|
-
import resolveProperties from '../utils/resolve-properties.js'
|
|
3
|
-
|
|
4
|
-
function resolveMatcher (bgioArguments, matcher, context) {
|
|
5
|
-
const resolvedMatcher = { ...matcher }
|
|
6
|
-
delete resolvedMatcher.state
|
|
7
|
-
delete resolvedMatcher.stateGroups
|
|
8
|
-
return resolveProperties(bgioArguments, resolvedMatcher, context)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function getEntityMatcher (entity) {
|
|
12
|
-
return {
|
|
13
|
-
...entity.rule,
|
|
14
|
-
...entity.state
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default function entityMatches (bgioArguments, matcher, entity, context) {
|
|
19
|
-
return matches(resolveMatcher(bgioArguments, matcher, context))(getEntityMatcher(entity))
|
|
20
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import conditionFactory from '../game-factory/condition/condition-factory.js';
|
|
2
|
-
|
|
3
|
-
export default function findMetCondition (
|
|
4
|
-
bgioArguments,
|
|
5
|
-
{ conditions = [] },
|
|
6
|
-
payload,
|
|
7
|
-
context,
|
|
8
|
-
) {
|
|
9
|
-
let success
|
|
10
|
-
for (const conditionRule of conditions) {
|
|
11
|
-
const result = conditionFactory(conditionRule)
|
|
12
|
-
.check(bgioArguments, payload, context);
|
|
13
|
-
if (result.conditionIsMet) {
|
|
14
|
-
success = {
|
|
15
|
-
...result,
|
|
16
|
-
conditionRule
|
|
17
|
-
}
|
|
18
|
-
break
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return success
|
|
22
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// get the most specific set of moves for current stage/phase
|
|
2
|
-
// this will probably all break for complex stages with multiple active players
|
|
3
|
-
export default function getCurrentMoves (state, { game, playerID, stageName }) {
|
|
4
|
-
const phaseName = state.ctx.phase
|
|
5
|
-
|
|
6
|
-
// currentPlayer used for single player editor mode
|
|
7
|
-
const stageNameToUse = stageName ?? state.ctx.activePlayers?.[playerID ?? state.ctx.currentPlayer]
|
|
8
|
-
const phaseOrRoot = game.phases?.[phaseName] ?? game
|
|
9
|
-
const stageOrPhaseOrRoot = phaseOrRoot.turn?.stages?.[stageNameToUse] ?? phaseOrRoot
|
|
10
|
-
|
|
11
|
-
return stageOrPhaseOrRoot.moves ?? {}
|
|
12
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import checkConditions from "./check-conditions.js";
|
|
2
|
-
import resolveProperties from './resolve-properties.js'
|
|
3
|
-
|
|
4
|
-
export default function getScenarioResults(bgioArguments, scenarios, context) {
|
|
5
|
-
let match
|
|
6
|
-
for (const scenario of scenarios) {
|
|
7
|
-
const conditionResults = checkConditions(bgioArguments, scenario)
|
|
8
|
-
if (conditionResults.conditionsAreMet) {
|
|
9
|
-
match = { scenario, conditionResults }
|
|
10
|
-
break
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (match?.scenario?.result) {
|
|
15
|
-
return resolveProperties(
|
|
16
|
-
bgioArguments,
|
|
17
|
-
match.scenario.result,
|
|
18
|
-
{ results: match.conditionResults.results }
|
|
19
|
-
)
|
|
20
|
-
} else {
|
|
21
|
-
return match
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/utils/get-steps.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// controls order of what players need to click first
|
|
2
|
-
const argNamesMap = {
|
|
3
|
-
PlaceNew: ['destination'],
|
|
4
|
-
RemoveEntity: ['entity'],
|
|
5
|
-
MoveEntity: ['entity', 'destination'],
|
|
6
|
-
TakeFrom: ['source', 'destination'],
|
|
7
|
-
SetState: ['entity', 'state'],
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// this might not be where special handling for setstate wants to live
|
|
11
|
-
export default function getSteps (bgioState, moveRule) {
|
|
12
|
-
return argNamesMap[moveRule.moveType]
|
|
13
|
-
.filter(argName => moveRule.arguments[argName].playerChoice)
|
|
14
|
-
.map(argName => ({
|
|
15
|
-
argName,
|
|
16
|
-
getClickable: argName === 'state'
|
|
17
|
-
? () => moveRule.arguments[argName].possibleValues.map((value) => ({
|
|
18
|
-
abstract: true,
|
|
19
|
-
...moveRule.arguments[argName],
|
|
20
|
-
value
|
|
21
|
-
}))
|
|
22
|
-
: (context) => bgioState.G.bank.findAll(
|
|
23
|
-
bgioState,
|
|
24
|
-
moveRule.arguments[argName],
|
|
25
|
-
context
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
}))
|
|
29
|
-
}
|
package/src/utils/get.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export default function get (obj, pathArray) {
|
|
2
|
-
let current = obj;
|
|
3
|
-
|
|
4
|
-
for (const step of pathArray) {
|
|
5
|
-
if (current === undefined) {
|
|
6
|
-
return current
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (step?.flatten) {
|
|
10
|
-
if (!Array.isArray(current)) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
current = current.flat();
|
|
15
|
-
|
|
16
|
-
if (step.map) {
|
|
17
|
-
current = current.map(item => get(item, step.map));
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
current = current[step];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return current;
|
|
25
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// recurse and replace. circular references not allowed
|
|
2
|
-
export default function transformJSON(data, rules) {
|
|
3
|
-
return JSON.parse(JSON.stringify(data), (key, value) => {
|
|
4
|
-
let result = value;
|
|
5
|
-
for (const rule of rules) {
|
|
6
|
-
if (rule.test(result)) {
|
|
7
|
-
result = rule.replace(result);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { serialize } from "wackson";
|
|
2
|
-
|
|
3
|
-
// todo: remember why reducing to id was preferred?
|
|
4
|
-
export default function preparePayload (payload) {
|
|
5
|
-
if (payload?.arguments) {
|
|
6
|
-
const payloadCopy = { ...payload }
|
|
7
|
-
payloadCopy.arguments =
|
|
8
|
-
Object.entries(payloadCopy.arguments).reduce((acc, [key, argument]) => ({
|
|
9
|
-
...acc,
|
|
10
|
-
[key]: argument.abstract ? argument : argument.entityId
|
|
11
|
-
}), {})
|
|
12
|
-
return JSON.parse(serialize(payloadCopy, { deduplicateInstances: false }))
|
|
13
|
-
} else {
|
|
14
|
-
return payload
|
|
15
|
-
}
|
|
16
|
-
}
|