@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/logic.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const DIFFICULTY_RANK = {
|
|
2
|
+
easy: -1,
|
|
3
|
+
normal: 0,
|
|
4
|
+
master_quest: 1,
|
|
5
|
+
hard: 2,
|
|
6
|
+
agent: 0,
|
|
7
|
+
special_agent: 1,
|
|
8
|
+
perfect_agent: 2,
|
|
9
|
+
perfect_dark: 3,
|
|
10
|
+
};
|
|
11
|
+
const isComplete = (state, objectiveId) => state.objectives[objectiveId] === 'complete';
|
|
12
|
+
/* Difficulty (or MM day/night) and Link's age gates. */
|
|
13
|
+
function meetsGates(req, ctx) {
|
|
14
|
+
const { state } = ctx;
|
|
15
|
+
if (req.difficulties && state.difficulty && !req.difficulties.includes(state.difficulty)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (req.minDifficulty !== undefined &&
|
|
19
|
+
ctx.diffRank < (ctx.difficultyRanks[req.minDifficulty] ?? 0)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return !req.age || Boolean(state.flags[`age_${req.age}`] || state.flags[`is_${req.age}`]);
|
|
23
|
+
}
|
|
24
|
+
/** The hint's prerequisites all hold in the current state. */
|
|
25
|
+
function meetsRequirements(req, ctx) {
|
|
26
|
+
const { state } = ctx;
|
|
27
|
+
if (!meetsGates(req, ctx))
|
|
28
|
+
return false;
|
|
29
|
+
return ((req.objectivesIncomplete ?? []).every(id => !isComplete(state, id)) &&
|
|
30
|
+
(req.objectivesComplete ?? []).every(id => isComplete(state, id)) &&
|
|
31
|
+
(req.inventory ?? []).every(item => ctx.inventory.has(item)) &&
|
|
32
|
+
(req.flags ?? []).every(flag => Boolean(state.flags[flag])));
|
|
33
|
+
}
|
|
34
|
+
/** Something the player already has or has done rules the hint out. */
|
|
35
|
+
function isExcluded(exc, ctx) {
|
|
36
|
+
return ((exc.inventory ?? []).some(item => ctx.inventory.has(item)) ||
|
|
37
|
+
(exc.flags ?? []).some(flag => Boolean(ctx.state.flags[flag])) ||
|
|
38
|
+
(exc.objectivesComplete ?? []).some(id => isComplete(ctx.state, id)));
|
|
39
|
+
}
|
|
40
|
+
/* Plot spoilers never go past tier 2, whatever the player asked for. */
|
|
41
|
+
function availableTiersFor(node, maxTier) {
|
|
42
|
+
const effectiveTier = node.isPlotSpoiler && maxTier === 3 ? 2 : maxTier;
|
|
43
|
+
const tiers = { 1: node.tiers['1'] };
|
|
44
|
+
if (effectiveTier >= 2)
|
|
45
|
+
tiers[2] = node.tiers['2'];
|
|
46
|
+
if (effectiveTier >= 3 && node.tiers['3'])
|
|
47
|
+
tiers[3] = node.tiers['3'];
|
|
48
|
+
return tiers;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Spoiler-safe-by-construction filter (C7):
|
|
52
|
+
* Evaluates hint conditions strictly on the client BEFORE constructing any LLM prompt,
|
|
53
|
+
* stripping higher tiers and excluding any hints whose prerequisites are not yet met.
|
|
54
|
+
*/
|
|
55
|
+
export function filterHintGraph(graph, state, maxTier, difficultyRanks = DIFFICULTY_RANK) {
|
|
56
|
+
/* Static progression hints don't hold in Randomizer mode (C7). */
|
|
57
|
+
if (state.variant === 'randomizer')
|
|
58
|
+
return [];
|
|
59
|
+
const ctx = {
|
|
60
|
+
state,
|
|
61
|
+
inventory: new Set(state.inventory),
|
|
62
|
+
diffRank: state.difficulty ? (difficultyRanks[state.difficulty] ?? 0) : 0,
|
|
63
|
+
difficultyRanks,
|
|
64
|
+
};
|
|
65
|
+
return graph.hints
|
|
66
|
+
.filter(node => node.locationIds.includes(state.locationId) &&
|
|
67
|
+
meetsRequirements(node.requires, ctx) &&
|
|
68
|
+
!isExcluded(node.excludes, ctx))
|
|
69
|
+
.map(node => ({
|
|
70
|
+
id: node.id,
|
|
71
|
+
reveals: node.reveals,
|
|
72
|
+
isPlotSpoiler: node.isPlotSpoiler,
|
|
73
|
+
availableTiers: availableTiersFor(node, maxTier),
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
const inYRange = (l, y) => l.yRange !== undefined && y >= l.yRange[0] && y <= l.yRange[1];
|
|
77
|
+
/**
|
|
78
|
+
* Layers the player could be on: the one listing their room; among several, those whose height
|
|
79
|
+
* range holds them (else all of them); with no room match, any whose height range holds them;
|
|
80
|
+
* failing all that, every layer.
|
|
81
|
+
*/
|
|
82
|
+
function layerCandidates(layers, position) {
|
|
83
|
+
const roomId = position.roomId;
|
|
84
|
+
const roomMatches = roomId === undefined ? [] : layers.filter(l => l.rooms.includes(roomId));
|
|
85
|
+
if (roomMatches.length === 1)
|
|
86
|
+
return roomMatches;
|
|
87
|
+
if (roomMatches.length > 1) {
|
|
88
|
+
const yMatches = roomMatches.filter(l => !l.yRange || inYRange(l, position.y));
|
|
89
|
+
return yMatches.length > 0 ? yMatches : roomMatches;
|
|
90
|
+
}
|
|
91
|
+
const yMatches = layers.filter(l => inYRange(l, position.y));
|
|
92
|
+
return yMatches.length > 0 ? yMatches : layers;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Room-first map layer selector with Y-range tiebreaking and hysteresis (H6, M6).
|
|
96
|
+
*/
|
|
97
|
+
export function selectMapLayer(mapConfig, position, previous, nowMs) {
|
|
98
|
+
const defaultLayer = [...mapConfig.layers].sort((a, b) => a.priority - b.priority)[0];
|
|
99
|
+
if (!defaultLayer)
|
|
100
|
+
throw new Error('Map config has no layers: invalid registry data');
|
|
101
|
+
if (!position) {
|
|
102
|
+
return previous ?? { layerId: defaultLayer.id, switchedAtMs: nowMs };
|
|
103
|
+
}
|
|
104
|
+
const candidates = layerCandidates(mapConfig.layers, position);
|
|
105
|
+
const chosen = [...candidates].sort((a, b) => a.priority - b.priority)[0] ?? defaultLayer;
|
|
106
|
+
if (previous && previous.layerId !== chosen.id) {
|
|
107
|
+
if (nowMs - previous.switchedAtMs < mapConfig.hysteresisMs) {
|
|
108
|
+
return previous;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (previous && previous.layerId === chosen.id) {
|
|
112
|
+
return previous;
|
|
113
|
+
}
|
|
114
|
+
return { layerId: chosen.id, switchedAtMs: nowMs };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Projects 3D world position + heading onto 2D SVG map space with handedness sign (H6, M5).
|
|
118
|
+
*/
|
|
119
|
+
export function worldToMapPoint(layer, pos) {
|
|
120
|
+
const [a, b, tx, c, d, ty] = layer.affine;
|
|
121
|
+
const u = a * pos.x + b * pos.z + tx;
|
|
122
|
+
const v = c * pos.x + d * pos.z + ty;
|
|
123
|
+
const rawHeading = layer.headingSign * pos.headingDeg + layer.headingOffsetDeg;
|
|
124
|
+
const screenHeadingDeg = ((rawHeading % 360) + 360) % 360;
|
|
125
|
+
return { u, v, screenHeadingDeg };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Inverse 2D map-to-world projection: converts SVG (u, v) coordinates on a layer back into 3D world [x, y, z].
|
|
129
|
+
*/
|
|
130
|
+
export function mapPointToWorld(layer, u, v, fallbackY = 0) {
|
|
131
|
+
const [a, b, tx, c, d, ty] = layer.affine;
|
|
132
|
+
const det = a * d - b * c;
|
|
133
|
+
const y = layer.yRange ? 0.5 * (layer.yRange[0] + layer.yRange[1]) : fallbackY;
|
|
134
|
+
if (Math.abs(det) < 1e-9) {
|
|
135
|
+
return [0, Math.round(y * 10) / 10, 0];
|
|
136
|
+
}
|
|
137
|
+
const du = u - tx;
|
|
138
|
+
const dv = v - ty;
|
|
139
|
+
const x = (d * du - b * dv) / det;
|
|
140
|
+
const z = (-c * du + a * dv) / det;
|
|
141
|
+
return [Math.round(x * 10) / 10, Math.round(y * 10) / 10, Math.round(z * 10) / 10];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Signed 2D triangle area helper for Layer-2 CI orientation tests (M7).
|
|
145
|
+
*/
|
|
146
|
+
export function signedTriangleArea2D(p1, p2, p3) {
|
|
147
|
+
return 0.5 * ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Filters manifest objectives down to those active for the current difficulty.
|
|
151
|
+
*/
|
|
152
|
+
export function getActiveObjectivesForDifficulty(manifest, locationId, difficulty) {
|
|
153
|
+
const loc = manifest.locations[locationId];
|
|
154
|
+
if (!loc?.objectives)
|
|
155
|
+
return [];
|
|
156
|
+
const diffRanks = manifest.difficulties
|
|
157
|
+
? Object.fromEntries(Object.entries(manifest.difficulties).map(([k, v]) => [k, v.rank]))
|
|
158
|
+
: DIFFICULTY_RANK;
|
|
159
|
+
const currentRank = difficulty ? (diffRanks[difficulty] ?? 0) : 0;
|
|
160
|
+
return loc.objectives.filter(o => {
|
|
161
|
+
if (o.difficulties && difficulty) {
|
|
162
|
+
return o.difficulties.includes(difficulty);
|
|
163
|
+
}
|
|
164
|
+
if (!o.minDifficulty)
|
|
165
|
+
return true;
|
|
166
|
+
const reqRank = diffRanks[o.minDifficulty] ?? 0;
|
|
167
|
+
return currentRank >= reqRank;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Evaluates effective completion status for a stage goal, honoring direct `state.objectives[obj.id]`
|
|
172
|
+
* as well as live inventory/flag completion rules (`completedByItems` / `completedByFlags`) in non-randomizer runs.
|
|
173
|
+
*/
|
|
174
|
+
export function getObjectiveStatus(obj, state) {
|
|
175
|
+
if (!state)
|
|
176
|
+
return 'incomplete';
|
|
177
|
+
const direct = state.objectives[obj.id];
|
|
178
|
+
if (direct === 'complete' || direct === 'failed') {
|
|
179
|
+
return direct;
|
|
180
|
+
}
|
|
181
|
+
if (state.variant !== 'randomizer') {
|
|
182
|
+
if (obj.completedByItems &&
|
|
183
|
+
obj.completedByItems.length > 0 &&
|
|
184
|
+
obj.completedByItems.every(id => state.inventory.includes(id))) {
|
|
185
|
+
return 'complete';
|
|
186
|
+
}
|
|
187
|
+
if (obj.completedByFlags &&
|
|
188
|
+
obj.completedByFlags.length > 0 &&
|
|
189
|
+
obj.completedByFlags.every(fl => Boolean(state.flags[fl]))) {
|
|
190
|
+
return 'complete';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return direct ?? 'incomplete';
|
|
194
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const NavAreaSchema: z.ZodObject<{
|
|
3
|
+
/** floor height (world y) */
|
|
4
|
+
floor: z.ZodNumber;
|
|
5
|
+
/** closed outlines as flat [x0, z0, x1, z1, …] lists; a point is inside by the even-odd rule */
|
|
6
|
+
loops: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
|
|
7
|
+
/** walking here costs this many times the distance (e.g. a damaging floor); default 1 */
|
|
8
|
+
costFactor: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
floor: number;
|
|
11
|
+
loops: number[][];
|
|
12
|
+
costFactor?: number | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
floor: number;
|
|
15
|
+
loops: number[][];
|
|
16
|
+
costFactor?: number | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export type NavArea = z.infer<typeof NavAreaSchema>;
|
|
19
|
+
export declare const NavLinkSchema: z.ZodObject<{
|
|
20
|
+
from: z.ZodNumber;
|
|
21
|
+
to: z.ZodNumber;
|
|
22
|
+
/** the opening's two ends (x, z); a route crosses somewhere along it */
|
|
23
|
+
a: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
24
|
+
b: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
25
|
+
/** how it's crossed: walk, drop off a ledge (no way back), a door, a lift, a teleporter */
|
|
26
|
+
kind: z.ZodEnum<["walk", "drop", "door", "lift", "teleport"]>;
|
|
27
|
+
/** for a teleporter: where it puts the player */
|
|
28
|
+
dest: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
29
|
+
/** only passable while this holds (e.g. carrying the right key); the UI evaluates it live */
|
|
30
|
+
requires: z.ZodOptional<z.ZodType<import("./condition.js").Condition, z.ZodTypeDef, import("./condition.js").Condition>>;
|
|
31
|
+
/** what `requires` means, for telling the player ("the blue key") */
|
|
32
|
+
requiresLabel: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
35
|
+
from: number;
|
|
36
|
+
to: number;
|
|
37
|
+
a: [number, number];
|
|
38
|
+
b: [number, number];
|
|
39
|
+
dest?: [number, number] | undefined;
|
|
40
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
41
|
+
requiresLabel?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
44
|
+
from: number;
|
|
45
|
+
to: number;
|
|
46
|
+
a: [number, number];
|
|
47
|
+
b: [number, number];
|
|
48
|
+
dest?: [number, number] | undefined;
|
|
49
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
50
|
+
requiresLabel?: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
export type NavLink = z.infer<typeof NavLinkSchema>;
|
|
53
|
+
export declare const NavGraphSchema: z.ZodObject<{
|
|
54
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
55
|
+
areas: z.ZodArray<z.ZodObject<{
|
|
56
|
+
/** floor height (world y) */
|
|
57
|
+
floor: z.ZodNumber;
|
|
58
|
+
/** closed outlines as flat [x0, z0, x1, z1, …] lists; a point is inside by the even-odd rule */
|
|
59
|
+
loops: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
|
|
60
|
+
/** walking here costs this many times the distance (e.g. a damaging floor); default 1 */
|
|
61
|
+
costFactor: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
floor: number;
|
|
64
|
+
loops: number[][];
|
|
65
|
+
costFactor?: number | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
floor: number;
|
|
68
|
+
loops: number[][];
|
|
69
|
+
costFactor?: number | undefined;
|
|
70
|
+
}>, "many">;
|
|
71
|
+
links: z.ZodArray<z.ZodObject<{
|
|
72
|
+
from: z.ZodNumber;
|
|
73
|
+
to: z.ZodNumber;
|
|
74
|
+
/** the opening's two ends (x, z); a route crosses somewhere along it */
|
|
75
|
+
a: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
76
|
+
b: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
77
|
+
/** how it's crossed: walk, drop off a ledge (no way back), a door, a lift, a teleporter */
|
|
78
|
+
kind: z.ZodEnum<["walk", "drop", "door", "lift", "teleport"]>;
|
|
79
|
+
/** for a teleporter: where it puts the player */
|
|
80
|
+
dest: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
81
|
+
/** only passable while this holds (e.g. carrying the right key); the UI evaluates it live */
|
|
82
|
+
requires: z.ZodOptional<z.ZodType<import("./condition.js").Condition, z.ZodTypeDef, import("./condition.js").Condition>>;
|
|
83
|
+
/** what `requires` means, for telling the player ("the blue key") */
|
|
84
|
+
requiresLabel: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
87
|
+
from: number;
|
|
88
|
+
to: number;
|
|
89
|
+
a: [number, number];
|
|
90
|
+
b: [number, number];
|
|
91
|
+
dest?: [number, number] | undefined;
|
|
92
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
93
|
+
requiresLabel?: string | undefined;
|
|
94
|
+
}, {
|
|
95
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
96
|
+
from: number;
|
|
97
|
+
to: number;
|
|
98
|
+
a: [number, number];
|
|
99
|
+
b: [number, number];
|
|
100
|
+
dest?: [number, number] | undefined;
|
|
101
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
102
|
+
requiresLabel?: string | undefined;
|
|
103
|
+
}>, "many">;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
schemaVersion: 1;
|
|
106
|
+
areas: {
|
|
107
|
+
floor: number;
|
|
108
|
+
loops: number[][];
|
|
109
|
+
costFactor?: number | undefined;
|
|
110
|
+
}[];
|
|
111
|
+
links: {
|
|
112
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
113
|
+
from: number;
|
|
114
|
+
to: number;
|
|
115
|
+
a: [number, number];
|
|
116
|
+
b: [number, number];
|
|
117
|
+
dest?: [number, number] | undefined;
|
|
118
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
119
|
+
requiresLabel?: string | undefined;
|
|
120
|
+
}[];
|
|
121
|
+
}, {
|
|
122
|
+
schemaVersion: 1;
|
|
123
|
+
areas: {
|
|
124
|
+
floor: number;
|
|
125
|
+
loops: number[][];
|
|
126
|
+
costFactor?: number | undefined;
|
|
127
|
+
}[];
|
|
128
|
+
links: {
|
|
129
|
+
kind: "walk" | "drop" | "door" | "lift" | "teleport";
|
|
130
|
+
from: number;
|
|
131
|
+
to: number;
|
|
132
|
+
a: [number, number];
|
|
133
|
+
b: [number, number];
|
|
134
|
+
dest?: [number, number] | undefined;
|
|
135
|
+
requires?: import("./condition.js").Condition | undefined;
|
|
136
|
+
requiresLabel?: string | undefined;
|
|
137
|
+
}[];
|
|
138
|
+
}>;
|
|
139
|
+
export type NavGraph = z.infer<typeof NavGraphSchema>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ConditionSchema } from './condition.js';
|
|
3
|
+
/*
|
|
4
|
+
* Where the player can walk on one map floor, for routing in the browser: areas (with their
|
|
5
|
+
* outline, to find which one a point is in) and one-way links between them through an opening.
|
|
6
|
+
* A pack's extractor produces it from the game's level data (local-assets navs/<layerId>.json);
|
|
7
|
+
* the UI plans routes over it without knowing the game. Coordinates are world x and z (the map's
|
|
8
|
+
* ground plane); heights are world y.
|
|
9
|
+
*/
|
|
10
|
+
const Point = z.tuple([z.number(), z.number()]);
|
|
11
|
+
export const NavAreaSchema = z.object({
|
|
12
|
+
/** floor height (world y) */
|
|
13
|
+
floor: z.number(),
|
|
14
|
+
/** closed outlines as flat [x0, z0, x1, z1, …] lists; a point is inside by the even-odd rule */
|
|
15
|
+
loops: z.array(z.array(z.number())),
|
|
16
|
+
/** walking here costs this many times the distance (e.g. a damaging floor); default 1 */
|
|
17
|
+
costFactor: z.number().positive().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const NavLinkSchema = z.object({
|
|
20
|
+
from: z.number().int().nonnegative(),
|
|
21
|
+
to: z.number().int().nonnegative(),
|
|
22
|
+
/** the opening's two ends (x, z); a route crosses somewhere along it */
|
|
23
|
+
a: Point,
|
|
24
|
+
b: Point,
|
|
25
|
+
/** how it's crossed: walk, drop off a ledge (no way back), a door, a lift, a teleporter */
|
|
26
|
+
kind: z.enum(['walk', 'drop', 'door', 'lift', 'teleport']),
|
|
27
|
+
/** for a teleporter: where it puts the player */
|
|
28
|
+
dest: Point.optional(),
|
|
29
|
+
/** only passable while this holds (e.g. carrying the right key); the UI evaluates it live */
|
|
30
|
+
requires: ConditionSchema.optional(),
|
|
31
|
+
/** what `requires` means, for telling the player ("the blue key") */
|
|
32
|
+
requiresLabel: z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
export const NavGraphSchema = z.object({
|
|
35
|
+
schemaVersion: z.literal(1),
|
|
36
|
+
areas: z.array(NavAreaSchema),
|
|
37
|
+
links: z.array(NavLinkSchema),
|
|
38
|
+
});
|