@wildshard/shard-format 0.56.0 → 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 +1 -1
- package/src/format/quests.ts +27 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
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": {
|
package/src/format/quests.ts
CHANGED
|
@@ -48,7 +48,17 @@ const raceCap = v.pipe(finite, v.safeInteger(), v.minValue(RACE_CAP_MIN_S), v.ma
|
|
|
48
48
|
const RACE_RESETS_MAX = 64;
|
|
49
49
|
const RACE_RESETS_MIN = 1;
|
|
50
50
|
const raceResets = v.pipe(v.array(id), v.minLength(RACE_RESETS_MIN), v.maxLength(RACE_RESETS_MAX));
|
|
51
|
-
|
|
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) });
|
|
52
62
|
const raceRows = v.pipe(v.array(race), v.maxLength(RACES_MAX));
|
|
53
63
|
const raceList = v.exactOptional(raceRows);
|
|
54
64
|
const choice = v.strictObject({ id, label: text, next: v.nullable(id), when: v.exactOptional(condition), sets: v.exactOptional(names), scene: v.exactOptional(id) });
|
|
@@ -61,6 +71,15 @@ const raw: v.GenericSchema<{ [K in keyof QuestDataInput]: QuestDataInput[K] }, Q
|
|
|
61
71
|
/** Plain quest graphs, declared flags/triggers and finite dialogue trees; hooks name platform-resolved script ports. */
|
|
62
72
|
|
|
63
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
|
+
}
|
|
64
83
|
/** Reject dangling flags, repeated identities, unreachable dialogue nodes and cycles before installing authored data. */
|
|
65
84
|
export function questDataRules(data: QuestData): string[] {
|
|
66
85
|
const errors: string[] = [], flags = new Set(data.flags);
|
|
@@ -78,6 +97,7 @@ export function questDataRules(data: QuestData): string[] {
|
|
|
78
97
|
raceIds.push(run.id); checkFlags([run.start, run.stop, ...(run.resets ?? [])]);
|
|
79
98
|
if (run.start === run.stop) { errors.push(`race ${run.id} starts and stops on one flag`); }
|
|
80
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));
|
|
81
101
|
}
|
|
82
102
|
unique(raceIds);
|
|
83
103
|
for (const d of data.dialogue) {
|
|
@@ -219,6 +239,9 @@ interface QuestDataInputFields {
|
|
|
219
239
|
fact: string;
|
|
220
240
|
cap: number;
|
|
221
241
|
resets?: (string)[];
|
|
242
|
+
laps?: number;
|
|
243
|
+
checkpoints?: (string)[];
|
|
244
|
+
ride?: 'vehicle' | 'foot' | 'any';
|
|
222
245
|
})[];
|
|
223
246
|
dialogue: ({
|
|
224
247
|
id: string;
|
|
@@ -364,6 +387,9 @@ interface QuestDataFields {
|
|
|
364
387
|
fact: string;
|
|
365
388
|
cap: number;
|
|
366
389
|
resets?: (string)[];
|
|
390
|
+
laps?: number;
|
|
391
|
+
checkpoints?: (string)[];
|
|
392
|
+
ride?: 'vehicle' | 'foot' | 'any';
|
|
367
393
|
})[];
|
|
368
394
|
dialogue: ({
|
|
369
395
|
id: string;
|