@wildshard/shard-format 0.56.0 → 0.59.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 +66 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.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,32 @@ 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
|
+
/** Meta MIRROR-SALT-ZONE MSZ33: a rival who races each run, an AI driver in the vehicle `dock` hands out (its kind and hull), along
|
|
62
|
+
* `line` (start to stop, x y z; a lap race's line is one lap, closing on its first point), at up to `speed` m/s on a straight
|
|
63
|
+
* and slower into a bend, eased within `band` m of the player (default 40) so he stays close; a player who finishes ahead
|
|
64
|
+
* of him raises `beat`. */
|
|
65
|
+
const RIVAL_LINE_MIN = 2;
|
|
66
|
+
const RIVAL_LINE_MAX = 512;
|
|
67
|
+
const RIVAL_SPEED_MIN = 1;
|
|
68
|
+
const RIVAL_SPEED_MAX = 80;
|
|
69
|
+
const RIVAL_BAND_MIN = 5;
|
|
70
|
+
const RIVAL_BAND_MAX = 500;
|
|
71
|
+
const rivalPoint = v.tuple([finite, finite, finite]);
|
|
72
|
+
const rivalLine = v.pipe(v.array(rivalPoint), v.minLength(RIVAL_LINE_MIN), v.maxLength(RIVAL_LINE_MAX));
|
|
73
|
+
const rivalSpeed = v.pipe(finite, v.minValue(RIVAL_SPEED_MIN), v.maxValue(RIVAL_SPEED_MAX));
|
|
74
|
+
const rivalBand = v.pipe(finite, v.minValue(RIVAL_BAND_MIN), v.maxValue(RIVAL_BAND_MAX));
|
|
75
|
+
const rival = v.strictObject({ name: text, dock: id, line: rivalLine, speed: rivalSpeed, band: v.exactOptional(rivalBand), beat: id });
|
|
76
|
+
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), rival: v.exactOptional(rival) });
|
|
52
77
|
const raceRows = v.pipe(v.array(race), v.maxLength(RACES_MAX));
|
|
53
78
|
const raceList = v.exactOptional(raceRows);
|
|
54
79
|
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 +86,23 @@ const raw: v.GenericSchema<{ [K in keyof QuestDataInput]: QuestDataInput[K] }, Q
|
|
|
61
86
|
/** Plain quest graphs, declared flags/triggers and finite dialogue trees; hooks name platform-resolved script ports. */
|
|
62
87
|
|
|
63
88
|
const reads = (c: v.InferOutput<typeof condition> | undefined): string[] => [...(c?.all ?? []), ...(c?.any ?? []), ...(c?.none ?? [])];
|
|
89
|
+
/** MSZ31: a race's checkpoints are neither its own start or stop nor named twice, and a lap race has one. */
|
|
90
|
+
function checkpointRules(run: { readonly id: string; readonly start: string; readonly stop: string; readonly laps?: number; readonly checkpoints?: readonly string[] }): string[] {
|
|
91
|
+
const checkpoints = run.checkpoints ?? [], errors: string[] = [];
|
|
92
|
+
if (checkpoints.some((flag): boolean => flag === run.start || flag === run.stop)) { errors.push(`race ${run.id} checkpoints its own start or stop`); }
|
|
93
|
+
if (new Set(checkpoints).size !== checkpoints.length) { errors.push(`race ${run.id} names a checkpoint twice`); }
|
|
94
|
+
// 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
|
|
95
|
+
if ((run.laps ?? RACE_LAPS_MIN) > RACE_LAPS_MIN && checkpoints.length < RACE_CHECKPOINTS_MIN) { errors.push(`race ${run.id} runs laps without checkpoints`); }
|
|
96
|
+
return errors;
|
|
97
|
+
}
|
|
98
|
+
/** MSZ33: the flags a race reads besides its start, stop and resets: its checkpoints and its rival's beat. */
|
|
99
|
+
function raceFlags(run: { readonly checkpoints?: readonly string[]; readonly rival?: { readonly beat: string } }): string[] {
|
|
100
|
+
return run.rival === undefined ? [...run.checkpoints ?? []] : [...run.checkpoints ?? [], run.rival.beat];
|
|
101
|
+
}
|
|
102
|
+
/** MSZ33: a win over the rival is its own flag, never the line the run starts or stops on. */
|
|
103
|
+
function rivalRules(run: { readonly id: string; readonly start: string; readonly stop: string; readonly rival?: { readonly beat: string } }): string[] {
|
|
104
|
+
return run.rival !== undefined && [run.start, run.stop].includes(run.rival.beat) ? [`race ${run.id} beats its rival on its own start or stop`] : [];
|
|
105
|
+
}
|
|
64
106
|
/** Reject dangling flags, repeated identities, unreachable dialogue nodes and cycles before installing authored data. */
|
|
65
107
|
export function questDataRules(data: QuestData): string[] {
|
|
66
108
|
const errors: string[] = [], flags = new Set(data.flags);
|
|
@@ -78,6 +120,7 @@ export function questDataRules(data: QuestData): string[] {
|
|
|
78
120
|
raceIds.push(run.id); checkFlags([run.start, run.stop, ...(run.resets ?? [])]);
|
|
79
121
|
if (run.start === run.stop) { errors.push(`race ${run.id} starts and stops on one flag`); }
|
|
80
122
|
if (run.resets?.some((flag): boolean => flag === run.start || flag === run.stop) === true) { errors.push(`race ${run.id} resets its own start or stop`); }
|
|
123
|
+
checkFlags(raceFlags(run)); errors.push(...checkpointRules(run), ...rivalRules(run));
|
|
81
124
|
}
|
|
82
125
|
unique(raceIds);
|
|
83
126
|
for (const d of data.dialogue) {
|
|
@@ -219,6 +262,17 @@ interface QuestDataInputFields {
|
|
|
219
262
|
fact: string;
|
|
220
263
|
cap: number;
|
|
221
264
|
resets?: (string)[];
|
|
265
|
+
laps?: number;
|
|
266
|
+
checkpoints?: (string)[];
|
|
267
|
+
ride?: 'vehicle' | 'foot' | 'any';
|
|
268
|
+
rival?: {
|
|
269
|
+
name: string;
|
|
270
|
+
dock: string;
|
|
271
|
+
line: ([number, number, number])[];
|
|
272
|
+
speed: number;
|
|
273
|
+
band?: number;
|
|
274
|
+
beat: string;
|
|
275
|
+
};
|
|
222
276
|
})[];
|
|
223
277
|
dialogue: ({
|
|
224
278
|
id: string;
|
|
@@ -364,6 +418,17 @@ interface QuestDataFields {
|
|
|
364
418
|
fact: string;
|
|
365
419
|
cap: number;
|
|
366
420
|
resets?: (string)[];
|
|
421
|
+
laps?: number;
|
|
422
|
+
checkpoints?: (string)[];
|
|
423
|
+
ride?: 'vehicle' | 'foot' | 'any';
|
|
424
|
+
rival?: {
|
|
425
|
+
name: string;
|
|
426
|
+
dock: string;
|
|
427
|
+
line: ([number, number, number])[];
|
|
428
|
+
speed: number;
|
|
429
|
+
band?: number;
|
|
430
|
+
beat: string;
|
|
431
|
+
};
|
|
367
432
|
})[];
|
|
368
433
|
dialogue: ({
|
|
369
434
|
id: string;
|