@wildshard/shard-format 0.57.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 +41 -2
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
|
@@ -58,7 +58,22 @@ const RACE_CHECKPOINTS_MAX = 32;
|
|
|
58
58
|
const raceLaps = v.pipe(finite, v.safeInteger(), v.minValue(RACE_LAPS_MIN), v.maxValue(RACE_LAPS_MAX));
|
|
59
59
|
const raceCheckpoints = v.pipe(v.array(id), v.minLength(RACE_CHECKPOINTS_MIN), v.maxLength(RACE_CHECKPOINTS_MAX));
|
|
60
60
|
const raceRide = v.picklist(['vehicle', 'foot', 'any']);
|
|
61
|
-
|
|
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) });
|
|
62
77
|
const raceRows = v.pipe(v.array(race), v.maxLength(RACES_MAX));
|
|
63
78
|
const raceList = v.exactOptional(raceRows);
|
|
64
79
|
const choice = v.strictObject({ id, label: text, next: v.nullable(id), when: v.exactOptional(condition), sets: v.exactOptional(names), scene: v.exactOptional(id) });
|
|
@@ -80,6 +95,14 @@ function checkpointRules(run: { readonly id: string; readonly start: string; rea
|
|
|
80
95
|
if ((run.laps ?? RACE_LAPS_MIN) > RACE_LAPS_MIN && checkpoints.length < RACE_CHECKPOINTS_MIN) { errors.push(`race ${run.id} runs laps without checkpoints`); }
|
|
81
96
|
return errors;
|
|
82
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
|
+
}
|
|
83
106
|
/** Reject dangling flags, repeated identities, unreachable dialogue nodes and cycles before installing authored data. */
|
|
84
107
|
export function questDataRules(data: QuestData): string[] {
|
|
85
108
|
const errors: string[] = [], flags = new Set(data.flags);
|
|
@@ -97,7 +120,7 @@ export function questDataRules(data: QuestData): string[] {
|
|
|
97
120
|
raceIds.push(run.id); checkFlags([run.start, run.stop, ...(run.resets ?? [])]);
|
|
98
121
|
if (run.start === run.stop) { errors.push(`race ${run.id} starts and stops on one flag`); }
|
|
99
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`); }
|
|
100
|
-
checkFlags(run
|
|
123
|
+
checkFlags(raceFlags(run)); errors.push(...checkpointRules(run), ...rivalRules(run));
|
|
101
124
|
}
|
|
102
125
|
unique(raceIds);
|
|
103
126
|
for (const d of data.dialogue) {
|
|
@@ -242,6 +265,14 @@ interface QuestDataInputFields {
|
|
|
242
265
|
laps?: number;
|
|
243
266
|
checkpoints?: (string)[];
|
|
244
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
|
+
};
|
|
245
276
|
})[];
|
|
246
277
|
dialogue: ({
|
|
247
278
|
id: string;
|
|
@@ -390,6 +421,14 @@ interface QuestDataFields {
|
|
|
390
421
|
laps?: number;
|
|
391
422
|
checkpoints?: (string)[];
|
|
392
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
|
+
};
|
|
393
432
|
})[];
|
|
394
433
|
dialogue: ({
|
|
395
434
|
id: string;
|