@dreamboard-games/sdk 0.5.0-alpha.3 → 0.5.0-alpha.30
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 +344 -21
- package/dist/board-element-DXLPBVk-.d.ts +13 -0
- package/dist/{chunk-LRILEVKC.js → chunk-63GWNBZX.js} +2763 -2327
- package/dist/chunk-63GWNBZX.js.map +1 -0
- package/dist/{chunk-SP234IY4.js → chunk-BVWJS3AB.js} +752 -343
- package/dist/chunk-BVWJS3AB.js.map +1 -0
- package/dist/{chunk-ZPRKWPEP.js → chunk-CWANHA4C.js} +284 -138
- package/dist/chunk-CWANHA4C.js.map +1 -0
- package/dist/chunk-CZRPUWCT.js +1602 -0
- package/dist/chunk-CZRPUWCT.js.map +1 -0
- package/dist/{chunk-FMM5LVJW.js → chunk-IEMZ26FI.js} +192 -383
- package/dist/chunk-IEMZ26FI.js.map +1 -0
- package/dist/{diagnostics-B0lgnuZ6.d.ts → diagnostics-D3mzqjxL.d.ts} +2 -3
- package/dist/extract-Bi6_tzUr.d.ts +6899 -0
- package/dist/index.d.ts +2058 -385
- package/dist/index.js +1260 -288
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +153 -8
- package/dist/react.js +1396 -30
- package/dist/react.js.map +1 -1
- package/dist/reducer.d.ts +592 -776
- package/dist/reducer.js +4617 -4055
- package/dist/reducer.js.map +1 -1
- package/dist/shortcuts-CuQXWAMv.d.ts +824 -0
- package/dist/testing.d.ts +59 -53
- package/dist/testing.js +335 -190
- package/dist/testing.js.map +1 -1
- package/dist/types-BlvVQ9WL.d.ts +125 -0
- package/package.json +17 -17
- package/dist/chunk-DMFVAZI2.js +0 -16
- package/dist/chunk-DMFVAZI2.js.map +0 -1
- 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/definition-BaHNPZol.d.ts +0 -4639
- package/dist/model-BHro6yXu.d.ts +0 -288
- package/dist/types-DimqnJBq.d.ts +0 -86
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
immutableCopy
|
|
3
|
-
} from "./chunk-DMFVAZI2.js";
|
|
4
|
-
import {
|
|
5
|
-
BoardStaticProjectionSchema,
|
|
6
|
-
GameEventDetailSchema,
|
|
7
|
-
GameEventSchema,
|
|
8
2
|
GameOutcomeSchema,
|
|
9
3
|
InteractionDescriptorSchema,
|
|
10
|
-
|
|
4
|
+
ProjectedGameEventDetailSchema,
|
|
5
|
+
ProjectedGameEventSchema,
|
|
11
6
|
SeatProjectionBundleSchema,
|
|
12
7
|
SimultaneousPhaseProjectionSchema,
|
|
13
8
|
SystemActionEventSchema,
|
|
9
|
+
ViewCardSchema
|
|
10
|
+
} from "./chunk-IEMZ26FI.js";
|
|
11
|
+
import {
|
|
12
|
+
BoardProjectionSchema,
|
|
13
|
+
PlayerIdSchema,
|
|
14
|
+
ProjectedTileSchema,
|
|
15
|
+
RuntimeJsonSchema,
|
|
14
16
|
canonicalizePluginRuntimeJson,
|
|
15
|
-
digestPluginRuntimeJson
|
|
16
|
-
|
|
17
|
+
digestPluginRuntimeJson,
|
|
18
|
+
immutableCopy
|
|
19
|
+
} from "./chunk-CZRPUWCT.js";
|
|
17
20
|
|
|
18
21
|
// src/shared/protocol/protocol.ts
|
|
19
22
|
var DREAMBOARD_PLUGIN_PROTOCOL = "dreamboard-plugin";
|
|
20
|
-
var DREAMBOARD_PLUGIN_PROTOCOL_VERSION =
|
|
23
|
+
var DREAMBOARD_PLUGIN_PROTOCOL_VERSION = 11;
|
|
21
24
|
|
|
22
25
|
// src/shared/protocol/schema.ts
|
|
23
|
-
import
|
|
24
|
-
var
|
|
25
|
-
var GameEventDetailSchema2 = GameEventDetailSchema;
|
|
26
|
+
import * as z from "zod";
|
|
27
|
+
var GameEventDetailSchema = ProjectedGameEventDetailSchema;
|
|
26
28
|
var SystemActionEventSchema2 = SystemActionEventSchema;
|
|
27
|
-
var
|
|
29
|
+
var GameEventSchema = ProjectedGameEventSchema;
|
|
28
30
|
var SeatProjectionBundleSchema2 = SeatProjectionBundleSchema;
|
|
29
|
-
var PlayerIdSchema = z.string().min(1);
|
|
30
31
|
var PluginPlayerSummarySchema = z.object({
|
|
31
32
|
playerId: PlayerIdSchema,
|
|
32
33
|
displayName: z.string(),
|
|
@@ -34,51 +35,67 @@ var PluginPlayerSummarySchema = z.object({
|
|
|
34
35
|
}).strict();
|
|
35
36
|
var PluginSessionDescriptorSchema = z.object({
|
|
36
37
|
sessionId: z.string().min(1),
|
|
37
|
-
players: z.array(PluginPlayerSummarySchema)
|
|
38
|
+
players: z.array(PluginPlayerSummarySchema),
|
|
39
|
+
assets: z.record(z.string(), z.instanceof(Blob)).optional()
|
|
38
40
|
}).strict();
|
|
39
41
|
var ZoneHandlesSnapshotSchema = z.object({
|
|
42
|
+
tiles: z.array(ProjectedTileSchema),
|
|
40
43
|
cardIds: z.array(z.string()),
|
|
41
|
-
cardViewsById: z.record(z.string(),
|
|
44
|
+
cardViewsById: z.record(z.string(), ViewCardSchema),
|
|
45
|
+
cardBacksById: z.record(z.string(), z.string()),
|
|
42
46
|
playableByCardId: z.record(
|
|
43
47
|
z.string(),
|
|
44
48
|
z.array(InteractionDescriptorSchema)
|
|
45
|
-
)
|
|
49
|
+
),
|
|
50
|
+
shuffled: z.literal(true).optional()
|
|
46
51
|
}).strict();
|
|
47
52
|
var SimultaneousPhaseSnapshotSchema = SimultaneousPhaseProjectionSchema;
|
|
48
53
|
var GameplayBasisSchema = z.object({
|
|
54
|
+
sessionId: z.string().min(1),
|
|
49
55
|
version: z.number().int().nonnegative(),
|
|
50
56
|
actionSetVersion: z.string().min(1),
|
|
51
57
|
perspectivePlayerId: PlayerIdSchema
|
|
52
58
|
}).strict();
|
|
53
59
|
var GameOutcomeSchema2 = GameOutcomeSchema;
|
|
60
|
+
var ProjectedViewSchema = z.record(z.string(), RuntimeJsonSchema).superRefine((view, context) => {
|
|
61
|
+
if (!Object.hasOwn(view, "boards")) return;
|
|
62
|
+
const boards = BoardProjectionSchema.safeParse(view.boards);
|
|
63
|
+
if (!boards.success) {
|
|
64
|
+
for (const issue of boards.error.issues) {
|
|
65
|
+
context.addIssue({
|
|
66
|
+
code: "custom",
|
|
67
|
+
path: ["boards", ...issue.path],
|
|
68
|
+
message: issue.message
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
54
73
|
var SeatFrameSchema = z.object({
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
players: z.array(PlayerIdSchema),
|
|
75
|
+
causedBy: z.string().min(1).optional(),
|
|
76
|
+
events: z.array(GameEventSchema).max(32),
|
|
77
|
+
view: ProjectedViewSchema.nullable(),
|
|
57
78
|
flow: z.object({
|
|
58
79
|
currentPhase: z.string().nullable(),
|
|
59
80
|
activePlayers: z.array(PlayerIdSchema),
|
|
60
81
|
simultaneousPhase: SimultaneousPhaseSnapshotSchema.nullable()
|
|
61
82
|
}).strict(),
|
|
62
83
|
availableInteractions: z.array(InteractionDescriptorSchema),
|
|
63
|
-
zones: z.record(
|
|
84
|
+
zones: z.record(
|
|
85
|
+
z.string(),
|
|
86
|
+
z.record(z.string(), ZoneHandlesSnapshotSchema)
|
|
87
|
+
)
|
|
64
88
|
}).strict();
|
|
65
89
|
var PluginGameplayFrameSchema = SeatFrameSchema.extend({
|
|
66
90
|
basis: GameplayBasisSchema
|
|
67
91
|
});
|
|
68
|
-
var InteractionResultSchema = z.
|
|
69
|
-
z.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
type: z.literal("interaction.result"),
|
|
76
|
-
clientActionId: z.string().min(1),
|
|
77
|
-
accepted: z.literal(false),
|
|
78
|
-
errorCode: z.string().min(1),
|
|
79
|
-
message: z.string().optional()
|
|
80
|
-
}).strict()
|
|
81
|
-
]);
|
|
92
|
+
var InteractionResultSchema = z.object({
|
|
93
|
+
type: z.literal("interaction.result"),
|
|
94
|
+
clientActionId: z.string().min(1),
|
|
95
|
+
accepted: z.literal(false),
|
|
96
|
+
errorCode: z.string().min(1),
|
|
97
|
+
message: z.string().optional()
|
|
98
|
+
}).strict();
|
|
82
99
|
var SubmitInteractionCommandSchema = z.object({
|
|
83
100
|
type: z.literal("interaction.submit"),
|
|
84
101
|
clientActionId: z.string().min(1),
|
|
@@ -94,13 +111,17 @@ var HostToPluginPayloadSchema = z.discriminatedUnion("type", [
|
|
|
94
111
|
}).strict(),
|
|
95
112
|
z.object({
|
|
96
113
|
type: z.literal("gameplay.frame"),
|
|
97
|
-
frame: PluginGameplayFrameSchema
|
|
114
|
+
frame: PluginGameplayFrameSchema,
|
|
115
|
+
acknowledgedClientActionId: z.string().min(1).optional()
|
|
98
116
|
}).strict(),
|
|
99
117
|
InteractionResultSchema
|
|
100
118
|
]);
|
|
101
119
|
var PluginToHostPayloadSchema = z.discriminatedUnion("type", [
|
|
102
120
|
z.object({ type: z.literal("runtime.ready") }).strict(),
|
|
103
|
-
z.object({
|
|
121
|
+
z.object({
|
|
122
|
+
type: z.literal("runtime.resume"),
|
|
123
|
+
pendingClientActionId: z.string().min(1).optional()
|
|
124
|
+
}).strict(),
|
|
104
125
|
z.object({
|
|
105
126
|
type: z.literal("runtime.ack"),
|
|
106
127
|
sequence: z.number().int().nonnegative(),
|
|
@@ -145,9 +166,10 @@ function parsePluginToHostEnvelope(value) {
|
|
|
145
166
|
|
|
146
167
|
// src/headless/sources/static.ts
|
|
147
168
|
import { createStore } from "@tanstack/store";
|
|
148
|
-
import
|
|
169
|
+
import * as z2 from "zod";
|
|
149
170
|
var SourceSnapshotSchema = z2.object({
|
|
150
171
|
me: z2.string().min(1),
|
|
172
|
+
causedBy: z2.string().min(1).optional(),
|
|
151
173
|
players: z2.array(PluginPlayerSummarySchema),
|
|
152
174
|
frame: SeatFrameSchema,
|
|
153
175
|
version: z2.number().int().nonnegative()
|
|
@@ -160,7 +182,8 @@ function staticSource(input) {
|
|
|
160
182
|
Object.freeze({
|
|
161
183
|
snapshot,
|
|
162
184
|
connection: "ready",
|
|
163
|
-
request: null
|
|
185
|
+
request: null,
|
|
186
|
+
failure: null
|
|
164
187
|
})
|
|
165
188
|
);
|
|
166
189
|
return {
|
|
@@ -170,29 +193,49 @@ function staticSource(input) {
|
|
|
170
193
|
},
|
|
171
194
|
dispose() {
|
|
172
195
|
store.setState(
|
|
173
|
-
(state) => Object.freeze({
|
|
196
|
+
(state) => Object.freeze({
|
|
197
|
+
snapshot: state.snapshot,
|
|
198
|
+
connection: "closed",
|
|
199
|
+
request: null,
|
|
200
|
+
failure: null
|
|
201
|
+
})
|
|
174
202
|
);
|
|
175
203
|
}
|
|
176
204
|
};
|
|
177
205
|
}
|
|
178
206
|
|
|
207
|
+
// src/shared/protocol/players.ts
|
|
208
|
+
var PLAYER_SEAT_COLORS = [
|
|
209
|
+
"#2563EB",
|
|
210
|
+
"#DC2626",
|
|
211
|
+
"#059669",
|
|
212
|
+
"#7C3AED",
|
|
213
|
+
"#DB2777",
|
|
214
|
+
"#0891B2",
|
|
215
|
+
"#65A30D",
|
|
216
|
+
"#EA580C"
|
|
217
|
+
];
|
|
218
|
+
function playerSeatColor(seatIndex) {
|
|
219
|
+
return PLAYER_SEAT_COLORS[seatIndex % PLAYER_SEAT_COLORS.length];
|
|
220
|
+
}
|
|
221
|
+
|
|
179
222
|
// src/shared/protocol/digest.ts
|
|
180
223
|
function computePluginActionSetVersion(input) {
|
|
181
224
|
return digestPluginRuntimeJson({
|
|
182
|
-
digestVersion: "plugin-action-set@
|
|
225
|
+
digestVersion: "plugin-action-set@6",
|
|
183
226
|
version: input.version,
|
|
184
227
|
availableInteractions: input.availableInteractions
|
|
185
228
|
});
|
|
186
229
|
}
|
|
187
230
|
function digestPluginGameplayFrame(frame) {
|
|
188
231
|
return digestPluginRuntimeJson({
|
|
189
|
-
digestVersion: "plugin-gameplay-frame@
|
|
232
|
+
digestVersion: "plugin-gameplay-frame@6",
|
|
190
233
|
frame
|
|
191
234
|
});
|
|
192
235
|
}
|
|
193
236
|
function digestPluginCommandRequest(command) {
|
|
194
237
|
return digestPluginRuntimeJson({
|
|
195
|
-
digestVersion: "plugin-command-request@
|
|
238
|
+
digestVersion: "plugin-command-request@6",
|
|
196
239
|
command
|
|
197
240
|
});
|
|
198
241
|
}
|
|
@@ -202,9 +245,11 @@ function materializePluginGameplayFrame(input) {
|
|
|
202
245
|
const dynamicProjection = SeatProjectionBundleSchema2.parse(
|
|
203
246
|
canonicalizePluginRuntimeJson(input.dynamicProjection)
|
|
204
247
|
);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
248
|
+
if (dynamicProjection.referenceBasis.sessionId !== input.sessionId || dynamicProjection.referenceBasis.version !== input.version) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
"Projection reference basis does not match the frame basis."
|
|
251
|
+
);
|
|
252
|
+
}
|
|
208
253
|
const registry = dynamicProjection.interactionsByRef ?? {};
|
|
209
254
|
const seat = dynamicProjection.seats[input.perspectivePlayerId] ?? null;
|
|
210
255
|
const availableInteractions = seat == null ? [] : hydrateInteractionRefs(
|
|
@@ -214,13 +259,16 @@ function materializePluginGameplayFrame(input) {
|
|
|
214
259
|
);
|
|
215
260
|
const zones = seat?.zones == null ? {} : hydrateZones(registry, seat.zones, "zones");
|
|
216
261
|
const frame = {
|
|
217
|
-
|
|
262
|
+
players: input.players,
|
|
263
|
+
...input.causedBy === void 0 ? {} : { causedBy: input.causedBy },
|
|
264
|
+
events: seat?.events ?? [],
|
|
218
265
|
basis: {
|
|
266
|
+
sessionId: input.sessionId,
|
|
219
267
|
version: input.version,
|
|
220
268
|
actionSetVersion: input.actionSetVersion,
|
|
221
269
|
perspectivePlayerId: input.perspectivePlayerId
|
|
222
270
|
},
|
|
223
|
-
view: materializeView(
|
|
271
|
+
view: materializeView(seat?.view, seat?.boards),
|
|
224
272
|
flow: {
|
|
225
273
|
currentPhase: input.currentPhase,
|
|
226
274
|
activePlayers: [...input.activePlayers],
|
|
@@ -231,31 +279,40 @@ function materializePluginGameplayFrame(input) {
|
|
|
231
279
|
};
|
|
232
280
|
return PluginGameplayFrameSchema.parse(frame);
|
|
233
281
|
}
|
|
234
|
-
function materializeView(
|
|
235
|
-
const parts = [
|
|
236
|
-
|
|
237
|
-
|
|
282
|
+
function materializeView(seatView, seatBoards) {
|
|
283
|
+
const parts = [
|
|
284
|
+
seatView,
|
|
285
|
+
seatBoards === void 0 ? void 0 : { boards: seatBoards }
|
|
286
|
+
].filter((part) => part !== void 0 && part !== null);
|
|
238
287
|
if (parts.length === 0) return null;
|
|
239
288
|
return Object.assign({}, ...parts);
|
|
240
289
|
}
|
|
241
290
|
function hydrateZones(registry, value, path) {
|
|
242
291
|
return Object.fromEntries(
|
|
243
|
-
Object.entries(value).map(([zoneId,
|
|
292
|
+
Object.entries(value).map(([zoneId, hosts]) => [
|
|
244
293
|
zoneId,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
294
|
+
Object.fromEntries(
|
|
295
|
+
Object.entries(hosts).map(([hostId, zone]) => [
|
|
296
|
+
hostId,
|
|
297
|
+
{
|
|
298
|
+
tiles: zone.tiles,
|
|
299
|
+
cardIds: zone.cardIds,
|
|
300
|
+
cardViewsById: zone.cardViewsById,
|
|
301
|
+
cardBacksById: zone.cardBacksById,
|
|
302
|
+
playableByCardId: Object.fromEntries(
|
|
303
|
+
Object.entries(zone.playableByCardId).map(([cardId, refs]) => [
|
|
304
|
+
cardId,
|
|
305
|
+
hydrateInteractionRefs(
|
|
306
|
+
registry,
|
|
307
|
+
refs,
|
|
308
|
+
`${path}.${zoneId}.${hostId}.playableByCardId.${cardId}`
|
|
309
|
+
)
|
|
310
|
+
])
|
|
311
|
+
),
|
|
312
|
+
...zone.shuffled ? { shuffled: true } : {}
|
|
313
|
+
}
|
|
314
|
+
])
|
|
315
|
+
)
|
|
259
316
|
])
|
|
260
317
|
);
|
|
261
318
|
}
|
|
@@ -279,10 +336,13 @@ function createSourceLifecycle(options) {
|
|
|
279
336
|
Object.freeze({
|
|
280
337
|
snapshot: null,
|
|
281
338
|
connection: "connecting",
|
|
282
|
-
request: null
|
|
339
|
+
request: null,
|
|
340
|
+
failure: null
|
|
283
341
|
})
|
|
284
342
|
);
|
|
285
343
|
let session = null;
|
|
344
|
+
let assetUrls = null;
|
|
345
|
+
const playerSummaries = /* @__PURE__ */ new Map();
|
|
286
346
|
let basis = null;
|
|
287
347
|
let pending = null;
|
|
288
348
|
let timer;
|
|
@@ -292,22 +352,33 @@ function createSourceLifecycle(options) {
|
|
|
292
352
|
clearTimeout(timer);
|
|
293
353
|
timer = void 0;
|
|
294
354
|
};
|
|
295
|
-
const
|
|
296
|
-
(state)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
355
|
+
const publish = (state) => {
|
|
356
|
+
if (state.request) Object.freeze(state.request);
|
|
357
|
+
store.setState(() => Object.freeze(state));
|
|
358
|
+
};
|
|
359
|
+
const recovering = () => {
|
|
360
|
+
if (closed) return;
|
|
361
|
+
publish({ ...store.get(), connection: "recovering", failure: null });
|
|
362
|
+
};
|
|
363
|
+
const close = (failure) => {
|
|
303
364
|
if (closed) return;
|
|
304
365
|
closed = true;
|
|
305
366
|
clearTimer();
|
|
306
|
-
|
|
367
|
+
for (const url of Object.values(assetUrls ?? {})) URL.revokeObjectURL(url);
|
|
368
|
+
pending?.reject(failure ?? new Error("Gameplay source disposed."));
|
|
307
369
|
pending = null;
|
|
308
370
|
options.close();
|
|
309
|
-
|
|
371
|
+
const snapshot = store.get().snapshot;
|
|
372
|
+
publish(
|
|
373
|
+
failure ? {
|
|
374
|
+
connection: "failed",
|
|
375
|
+
snapshot,
|
|
376
|
+
request: null,
|
|
377
|
+
failure: Object.freeze(failure)
|
|
378
|
+
} : { connection: "closed", snapshot, request: null, failure: null }
|
|
379
|
+
);
|
|
310
380
|
};
|
|
381
|
+
const fail = (error) => close(error);
|
|
311
382
|
const arm = () => {
|
|
312
383
|
clearTimer();
|
|
313
384
|
timer = setTimeout(() => {
|
|
@@ -316,24 +387,16 @@ function createSourceLifecycle(options) {
|
|
|
316
387
|
return;
|
|
317
388
|
}
|
|
318
389
|
recovered = true;
|
|
319
|
-
|
|
390
|
+
recovering();
|
|
320
391
|
try {
|
|
321
|
-
options.recover();
|
|
322
|
-
if (pending
|
|
323
|
-
arm();
|
|
392
|
+
options.recover(pending?.command.clientActionId);
|
|
393
|
+
if (pending) options.send(pending.command);
|
|
394
|
+
if (pending) arm();
|
|
324
395
|
} catch (error) {
|
|
325
396
|
fail(asError(error));
|
|
326
397
|
}
|
|
327
398
|
}, options.timeoutMs ?? 1e4);
|
|
328
399
|
};
|
|
329
|
-
const finishBarrier = () => {
|
|
330
|
-
if (!pending?.accepted) return;
|
|
331
|
-
const frame = store.get().snapshot;
|
|
332
|
-
if (!frame || frame.version <= pending.command.basis.version) return;
|
|
333
|
-
clearTimer();
|
|
334
|
-
pending = null;
|
|
335
|
-
patch({ request: null, connection: "ready" });
|
|
336
|
-
};
|
|
337
400
|
const start = async (operation, interactionId, params) => {
|
|
338
401
|
const state = store.get();
|
|
339
402
|
if (closed || state.connection !== "ready" || !basis)
|
|
@@ -353,13 +416,14 @@ function createSourceLifecycle(options) {
|
|
|
353
416
|
);
|
|
354
417
|
recovered = false;
|
|
355
418
|
const promise = new Promise((resolve, reject) => {
|
|
356
|
-
pending = { command, resolve, reject
|
|
419
|
+
pending = { command, resolve, reject };
|
|
357
420
|
});
|
|
358
|
-
|
|
421
|
+
publish({
|
|
422
|
+
...state,
|
|
359
423
|
request: {
|
|
424
|
+
clientActionId: command.clientActionId,
|
|
360
425
|
interactionId,
|
|
361
|
-
operation
|
|
362
|
-
phase: "awaiting-result"
|
|
426
|
+
operation
|
|
363
427
|
}
|
|
364
428
|
});
|
|
365
429
|
arm();
|
|
@@ -377,37 +441,36 @@ function createSourceLifecycle(options) {
|
|
|
377
441
|
},
|
|
378
442
|
submit: (interactionId, params) => start("submit", interactionId, params),
|
|
379
443
|
cancel: (interactionId) => start("cancel", interactionId),
|
|
380
|
-
dispose: () =>
|
|
444
|
+
dispose: () => close(null)
|
|
381
445
|
};
|
|
382
446
|
return {
|
|
383
447
|
source,
|
|
384
448
|
retry() {
|
|
385
449
|
if (closed || !pending) return;
|
|
386
450
|
try {
|
|
387
|
-
|
|
388
|
-
else options.send(pending.command);
|
|
451
|
+
options.send(pending.command);
|
|
389
452
|
} catch (error) {
|
|
390
453
|
fail(asError(error));
|
|
391
454
|
}
|
|
392
455
|
},
|
|
393
456
|
fail,
|
|
394
|
-
recovering
|
|
395
|
-
if (!closed) patch({ connection: "recovering" });
|
|
396
|
-
},
|
|
457
|
+
recovering,
|
|
397
458
|
session(value) {
|
|
398
459
|
if (closed) return;
|
|
399
|
-
const parsed = PluginSessionDescriptorSchema.parse(value);
|
|
460
|
+
const { assets, ...parsed } = PluginSessionDescriptorSchema.parse(value);
|
|
400
461
|
if ((context?.sessionId ?? session?.sessionId) && parsed.sessionId !== (context?.sessionId ?? session?.sessionId)) {
|
|
401
462
|
fail(new Error("Gameplay session changed."));
|
|
402
463
|
return;
|
|
403
464
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
465
|
+
session ??= immutableCopy(parsed);
|
|
466
|
+
assetUrls ??= Object.fromEntries(
|
|
467
|
+
Object.entries(assets ?? {}).map(([path, blob]) => [
|
|
468
|
+
path,
|
|
469
|
+
URL.createObjectURL(blob)
|
|
470
|
+
])
|
|
471
|
+
);
|
|
409
472
|
},
|
|
410
|
-
frame(value) {
|
|
473
|
+
frame(value, acknowledgedClientActionId) {
|
|
411
474
|
if (closed) return;
|
|
412
475
|
const parsed = PluginGameplayFrameSchema.parse(value);
|
|
413
476
|
if (!session) {
|
|
@@ -418,67 +481,148 @@ function createSourceLifecycle(options) {
|
|
|
418
481
|
sessionId: session.sessionId,
|
|
419
482
|
playerId: parsed.basis.perspectivePlayerId
|
|
420
483
|
};
|
|
421
|
-
if (parsed.basis.
|
|
484
|
+
if (parsed.basis.sessionId !== context.sessionId) {
|
|
485
|
+
fail(new Error("Gameplay authority session changed."));
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const changedSeat = parsed.basis.perspectivePlayerId !== context.playerId;
|
|
489
|
+
if (changedSeat && !options.followHostSeat) {
|
|
422
490
|
fail(new Error("Gameplay perspective changed."));
|
|
423
491
|
return;
|
|
424
492
|
}
|
|
425
|
-
if (!
|
|
493
|
+
if (!parsed.players.includes(parsed.basis.perspectivePlayerId)) {
|
|
426
494
|
fail(new Error("Gameplay seat is absent from session."));
|
|
427
495
|
return;
|
|
428
496
|
}
|
|
429
|
-
if (
|
|
430
|
-
|
|
497
|
+
if (changedSeat) {
|
|
498
|
+
clearTimer();
|
|
499
|
+
pending?.reject(new Error("Gameplay perspective changed."));
|
|
500
|
+
pending = null;
|
|
501
|
+
recovered = false;
|
|
502
|
+
context = { ...context, playerId: parsed.basis.perspectivePlayerId };
|
|
503
|
+
}
|
|
504
|
+
const confirmed = pending && pending.command.clientActionId === acknowledgedClientActionId ? pending : null;
|
|
505
|
+
if (confirmed) {
|
|
506
|
+
clearTimer();
|
|
507
|
+
pending = null;
|
|
508
|
+
recovered = false;
|
|
509
|
+
}
|
|
510
|
+
if (!changedSeat && basis && parsed.basis.version <= basis.version) {
|
|
511
|
+
if (confirmed || store.get().connection === "recovering") {
|
|
512
|
+
publish({
|
|
513
|
+
...store.get(),
|
|
514
|
+
snapshot: store.get().snapshot,
|
|
515
|
+
request: confirmed ? null : store.get().request,
|
|
516
|
+
connection: "ready",
|
|
517
|
+
failure: null
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
confirmed?.resolve({ accepted: true });
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const { basis: nextBasis, ...frame } = immutableCopy(
|
|
524
|
+
withCardImageUrls(parsed, assetUrls)
|
|
525
|
+
);
|
|
431
526
|
basis = nextBasis;
|
|
432
|
-
|
|
527
|
+
publish({
|
|
528
|
+
failure: null,
|
|
529
|
+
request: changedSeat || confirmed ? null : store.get().request,
|
|
433
530
|
snapshot: Object.freeze({
|
|
434
531
|
me: context.playerId,
|
|
435
|
-
players:
|
|
532
|
+
players: Object.freeze(
|
|
533
|
+
frame.players.map((playerId, index) => {
|
|
534
|
+
let summary = playerSummaries.get(playerId);
|
|
535
|
+
if (!summary) {
|
|
536
|
+
const metadata = session.players.find(
|
|
537
|
+
(player) => player.playerId === playerId
|
|
538
|
+
);
|
|
539
|
+
summary = Object.freeze({
|
|
540
|
+
playerId,
|
|
541
|
+
displayName: metadata?.displayName ?? `Player ${index + 1}`,
|
|
542
|
+
color: metadata?.color ?? playerSeatColor(index)
|
|
543
|
+
});
|
|
544
|
+
playerSummaries.set(playerId, summary);
|
|
545
|
+
}
|
|
546
|
+
return summary;
|
|
547
|
+
})
|
|
548
|
+
),
|
|
549
|
+
...frame.causedBy === void 0 ? {} : { causedBy: frame.causedBy },
|
|
436
550
|
frame: Object.freeze(frame),
|
|
437
551
|
version: basis.version
|
|
438
552
|
}),
|
|
439
553
|
connection: "ready"
|
|
440
554
|
});
|
|
441
|
-
|
|
555
|
+
confirmed?.resolve({ accepted: true });
|
|
442
556
|
},
|
|
443
557
|
result(value) {
|
|
444
558
|
if (closed) return;
|
|
445
559
|
const result = InteractionResultSchema.parse(value);
|
|
446
|
-
if (!pending || result.clientActionId !== pending.command.clientActionId
|
|
560
|
+
if (!pending || result.clientActionId !== pending.command.clientActionId)
|
|
447
561
|
return;
|
|
448
|
-
pending
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
562
|
+
const rejected = pending;
|
|
563
|
+
clearTimer();
|
|
564
|
+
pending = null;
|
|
565
|
+
publish({
|
|
566
|
+
snapshot: store.get().snapshot,
|
|
567
|
+
request: null,
|
|
568
|
+
connection: "ready",
|
|
569
|
+
failure: null
|
|
570
|
+
});
|
|
571
|
+
rejected.resolve(
|
|
572
|
+
immutableCopy({
|
|
573
|
+
accepted: false,
|
|
574
|
+
errorCode: result.errorCode,
|
|
575
|
+
...result.message === void 0 ? {} : { message: result.message }
|
|
576
|
+
})
|
|
456
577
|
);
|
|
457
|
-
if (!result.accepted) {
|
|
458
|
-
clearTimer();
|
|
459
|
-
pending = null;
|
|
460
|
-
patch({ request: null, connection: "ready" });
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
pending.accepted = true;
|
|
464
|
-
recovered = false;
|
|
465
|
-
patch({ request: { ...store.get().request, phase: "awaiting-frame" } });
|
|
466
|
-
arm();
|
|
467
|
-
finishBarrier();
|
|
468
578
|
}
|
|
469
579
|
};
|
|
470
580
|
}
|
|
471
581
|
function asError(error) {
|
|
472
582
|
return error instanceof Error ? error : new Error(String(error));
|
|
473
583
|
}
|
|
584
|
+
function withCardImageUrls(frame, urls) {
|
|
585
|
+
if (urls === null || Object.keys(urls).length === 0) return frame;
|
|
586
|
+
return {
|
|
587
|
+
...frame,
|
|
588
|
+
zones: Object.fromEntries(
|
|
589
|
+
Object.entries(frame.zones).map(([zoneId, hosts]) => [
|
|
590
|
+
zoneId,
|
|
591
|
+
Object.fromEntries(
|
|
592
|
+
Object.entries(hosts).map(([hostId, zone]) => [
|
|
593
|
+
hostId,
|
|
594
|
+
{
|
|
595
|
+
...zone,
|
|
596
|
+
cardViewsById: Object.fromEntries(
|
|
597
|
+
Object.entries(zone.cardViewsById).map(([cardId, card]) => [
|
|
598
|
+
cardId,
|
|
599
|
+
{
|
|
600
|
+
...card,
|
|
601
|
+
frontImage: card.frontImage === void 0 ? void 0 : urls[card.frontImage] ?? card.frontImage,
|
|
602
|
+
backImage: card.backImage === void 0 ? void 0 : urls[card.backImage] ?? card.backImage
|
|
603
|
+
}
|
|
604
|
+
])
|
|
605
|
+
),
|
|
606
|
+
cardBacksById: Object.fromEntries(
|
|
607
|
+
Object.entries(zone.cardBacksById).map(([cardId, path]) => [
|
|
608
|
+
cardId,
|
|
609
|
+
urls[path] ?? path
|
|
610
|
+
])
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
])
|
|
614
|
+
)
|
|
615
|
+
])
|
|
616
|
+
)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
474
619
|
|
|
475
620
|
export {
|
|
476
621
|
DREAMBOARD_PLUGIN_PROTOCOL,
|
|
477
622
|
DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
|
|
478
|
-
|
|
479
|
-
GameEventDetailSchema2 as GameEventDetailSchema,
|
|
623
|
+
GameEventDetailSchema,
|
|
480
624
|
SystemActionEventSchema2 as SystemActionEventSchema,
|
|
481
|
-
|
|
625
|
+
GameEventSchema,
|
|
482
626
|
SeatProjectionBundleSchema2 as SeatProjectionBundleSchema,
|
|
483
627
|
PluginPlayerSummarySchema,
|
|
484
628
|
PluginSessionDescriptorSchema,
|
|
@@ -502,10 +646,12 @@ export {
|
|
|
502
646
|
parsePluginToHostEnvelope,
|
|
503
647
|
SourceSnapshotSchema,
|
|
504
648
|
staticSource,
|
|
649
|
+
PLAYER_SEAT_COLORS,
|
|
650
|
+
playerSeatColor,
|
|
505
651
|
createSourceLifecycle,
|
|
506
652
|
computePluginActionSetVersion,
|
|
507
653
|
digestPluginGameplayFrame,
|
|
508
654
|
digestPluginCommandRequest,
|
|
509
655
|
materializePluginGameplayFrame
|
|
510
656
|
};
|
|
511
|
-
//# sourceMappingURL=chunk-
|
|
657
|
+
//# sourceMappingURL=chunk-CWANHA4C.js.map
|