@wildshard/shard-format 0.55.2 → 0.57.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.55.2",
3
+ "version": "0.57.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -18,11 +18,9 @@ const entry = v.strictObject({ id: key, kind: entryKind, tab: key, name: text, n
18
18
  const stat = v.strictObject({ label: text, value: v.picklist(['seen', 'taken', 'best', 'rarity', 'status']),
19
19
  fallback: v.exactOptional(text), suffix: v.exactOptional(text), words: v.exactOptional(v.record(key, text)) });
20
20
  const stats = v.pipe(v.array(stat), v.maxLength(8));
21
- const iconSelectors = { entryKind: v.exactOptional(entryKind), matchKind: v.exactOptional(key) };
22
- const legacyIcon = v.strictObject({ ...iconSelectors, icon: v.picklist(['antlers', 'ghost', 'ironhide', 'deer', 'boar', 'elk', 'bear']) });
23
21
  const iconImage = v.pipe(text, v.check(sketchReference, 'bounded inert SVG data or admitted image hash'));
24
- const imageIcon = v.strictObject({ ...iconSelectors, image: iconImage, tint: v.exactOptional(v.literal('currentColor')) });
25
- const icon = v.union([imageIcon, legacyIcon]);
22
+ const icon = v.strictObject({ entryKind: v.exactOptional(entryKind), matchKind: v.exactOptional(key),
23
+ image: iconImage, tint: v.exactOptional(v.literal('currentColor')) });
26
24
  const cell = v.strictObject({ x: finite, y: finite, w: positive, h: positive });
27
25
  const trophy = v.strictObject({ entry: key, outline: key, mount: v.exactOptional(v.strictObject({ kind: key, variant: key })), title: text });
