@dreamboard-games/sdk 0.5.0-alpha.3 → 0.5.0-alpha.4
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/README.md +52 -2
- package/dist/board-target-B0QG6OYx.d.ts +8 -0
- package/dist/chunk-3JXUL4VN.js +139 -0
- package/dist/chunk-3JXUL4VN.js.map +1 -0
- package/dist/{chunk-LRILEVKC.js → chunk-C77SYIVT.js} +82 -109
- package/dist/chunk-C77SYIVT.js.map +1 -0
- package/dist/{chunk-SP234IY4.js → chunk-OOFMBCFF.js} +178 -203
- package/dist/chunk-OOFMBCFF.js.map +1 -0
- package/dist/{chunk-ZPRKWPEP.js → chunk-UG2Q4NLG.js} +108 -29
- package/dist/chunk-UG2Q4NLG.js.map +1 -0
- package/dist/{chunk-FMM5LVJW.js → chunk-XU6WJW6K.js} +26 -12
- package/dist/chunk-XU6WJW6K.js.map +1 -0
- package/dist/{diagnostics-B0lgnuZ6.d.ts → diagnostics-B8d5aLad.d.ts} +2 -2
- package/dist/{definition-BaHNPZol.d.ts → extract-gVKcB8Og.d.ts} +484 -387
- package/dist/index.d.ts +404 -175
- package/dist/index.js +266 -215
- package/dist/index.js.map +1 -1
- package/dist/model-vdpLHrxh.d.ts +432 -0
- package/dist/react.d.ts +35 -7
- package/dist/react.js +136 -8
- package/dist/react.js.map +1 -1
- package/dist/reducer.d.ts +169 -118
- package/dist/reducer.js +206 -328
- package/dist/reducer.js.map +1 -1
- package/dist/testing.d.ts +5 -3
- package/dist/testing.js +9 -6
- package/dist/testing.js.map +1 -1
- package/dist/{types-DimqnJBq.d.ts → types-Bj5ZLTUV.d.ts} +38 -10
- package/package.json +19 -16
- package/dist/chunk-FMM5LVJW.js.map +0 -1
- package/dist/chunk-LRILEVKC.js.map +0 -1
- package/dist/chunk-SP234IY4.js.map +0 -1
- package/dist/chunk-VUWNJXLJ.js +0 -52
- package/dist/chunk-VUWNJXLJ.js.map +0 -1
- package/dist/chunk-ZPRKWPEP.js.map +0 -1
- package/dist/model-BHro6yXu.d.ts +0 -288
package/dist/reducer.js
CHANGED
|
@@ -22,8 +22,9 @@ import {
|
|
|
22
22
|
noopDiagnosticsSink,
|
|
23
23
|
parseBoardRefKey,
|
|
24
24
|
perPlayerBoardRef,
|
|
25
|
-
sharedBoardRef
|
|
26
|
-
|
|
25
|
+
sharedBoardRef,
|
|
26
|
+
validatedReducerDefinition
|
|
27
|
+
} from "./chunk-C77SYIVT.js";
|
|
27
28
|
import {
|
|
28
29
|
createHexBoardGeometry,
|
|
29
30
|
fromCoordinates,
|
|
@@ -33,8 +34,11 @@ import {
|
|
|
33
34
|
ring,
|
|
34
35
|
runtime_schema_exports,
|
|
35
36
|
spiral
|
|
36
|
-
} from "./chunk-
|
|
37
|
-
import
|
|
37
|
+
} from "./chunk-XU6WJW6K.js";
|
|
38
|
+
import {
|
|
39
|
+
isPlayerBoardSpaceTarget,
|
|
40
|
+
samePlayerBoardSpaceTarget
|
|
41
|
+
} from "./chunk-3JXUL4VN.js";
|
|
38
42
|
|
|
39
43
|
// src/reducer/manifest/compiler.ts
|
|
40
44
|
import { z as z2 } from "zod";
|
|
@@ -45,145 +49,6 @@ function buildTypedRecord(ids, initial) {
|
|
|
45
49
|
return Object.fromEntries(ids.map((id) => [id, createValue(id)]));
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
// src/reducer/manifest/preset-card-sets.ts
|
|
49
|
-
var STANDARD_DECK_ID = "standard_52_deck";
|
|
50
|
-
function createEnumPropertySchema(enums, description) {
|
|
51
|
-
return {
|
|
52
|
-
type: "enum",
|
|
53
|
-
description,
|
|
54
|
-
enums
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function createStringPropertySchema(description) {
|
|
58
|
-
return {
|
|
59
|
-
type: "string",
|
|
60
|
-
description
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function createStandard52CardDeck(defaultHome = { type: "detached" }) {
|
|
64
|
-
const suits = ["SPADES", "HEARTS", "CLUBS", "DIAMONDS"];
|
|
65
|
-
const ranks = [
|
|
66
|
-
"3",
|
|
67
|
-
"4",
|
|
68
|
-
"5",
|
|
69
|
-
"6",
|
|
70
|
-
"7",
|
|
71
|
-
"8",
|
|
72
|
-
"9",
|
|
73
|
-
"10",
|
|
74
|
-
"J",
|
|
75
|
-
"Q",
|
|
76
|
-
"K",
|
|
77
|
-
"A",
|
|
78
|
-
"2"
|
|
79
|
-
];
|
|
80
|
-
const cards = [];
|
|
81
|
-
for (const suit of suits) {
|
|
82
|
-
for (const rank of ranks) {
|
|
83
|
-
cards.push({
|
|
84
|
-
type: `${suit}_${rank}`,
|
|
85
|
-
name: `${rank} of ${suit}`,
|
|
86
|
-
imageUrl: `/cards/${suit.toLowerCase()}_${rank.toLowerCase()}.png`,
|
|
87
|
-
text: `A playing card: ${rank} of ${suit}. Value: ${getBigTwoCardValue(rank)}, Suit value: ${getSuitValue(suit)}`,
|
|
88
|
-
count: 1,
|
|
89
|
-
cardType: `${suit}_${rank}`,
|
|
90
|
-
properties: {
|
|
91
|
-
suit,
|
|
92
|
-
rank
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
id: STANDARD_DECK_ID,
|
|
99
|
-
name: "Standard 52-Card Deck",
|
|
100
|
-
type: "manual",
|
|
101
|
-
defaultHome,
|
|
102
|
-
cards,
|
|
103
|
-
cardSchema: {
|
|
104
|
-
properties: {
|
|
105
|
-
suit: createEnumPropertySchema(
|
|
106
|
-
["SPADES", "HEARTS", "CLUBS", "DIAMONDS"],
|
|
107
|
-
"The suit of the card"
|
|
108
|
-
),
|
|
109
|
-
rank: createStringPropertySchema("The rank of the card")
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function addStandardDecksIfNeeded(manifest) {
|
|
115
|
-
return {
|
|
116
|
-
...manifest,
|
|
117
|
-
cardSets: manifest.cardSets.map(
|
|
118
|
-
(cardSet) => cardSet.type === "preset" && cardSet.presetId === STANDARD_DECK_ID ? {
|
|
119
|
-
...createStandard52CardDeck(cardSet.defaultHome),
|
|
120
|
-
id: cardSet.id,
|
|
121
|
-
name: cardSet.name
|
|
122
|
-
} : cardSet
|
|
123
|
-
)
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function materializePresetCardSet(presetCardSet) {
|
|
127
|
-
if (presetCardSet.presetId !== STANDARD_DECK_ID) {
|
|
128
|
-
throw new Error(`Unsupported preset deck: ${presetCardSet.presetId}`);
|
|
129
|
-
}
|
|
130
|
-
const standardDeck = createStandard52CardDeck(presetCardSet.defaultHome);
|
|
131
|
-
return {
|
|
132
|
-
...standardDeck,
|
|
133
|
-
id: presetCardSet.id,
|
|
134
|
-
name: presetCardSet.name
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function materializeCardSet(cardSet) {
|
|
138
|
-
return cardSet.type === "manual" ? cardSet : materializePresetCardSet(cardSet);
|
|
139
|
-
}
|
|
140
|
-
function getBigTwoCardValue(rank) {
|
|
141
|
-
switch (rank) {
|
|
142
|
-
case "3":
|
|
143
|
-
return 3;
|
|
144
|
-
case "4":
|
|
145
|
-
return 4;
|
|
146
|
-
case "5":
|
|
147
|
-
return 5;
|
|
148
|
-
case "6":
|
|
149
|
-
return 6;
|
|
150
|
-
case "7":
|
|
151
|
-
return 7;
|
|
152
|
-
case "8":
|
|
153
|
-
return 8;
|
|
154
|
-
case "9":
|
|
155
|
-
return 9;
|
|
156
|
-
case "10":
|
|
157
|
-
return 10;
|
|
158
|
-
case "J":
|
|
159
|
-
return 11;
|
|
160
|
-
case "Q":
|
|
161
|
-
return 12;
|
|
162
|
-
case "K":
|
|
163
|
-
return 13;
|
|
164
|
-
case "A":
|
|
165
|
-
return 14;
|
|
166
|
-
case "2":
|
|
167
|
-
return 15;
|
|
168
|
-
default:
|
|
169
|
-
return 0;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function getSuitValue(suit) {
|
|
173
|
-
switch (suit) {
|
|
174
|
-
case "DIAMONDS":
|
|
175
|
-
return 1;
|
|
176
|
-
case "CLUBS":
|
|
177
|
-
return 2;
|
|
178
|
-
case "HEARTS":
|
|
179
|
-
return 3;
|
|
180
|
-
case "SPADES":
|
|
181
|
-
return 4;
|
|
182
|
-
default:
|
|
183
|
-
return 0;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
52
|
// src/reducer/manifest/manifest-validation.ts
|
|
188
53
|
function isHexBoardSpec(board) {
|
|
189
54
|
return board.layout === "hex";
|
|
@@ -223,37 +88,11 @@ function validateRecordKey(value, path) {
|
|
|
223
88
|
function collectKeyIssues(entries) {
|
|
224
89
|
return entries.flatMap(({ value, path }) => validateRecordKey(value, path));
|
|
225
90
|
}
|
|
226
|
-
function toHandleKey(input) {
|
|
227
|
-
if (!/[_-]/.test(input)) {
|
|
228
|
-
return input.charAt(0).toLowerCase() + input.slice(1);
|
|
229
|
-
}
|
|
230
|
-
const [first = "", ...rest] = input.split(/[_-]/g).filter(Boolean);
|
|
231
|
-
return [
|
|
232
|
-
first.toLowerCase(),
|
|
233
|
-
...rest.map((part) => {
|
|
234
|
-
const lower = part.toLowerCase();
|
|
235
|
-
return lower.charAt(0).toUpperCase() + lower.slice(1);
|
|
236
|
-
})
|
|
237
|
-
].join("");
|
|
238
|
-
}
|
|
239
|
-
function collectHandleKeyCollisions(values, label) {
|
|
240
|
-
const idsByHandle = /* @__PURE__ */ new Map();
|
|
241
|
-
for (const value of values) {
|
|
242
|
-
const handle = toHandleKey(value);
|
|
243
|
-
idsByHandle.set(handle, [...idsByHandle.get(handle) ?? [], value]);
|
|
244
|
-
}
|
|
245
|
-
return [...idsByHandle.entries()].filter(([, ids]) => ids.length > 1).map(
|
|
246
|
-
([handle, ids]) => `${label} values ${ids.join(", ")} all generate handle '${handle}'.`
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
function dedupeSorted(values) {
|
|
250
|
-
return Array.from(new Set(values)).sort();
|
|
251
|
-
}
|
|
252
91
|
function renderCardInstanceIds(card) {
|
|
253
92
|
return card.count > 1 ? Array.from(
|
|
254
93
|
{ length: card.count },
|
|
255
|
-
(_, index) => `${card.
|
|
256
|
-
) : [card.
|
|
94
|
+
(_, index) => `${card.id}-${index + 1}`
|
|
95
|
+
) : [card.id];
|
|
257
96
|
}
|
|
258
97
|
function collectPropertySchemaKeyIssues(schema, path) {
|
|
259
98
|
if (!schema) {
|
|
@@ -294,9 +133,6 @@ function collectObjectSchemaKeyIssues(schema, path) {
|
|
|
294
133
|
return issues;
|
|
295
134
|
}
|
|
296
135
|
function collectCardSchemaKeyIssues(cardSet, path) {
|
|
297
|
-
if (cardSet.type !== "manual") {
|
|
298
|
-
return [];
|
|
299
|
-
}
|
|
300
136
|
const schema = cardSet.cardSchema;
|
|
301
137
|
if ("variants" in schema) {
|
|
302
138
|
return [
|
|
@@ -426,9 +262,6 @@ function validateSlotHostsAndHomes(manifest) {
|
|
|
426
262
|
}
|
|
427
263
|
};
|
|
428
264
|
for (const [cardSetIndex, cardSet] of manifest.cardSets.entries()) {
|
|
429
|
-
if (cardSet.type !== "manual") {
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
265
|
validateHome(
|
|
433
266
|
cardSet.defaultHome,
|
|
434
267
|
`manifest.cardSets[${cardSetIndex}].defaultHome`
|
|
@@ -492,7 +325,7 @@ function validateCardHomes(manifest) {
|
|
|
492
325
|
for (const [cardSetIndex, cardSet] of manifest.cardSets.entries()) {
|
|
493
326
|
if (!cardSet.defaultHome) {
|
|
494
327
|
issues.push(
|
|
495
|
-
`manifest.cardSets[${cardSetIndex}].defaultHome:
|
|
328
|
+
`manifest.cardSets[${cardSetIndex}].defaultHome: Card sets must declare defaultHome.`
|
|
496
329
|
);
|
|
497
330
|
continue;
|
|
498
331
|
}
|
|
@@ -513,13 +346,26 @@ function validateCardHomes(manifest) {
|
|
|
513
346
|
`manifest.cardSets[${cardSetIndex}].defaultHome`,
|
|
514
347
|
`Card set '${cardSet.id}' defaultHome`
|
|
515
348
|
);
|
|
516
|
-
for (const [cardIndex, card] of
|
|
349
|
+
for (const [cardIndex, card] of cardSet.cards.entries()) {
|
|
517
350
|
const path = `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].home`;
|
|
518
|
-
validateCardHome(card.home, path, `Card '${card.
|
|
351
|
+
validateCardHome(card.home, path, `Card '${card.id}'`);
|
|
519
352
|
}
|
|
520
353
|
}
|
|
521
354
|
return issues;
|
|
522
355
|
}
|
|
356
|
+
var CARD_IMAGE_PATH = /^assets\/(?:[\w-][\w.-]*\/)*[\w-][\w.-]*\.(?:avif|gif|jpe?g|png|svg|webp)$/i;
|
|
357
|
+
function validateCardImages(manifest) {
|
|
358
|
+
return manifest.cardSets.flatMap(
|
|
359
|
+
(cardSet, cardSetIndex) => cardSet.cards.flatMap(
|
|
360
|
+
(card, cardIndex) => ["frontImage", "backImage"].flatMap((key) => {
|
|
361
|
+
const image = card[key];
|
|
362
|
+
return image === void 0 || CARD_IMAGE_PATH.test(image) ? [] : [
|
|
363
|
+
`manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].${key}: '${image}' must be an image path under assets/, such as assets/cards/front.webp.`
|
|
364
|
+
];
|
|
365
|
+
})
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
523
369
|
function homeTargetsBoard(home) {
|
|
524
370
|
return home?.type === "space" || home?.type === "container" || home?.type === "edge" || home?.type === "vertex";
|
|
525
371
|
}
|
|
@@ -763,15 +609,15 @@ function collectBoardRecordKeyIssues(manifest) {
|
|
|
763
609
|
}
|
|
764
610
|
function collectManifestRecordKeyIssues(manifest) {
|
|
765
611
|
const cardSets = manifest.cardSets;
|
|
766
|
-
const
|
|
767
|
-
(cardSet, cardSetIndex) => cardSet.
|
|
612
|
+
const cards = cardSets.flatMap(
|
|
613
|
+
(cardSet, cardSetIndex) => cardSet.cards.flatMap(
|
|
768
614
|
(card, cardIndex) => renderCardInstanceIds(card).map((cardId) => ({
|
|
769
615
|
card,
|
|
770
616
|
cardId,
|
|
771
617
|
cardIndex,
|
|
772
618
|
cardSetIndex
|
|
773
619
|
}))
|
|
774
|
-
)
|
|
620
|
+
)
|
|
775
621
|
);
|
|
776
622
|
return [
|
|
777
623
|
...collectKeyIssues([
|
|
@@ -779,10 +625,10 @@ function collectManifestRecordKeyIssues(manifest) {
|
|
|
779
625
|
value: cardSet.id,
|
|
780
626
|
path: `manifest.cardSets[${index}].id`
|
|
781
627
|
})),
|
|
782
|
-
...
|
|
628
|
+
...cards.flatMap(({ card, cardId, cardIndex, cardSetIndex }) => [
|
|
783
629
|
{
|
|
784
|
-
value: card.
|
|
785
|
-
path: `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].
|
|
630
|
+
value: card.id,
|
|
631
|
+
path: `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].id`
|
|
786
632
|
},
|
|
787
633
|
{
|
|
788
634
|
value: card.cardType,
|
|
@@ -845,19 +691,46 @@ function collectManifestRecordKeyIssues(manifest) {
|
|
|
845
691
|
`manifest.dieTypes[${typeIndex}].fieldsSchema`
|
|
846
692
|
)
|
|
847
693
|
),
|
|
848
|
-
...collectBoardRecordKeyIssues(manifest)
|
|
849
|
-
...collectHandleKeyCollisions(
|
|
850
|
-
dedupeSorted(manualCards.map(({ card }) => card.cardType ?? card.type)),
|
|
851
|
-
"Card type"
|
|
852
|
-
),
|
|
853
|
-
...collectHandleKeyCollisions(
|
|
854
|
-
dedupeSorted((manifest.zones ?? []).map((zone) => zone.id)),
|
|
855
|
-
"Zone"
|
|
856
|
-
)
|
|
694
|
+
...collectBoardRecordKeyIssues(manifest)
|
|
857
695
|
];
|
|
858
696
|
}
|
|
859
|
-
function
|
|
697
|
+
function validateCounts(manifest) {
|
|
860
698
|
const errors = [];
|
|
699
|
+
const check = (count, path) => {
|
|
700
|
+
if (!Number.isSafeInteger(count) || count < 1) {
|
|
701
|
+
errors.push(`${path}: Expected a positive safe integer.`);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
manifest.cardSets.forEach((set, setIndex) => {
|
|
705
|
+
set.cards.forEach(
|
|
706
|
+
(card, index) => check(card.count, `manifest.cardSets[${setIndex}].cards[${index}].count`)
|
|
707
|
+
);
|
|
708
|
+
});
|
|
709
|
+
for (const family of ["pieceSeeds", "dieSeeds"]) {
|
|
710
|
+
manifest[family]?.forEach((seed, index) => {
|
|
711
|
+
if (seed.count !== void 0)
|
|
712
|
+
check(seed.count, `manifest.${family}[${index}].count`);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
check(manifest.players.minPlayers, "manifest.players.minPlayers");
|
|
716
|
+
check(manifest.players.maxPlayers, "manifest.players.maxPlayers");
|
|
717
|
+
if (manifest.players.minPlayers > manifest.players.maxPlayers) {
|
|
718
|
+
errors.push("manifest.players: minPlayers must not exceed maxPlayers.");
|
|
719
|
+
}
|
|
720
|
+
return errors;
|
|
721
|
+
}
|
|
722
|
+
function assertValidManifest(manifest) {
|
|
723
|
+
const validation = validateManifestAuthoring(manifest);
|
|
724
|
+
if (validation.errors.length) {
|
|
725
|
+
throw new Error(
|
|
726
|
+
`Invalid topology manifest:
|
|
727
|
+
${validation.errors.join("\n")}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function validateManifestAuthoring(manifest) {
|
|
732
|
+
const errors = validateCounts(manifest);
|
|
733
|
+
if (errors.length) return { errors, warnings: [] };
|
|
861
734
|
errors.push(...collectManifestRecordKeyIssues(manifest));
|
|
862
735
|
errors.push(
|
|
863
736
|
...collectDuplicateIdIssues({
|
|
@@ -871,12 +744,12 @@ function validateManifestAuthoring(manifest) {
|
|
|
871
744
|
errors.push(
|
|
872
745
|
...collectDuplicateIdIssues({
|
|
873
746
|
entries: manifest.cardSets.flatMap(
|
|
874
|
-
(cardSet, cardSetIndex) => cardSet.
|
|
747
|
+
(cardSet, cardSetIndex) => cardSet.cards.flatMap(
|
|
875
748
|
(card, cardIndex) => renderCardInstanceIds(card).map((cardId) => ({
|
|
876
749
|
id: cardId,
|
|
877
|
-
path: `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].
|
|
750
|
+
path: `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].id`
|
|
878
751
|
}))
|
|
879
|
-
)
|
|
752
|
+
)
|
|
880
753
|
),
|
|
881
754
|
label: "card runtime id"
|
|
882
755
|
})
|
|
@@ -956,6 +829,22 @@ function validateManifestAuthoring(manifest) {
|
|
|
956
829
|
errors.push(...validateSlotHostsAndHomes(manifest));
|
|
957
830
|
errors.push(...validatePlayerScopedSeedHomes(manifest));
|
|
958
831
|
errors.push(...validateCardHomes(manifest));
|
|
832
|
+
for (const [cardSetIndex, cardSet] of manifest.cardSets.entries()) {
|
|
833
|
+
for (const [cardIndex, card] of cardSet.cards.entries()) {
|
|
834
|
+
const path = `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}]`;
|
|
835
|
+
if (typeof card.id !== "string" || card.id.length === 0) {
|
|
836
|
+
errors.push(`${path}.id: Card definition id is required.`);
|
|
837
|
+
}
|
|
838
|
+
if (typeof card.cardType !== "string" || card.cardType.length === 0) {
|
|
839
|
+
errors.push(`${path}.cardType: Card category is required.`);
|
|
840
|
+
} else if ("variants" in cardSet.cardSchema && !Object.hasOwn(cardSet.cardSchema.variants, card.cardType)) {
|
|
841
|
+
errors.push(
|
|
842
|
+
`${path}.cardType: Unknown card category '${card.cardType}' for card set '${cardSet.id}'.`
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
errors.push(...validateCardImages(manifest));
|
|
959
848
|
errors.push(...validateHexBoardVertexRefs(manifest));
|
|
960
849
|
return {
|
|
961
850
|
errors,
|
|
@@ -969,9 +858,6 @@ function isCardPropertySchemaVariants(schema) {
|
|
|
969
858
|
}
|
|
970
859
|
function mergeSharedCardProperties(schema, cardType) {
|
|
971
860
|
const variant = schema.variants[cardType];
|
|
972
|
-
if (!variant) {
|
|
973
|
-
return null;
|
|
974
|
-
}
|
|
975
861
|
return {
|
|
976
862
|
properties: {
|
|
977
863
|
...schema.shared ?? {},
|
|
@@ -982,7 +868,7 @@ function mergeSharedCardProperties(schema, cardType) {
|
|
|
982
868
|
function hasPropertySchemaDefault(property) {
|
|
983
869
|
return Boolean(property && "default" in property);
|
|
984
870
|
}
|
|
985
|
-
function
|
|
871
|
+
function dedupeSorted(values) {
|
|
986
872
|
return Array.from(new Set(values)).sort();
|
|
987
873
|
}
|
|
988
874
|
function sortedObject(entries) {
|
|
@@ -997,10 +883,10 @@ function renderCardInstanceIds2(card) {
|
|
|
997
883
|
if (card.count > 1) {
|
|
998
884
|
return Array.from(
|
|
999
885
|
{ length: card.count },
|
|
1000
|
-
(_, index) => `${card.
|
|
886
|
+
(_, index) => `${card.id}-${index + 1}`
|
|
1001
887
|
);
|
|
1002
888
|
}
|
|
1003
|
-
return [card.
|
|
889
|
+
return [card.id];
|
|
1004
890
|
}
|
|
1005
891
|
function expandSeedIds2(seeds) {
|
|
1006
892
|
const expanded = [];
|
|
@@ -1135,7 +1021,7 @@ function deriveSquareEdges(spaces) {
|
|
|
1135
1021
|
for (const side of SQUARE_SIDES) {
|
|
1136
1022
|
const geometryKey = squareEdgeGeometryKey(space, side);
|
|
1137
1023
|
const existing = edgeMap.get(geometryKey);
|
|
1138
|
-
const nextSpaceIds =
|
|
1024
|
+
const nextSpaceIds = dedupeSorted([
|
|
1139
1025
|
...existing?.spaceIds ?? [],
|
|
1140
1026
|
space.id
|
|
1141
1027
|
]);
|
|
@@ -1159,7 +1045,7 @@ function deriveSquareVertices(spaces) {
|
|
|
1159
1045
|
for (const corner of SQUARE_CORNERS) {
|
|
1160
1046
|
const geometryKey = squareCornerGeometryKey(space, corner);
|
|
1161
1047
|
const existing = vertexMap.get(geometryKey);
|
|
1162
|
-
const nextSpaceIds =
|
|
1048
|
+
const nextSpaceIds = dedupeSorted([
|
|
1163
1049
|
...existing?.spaceIds ?? [],
|
|
1164
1050
|
space.id
|
|
1165
1051
|
]);
|
|
@@ -1343,8 +1229,8 @@ function analyzeBoards(manifest, playerIds) {
|
|
|
1343
1229
|
function isSingletonExplicitSeed(seed) {
|
|
1344
1230
|
return typeof seed.id === "string" && seed.id.length > 0 && (seed.count ?? 1) === 1;
|
|
1345
1231
|
}
|
|
1346
|
-
function analyzeManifest(
|
|
1347
|
-
|
|
1232
|
+
function analyzeManifest(manifest, runtimePlayerIds) {
|
|
1233
|
+
assertValidManifest(manifest);
|
|
1348
1234
|
const playerIds = runtimePlayerIds ? [...runtimePlayerIds] : Array.from(
|
|
1349
1235
|
{ length: manifest.players.maxPlayers },
|
|
1350
1236
|
(_, index) => `player-${index + 1}`
|
|
@@ -1355,15 +1241,13 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1355
1241
|
const playerZones = (manifest.zones ?? []).filter(
|
|
1356
1242
|
(zone) => zone.scope === "perPlayer"
|
|
1357
1243
|
);
|
|
1358
|
-
const zoneIds =
|
|
1359
|
-
const cardSets = manifest.cardSets
|
|
1360
|
-
const cardSetIds =
|
|
1361
|
-
const cardTypes =
|
|
1362
|
-
cardSets.flatMap(
|
|
1363
|
-
(cardSet) => cardSet.cards.map((card) => card.cardType ?? card.type)
|
|
1364
|
-
)
|
|
1244
|
+
const zoneIds = dedupeSorted((manifest.zones ?? []).map((zone) => zone.id));
|
|
1245
|
+
const cardSets = manifest.cardSets;
|
|
1246
|
+
const cardSetIds = dedupeSorted(cardSets.map((cardSet) => cardSet.id));
|
|
1247
|
+
const cardTypes = dedupeSorted(
|
|
1248
|
+
cardSets.flatMap((cardSet) => cardSet.cards.map((card) => card.cardType))
|
|
1365
1249
|
);
|
|
1366
|
-
const cardIds =
|
|
1250
|
+
const cardIds = dedupeSorted(
|
|
1367
1251
|
cardSets.flatMap((cardSet) => cardSet.cards.flatMap(renderCardInstanceIds2))
|
|
1368
1252
|
);
|
|
1369
1253
|
const cardSetIdByCardId = /* @__PURE__ */ new Map();
|
|
@@ -1372,7 +1256,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1372
1256
|
for (const card of cardSet.cards) {
|
|
1373
1257
|
for (const cardId of renderCardInstanceIds2(card)) {
|
|
1374
1258
|
cardSetIdByCardId.set(cardId, cardSet.id);
|
|
1375
|
-
cardTypeByCardId.set(cardId, card.cardType
|
|
1259
|
+
cardTypeByCardId.set(cardId, card.cardType);
|
|
1376
1260
|
}
|
|
1377
1261
|
}
|
|
1378
1262
|
}
|
|
@@ -1380,14 +1264,14 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1380
1264
|
for (const zone of sharedZones) {
|
|
1381
1265
|
sharedZoneCardSetIds.set(
|
|
1382
1266
|
zone.id,
|
|
1383
|
-
|
|
1267
|
+
dedupeSorted(zone.allowedCardSetIds ?? [])
|
|
1384
1268
|
);
|
|
1385
1269
|
}
|
|
1386
1270
|
const playerZoneCardSetIds = /* @__PURE__ */ new Map();
|
|
1387
1271
|
for (const zone of playerZones) {
|
|
1388
1272
|
playerZoneCardSetIds.set(
|
|
1389
1273
|
zone.id,
|
|
1390
|
-
|
|
1274
|
+
dedupeSorted(zone.allowedCardSetIds ?? [])
|
|
1391
1275
|
);
|
|
1392
1276
|
}
|
|
1393
1277
|
const zoneCardSetIdsById = /* @__PURE__ */ new Map();
|
|
@@ -1408,7 +1292,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1408
1292
|
}
|
|
1409
1293
|
}
|
|
1410
1294
|
for (const [cardSetId, zoneIds2] of sharedZoneIdsByCardSetId.entries()) {
|
|
1411
|
-
sharedZoneIdsByCardSetId.set(cardSetId,
|
|
1295
|
+
sharedZoneIdsByCardSetId.set(cardSetId, dedupeSorted(zoneIds2));
|
|
1412
1296
|
}
|
|
1413
1297
|
const sharedZoneIdSet = new Set(sharedZones.map((zone) => zone.id));
|
|
1414
1298
|
const homeSharedZoneIdsByCardType = new Map(
|
|
@@ -1419,7 +1303,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1419
1303
|
if (card.home?.type !== "zone" || !sharedZoneIdSet.has(card.home.zoneId)) {
|
|
1420
1304
|
continue;
|
|
1421
1305
|
}
|
|
1422
|
-
const cardType = card.cardType
|
|
1306
|
+
const cardType = card.cardType;
|
|
1423
1307
|
const zoneIds2 = homeSharedZoneIdsByCardType.get(cardType) ?? [];
|
|
1424
1308
|
zoneIds2.push(card.home.zoneId);
|
|
1425
1309
|
homeSharedZoneIdsByCardType.set(cardType, zoneIds2);
|
|
@@ -1427,7 +1311,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1427
1311
|
}
|
|
1428
1312
|
const homeSharedZoneIdByCardType = /* @__PURE__ */ new Map();
|
|
1429
1313
|
for (const [cardType, zoneIds2] of homeSharedZoneIdsByCardType.entries()) {
|
|
1430
|
-
const uniqueZoneIds =
|
|
1314
|
+
const uniqueZoneIds = dedupeSorted(zoneIds2);
|
|
1431
1315
|
homeSharedZoneIdsByCardType.set(cardType, uniqueZoneIds);
|
|
1432
1316
|
const [homeZoneId] = uniqueZoneIds;
|
|
1433
1317
|
if (uniqueZoneIds.length === 1 && homeZoneId !== void 0) {
|
|
@@ -1440,7 +1324,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1440
1324
|
zone.visibility ?? "public"
|
|
1441
1325
|
])
|
|
1442
1326
|
);
|
|
1443
|
-
const resourceIds =
|
|
1327
|
+
const resourceIds = dedupeSorted(
|
|
1444
1328
|
(manifest.resources ?? []).map((resource) => resource.id)
|
|
1445
1329
|
);
|
|
1446
1330
|
const resourcePresentationById = sortedObject(
|
|
@@ -1452,7 +1336,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1452
1336
|
}
|
|
1453
1337
|
])
|
|
1454
1338
|
);
|
|
1455
|
-
const pieceTypeIds =
|
|
1339
|
+
const pieceTypeIds = dedupeSorted(
|
|
1456
1340
|
(manifest.pieceTypes ?? []).map((pieceType) => pieceType.id)
|
|
1457
1341
|
);
|
|
1458
1342
|
const pieceTypeSchemasById = new Map(
|
|
@@ -1464,7 +1348,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1464
1348
|
const pieceTypeSlotIdsById = new Map(
|
|
1465
1349
|
(manifest.pieceTypes ?? []).map((pieceType) => [
|
|
1466
1350
|
pieceType.id,
|
|
1467
|
-
|
|
1351
|
+
dedupeSorted((pieceType.slots ?? []).map((slot) => slot.id))
|
|
1468
1352
|
])
|
|
1469
1353
|
);
|
|
1470
1354
|
const pieceTypeIdByPieceId = /* @__PURE__ */ new Map();
|
|
@@ -1473,8 +1357,8 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1473
1357
|
pieceTypeIdByPieceId.set(pieceId, seed.typeId);
|
|
1474
1358
|
}
|
|
1475
1359
|
}
|
|
1476
|
-
const pieceIds =
|
|
1477
|
-
const dieTypeIds =
|
|
1360
|
+
const pieceIds = dedupeSorted(pieceTypeIdByPieceId.keys());
|
|
1361
|
+
const dieTypeIds = dedupeSorted(
|
|
1478
1362
|
(manifest.dieTypes ?? []).map((dieType) => dieType.id)
|
|
1479
1363
|
);
|
|
1480
1364
|
const dieTypeSchemasById = new Map(
|
|
@@ -1486,7 +1370,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1486
1370
|
const dieTypeSlotIdsById = new Map(
|
|
1487
1371
|
(manifest.dieTypes ?? []).map((dieType) => [
|
|
1488
1372
|
dieType.id,
|
|
1489
|
-
|
|
1373
|
+
dedupeSorted((dieType.slots ?? []).map((slot) => slot.id))
|
|
1490
1374
|
])
|
|
1491
1375
|
);
|
|
1492
1376
|
const dieTypeIdByDieId = /* @__PURE__ */ new Map();
|
|
@@ -1495,7 +1379,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1495
1379
|
dieTypeIdByDieId.set(dieId, seed.typeId);
|
|
1496
1380
|
}
|
|
1497
1381
|
}
|
|
1498
|
-
const dieIds =
|
|
1382
|
+
const dieIds = dedupeSorted(dieTypeIdByDieId.keys());
|
|
1499
1383
|
const strictSlotHosts = [
|
|
1500
1384
|
...(manifest.pieceSeeds ?? []).flatMap((seed) => {
|
|
1501
1385
|
if (!isSingletonExplicitSeed(seed)) {
|
|
@@ -1527,13 +1411,13 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1527
1411
|
(left, right) => left.kind.localeCompare(right.kind) || left.id.localeCompare(right.id)
|
|
1528
1412
|
);
|
|
1529
1413
|
const analyzedBoards = analyzeBoards(manifest, playerIds);
|
|
1530
|
-
const boardBaseIds =
|
|
1414
|
+
const boardBaseIds = dedupeSorted(
|
|
1531
1415
|
analyzedBoards.map(({ board }) => board.id)
|
|
1532
1416
|
);
|
|
1533
|
-
const boardIds =
|
|
1417
|
+
const boardIds = dedupeSorted(
|
|
1534
1418
|
analyzedBoards.flatMap((entry) => entry.runtimeBoardIds)
|
|
1535
1419
|
);
|
|
1536
|
-
const boardTypeIds =
|
|
1420
|
+
const boardTypeIds = dedupeSorted(
|
|
1537
1421
|
analyzedBoards.map((board) => board.boardTypeId).filter((typeId) => typeof typeId === "string")
|
|
1538
1422
|
);
|
|
1539
1423
|
const boardLayoutById = /* @__PURE__ */ new Map();
|
|
@@ -1555,14 +1439,14 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1555
1439
|
boardIdsByBaseId.set(analyzedBoard.board.id, analyzedBoard.runtimeBoardIds);
|
|
1556
1440
|
boardIdsByLayout.set(
|
|
1557
1441
|
analyzedBoard.board.layout,
|
|
1558
|
-
|
|
1442
|
+
dedupeSorted([
|
|
1559
1443
|
...boardIdsByLayout.get(analyzedBoard.board.layout) ?? [],
|
|
1560
1444
|
...analyzedBoard.runtimeBoardIds
|
|
1561
1445
|
])
|
|
1562
1446
|
);
|
|
1563
1447
|
boardBaseIdsByLayout.set(
|
|
1564
1448
|
analyzedBoard.board.layout,
|
|
1565
|
-
|
|
1449
|
+
dedupeSorted([
|
|
1566
1450
|
...boardBaseIdsByLayout.get(analyzedBoard.board.layout) ?? [],
|
|
1567
1451
|
analyzedBoard.board.id
|
|
1568
1452
|
])
|
|
@@ -1580,10 +1464,10 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1580
1464
|
container.host.type === "space" ? { type: "space", spaceId: container.host.spaceId } : { type: "board" }
|
|
1581
1465
|
])
|
|
1582
1466
|
);
|
|
1583
|
-
const runtimeRelationTypeIds = analyzedBoard.layout === "hex" ? ["adjacent"] : analyzedBoard.layout === "square" ?
|
|
1467
|
+
const runtimeRelationTypeIds = analyzedBoard.layout === "hex" ? ["adjacent"] : analyzedBoard.layout === "square" ? dedupeSorted([
|
|
1584
1468
|
"adjacent",
|
|
1585
1469
|
...analyzedBoard.relations.map((relation) => relation.typeId)
|
|
1586
|
-
]) :
|
|
1470
|
+
]) : dedupeSorted(
|
|
1587
1471
|
analyzedBoard.relations.map((relation) => relation.typeId)
|
|
1588
1472
|
);
|
|
1589
1473
|
for (const runtimeBoardId of analyzedBoard.runtimeBoardIds) {
|
|
@@ -1597,7 +1481,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1597
1481
|
if (analyzedBoard.boardTypeId) {
|
|
1598
1482
|
boardIdsByTypeId.set(
|
|
1599
1483
|
analyzedBoard.boardTypeId,
|
|
1600
|
-
|
|
1484
|
+
dedupeSorted([
|
|
1601
1485
|
...boardIdsByTypeId.get(analyzedBoard.boardTypeId) ?? [],
|
|
1602
1486
|
...analyzedBoard.runtimeBoardIds
|
|
1603
1487
|
])
|
|
@@ -1609,7 +1493,7 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1609
1493
|
}
|
|
1610
1494
|
spaceIdsByTypeId.set(
|
|
1611
1495
|
space.typeId,
|
|
1612
|
-
|
|
1496
|
+
dedupeSorted([...spaceIdsByTypeId.get(space.typeId) ?? [], space.id])
|
|
1613
1497
|
);
|
|
1614
1498
|
}
|
|
1615
1499
|
if (analyzedBoard.layout !== "generic") {
|
|
@@ -1620,9 +1504,9 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1620
1504
|
}
|
|
1621
1505
|
edgeIdsByTypeId.set(
|
|
1622
1506
|
edge.typeId,
|
|
1623
|
-
|
|
1507
|
+
dedupeSorted([...edgeIdsByTypeId.get(edge.typeId) ?? [], edge.id])
|
|
1624
1508
|
);
|
|
1625
|
-
edgeIdsForBoardByType[edge.typeId] =
|
|
1509
|
+
edgeIdsForBoardByType[edge.typeId] = dedupeSorted([
|
|
1626
1510
|
...edgeIdsForBoardByType[edge.typeId] ?? [],
|
|
1627
1511
|
edge.id
|
|
1628
1512
|
]);
|
|
@@ -1634,12 +1518,12 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1634
1518
|
}
|
|
1635
1519
|
vertexIdsByTypeId.set(
|
|
1636
1520
|
vertex.typeId,
|
|
1637
|
-
|
|
1521
|
+
dedupeSorted([
|
|
1638
1522
|
...vertexIdsByTypeId.get(vertex.typeId) ?? [],
|
|
1639
1523
|
vertex.id
|
|
1640
1524
|
])
|
|
1641
1525
|
);
|
|
1642
|
-
vertexIdsForBoardByType[vertex.typeId] =
|
|
1526
|
+
vertexIdsForBoardByType[vertex.typeId] = dedupeSorted([
|
|
1643
1527
|
...vertexIdsForBoardByType[vertex.typeId] ?? [],
|
|
1644
1528
|
vertex.id
|
|
1645
1529
|
]);
|
|
@@ -1653,30 +1537,30 @@ function analyzeManifest(inputManifest, runtimePlayerIds) {
|
|
|
1653
1537
|
}
|
|
1654
1538
|
}
|
|
1655
1539
|
}
|
|
1656
|
-
const relationTypeIds =
|
|
1540
|
+
const relationTypeIds = dedupeSorted(
|
|
1657
1541
|
Array.from(relationTypeIdsByBoardId.values()).flat()
|
|
1658
1542
|
);
|
|
1659
|
-
const edgeIds =
|
|
1543
|
+
const edgeIds = dedupeSorted(
|
|
1660
1544
|
analyzedBoards.flatMap(
|
|
1661
1545
|
(board) => board.layout === "generic" ? [] : board.edges.map((edge) => edge.id)
|
|
1662
1546
|
)
|
|
1663
1547
|
);
|
|
1664
|
-
const edgeTypeIds =
|
|
1665
|
-
const vertexIds =
|
|
1548
|
+
const edgeTypeIds = dedupeSorted(edgeIdsByTypeId.keys());
|
|
1549
|
+
const vertexIds = dedupeSorted(
|
|
1666
1550
|
analyzedBoards.flatMap(
|
|
1667
1551
|
(board) => board.layout === "generic" ? [] : board.vertices.map((vertex) => vertex.id)
|
|
1668
1552
|
)
|
|
1669
1553
|
);
|
|
1670
|
-
const vertexTypeIds =
|
|
1671
|
-
const boardContainerIds =
|
|
1554
|
+
const vertexTypeIds = dedupeSorted(vertexIdsByTypeId.keys());
|
|
1555
|
+
const boardContainerIds = dedupeSorted(
|
|
1672
1556
|
analyzedBoards.flatMap(
|
|
1673
1557
|
(board) => board.layout === "hex" ? [] : board.containers.map((container) => container.id)
|
|
1674
1558
|
)
|
|
1675
1559
|
);
|
|
1676
|
-
const spaceIds =
|
|
1560
|
+
const spaceIds = dedupeSorted(
|
|
1677
1561
|
analyzedBoards.flatMap((board) => board.spaces.map((space) => space.id))
|
|
1678
1562
|
);
|
|
1679
|
-
const spaceTypeIds =
|
|
1563
|
+
const spaceTypeIds = dedupeSorted(
|
|
1680
1564
|
analyzedBoards.flatMap(
|
|
1681
1565
|
(board) => board.spaces.map((space) => space.typeId).filter((typeId) => typeof typeId === "string")
|
|
1682
1566
|
)
|
|
@@ -1818,13 +1702,6 @@ function materializeCardPropertiesDefaults(schema, cardType, analysis) {
|
|
|
1818
1702
|
return materializeObjectSchemaDefaults(objectSchema, analysis);
|
|
1819
1703
|
}
|
|
1820
1704
|
function materializeManifestTable(options) {
|
|
1821
|
-
const validation = validateManifestAuthoring(options.manifest);
|
|
1822
|
-
if (validation.errors.length > 0) {
|
|
1823
|
-
throw new Error(
|
|
1824
|
-
`Cannot materialize invalid topology manifest:
|
|
1825
|
-
${validation.errors.join("\n")}`
|
|
1826
|
-
);
|
|
1827
|
-
}
|
|
1828
1705
|
const analysis = analyzeManifest(options.manifest, options.playerIds);
|
|
1829
1706
|
const manifest = analysis.manifest;
|
|
1830
1707
|
const playerIds = [...options.playerIds];
|
|
@@ -2031,32 +1908,33 @@ ${validation.errors.join("\n")}`
|
|
|
2031
1908
|
);
|
|
2032
1909
|
};
|
|
2033
1910
|
for (const [cardSetIndex, cardSet] of manifest.cardSets.entries()) {
|
|
2034
|
-
const
|
|
2035
|
-
for (const [cardIndex, card] of materializedCardSet.cards.entries()) {
|
|
1911
|
+
for (const [cardIndex, card] of cardSet.cards.entries()) {
|
|
2036
1912
|
const cardInstanceIds = renderCardInstanceIds2(card);
|
|
2037
1913
|
for (const [instanceIndex, cardId] of cardInstanceIds.entries()) {
|
|
2038
1914
|
cards[cardId] = {
|
|
2039
1915
|
id: cardId,
|
|
2040
|
-
cardSetId:
|
|
2041
|
-
cardType: card.cardType
|
|
1916
|
+
cardSetId: cardSet.id,
|
|
1917
|
+
cardType: card.cardType,
|
|
2042
1918
|
name: card.name,
|
|
2043
1919
|
text: card.text,
|
|
1920
|
+
frontImage: card.frontImage,
|
|
1921
|
+
backImage: card.backImage,
|
|
2044
1922
|
properties: {
|
|
2045
1923
|
...materializeCardPropertiesDefaults(
|
|
2046
|
-
|
|
2047
|
-
card.cardType
|
|
1924
|
+
cardSet.cardSchema,
|
|
1925
|
+
card.cardType,
|
|
2048
1926
|
analysis
|
|
2049
1927
|
),
|
|
2050
1928
|
...card.properties ?? {}
|
|
2051
1929
|
}
|
|
2052
1930
|
};
|
|
2053
|
-
const resolvedHome = card.home ??
|
|
1931
|
+
const resolvedHome = card.home ?? cardSet.defaultHome;
|
|
2054
1932
|
const path = card.home === void 0 ? `manifest.cardSets[${cardSetIndex}].defaultHome` : `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].home`;
|
|
2055
1933
|
componentLocations[cardId] = materializeComponentLocation(
|
|
2056
1934
|
resolvedHome,
|
|
2057
1935
|
{
|
|
2058
1936
|
path,
|
|
2059
|
-
label: `Card '${card.
|
|
1937
|
+
label: `Card '${card.id}' instance ${instanceIndex + 1}`
|
|
2060
1938
|
}
|
|
2061
1939
|
);
|
|
2062
1940
|
}
|
|
@@ -2574,7 +2452,7 @@ function createTableSchema(analysis, ids) {
|
|
|
2574
2452
|
const properties = schema && "variants" in schema ? objectSchema({
|
|
2575
2453
|
properties: {
|
|
2576
2454
|
...schema.shared,
|
|
2577
|
-
...schema.variants[type]
|
|
2455
|
+
...schema.variants[type].properties
|
|
2578
2456
|
}
|
|
2579
2457
|
}) : objectSchema(schema);
|
|
2580
2458
|
return z.object({
|
|
@@ -2584,6 +2462,8 @@ function createTableSchema(analysis, ids) {
|
|
|
2584
2462
|
cardType: z.literal(type),
|
|
2585
2463
|
name: z.string().optional(),
|
|
2586
2464
|
text: z.string().optional(),
|
|
2465
|
+
frontImage: z.string().optional(),
|
|
2466
|
+
backImage: z.string().optional(),
|
|
2587
2467
|
properties
|
|
2588
2468
|
});
|
|
2589
2469
|
}
|
|
@@ -2961,7 +2841,7 @@ function createTableSchema(analysis, ids) {
|
|
|
2961
2841
|
|
|
2962
2842
|
// src/reducer/manifest/compiler.ts
|
|
2963
2843
|
function compileManifest(manifest) {
|
|
2964
|
-
const source = manifest;
|
|
2844
|
+
const source = structuredClone(manifest);
|
|
2965
2845
|
const analysis = analyzeManifest(source);
|
|
2966
2846
|
const initial = materializeManifestTable({
|
|
2967
2847
|
manifest: source,
|
|
@@ -2982,6 +2862,7 @@ function compileManifest(manifest) {
|
|
|
2982
2862
|
sharedZoneIds,
|
|
2983
2863
|
playerZoneIds,
|
|
2984
2864
|
resourcePresentationById: analysis.resourcePresentationById,
|
|
2865
|
+
ownerResourceIds: (source.resources ?? []).filter((resource) => resource.visibility === "owner").map((resource) => resource.id).sort(),
|
|
2985
2866
|
handVisibilityById: Object.fromEntries(
|
|
2986
2867
|
playerZoneIds.map((id) => [
|
|
2987
2868
|
id,
|
|
@@ -3394,9 +3275,15 @@ function validateDefineGamePhaseNames(definition) {
|
|
|
3394
3275
|
);
|
|
3395
3276
|
}
|
|
3396
3277
|
}
|
|
3397
|
-
function
|
|
3278
|
+
function validateDefineGamePhases(definition) {
|
|
3398
3279
|
for (const [phaseName, phase] of Object.entries(definition.phases)) {
|
|
3399
3280
|
const phaseRecord = typeof phase === "object" && phase !== null ? phase : null;
|
|
3281
|
+
for (const interaction of Object.values(phaseRecord?.interactions ?? {})) {
|
|
3282
|
+
validateInteractionLikeDefinition(
|
|
3283
|
+
interaction,
|
|
3284
|
+
"defineInteraction"
|
|
3285
|
+
);
|
|
3286
|
+
}
|
|
3400
3287
|
if (!phaseRecord || phaseRecord.kind !== "simultaneousPlayer") {
|
|
3401
3288
|
continue;
|
|
3402
3289
|
}
|
|
@@ -3415,15 +3302,10 @@ function validateDefineGameSimultaneousPhases(definition) {
|
|
|
3415
3302
|
`defineGame: phases.${phaseName}.interactions.submit conflicts with the reserved simultaneous submit interaction id.`
|
|
3416
3303
|
);
|
|
3417
3304
|
}
|
|
3418
|
-
|
|
3419
|
-
phaseRecord.submit
|
|
3420
|
-
|
|
3305
|
+
validateInteractionLikeDefinition(
|
|
3306
|
+
phaseRecord.submit,
|
|
3307
|
+
`defineGame: phases.${phaseName}.submit`
|
|
3421
3308
|
);
|
|
3422
|
-
validateManyCommitPolicy({
|
|
3423
|
-
inputs: phaseRecord.submit.inputs,
|
|
3424
|
-
commit: phaseRecord.submit.commit,
|
|
3425
|
-
context: `defineGame: phases.${phaseName}.submit`
|
|
3426
|
-
});
|
|
3427
3309
|
}
|
|
3428
3310
|
}
|
|
3429
3311
|
|
|
@@ -3746,17 +3628,17 @@ function makeBoardCollector(kind) {
|
|
|
3746
3628
|
projection: "resolved",
|
|
3747
3629
|
targetKind: target.targetKind,
|
|
3748
3630
|
boardId: target.boardId,
|
|
3749
|
-
valueKind:
|
|
3631
|
+
valueKind: "board-id",
|
|
3750
3632
|
eligibleTargets: target.eligible({
|
|
3751
3633
|
state,
|
|
3752
3634
|
playerId,
|
|
3753
3635
|
q
|
|
3754
|
-
})
|
|
3636
|
+
})
|
|
3755
3637
|
}),
|
|
3756
3638
|
meta: {
|
|
3757
3639
|
targetKind: target.targetKind,
|
|
3758
3640
|
boardId: target.boardId,
|
|
3759
|
-
valueKind:
|
|
3641
|
+
valueKind: "board-id"
|
|
3760
3642
|
}
|
|
3761
3643
|
};
|
|
3762
3644
|
};
|
|
@@ -3773,7 +3655,7 @@ function playerSpaceInput(options) {
|
|
|
3773
3655
|
);
|
|
3774
3656
|
return {
|
|
3775
3657
|
kind: "board-space",
|
|
3776
|
-
schema: z5.
|
|
3658
|
+
schema: z5.strictObject({
|
|
3777
3659
|
boardId: z5.literal(target.boardId),
|
|
3778
3660
|
playerId: playerIdSchema,
|
|
3779
3661
|
spaceId: z5.string()
|
|
@@ -3794,19 +3676,19 @@ function playerSpaceInput(options) {
|
|
|
3794
3676
|
domain: (state, playerId, q) => ({
|
|
3795
3677
|
type: "boardTarget",
|
|
3796
3678
|
projection: "resolved",
|
|
3797
|
-
targetKind:
|
|
3679
|
+
targetKind: "space",
|
|
3798
3680
|
boardId: target.boardId,
|
|
3799
|
-
valueKind:
|
|
3681
|
+
valueKind: "player-board-space",
|
|
3800
3682
|
eligibleTargets: target.eligible({
|
|
3801
3683
|
state,
|
|
3802
3684
|
playerId,
|
|
3803
3685
|
q
|
|
3804
|
-
})
|
|
3686
|
+
})
|
|
3805
3687
|
}),
|
|
3806
3688
|
meta: {
|
|
3807
3689
|
targetKind: target.targetKind,
|
|
3808
3690
|
boardId: target.boardId,
|
|
3809
|
-
valueKind:
|
|
3691
|
+
valueKind: "player-board-space"
|
|
3810
3692
|
}
|
|
3811
3693
|
};
|
|
3812
3694
|
}
|
|
@@ -3901,40 +3783,35 @@ function createBoardTargetBuilder(targetKind, boardId) {
|
|
|
3901
3783
|
);
|
|
3902
3784
|
}
|
|
3903
3785
|
function createPlayerSpaceTargetBuilder(boardId) {
|
|
3904
|
-
return createTargetRuleBuilder(
|
|
3905
|
-
(
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3786
|
+
return createTargetRuleBuilder((predicates) => ({
|
|
3787
|
+
...createTargetRule(
|
|
3788
|
+
({ state, q }) => {
|
|
3789
|
+
const spacesForPlayer = (playerId) => candidateIdsForKind(
|
|
3790
|
+
q,
|
|
3791
|
+
`${boardId}:${playerId}`,
|
|
3792
|
+
"space"
|
|
3793
|
+
);
|
|
3794
|
+
return state.table.playerOrder.flatMap(
|
|
3795
|
+
(playerId) => spacesForPlayer(playerId).map((spaceId) => ({
|
|
3796
|
+
boardId,
|
|
3797
|
+
playerId,
|
|
3798
|
+
spaceId
|
|
3799
|
+
}))
|
|
3800
|
+
);
|
|
3801
|
+
},
|
|
3802
|
+
predicates,
|
|
3803
|
+
{
|
|
3804
|
+
missingCandidateIssue: {
|
|
3805
|
+
errorCode: "BOARD_TARGET_NOT_ELIGIBLE",
|
|
3806
|
+
message: "Board target is not eligible."
|
|
3920
3807
|
},
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
}
|
|
3929
|
-
),
|
|
3930
|
-
boardId,
|
|
3931
|
-
targetKind: "space",
|
|
3932
|
-
valueKind: "player-board-space"
|
|
3933
|
-
})
|
|
3934
|
-
);
|
|
3935
|
-
}
|
|
3936
|
-
function isPlayerBoardSpaceTarget(value) {
|
|
3937
|
-
return typeof value === "object" && value !== null && "boardId" in value && "playerId" in value && "spaceId" in value;
|
|
3808
|
+
equals: (left, right) => isPlayerBoardSpaceTarget(left) && isPlayerBoardSpaceTarget(right) && samePlayerBoardSpaceTarget(left, right)
|
|
3809
|
+
}
|
|
3810
|
+
),
|
|
3811
|
+
boardId,
|
|
3812
|
+
targetKind: "space",
|
|
3813
|
+
valueKind: "player-board-space"
|
|
3814
|
+
}));
|
|
3938
3815
|
}
|
|
3939
3816
|
function makeBoardTargetFactory(targetKind) {
|
|
3940
3817
|
return function target(boardId) {
|
|
@@ -4208,10 +4085,12 @@ function createPhaseAuthoring(_contract, schema) {
|
|
|
4208
4085
|
}
|
|
4209
4086
|
function createContractAuthoring(contract) {
|
|
4210
4087
|
const phaseCache = /* @__PURE__ */ new Map();
|
|
4211
|
-
const assemble = (definition) =>
|
|
4212
|
-
contract
|
|
4213
|
-
|
|
4214
|
-
|
|
4088
|
+
const assemble = (definition) => {
|
|
4089
|
+
const game = { ...definition, contract };
|
|
4090
|
+
validateDefineGamePhaseNames(game);
|
|
4091
|
+
validateDefineGamePhases(game);
|
|
4092
|
+
return { ...game, [validatedReducerDefinition]: true };
|
|
4093
|
+
};
|
|
4215
4094
|
return {
|
|
4216
4095
|
contract,
|
|
4217
4096
|
view: defineView(),
|
|
@@ -4303,11 +4182,6 @@ function defineGameContract(definition) {
|
|
|
4303
4182
|
}
|
|
4304
4183
|
|
|
4305
4184
|
// src/reducer/authoring/game.ts
|
|
4306
|
-
function defineGameDefinition(definition) {
|
|
4307
|
-
validateDefineGamePhaseNames(definition);
|
|
4308
|
-
validateDefineGameSimultaneousPhases(definition);
|
|
4309
|
-
return definition;
|
|
4310
|
-
}
|
|
4311
4185
|
function createGame(model) {
|
|
4312
4186
|
const manifest = "literals" in model.manifest ? model.manifest : compileManifest(model.manifest);
|
|
4313
4187
|
return createContractAuthoring(defineGameContract({ ...model, manifest }));
|
|
@@ -4336,7 +4210,11 @@ function memoize(fn) {
|
|
|
4336
4210
|
|
|
4337
4211
|
// src/reducer/manifest/authoring.ts
|
|
4338
4212
|
function defineTopologyManifest(manifest) {
|
|
4339
|
-
|
|
4213
|
+
const validated = structuredClone(manifest);
|
|
4214
|
+
assertValidManifest(
|
|
4215
|
+
validated
|
|
4216
|
+
);
|
|
4217
|
+
return validated;
|
|
4340
4218
|
}
|
|
4341
4219
|
export {
|
|
4342
4220
|
FrameworkErrorCodes,
|