@gameslate/sdk 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +38 -2
- package/bin/gameslate-plugin.mjs +26 -0
- package/build/build-plugin.mjs +103 -0
- package/lib/assets.d.ts +1788 -0
- package/lib/assets.js +107 -0
- package/lib/bytes.d.ts +33 -0
- package/lib/bytes.js +89 -0
- package/lib/catalogue.d.ts +1228 -0
- package/lib/catalogue.js +305 -0
- package/lib/chips.d.ts +18 -0
- package/lib/chips.js +28 -0
- package/lib/condition.d.ts +58 -0
- package/lib/condition.js +125 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +16 -0
- package/lib/logic.d.ts +68 -0
- package/lib/logic.js +194 -0
- package/lib/navigation.d.ts +139 -0
- package/lib/navigation.js +38 -0
- package/lib/pack.d.ts +933 -0
- package/lib/pack.js +29 -0
- package/lib/pins.d.ts +19 -0
- package/lib/pins.js +35 -0
- package/lib/plugin/contract.d.ts +111 -0
- package/lib/plugin/contract.js +1 -0
- package/lib/plugin/index.d.ts +3 -0
- package/lib/plugin/index.js +9 -0
- package/lib/plugin/sandbox-guest.d.ts +12 -0
- package/lib/plugin/sandbox-guest.js +128 -0
- package/lib/plugin/seqlock.d.ts +8 -0
- package/lib/plugin/seqlock.js +19 -0
- package/lib/plugin-manifest.d.ts +131 -0
- package/lib/plugin-manifest.js +54 -0
- package/lib/plugins-api.d.ts +445 -0
- package/lib/plugins-api.js +38 -0
- package/lib/registry.d.ts +2231 -0
- package/lib/registry.js +170 -0
- package/lib/sandbox-protocol.d.ts +1363 -0
- package/lib/sandbox-protocol.js +39 -0
- package/lib/status.d.ts +24 -0
- package/lib/status.js +75 -0
- package/lib/types.d.ts +2684 -0
- package/lib/types.js +282 -0
- package/lib/views.d.ts +204 -0
- package/lib/views.js +35 -0
- package/package.json +53 -3
package/lib/catalogue.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { collectReferences, ConditionSchema } from './condition.js';
|
|
3
|
+
/*
|
|
4
|
+
* A pack's catalogue: the static, declarative half of the game contract
|
|
5
|
+
* (.claude/rules/game-packs.md). Every status in it is a Condition; the UI renders it without
|
|
6
|
+
* knowing which game it is.
|
|
7
|
+
*/
|
|
8
|
+
const Id = z.string().regex(/^[A-Za-z0-9_:.-]+$/, 'ids are letters, digits and _ : . - only');
|
|
9
|
+
export const ItemSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
id: Id,
|
|
12
|
+
label: z.string().min(1),
|
|
13
|
+
/** local-assets icon id (`/local-assets/<game>/icons/<icon>.webp`) */
|
|
14
|
+
icon: z.string().optional(),
|
|
15
|
+
category: z.string().optional(),
|
|
16
|
+
/** short text for slot fallbacks when no icon is extracted */
|
|
17
|
+
short: z.string().optional(),
|
|
18
|
+
/** where/how it's obtained, spoiler-light */
|
|
19
|
+
source: z.string().optional(),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
export const CounterSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
id: Id,
|
|
25
|
+
label: z.string().min(1),
|
|
26
|
+
icon: z.string().optional(),
|
|
27
|
+
/** fixed maximum, or another counter id holding it */
|
|
28
|
+
max: z.union([z.number(), Id]).optional(),
|
|
29
|
+
/** values → display text (e.g. wallet tier 0/1/2 → 99/200/500) */
|
|
30
|
+
display: z.record(z.string(), z.string()).optional(),
|
|
31
|
+
})
|
|
32
|
+
.strict();
|
|
33
|
+
export const LayoutSchema = z.discriminatedUnion('kind', [
|
|
34
|
+
z
|
|
35
|
+
.object({
|
|
36
|
+
kind: z.literal('slotGrid'),
|
|
37
|
+
id: Id,
|
|
38
|
+
title: z.string(),
|
|
39
|
+
columns: z.number().int().min(1).max(12),
|
|
40
|
+
/** item ids in display order */
|
|
41
|
+
slots: z.array(Id).min(1),
|
|
42
|
+
})
|
|
43
|
+
.strict(),
|
|
44
|
+
z
|
|
45
|
+
.object({
|
|
46
|
+
kind: z.literal('counters'),
|
|
47
|
+
id: Id,
|
|
48
|
+
title: z.string(),
|
|
49
|
+
counters: z.array(Id).min(1),
|
|
50
|
+
})
|
|
51
|
+
.strict(),
|
|
52
|
+
]);
|
|
53
|
+
export const MissionStepSchema = z
|
|
54
|
+
.object({ id: Id, label: z.string().min(1), done: ConditionSchema })
|
|
55
|
+
.strict();
|
|
56
|
+
export const MissionSchema = z
|
|
57
|
+
.object({
|
|
58
|
+
id: Id,
|
|
59
|
+
title: z.string().min(1),
|
|
60
|
+
group: z.enum(['main', 'side']),
|
|
61
|
+
/** heading this mission is shown under (e.g. "Spiritual Stones", "House of Skulltula") */
|
|
62
|
+
section: z.string().optional(),
|
|
63
|
+
location: z.string().optional(),
|
|
64
|
+
detail: z.string().optional(),
|
|
65
|
+
done: ConditionSchema,
|
|
66
|
+
/** shown only while this holds (e.g. adult-only quests) */
|
|
67
|
+
availableWhen: ConditionSchema.optional(),
|
|
68
|
+
progress: z
|
|
69
|
+
.object({ counter: Id, target: z.number().int().positive() })
|
|
70
|
+
.strict()
|
|
71
|
+
.optional(),
|
|
72
|
+
steps: z.array(MissionStepSchema).optional(),
|
|
73
|
+
/** prompt for the "Ask Guide" button */
|
|
74
|
+
ask: z.string().optional(),
|
|
75
|
+
})
|
|
76
|
+
.strict();
|
|
77
|
+
export const ReferenceEntrySchema = z
|
|
78
|
+
.object({
|
|
79
|
+
id: Id,
|
|
80
|
+
title: z.string().min(1),
|
|
81
|
+
badge: z.string().optional(),
|
|
82
|
+
/** e.g. ocarina note glyphs: up/down/left/right/a */
|
|
83
|
+
sequence: z.array(z.string()).optional(),
|
|
84
|
+
notes: z.array(z.string()).optional(),
|
|
85
|
+
rows: z.array(z.object({ label: z.string(), detail: z.string() }).strict()).optional(),
|
|
86
|
+
/** hidden (or shown greyed under "show all") until this holds; absent = always shown */
|
|
87
|
+
revealWhen: ConditionSchema.optional(),
|
|
88
|
+
})
|
|
89
|
+
.strict();
|
|
90
|
+
export const ReferenceSectionSchema = z
|
|
91
|
+
.object({
|
|
92
|
+
id: Id,
|
|
93
|
+
title: z.string().min(1),
|
|
94
|
+
badge: z.string().optional(),
|
|
95
|
+
defaultOpen: z.boolean().optional(),
|
|
96
|
+
entries: z.array(ReferenceEntrySchema).min(1),
|
|
97
|
+
})
|
|
98
|
+
.strict();
|
|
99
|
+
export const CollectibleEntrySchema = z
|
|
100
|
+
.object({
|
|
101
|
+
id: z.string().min(1),
|
|
102
|
+
name: z.string().min(1),
|
|
103
|
+
/** location id (registry) and a display name for grouping */
|
|
104
|
+
locationId: z.string().optional(),
|
|
105
|
+
locationName: z.string().optional(),
|
|
106
|
+
/** absent = this entry's state isn't tracked (shown as "not tracked", never "missing") */
|
|
107
|
+
collectedBy: ConditionSchema.optional(),
|
|
108
|
+
/** alternatives, each a list of requirements: [["Child", "a weapon", "at night"]] */
|
|
109
|
+
needs: z.array(z.array(z.string())).optional(),
|
|
110
|
+
/** map pin to wayfind to, when one exists */
|
|
111
|
+
pinId: z.string().optional(),
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
export const CollectibleSetSchema = z
|
|
115
|
+
.object({
|
|
116
|
+
id: Id,
|
|
117
|
+
title: z.string().min(1),
|
|
118
|
+
/** singular noun for prompts ("Gold Skulltula") */
|
|
119
|
+
noun: z.string().min(1),
|
|
120
|
+
icon: z.string().optional(),
|
|
121
|
+
/** counter that totals the set (opens the checklist from Inventory) */
|
|
122
|
+
counter: Id.optional(),
|
|
123
|
+
/** entries declared here… */
|
|
124
|
+
entries: z.array(CollectibleEntrySchema).optional(),
|
|
125
|
+
/** …or loaded at runtime from a locally generated file (`local-assets/<game>/<file>`) */
|
|
126
|
+
localSource: z.object({ file: z.string(), key: z.string() }).strict().optional(),
|
|
127
|
+
})
|
|
128
|
+
.strict();
|
|
129
|
+
export const ChipSchema = z
|
|
130
|
+
.object({
|
|
131
|
+
id: Id,
|
|
132
|
+
label: z.string().min(1),
|
|
133
|
+
prompt: z.string().min(1),
|
|
134
|
+
when: ConditionSchema.optional(),
|
|
135
|
+
})
|
|
136
|
+
.strict();
|
|
137
|
+
/**
|
|
138
|
+
* Status rules for registry map pins the pack knows more about than the registry does
|
|
139
|
+
* (e.g. "an Owl Statue here is activated when owl bit N is set"). A rule applies to every pin it
|
|
140
|
+
* matches; matching fields combine with AND.
|
|
141
|
+
*/
|
|
142
|
+
export const PinRuleSchema = z
|
|
143
|
+
.object({
|
|
144
|
+
id: Id,
|
|
145
|
+
match: z
|
|
146
|
+
.object({
|
|
147
|
+
at: z.string().min(1).optional(),
|
|
148
|
+
/* the pin's effective kind (objective, poi, npc, …) */
|
|
149
|
+
kind: z.string().min(1).optional(),
|
|
150
|
+
ids: z.array(z.string().min(1)).min(1).optional(),
|
|
151
|
+
label: z.string().min(1).optional(),
|
|
152
|
+
labelContains: z.string().min(1).optional(),
|
|
153
|
+
})
|
|
154
|
+
.strict()
|
|
155
|
+
.refine(m => Object.keys(m).length > 0, 'match needs at least one field'),
|
|
156
|
+
collectedBy: ConditionSchema.optional(),
|
|
157
|
+
/* e.g. an NPC that is only in this room on one day of the cycle */
|
|
158
|
+
hiddenWhen: ConditionSchema.optional(),
|
|
159
|
+
/* local-assets icon id drawn for the pin when it was extracted on the PC */
|
|
160
|
+
icon: Id.optional(),
|
|
161
|
+
})
|
|
162
|
+
.strict()
|
|
163
|
+
.refine(r => r.collectedBy ?? r.hiddenWhen ?? r.icon, 'rule needs collectedBy, hiddenWhen or icon');
|
|
164
|
+
/** A kind of map pin the player can show or hide (e.g. Doom's ammo, health bonuses). */
|
|
165
|
+
export const PinCategorySchema = z.object({
|
|
166
|
+
id: Id,
|
|
167
|
+
label: z.string(),
|
|
168
|
+
/** shown until the player says otherwise */
|
|
169
|
+
shownByDefault: z.boolean(),
|
|
170
|
+
/** the map glyph for its pins: key, weapon, health, armor, ammo, powerup, bonus, secret, door, switch, item */
|
|
171
|
+
icon: z.string().optional(),
|
|
172
|
+
});
|
|
173
|
+
export const CatalogueSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
items: z.array(ItemSchema),
|
|
176
|
+
counters: z.array(CounterSchema),
|
|
177
|
+
/** flag sets the pack's decoder streams (bit conditions may only reference these) */
|
|
178
|
+
flagSets: z.array(Id),
|
|
179
|
+
inventoryLayouts: z.array(LayoutSchema),
|
|
180
|
+
missions: z.array(MissionSchema),
|
|
181
|
+
collectibles: z.array(CollectibleSetSchema),
|
|
182
|
+
reference: z.array(ReferenceSectionSchema),
|
|
183
|
+
chips: z.array(ChipSchema),
|
|
184
|
+
pinRules: z.array(PinRuleSchema),
|
|
185
|
+
/** pin categories the map's options let the player filter; pins name theirs */
|
|
186
|
+
pinCategories: z.array(PinCategorySchema).optional(),
|
|
187
|
+
})
|
|
188
|
+
.strict();
|
|
189
|
+
function duplicates(ids) {
|
|
190
|
+
const seen = new Set();
|
|
191
|
+
return ids.filter(id => (seen.has(id) ? true : (seen.add(id), false)));
|
|
192
|
+
}
|
|
193
|
+
const siteIf = (where, cond) => cond ? [[where, cond]] : [];
|
|
194
|
+
function missionSites(cat) {
|
|
195
|
+
return cat.missions.flatMap((m) => [
|
|
196
|
+
[`mission ${m.id}.done`, m.done],
|
|
197
|
+
...siteIf(`mission ${m.id}.availableWhen`, m.availableWhen),
|
|
198
|
+
...(m.steps ?? []).map((st) => [`mission ${m.id} step ${st.id}`, st.done]),
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
function pinRuleSites(cat) {
|
|
202
|
+
return cat.pinRules.flatMap((r) => [
|
|
203
|
+
...siteIf(`pin rule ${r.id}.collectedBy`, r.collectedBy),
|
|
204
|
+
...siteIf(`pin rule ${r.id}.hiddenWhen`, r.hiddenWhen),
|
|
205
|
+
]);
|
|
206
|
+
}
|
|
207
|
+
/** Every place a condition appears, labelled for error messages. */
|
|
208
|
+
function conditionSites(cat) {
|
|
209
|
+
const sites = [...missionSites(cat), ...pinRuleSites(cat)];
|
|
210
|
+
for (const sec of cat.reference) {
|
|
211
|
+
for (const e of sec.entries) {
|
|
212
|
+
if (e.revealWhen)
|
|
213
|
+
sites.push([`reference ${sec.id}/${e.id}`, e.revealWhen]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (const set of cat.collectibles) {
|
|
217
|
+
for (const e of set.entries ?? []) {
|
|
218
|
+
if (e.collectedBy)
|
|
219
|
+
sites.push([`collectibles ${set.id}/${e.id}`, e.collectedBy]);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const chip of cat.chips)
|
|
223
|
+
if (chip.when)
|
|
224
|
+
sites.push([`chip ${chip.id}`, chip.when]);
|
|
225
|
+
return sites;
|
|
226
|
+
}
|
|
227
|
+
function checkConditionReferences(where, cond, known) {
|
|
228
|
+
const refs = collectReferences(cond);
|
|
229
|
+
return [
|
|
230
|
+
...refs.items
|
|
231
|
+
.filter(id => !known.items.has(id))
|
|
232
|
+
.map(id => `${where}: unknown item "${id}"`),
|
|
233
|
+
...refs.counters
|
|
234
|
+
.filter(id => !known.counters.has(id))
|
|
235
|
+
.map(id => `${where}: unknown counter "${id}"`),
|
|
236
|
+
...refs.missions
|
|
237
|
+
.filter(id => !known.missions.has(id))
|
|
238
|
+
.map(id => `${where}: unknown mission "${id}"`),
|
|
239
|
+
...refs.flagSets
|
|
240
|
+
.filter(id => !known.flagSets.has(id))
|
|
241
|
+
.map(id => `${where}: undeclared flag set "${id}"`),
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
function checkDuplicateIds(cat) {
|
|
245
|
+
const groups = [
|
|
246
|
+
['item', cat.items.map(i => i.id)],
|
|
247
|
+
['counter', cat.counters.map(c => c.id)],
|
|
248
|
+
['mission', cat.missions.map(m => m.id)],
|
|
249
|
+
['collectible set', cat.collectibles.map(c => c.id)],
|
|
250
|
+
['reference section', cat.reference.map(r => r.id)],
|
|
251
|
+
['chip', cat.chips.map(c => c.id)],
|
|
252
|
+
['pin rule', cat.pinRules.map(r => r.id)],
|
|
253
|
+
];
|
|
254
|
+
return groups.flatMap(([what, ids]) => duplicates(ids).map(d => `duplicate ${what} id "${d}"`));
|
|
255
|
+
}
|
|
256
|
+
function checkStructure(cat, known) {
|
|
257
|
+
const problems = [];
|
|
258
|
+
for (const m of cat.missions) {
|
|
259
|
+
if (m.progress && !known.counters.has(m.progress.counter)) {
|
|
260
|
+
problems.push(`mission ${m.id}.progress: unknown counter "${m.progress.counter}"`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
for (const set of cat.collectibles) {
|
|
264
|
+
if (!set.entries && !set.localSource)
|
|
265
|
+
problems.push(`collectibles ${set.id}: needs entries or a localSource`);
|
|
266
|
+
if (set.counter && !known.counters.has(set.counter)) {
|
|
267
|
+
problems.push(`collectibles ${set.id}.counter: unknown counter "${set.counter}"`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const layout of cat.inventoryLayouts) {
|
|
271
|
+
const [ids, pool, noun] = layout.kind === 'slotGrid'
|
|
272
|
+
? [layout.slots, known.items, 'item']
|
|
273
|
+
: [layout.counters, known.counters, 'counter'];
|
|
274
|
+
for (const id of ids.filter(x => !pool.has(x)))
|
|
275
|
+
problems.push(`layout ${layout.id}: unknown ${noun} "${id}"`);
|
|
276
|
+
}
|
|
277
|
+
for (const c of cat.counters) {
|
|
278
|
+
if (typeof c.max === 'string' && !known.counters.has(c.max)) {
|
|
279
|
+
problems.push(`counter ${c.id}.max: unknown counter "${c.max}"`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return problems;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The pack contract check: schema-valid, ids unique, and every condition, layout slot and
|
|
286
|
+
* progress counter refers to something the catalogue declares. Returns problems (empty = ok).
|
|
287
|
+
*/
|
|
288
|
+
export function checkCatalogue(input) {
|
|
289
|
+
const parsed = CatalogueSchema.safeParse(input);
|
|
290
|
+
if (!parsed.success) {
|
|
291
|
+
return parsed.error.issues.map(i => `schema: ${i.path.join('.')}: ${i.message}`);
|
|
292
|
+
}
|
|
293
|
+
const cat = parsed.data;
|
|
294
|
+
const known = {
|
|
295
|
+
items: new Set(cat.items.map(i => i.id)),
|
|
296
|
+
counters: new Set(cat.counters.map(c => c.id)),
|
|
297
|
+
missions: new Set(cat.missions.map(m => m.id)),
|
|
298
|
+
flagSets: new Set(cat.flagSets),
|
|
299
|
+
};
|
|
300
|
+
return [
|
|
301
|
+
...checkDuplicateIds(cat),
|
|
302
|
+
...conditionSites(cat).flatMap(([where, cond]) => checkConditionReferences(where, cond, known)),
|
|
303
|
+
...checkStructure(cat, known),
|
|
304
|
+
];
|
|
305
|
+
}
|
package/lib/chips.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Catalogue } from './catalogue.js';
|
|
2
|
+
import type { EvaluationContext } from './condition.js';
|
|
3
|
+
import type { GameState } from './types.js';
|
|
4
|
+
/** Values a chip's label and prompt may reference: `{location}`, `{difficulty}`, `{counter:id}`. */
|
|
5
|
+
export interface ChipVars {
|
|
6
|
+
location: string;
|
|
7
|
+
difficulty?: string;
|
|
8
|
+
}
|
|
9
|
+
/** null when a referenced value isn't available, so the caller drops the chip instead of
|
|
10
|
+
* showing "{difficulty}" or "undefined" to the player. */
|
|
11
|
+
export declare function fillChipText(text: string, vars: ChipVars, state: GameState): string | null;
|
|
12
|
+
export interface FilledChip {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
prompt: string;
|
|
16
|
+
}
|
|
17
|
+
/** The pack's chips whose `when` is met right now, with placeholders filled, in catalogue order. */
|
|
18
|
+
export declare function getActiveChips(catalogue: Catalogue, state: GameState, vars: ChipVars, ctx?: EvaluationContext): FilledChip[];
|
package/lib/chips.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { evaluate, readCounter } from './condition.js';
|
|
2
|
+
const PLACEHOLDER_RE = /\{(location|difficulty|counter:[A-Za-z0-9_:.-]+)\}/g;
|
|
3
|
+
/** null when a referenced value isn't available, so the caller drops the chip instead of
|
|
4
|
+
* showing "{difficulty}" or "undefined" to the player. */
|
|
5
|
+
export function fillChipText(text, vars, state) {
|
|
6
|
+
let missing = false;
|
|
7
|
+
const out = text.replace(PLACEHOLDER_RE, (_m, key) => {
|
|
8
|
+
const value = key.startsWith('counter:')
|
|
9
|
+
? readCounter(state, key.slice('counter:'.length))?.toString()
|
|
10
|
+
: key === 'location'
|
|
11
|
+
? vars.location
|
|
12
|
+
: vars.difficulty;
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
missing = true;
|
|
15
|
+
return value ?? '';
|
|
16
|
+
});
|
|
17
|
+
return missing ? null : out;
|
|
18
|
+
}
|
|
19
|
+
/** The pack's chips whose `when` is met right now, with placeholders filled, in catalogue order. */
|
|
20
|
+
export function getActiveChips(catalogue, state, vars, ctx = {}) {
|
|
21
|
+
return catalogue.chips.flatMap((chip) => {
|
|
22
|
+
if (chip.when && evaluate(chip.when, state, ctx) !== 'met')
|
|
23
|
+
return [];
|
|
24
|
+
const label = fillChipText(chip.label, vars, state);
|
|
25
|
+
const prompt = fillChipText(chip.prompt, vars, state);
|
|
26
|
+
return label && prompt ? [{ id: chip.id, label, prompt }] : [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { GameState } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One condition language for everything a pack declares: mission done, collectible collected,
|
|
5
|
+
* reference entry revealed, AI chip shown. Evaluated only here, so status logic never ends up
|
|
6
|
+
* hand-written in widgets (docs/architecture-v3.md § Conditions).
|
|
7
|
+
*/
|
|
8
|
+
export type Condition = {
|
|
9
|
+
has: string;
|
|
10
|
+
} | {
|
|
11
|
+
flag: string;
|
|
12
|
+
} | {
|
|
13
|
+
bit: {
|
|
14
|
+
set: string;
|
|
15
|
+
index: number;
|
|
16
|
+
mask: number;
|
|
17
|
+
};
|
|
18
|
+
} | {
|
|
19
|
+
counter: string;
|
|
20
|
+
gte?: number;
|
|
21
|
+
lte?: number;
|
|
22
|
+
} | {
|
|
23
|
+
mission: string;
|
|
24
|
+
} | {
|
|
25
|
+
at: string;
|
|
26
|
+
} | {
|
|
27
|
+
difficulty: string;
|
|
28
|
+
} | {
|
|
29
|
+
variant: string;
|
|
30
|
+
} | {
|
|
31
|
+
all: Condition[];
|
|
32
|
+
} | {
|
|
33
|
+
any: Condition[];
|
|
34
|
+
} | {
|
|
35
|
+
not: Condition;
|
|
36
|
+
};
|
|
37
|
+
export declare const ConditionSchema: z.ZodType<Condition>;
|
|
38
|
+
/**
|
|
39
|
+
* `unknown` means the state needed to decide isn't streamed (an old bridge, an untracked flag
|
|
40
|
+
* set). It is never collapsed to `unmet`: showing "missing" for something the player has
|
|
41
|
+
* collected is the bug this prevents (.claude/rules/fail-loud.md).
|
|
42
|
+
*/
|
|
43
|
+
export type ConditionResult = 'met' | 'unmet' | 'unknown';
|
|
44
|
+
export interface EvaluationContext {
|
|
45
|
+
/** Resolves `{ mission }` conditions. Missing → those conditions are `unknown`. */
|
|
46
|
+
missionStatus?: (missionId: string) => ConditionResult;
|
|
47
|
+
}
|
|
48
|
+
/** Counters fall back to legacy v1 `stats` so old launch wrappers keep working mid-migration. */
|
|
49
|
+
export declare function readCounter(state: GameState, id: string): number | undefined;
|
|
50
|
+
export declare function evaluate(cond: Condition, state: GameState, ctx?: EvaluationContext): ConditionResult;
|
|
51
|
+
/** Every id a condition refers to, for the pack contract check. */
|
|
52
|
+
export interface ConditionReferences {
|
|
53
|
+
items: string[];
|
|
54
|
+
missions: string[];
|
|
55
|
+
counters: string[];
|
|
56
|
+
flagSets: string[];
|
|
57
|
+
}
|
|
58
|
+
export declare function collectReferences(cond: Condition): ConditionReferences;
|
package/lib/condition.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const ConditionSchema = z.lazy(() => z.union([
|
|
3
|
+
z.object({ has: z.string().min(1) }).strict(),
|
|
4
|
+
z.object({ flag: z.string().min(1) }).strict(),
|
|
5
|
+
z
|
|
6
|
+
.object({
|
|
7
|
+
bit: z
|
|
8
|
+
.object({
|
|
9
|
+
set: z.string().min(1),
|
|
10
|
+
index: z.number().int().nonnegative(),
|
|
11
|
+
mask: z.number().int().min(1).max(255),
|
|
12
|
+
})
|
|
13
|
+
.strict(),
|
|
14
|
+
})
|
|
15
|
+
.strict(),
|
|
16
|
+
z
|
|
17
|
+
.object({
|
|
18
|
+
counter: z.string().min(1),
|
|
19
|
+
gte: z.number().optional(),
|
|
20
|
+
lte: z.number().optional(),
|
|
21
|
+
})
|
|
22
|
+
.strict(),
|
|
23
|
+
z.object({ mission: z.string().min(1) }).strict(),
|
|
24
|
+
z.object({ at: z.string().min(1) }).strict(),
|
|
25
|
+
z.object({ difficulty: z.string().min(1) }).strict(),
|
|
26
|
+
z.object({ variant: z.string().min(1) }).strict(),
|
|
27
|
+
z.object({ all: z.array(ConditionSchema).min(1) }).strict(),
|
|
28
|
+
z.object({ any: z.array(ConditionSchema).min(1) }).strict(),
|
|
29
|
+
z.object({ not: ConditionSchema }).strict(),
|
|
30
|
+
]));
|
|
31
|
+
function fromBoolean(value) {
|
|
32
|
+
return value ? 'met' : 'unmet';
|
|
33
|
+
}
|
|
34
|
+
/** An optional state field: absent means "not streamed", so unknown rather than unmet. */
|
|
35
|
+
function fromOptional(actual, expected) {
|
|
36
|
+
return actual === undefined ? 'unknown' : fromBoolean(actual === expected);
|
|
37
|
+
}
|
|
38
|
+
/** Counters fall back to legacy v1 `stats` so old launch wrappers keep working mid-migration. */
|
|
39
|
+
export function readCounter(state, id) {
|
|
40
|
+
return state.counters?.[id] ?? state.stats?.[id];
|
|
41
|
+
}
|
|
42
|
+
function evaluateAll(parts, state, ctx) {
|
|
43
|
+
const results = parts.map(p => evaluate(p, state, ctx));
|
|
44
|
+
if (results.includes('unmet'))
|
|
45
|
+
return 'unmet';
|
|
46
|
+
return results.includes('unknown') ? 'unknown' : 'met';
|
|
47
|
+
}
|
|
48
|
+
function evaluateAny(parts, state, ctx) {
|
|
49
|
+
const results = parts.map(p => evaluate(p, state, ctx));
|
|
50
|
+
if (results.includes('met'))
|
|
51
|
+
return 'met';
|
|
52
|
+
return results.includes('unknown') ? 'unknown' : 'unmet';
|
|
53
|
+
}
|
|
54
|
+
function evaluateCounter(cond, state) {
|
|
55
|
+
const value = readCounter(state, cond.counter);
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
return 'unknown';
|
|
58
|
+
if (cond.gte !== undefined && value < cond.gte)
|
|
59
|
+
return 'unmet';
|
|
60
|
+
if (cond.lte !== undefined && value > cond.lte)
|
|
61
|
+
return 'unmet';
|
|
62
|
+
return 'met';
|
|
63
|
+
}
|
|
64
|
+
/** Leaf conditions read state directly; `null` means "not a leaf". */
|
|
65
|
+
function evaluateLeaf(cond, state, ctx) {
|
|
66
|
+
if ('has' in cond)
|
|
67
|
+
return fromBoolean(state.inventory.includes(cond.has));
|
|
68
|
+
if ('flag' in cond) {
|
|
69
|
+
const value = state.flags[cond.flag];
|
|
70
|
+
return value === undefined ? 'unknown' : fromBoolean(value);
|
|
71
|
+
}
|
|
72
|
+
if ('bit' in cond) {
|
|
73
|
+
const byte = state.flagSets?.[cond.bit.set]?.[cond.bit.index];
|
|
74
|
+
return byte === undefined ? 'unknown' : fromBoolean((byte & cond.bit.mask) !== 0);
|
|
75
|
+
}
|
|
76
|
+
if ('counter' in cond)
|
|
77
|
+
return evaluateCounter(cond, state);
|
|
78
|
+
if ('mission' in cond)
|
|
79
|
+
return ctx.missionStatus?.(cond.mission) ?? 'unknown';
|
|
80
|
+
if ('at' in cond)
|
|
81
|
+
return fromBoolean(state.locationId === cond.at);
|
|
82
|
+
if ('difficulty' in cond)
|
|
83
|
+
return fromOptional(state.difficulty, cond.difficulty);
|
|
84
|
+
if ('variant' in cond)
|
|
85
|
+
return fromOptional(state.variant, cond.variant);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
function negate(result) {
|
|
89
|
+
if (result === 'unknown')
|
|
90
|
+
return 'unknown';
|
|
91
|
+
return result === 'met' ? 'unmet' : 'met';
|
|
92
|
+
}
|
|
93
|
+
export function evaluate(cond, state, ctx = {}) {
|
|
94
|
+
const leaf = evaluateLeaf(cond, state, ctx);
|
|
95
|
+
if (leaf !== null)
|
|
96
|
+
return leaf;
|
|
97
|
+
if ('all' in cond)
|
|
98
|
+
return evaluateAll(cond.all, state, ctx);
|
|
99
|
+
if ('any' in cond)
|
|
100
|
+
return evaluateAny(cond.any, state, ctx);
|
|
101
|
+
if ('not' in cond)
|
|
102
|
+
return negate(evaluate(cond.not, state, ctx));
|
|
103
|
+
throw new Error(`Unhandled condition shape: ${JSON.stringify(cond)}`);
|
|
104
|
+
}
|
|
105
|
+
export function collectReferences(cond) {
|
|
106
|
+
const out = { items: [], missions: [], counters: [], flagSets: [] };
|
|
107
|
+
const walk = (c) => {
|
|
108
|
+
if ('has' in c)
|
|
109
|
+
out.items.push(c.has);
|
|
110
|
+
else if ('mission' in c)
|
|
111
|
+
out.missions.push(c.mission);
|
|
112
|
+
else if ('counter' in c)
|
|
113
|
+
out.counters.push(c.counter);
|
|
114
|
+
else if ('bit' in c)
|
|
115
|
+
out.flagSets.push(c.bit.set);
|
|
116
|
+
else if ('all' in c)
|
|
117
|
+
c.all.forEach(walk);
|
|
118
|
+
else if ('any' in c)
|
|
119
|
+
c.any.forEach(walk);
|
|
120
|
+
else if ('not' in c)
|
|
121
|
+
walk(c.not);
|
|
122
|
+
};
|
|
123
|
+
walk(cond);
|
|
124
|
+
return out;
|
|
125
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './registry.js';
|
|
3
|
+
export * from './logic.js';
|
|
4
|
+
export * from './condition.js';
|
|
5
|
+
export * from './catalogue.js';
|
|
6
|
+
export * from './status.js';
|
|
7
|
+
export * from './pins.js';
|
|
8
|
+
export * from './chips.js';
|
|
9
|
+
export * from './pack.js';
|
|
10
|
+
export * from './views.js';
|
|
11
|
+
export * from './bytes.js';
|
|
12
|
+
export * from './navigation.js';
|
|
13
|
+
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './sandbox-protocol.js';
|
|
15
|
+
export * from './assets.js';
|
|
16
|
+
export * from './plugins-api.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './registry.js';
|
|
3
|
+
export * from './logic.js';
|
|
4
|
+
export * from './condition.js';
|
|
5
|
+
export * from './catalogue.js';
|
|
6
|
+
export * from './status.js';
|
|
7
|
+
export * from './pins.js';
|
|
8
|
+
export * from './chips.js';
|
|
9
|
+
export * from './pack.js';
|
|
10
|
+
export * from './views.js';
|
|
11
|
+
export * from './bytes.js';
|
|
12
|
+
export * from './navigation.js';
|
|
13
|
+
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './sandbox-protocol.js';
|
|
15
|
+
export * from './assets.js';
|
|
16
|
+
export * from './plugins-api.js';
|
package/lib/logic.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { GameManifest, HintGraph, LocationMapConfig, MapLayer, ObjectiveMeta } from './registry.js';
|
|
2
|
+
import type { GameState, ObjectiveStatus, Position3D } from './types.js';
|
|
3
|
+
export interface FilteredHint {
|
|
4
|
+
id: string;
|
|
5
|
+
reveals: string[];
|
|
6
|
+
isPlotSpoiler: boolean;
|
|
7
|
+
availableTiers: {
|
|
8
|
+
1: string;
|
|
9
|
+
2?: string;
|
|
10
|
+
3?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Spoiler-safe-by-construction filter (C7):
|
|
15
|
+
* Evaluates hint conditions strictly on the client BEFORE constructing any LLM prompt,
|
|
16
|
+
* stripping higher tiers and excluding any hints whose prerequisites are not yet met.
|
|
17
|
+
*/
|
|
18
|
+
export declare function filterHintGraph(graph: HintGraph, state: GameState, maxTier: 1 | 2 | 3, difficultyRanks?: Record<string, number>): FilteredHint[];
|
|
19
|
+
export interface LayerSelectionState {
|
|
20
|
+
layerId: string;
|
|
21
|
+
switchedAtMs: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Room-first map layer selector with Y-range tiebreaking and hysteresis (H6, M6).
|
|
25
|
+
*/
|
|
26
|
+
export declare function selectMapLayer(mapConfig: LocationMapConfig, position: Position3D | null, previous: LayerSelectionState | null, nowMs: number): LayerSelectionState;
|
|
27
|
+
export interface ProjectedPin {
|
|
28
|
+
u: number;
|
|
29
|
+
v: number;
|
|
30
|
+
screenHeadingDeg: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Projects 3D world position + heading onto 2D SVG map space with handedness sign (H6, M5).
|
|
34
|
+
*/
|
|
35
|
+
export declare function worldToMapPoint(layer: MapLayer, pos: Position3D): ProjectedPin;
|
|
36
|
+
/**
|
|
37
|
+
* Inverse 2D map-to-world projection: converts SVG (u, v) coordinates on a layer back into 3D world [x, y, z].
|
|
38
|
+
*/
|
|
39
|
+
export declare function mapPointToWorld(layer: MapLayer, u: number, v: number, fallbackY?: number): [number, number, number];
|
|
40
|
+
/**
|
|
41
|
+
* Signed 2D triangle area helper for Layer-2 CI orientation tests (M7).
|
|
42
|
+
*/
|
|
43
|
+
export declare function signedTriangleArea2D(p1: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
}, p2: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}, p3: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
}): number;
|
|
53
|
+
/**
|
|
54
|
+
* Filters manifest objectives down to those active for the current difficulty.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getActiveObjectivesForDifficulty(manifest: GameManifest, locationId: string, difficulty?: string): {
|
|
57
|
+
label: string;
|
|
58
|
+
id: string;
|
|
59
|
+
minDifficulty?: string | undefined;
|
|
60
|
+
difficulties?: string[] | undefined;
|
|
61
|
+
completedByItems?: string[] | undefined;
|
|
62
|
+
completedByFlags?: string[] | undefined;
|
|
63
|
+
}[];
|
|
64
|
+
/**
|
|
65
|
+
* Evaluates effective completion status for a stage goal, honoring direct `state.objectives[obj.id]`
|
|
66
|
+
* as well as live inventory/flag completion rules (`completedByItems` / `completedByFlags`) in non-randomizer runs.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getObjectiveStatus(obj: ObjectiveMeta, state: GameState | null | undefined): ObjectiveStatus;
|