28
26
  const wall = v.strictObject({ cabin: natural, at: v.tuple([finite, finite, finite]), yaw: finite, width: positive,
@@ -51,14 +49,14 @@ export function journalRowRules(row: JournalRow): readonly string[] {
51
49
  }
52
50
  /** All raster images must be charged immutable library roots; logical URLs are resolved by the admitted product. */
53
51
  export function journalImageRefs(row: JournalRow): readonly string[] {
54
- const icons = row.icons.flatMap((value: Readonly<JournalIcon>): string[] => 'image' in value && !value.image.startsWith('data:') ? [value.image] : []);
52
+ const icons = row.icons.flatMap((value: Readonly<JournalIcon>): string[] => value.image.startsWith('data:') ? [] : [value.image]);
55
53
  return [...new Set([...row.entries.flatMap(value => [value.plate.sketch, ...value.plate.silhouette === undefined ? [] : [value.plate.silhouette]]),
56
54
  ...row.chalk === undefined ? [] : [row.chalk.atlas], ...icons])];
57
55
  }
58
56
 
59
57
  /** Admitted data contracts, independent of validator implementation metadata. */
60
58
  export type JournalRowInput = JournalRow;
61
- type JournalIcon = { entryKind?: 'species' | 'variant' | 'elite' | 'boss' | 'place'; matchKind?: string } & ({ image: string; tint?: 'currentColor' } | { icon: 'antlers' | 'ghost' | 'ironhide' | 'deer' | 'boar' | 'elk' | 'bear' });
59
+ interface JournalIcon { entryKind?: 'species' | 'variant' | 'elite' | 'boss' | 'place'; matchKind?: string; image: string; tint?: 'currentColor' }
62
60
  interface JournalRowFields {
63
61
  kind: 'journal';
64
62
  id: string;
@@ -3,10 +3,10 @@ import { parseSketchSvg, sketchReference, type CompendiumSketch } from './sketch
3
3
  import type { ShardRows } from './rows.ts';
4
4
 
5
5
  const prefix = 'data:image/svg+xml,';
6
- type SketchRow = Readonly<{ kind: 'journal'; icons: readonly Readonly<{ image?: string; icon?: string }>[] }> | Readonly<{ kind?: never; entries: readonly Readonly<{ sketch: string }>[] }>;
6
+ type SketchRow = Readonly<{ kind: 'journal'; icons: readonly Readonly<{ image: string }>[] }> | Readonly<{ kind?: never; entries: readonly Readonly<{ sketch: string }>[] }>;
7
7
  function sketchRefs(row: SketchRow): string[] {
8
8
  if (row.kind === 'journal') {
9
- return row.icons.flatMap((value: Readonly<{ image?: string; icon?: string }>): string[] => value.image?.startsWith(prefix) === true ? [value.image] : []);
9
+ return row.icons.flatMap((value: Readonly<{ image: string }>): string[] => value.image.startsWith(prefix) ? [value.image] : []);
10
10
  }
11
11
  return row.entries.map((entry: Readonly<{ sketch: string }>): string => entry.sketch);
12
12
  }
@@ -6,11 +6,32 @@ const text = v.pipe(v.string(), v.minLength(1), v.maxLength(512));
6
6
  const finite = v.pipe(v.number(), v.finite());
7
7
  const names = v.pipe(v.array(id), v.maxLength(128));
8
8
  const condition = v.strictObject({ all: v.exactOptional(names), any: v.exactOptional(names), none: v.exactOptional(names) });
9
- const marker = v.strictObject({ id, label: text, short: v.exactOptional(v.pipe(text, v.maxLength(18))), at: v.strictObject({ poi: v.literal('world'), x: finite, z: finite, y: v.exactOptional(finite) }), hideWhen: v.exactOptional(condition) });
9
+ const worldAt = v.strictObject({ poi: v.literal('world'), x: finite, z: finite, y: v.exactOptional(finite) });
10
+ const marker = v.strictObject({ id, label: text, short: v.exactOptional(v.pipe(text, v.maxLength(18))), at: worldAt, hideWhen: v.exactOptional(condition) });
10
11
  const markers = v.pipe(v.array(marker), v.maxLength(32));
11
12
  const done = v.pipe(condition, v.check((c) => [...(c.all ?? []), ...(c.any ?? []), ...(c.none ?? [])].length > 0, 'nonempty done condition'));
12
- const step = v.strictObject({ id, objective: text, chip: v.exactOptional(v.pipe(text, v.maxLength(18))), hint: v.exactOptional(text), done, count: v.exactOptional(names), markers: v.exactOptional(markers) });
13
- const quest = v.strictObject({ id, title: text, track: v.exactOptional(v.boolean()), completeFlag: id, startWhen: v.exactOptional(condition), intro: v.exactOptional(v.strictObject({ objective: text, chip: v.exactOptional(v.pipe(text, v.maxLength(18))), hint: v.exactOptional(text), markers: v.exactOptional(markers) })), steps: v.pipe(v.array(step), v.minLength(1), v.maxLength(64)), onComplete: v.exactOptional(v.strictObject({ fact: v.exactOptional(id), scene: v.exactOptional(id), coins: v.exactOptional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(100))) })) });
13
+ /** Meta MOSSGATE-ZONE MZ31 (QA 11-19 row 35, "nothing happens"): where a quest beat lands, and how. The engine flares the
14
+ * spot in `colour`, spreads its light over the ground for `radius` metres, pops a small reward there and sounds one of its own
15
+ * synth voices (`InteractSfx`, no recorded audio). */
16
+ const SPREAD_MIN = 1;
17
+ const SPREAD_MAX = 40;
18
+ const colour = v.pipe(v.string(), v.regex(/^#[0-9a-fA-F]{6}$/u));
19
+ const spread = v.pipe(finite, v.minValue(SPREAD_MIN), v.maxValue(SPREAD_MAX));
20
+ const voice = v.picklist(['chime', 'glyph', 'ignite', 'chest', 'lever', 'plate', 'door', 'grate']);
21
+ const landing = { at: v.omit(worldAt, ['poi']), colour: v.exactOptional(colour), radius: v.exactOptional(spread), sound: v.exactOptional(voice) };
22
+ /** A step's landing: shown where the step was done, the moment its `done` first holds. */
23
+ const feedback = v.strictObject(landing);
24
+ /** A quest's payoff: a bigger landing as it completes, the score's reward take (`music`, default `dawn`), then the next goal
25
+ * (`next`) on the tracker. The world change is `onComplete.scene`, the shard's own declared scene hook. */
26
+ const music = v.picklist(['dawn', 'none']);
27
+ const payoff = v.strictObject({ ...landing, music: v.exactOptional(music), next: v.exactOptional(text) });
28
+ const optionalPayoff = v.exactOptional(payoff);
29
+ /** MZ31: a quest beat's landing (a step's `feedback`, the base of a quest's `onComplete.payoff`). */
30
+ interface QuestFeedbackRows { at: Record<'x' | 'z', number> & Partial<Record<'y', number>>; colour?: string; radius?: number; sound?: 'chime' | 'glyph' | 'ignite' | 'chest' | 'lever' | 'plate' | 'door' | 'grate' }
31
+ /** MZ31: a quest's payoff as it completes. */
32
+ interface QuestPayoffRows extends QuestFeedbackRows { music?: 'dawn' | 'none'; next?: string }
33
+ const step = v.strictObject({ id, objective: text, chip: v.exactOptional(v.pipe(text, v.maxLength(18))), hint: v.exactOptional(text), done, count: v.exactOptional(names), markers: v.exactOptional(markers), feedback: v.exactOptional(feedback) });
34
+ const quest = v.strictObject({ id, title: text, track: v.exactOptional(v.boolean()), completeFlag: id, startWhen: v.exactOptional(condition), intro: v.exactOptional(v.strictObject({ objective: text, chip: v.exactOptional(v.pipe(text, v.maxLength(18))), hint: v.exactOptional(text), markers: v.exactOptional(markers) })), steps: v.pipe(v.array(step), v.minLength(1), v.maxLength(64)), onComplete: v.exactOptional(v.strictObject({ fact: v.exactOptional(id), scene: v.exactOptional(id), coins: v.exactOptional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(100))), payoff: optionalPayoff })) });
14
35
  /** Complete presentation chapter after its native completion owner is omitted. */
15
36
  export const QuestPresentationChapterSchema:v.GenericSchema<Omit<QuestDataInput['quests'][number],'onComplete'>,Omit<QuestData['quests'][number],'onComplete'>>=v.omit(quest,['onComplete']);
16
37
  const trigger = v.variant('kind', [
@@ -27,7 +48,17 @@ const raceCap = v.pipe(finite, v.safeInteger(), v.minValue(RACE_CAP_MIN_S), v.ma
27
48
  const RACE_RESETS_MAX = 64;
28
49
  const RACE_RESETS_MIN = 1;
29
50
  const raceResets = v.pipe(v.array(id), v.minLength(RACE_RESETS_MIN), v.maxLength(RACE_RESETS_MAX));
30
- const race = v.strictObject({ id, start: id, stop: id, fact: id, cap: raceCap, resets: v.exactOptional(raceResets) });
51
+ /** Meta MIRROR-SALT-ZONE MSZ31: a race of `laps` laps (1 to 20, default 1); each lap crosses `checkpoints` in order before
52
+ * `stop` counts it (a lap that misses one is void); `ride` says how it is run (`vehicle`, `foot`, `any`, default `any`): a run
53
+ * begun the wrong way is refused at `start`. */
54
+ const RACE_LAPS_MIN = 1;
55
+ const RACE_LAPS_MAX = 20;
56
+ const RACE_CHECKPOINTS_MIN = 1;
57
+ const RACE_CHECKPOINTS_MAX = 32;
58
+ const raceLaps = v.pipe(finite, v.safeInteger(), v.minValue(RACE_LAPS_MIN), v.maxValue(RACE_LAPS_MAX));
59
+ const raceCheckpoints = v.pipe(v.array(id), v.minLength(RACE_CHECKPOINTS_MIN), v.maxLength(RACE_CHECKPOINTS_MAX));
60
+ const raceRide = v.picklist(['vehicle', 'foot', 'any']);
61
+ const race = v.strictObject({ id, start: id, stop: id, fact: id, cap: raceCap, resets: v.exactOptional(raceResets), laps: v.exactOptional(raceLaps), checkpoints: v.exactOptional(raceCheckpoints), ride: v.exactOptional(raceRide) });
31
62
  const raceRows = v.pipe(v.array(race), v.maxLength(RACES_MAX));
32
63
  const raceList = v.exactOptional(raceRows);
33
64
  const choice = v.strictObject({ id, label: text, next: v.nullable(id), when: v.exactOptional(condition), sets: v.exactOptional(names), scene: v.exactOptional(id) });
@@ -40,6 +71,15 @@ const raw: v.GenericSchema<{ [K in keyof QuestDataInput]: QuestDataInput[K] }, Q
40
71
  /** Plain quest graphs, declared flags/triggers and finite dialogue trees; hooks name platform-resolved script ports. */
41
72
 
42
73
  const reads = (c: v.InferOutput<typeof condition> | undefined): string[] => [...(c?.all ?? []), ...(c?.any ?? []), ...(c?.none ?? [])];
74
+ /** MSZ31: a race's checkpoints are neither its own start or stop nor named twice, and a lap race has one. */
75
+ function checkpointRules(run: { readonly id: string; readonly start: string; readonly stop: string; readonly laps?: number; readonly checkpoints?: readonly string[] }): string[] {
76
+ const checkpoints = run.checkpoints ?? [], errors: string[] = [];
77
+ if (checkpoints.some((flag): boolean => flag === run.start || flag === run.stop)) { errors.push(`race ${run.id} checkpoints its own start or stop`); }
78
+ if (new Set(checkpoints).size !== checkpoints.length) { errors.push(`race ${run.id} names a checkpoint twice`); }
79
+ // A lap counts at the stop only once its checkpoints are crossed, so a lap race without one could be won by stepping over the line
80
+ if ((run.laps ?? RACE_LAPS_MIN) > RACE_LAPS_MIN && checkpoints.length < RACE_CHECKPOINTS_MIN) { errors.push(`race ${run.id} runs laps without checkpoints`); }
81
+ return errors;
82
+ }
43
83
  /** Reject dangling flags, repeated identities, unreachable dialogue nodes and cycles before installing authored data. */
44
84
  export function questDataRules(data: QuestData): string[] {
45
85
  const errors: string[] = [], flags = new Set(data.flags);
@@ -57,6 +97,7 @@ export function questDataRules(data: QuestData): string[] {
57
97
  raceIds.push(run.id); checkFlags([run.start, run.stop, ...(run.resets ?? [])]);
58
98
  if (run.start === run.stop) { errors.push(`race ${run.id} starts and stops on one flag`); }
59
99
  if (run.resets?.some((flag): boolean => flag === run.start || flag === run.stop) === true) { errors.push(`race ${run.id} resets its own start or stop`); }
100
+ checkFlags(run.checkpoints ?? []); errors.push(...checkpointRules(run));
60
101
  }
61
102
  unique(raceIds);
62
103
  for (const d of data.dialogue) {
@@ -133,6 +174,7 @@ interface QuestDataInputFields {
133
174
  none?: (string)[];
134
175
  };
135
176
  count?: (string)[];
177
+ feedback?: QuestFeedbackRows;
136
178
  markers?: ({
137
179
  id: string;
138
180
  label: string;
@@ -154,6 +196,7 @@ interface QuestDataInputFields {
154
196
  fact?: string;
155
197
  scene?: string;
156
198
  coins?: number;
199
+ payoff?: QuestPayoffRows;
157
200
  };
158
201
  })[];
159
202
  triggers: (({
@@ -196,6 +239,9 @@ interface QuestDataInputFields {
196
239
  fact: string;
197
240
  cap: number;
198
241
  resets?: (string)[];
242
+ laps?: number;
243
+ checkpoints?: (string)[];
244
+ ride?: 'vehicle' | 'foot' | 'any';
199
245
  })[];
200
246
  dialogue: ({
201
247
  id: string;
@@ -276,6 +322,7 @@ interface QuestDataFields {
276
322
  none?: (string)[];
277
323
  };
278
324
  count?: (string)[];
325
+ feedback?: QuestFeedbackRows;
279
326
  markers?: ({
280
327
  id: string;
281
328
  label: string;
@@ -297,6 +344,7 @@ interface QuestDataFields {
297
344
  fact?: string;
298
345
  scene?: string;
299
346
  coins?: number;
347
+ payoff?: QuestPayoffRows;
300
348
  };
301
349
  })[];
302
350
  triggers: (({
@@ -339,6 +387,9 @@ interface QuestDataFields {
339
387
  fact: string;
340
388
  cap: number;
341
389
  resets?: (string)[];
390
+ laps?: number;
391
+ checkpoints?: (string)[];
392
+ ride?: 'vehicle' | 'foot' | 'any';
342
393
  })[];
343
394
  dialogue: ({
344
395
  id: string;