@bendyline/molen-tooling 0.0.9 → 0.0.11
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/dist/capture/harness.js +261 -240
- package/dist/capture/worldgen-preview.js +309 -309
- package/dist/cli.mjs +6 -5
- package/dist/docs-src/guide/3d-model-assets.md +13 -0
- package/dist/docs-src/guide/adaptive-performance.md +5 -2
- package/dist/docs-src/guide/aircraft.md +113 -40
- package/dist/docs-src/guide/ambient-life.md +100 -11
- package/dist/docs-src/guide/audio.md +1 -1
- package/dist/docs-src/guide/boats.md +99 -0
- package/dist/docs-src/guide/determinism.md +1 -1
- package/dist/docs-src/guide/dioramas.md +167 -0
- package/dist/docs-src/guide/earth-view.md +241 -3
- package/dist/docs-src/guide/entities.md +32 -1
- package/dist/docs-src/guide/figures.md +7 -1
- package/dist/docs-src/guide/graphics-performance.md +16 -3
- package/dist/docs-src/guide/medium-fi.md +15 -6
- package/dist/docs-src/guide/regional-world.md +387 -0
- package/dist/docs-src/guide/sky.md +3 -2
- package/dist/docs-src/guide/surface-rendering.md +4 -1
- package/dist/docs-src/guide/vehicle-interiors.md +40 -2
- package/dist/docs-src/guide/vehicles.md +121 -19
- package/dist/docs-src/guide/weather.md +45 -3
- package/dist/docs-src/guide/worldgen.md +15 -1
- package/dist/docs-src/llms.txt +7 -4
- package/dist/docs-src/schemas/README.md +3 -0
- package/dist/docs-src/schemas/archstyle.md +144 -0
- package/dist/docs-src/schemas/components.md +1589 -137
- package/dist/docs-src/schemas/ecology-atlas.md +236 -0
- package/dist/docs-src/schemas/region-atlas.md +6 -0
- package/dist/docs-src/schemas/regional-catalog.md +1436 -0
- package/dist/docs-src/schemas/scatter.md +110 -4
- package/dist/docs-src/schemas/scene.md +6 -3
- package/dist/docs-src/schemas/terrain-package.md +41 -0
- package/dist/docs-src/schemas/transport-network.md +4 -2
- package/dist/docs-src/schemas/wildlife-ranges.md +251 -0
- package/dist/docs-src/schemas/worldgen-batch.md +21 -0
- package/dist/index.mjs +1 -1
- package/dist/{mcp-BbHk4ibu.mjs → mcp-BbxqqnD1.mjs} +3 -2
- package/dist/{ops-CErtZh2t.mjs → ops-b4Pag8U-.mjs} +7 -5
- package/dist/templates/city-courier/README.md +18 -0
- package/dist/templates/city-courier/gen/molen-types.ts +217 -15
- package/dist/templates/city-courier/index.html +1 -1
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +219 -17
- package/dist/templates/city-courier/src/audio.ts +26 -4
- package/dist/templates/city-courier/src/game-shell.css +7 -3
- package/dist/templates/city-courier/src/main.ts +25 -3
- package/dist/templates/city-courier/src/shared/accessibility.css +325 -0
- package/dist/templates/city-courier/src/shared/game-controls.ts +406 -0
- package/dist/templates/city-courier/src/shared/game-descriptions.ts +143 -0
- package/dist/templates/city-courier/src/shared/playback.ts +146 -0
- package/dist/templates/city-courier/src/worker.ts +5 -1
- package/dist/templates/cubes/index.html +6 -1
- package/dist/templates/cubes/src/main.ts +25 -2
- package/dist/templates/cubes/src/shared/accessibility.css +325 -0
- package/dist/templates/cubes/src/shared/playback.ts +146 -0
- package/dist/templates/cubes/src/vite-env.d.ts +1 -0
- package/dist/templates/cubes/src/worker.ts +1 -0
- package/dist/templates/data-viz/README.md +4 -0
- package/dist/templates/data-viz/index.html +6 -1
- package/dist/templates/data-viz/src/main.ts +53 -11
- package/dist/templates/data-viz/src/shared/accessibility.css +325 -0
- package/dist/templates/data-viz/src/shared/playback.ts +146 -0
- package/dist/templates/data-viz/src/vite-env.d.ts +1 -0
- package/dist/templates/data-viz/src/worker.ts +1 -0
- package/dist/templates/figures-gallery/index.html +6 -1
- package/dist/templates/figures-gallery/src/main.ts +21 -2
- package/dist/templates/figures-gallery/src/shared/accessibility.css +325 -0
- package/dist/templates/figures-gallery/src/shared/playback.ts +146 -0
- package/dist/templates/figures-gallery/src/vite-env.d.ts +1 -0
- package/dist/templates/figures-gallery/src/worker.ts +1 -0
- package/dist/templates/index.json +36 -16
- package/dist/templates/skybound/README.md +18 -0
- package/dist/templates/skybound/gen/molen-types.ts +217 -15
- package/dist/templates/skybound/index.html +1 -1
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +219 -17
- package/dist/templates/skybound/src/audio.ts +26 -4
- package/dist/templates/skybound/src/game-shell.css +7 -3
- package/dist/templates/skybound/src/main.ts +25 -3
- package/dist/templates/skybound/src/shared/accessibility.css +325 -0
- package/dist/templates/skybound/src/shared/game-controls.ts +406 -0
- package/dist/templates/skybound/src/shared/game-descriptions.ts +143 -0
- package/dist/templates/skybound/src/shared/playback.ts +146 -0
- package/dist/templates/skybound/src/worker.ts +1 -1
- package/dist/templates/terrain-flyover/README.md +5 -1
- package/dist/templates/terrain-flyover/index.html +4 -1
- package/dist/templates/terrain-flyover/src/main.ts +40 -39
- package/dist/templates/top-down-arena/index.html +6 -1
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +219 -17
- package/dist/templates/top-down-arena/src/audio.ts +26 -4
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +217 -15
- package/dist/templates/top-down-arena/src/main.ts +31 -5
- package/dist/templates/top-down-arena/src/shared/accessibility.css +325 -0
- package/dist/templates/top-down-arena/src/shared/playback.ts +146 -0
- package/dist/templates/top-down-arena/src/worker.ts +1 -1
- package/package.json +12 -12
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { describeGame, type GameKind, type GameReader } from './game-descriptions';
|
|
2
|
+
import { createPlayback, type PlaybackClient, type PlaybackInput } from './playback';
|
|
3
|
+
import './accessibility.css';
|
|
4
|
+
|
|
5
|
+
type Payload = { dir: number[] } | { held: boolean } | { yaw: number };
|
|
6
|
+
type Command = [type: string, payload?: Payload];
|
|
7
|
+
interface GameClient extends PlaybackClient, GameReader {
|
|
8
|
+
command(type: string, payload?: Payload): void;
|
|
9
|
+
onEvent(type: string, callback: (event: { type: string }) => void): () => void;
|
|
10
|
+
}
|
|
11
|
+
interface Action {
|
|
12
|
+
label: string;
|
|
13
|
+
commands: Command[];
|
|
14
|
+
ticks: number;
|
|
15
|
+
}
|
|
16
|
+
const cmd = (type: string, payload?: Payload): Command => [type, payload];
|
|
17
|
+
export function gameActions(kind: GameKind): Action[] {
|
|
18
|
+
if (kind === 'skybound')
|
|
19
|
+
return [
|
|
20
|
+
{ label: 'Step east', commands: [cmd('move', { dir: [1, 0] })], ticks: 6 },
|
|
21
|
+
{ label: 'Step west', commands: [cmd('move', { dir: [-1, 0] })], ticks: 6 },
|
|
22
|
+
{
|
|
23
|
+
label: 'Jump east',
|
|
24
|
+
commands: [cmd('move', { dir: [1, 0] }), cmd('jump', { held: true })],
|
|
25
|
+
ticks: 24,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Jump west',
|
|
29
|
+
commands: [cmd('move', { dir: [-1, 0] }), cmd('jump', { held: true })],
|
|
30
|
+
ticks: 24,
|
|
31
|
+
},
|
|
32
|
+
{ label: 'Jump straight up', commands: [cmd('jump', { held: true })], ticks: 24 },
|
|
33
|
+
{ label: 'Wait briefly', commands: [], ticks: 6 },
|
|
34
|
+
];
|
|
35
|
+
if (kind === 'courier')
|
|
36
|
+
return [
|
|
37
|
+
{ label: 'Accelerate', commands: [cmd('drive', { dir: [0, -1] })], ticks: 15 },
|
|
38
|
+
{ label: 'Accelerate and steer left', commands: [cmd('drive', { dir: [-1, -1] })], ticks: 6 },
|
|
39
|
+
{ label: 'Accelerate and steer right', commands: [cmd('drive', { dir: [1, -1] })], ticks: 6 },
|
|
40
|
+
{ label: 'Steer left while coasting', commands: [cmd('drive', { dir: [-1, 0] })], ticks: 6 },
|
|
41
|
+
{ label: 'Steer right while coasting', commands: [cmd('drive', { dir: [1, 0] })], ticks: 6 },
|
|
42
|
+
{ label: 'Reverse', commands: [cmd('drive', { dir: [0, 1] })], ticks: 6 },
|
|
43
|
+
{ label: 'Brake', commands: [cmd('brake', { held: true })], ticks: 15 },
|
|
44
|
+
{ label: 'Coast briefly', commands: [], ticks: 6 },
|
|
45
|
+
];
|
|
46
|
+
return [
|
|
47
|
+
{ label: 'Walk forward', commands: [cmd('move', { dir: [0, -1] })], ticks: 6 },
|
|
48
|
+
{ label: 'Walk backward', commands: [cmd('move', { dir: [0, 1] })], ticks: 6 },
|
|
49
|
+
{ label: 'Step left', commands: [cmd('move', { dir: [-1, 0] })], ticks: 6 },
|
|
50
|
+
{ label: 'Step right', commands: [cmd('move', { dir: [1, 0] })], ticks: 6 },
|
|
51
|
+
{ label: 'Turn left 45 degrees', commands: [cmd('look', { yaw: -Math.PI / 4 })], ticks: 1 },
|
|
52
|
+
{ label: 'Turn right 45 degrees', commands: [cmd('look', { yaw: Math.PI / 4 })], ticks: 1 },
|
|
53
|
+
{ label: 'Strike', commands: [cmd('attack')], ticks: 13 },
|
|
54
|
+
{ label: 'Interact', commands: [cmd('interact')], ticks: 1 },
|
|
55
|
+
{ label: 'Drink potion', commands: [cmd('heal')], ticks: 1 },
|
|
56
|
+
{ label: 'Wait briefly', commands: [], ticks: 6 },
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
function neutral(kind: GameKind): Command[] {
|
|
60
|
+
return kind === 'courier'
|
|
61
|
+
? [cmd('drive', { dir: [0, 0] }), cmd('brake', { held: false })]
|
|
62
|
+
: kind === 'skybound'
|
|
63
|
+
? [cmd('move', { dir: [0, 0] }), cmd('jump', { held: false })]
|
|
64
|
+
: [cmd('move', { dir: [0, 0] }), cmd('turn', { dir: [0, 0] })];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createGameControls(options: {
|
|
68
|
+
kind: GameKind;
|
|
69
|
+
client: GameClient;
|
|
70
|
+
input?: PlaybackInput | undefined;
|
|
71
|
+
canvas: HTMLCanvasElement;
|
|
72
|
+
}): { restart(): void; dispose(): void } {
|
|
73
|
+
const { kind, client, input, canvas } = options;
|
|
74
|
+
const main = canvas.parentElement as HTMLElement;
|
|
75
|
+
const toolbar = document.createElement('nav');
|
|
76
|
+
toolbar.className = 'access-toolbar';
|
|
77
|
+
toolbar.setAttribute('aria-label', 'Game options');
|
|
78
|
+
main.append(toolbar);
|
|
79
|
+
const header = document.querySelector('.topbar');
|
|
80
|
+
const headerObserver = new ResizeObserver(() => {
|
|
81
|
+
main.style.setProperty(
|
|
82
|
+
'--game-header-height',
|
|
83
|
+
`${header?.getBoundingClientRect().height ?? 0}px`,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
if (header) headerObserver.observe(header);
|
|
87
|
+
const playback = createPlayback({ client, input, canvas, container: toolbar });
|
|
88
|
+
const button = (name: string, parent: HTMLElement, action: () => void): HTMLButtonElement => {
|
|
89
|
+
const b = document.createElement('button');
|
|
90
|
+
b.type = 'button';
|
|
91
|
+
b.textContent = name;
|
|
92
|
+
b.addEventListener('click', action);
|
|
93
|
+
parent.append(b);
|
|
94
|
+
return b;
|
|
95
|
+
};
|
|
96
|
+
let textMode = false;
|
|
97
|
+
let busy = false;
|
|
98
|
+
let disposed = false;
|
|
99
|
+
const panel = document.createElement('section');
|
|
100
|
+
panel.id = 'text-play';
|
|
101
|
+
panel.className = 'text-play-panel';
|
|
102
|
+
panel.hidden = true;
|
|
103
|
+
panel.setAttribute('aria-labelledby', 'text-play-title');
|
|
104
|
+
panel.innerHTML =
|
|
105
|
+
'<h1 id="text-play-title" tabindex="-1">Text play</h1><p>The world waits while you read. Each action advances a short, fixed amount of game time, then pauses again. The same collisions, hazards, objectives and score apply. Coordinates use east and south as positive directions.</p><p id="text-summary" role="status" aria-atomic="true"></p><label class="fine-actions"><input id="fine-actions" type="checkbox" /> Precise actions: 2 ticks per action</label><div class="text-actions" role="group" aria-label="Game actions"></div><h2>Surroundings and objectives</h2><ul id="text-surroundings"></ul>';
|
|
106
|
+
(panel.querySelector('h1') as HTMLElement).textContent =
|
|
107
|
+
`${kind === 'courier' ? 'City Courier' : kind === 'skybound' ? 'Skybound' : 'The Lantern Vault'} — Text play`;
|
|
108
|
+
main.append(panel);
|
|
109
|
+
const live = document.createElement('p');
|
|
110
|
+
live.className = 'access-sr-only';
|
|
111
|
+
live.setAttribute('role', 'status');
|
|
112
|
+
live.setAttribute('aria-atomic', 'true');
|
|
113
|
+
main.append(live);
|
|
114
|
+
const summary = panel.querySelector('#text-summary') as HTMLElement;
|
|
115
|
+
const surroundings = panel.querySelector('ul') as HTMLElement;
|
|
116
|
+
function describe(): void {
|
|
117
|
+
canvas.dataset.tick = String(client.tick);
|
|
118
|
+
const description = describeGame(kind, client, true);
|
|
119
|
+
summary.textContent = description.summary;
|
|
120
|
+
surroundings.replaceChildren(
|
|
121
|
+
...description.surroundings.map((text) => {
|
|
122
|
+
const li = document.createElement('li');
|
|
123
|
+
li.textContent = text;
|
|
124
|
+
return li;
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const textToggle = button('Text play', toolbar, () => {
|
|
129
|
+
if (busy) return;
|
|
130
|
+
textMode = !textMode;
|
|
131
|
+
playback.setPaused(true);
|
|
132
|
+
playback.setVisible(!textMode);
|
|
133
|
+
playback.button.hidden = textMode;
|
|
134
|
+
touchToggle.hidden = textMode;
|
|
135
|
+
panel.hidden = !textMode;
|
|
136
|
+
document.body.classList.toggle('text-play', textMode);
|
|
137
|
+
canvas.setAttribute('aria-hidden', String(textMode));
|
|
138
|
+
canvas.tabIndex = textMode ? -1 : 0;
|
|
139
|
+
textToggle.textContent = textMode ? 'Return to visual play' : 'Text play';
|
|
140
|
+
textToggle.setAttribute('aria-expanded', String(textMode));
|
|
141
|
+
if (textMode) {
|
|
142
|
+
if (document.pointerLockElement === canvas) document.exitPointerLock();
|
|
143
|
+
describe();
|
|
144
|
+
(panel.querySelector('h1') as HTMLElement).focus();
|
|
145
|
+
} else {
|
|
146
|
+
textToggle.focus();
|
|
147
|
+
live.textContent = 'Visual play is paused. Choose Resume animation to continue.';
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
textToggle.setAttribute('aria-controls', panel.id);
|
|
151
|
+
textToggle.setAttribute('aria-expanded', 'false');
|
|
152
|
+
const touch = document.createElement('fieldset');
|
|
153
|
+
touch.className = 'touch-controls';
|
|
154
|
+
touch.id = 'touch-controls';
|
|
155
|
+
touch.innerHTML = '<legend>Hold to move; combine buttons to move and act</legend>';
|
|
156
|
+
main.append(touch);
|
|
157
|
+
let showTouch = matchMedia('(any-pointer: coarse)').matches;
|
|
158
|
+
touch.hidden = !showTouch;
|
|
159
|
+
const touchToggle = button('Touch controls', toolbar, () => {
|
|
160
|
+
showTouch = !showTouch;
|
|
161
|
+
touch.hidden = !showTouch;
|
|
162
|
+
touchToggle.setAttribute('aria-expanded', String(showTouch));
|
|
163
|
+
clearTouch();
|
|
164
|
+
});
|
|
165
|
+
touchToggle.setAttribute('aria-controls', touch.id);
|
|
166
|
+
touchToggle.setAttribute('aria-expanded', String(showTouch));
|
|
167
|
+
const cleanups: Array<() => void> = [];
|
|
168
|
+
const resets: Array<() => void> = [];
|
|
169
|
+
function clearTouch(): void {
|
|
170
|
+
for (const reset of resets) reset();
|
|
171
|
+
}
|
|
172
|
+
const keys: [string, string][] =
|
|
173
|
+
kind === 'skybound'
|
|
174
|
+
? [
|
|
175
|
+
['West', 'left'],
|
|
176
|
+
['East', 'right'],
|
|
177
|
+
['Jump', 'jump'],
|
|
178
|
+
]
|
|
179
|
+
: kind === 'courier'
|
|
180
|
+
? [
|
|
181
|
+
['Left', 'left'],
|
|
182
|
+
['Forward', 'up'],
|
|
183
|
+
['Right', 'right'],
|
|
184
|
+
['Reverse', 'down'],
|
|
185
|
+
['Brake', 'brake'],
|
|
186
|
+
]
|
|
187
|
+
: [
|
|
188
|
+
['Left', 'left'],
|
|
189
|
+
['Forward', 'up'],
|
|
190
|
+
['Right', 'right'],
|
|
191
|
+
['Back', 'down'],
|
|
192
|
+
['Turn left', 'turnLeft'],
|
|
193
|
+
['Turn right', 'turnRight'],
|
|
194
|
+
['Strike', 'attack'],
|
|
195
|
+
['Interact', 'interact'],
|
|
196
|
+
['Potion', 'heal'],
|
|
197
|
+
];
|
|
198
|
+
for (const [label, action] of keys) {
|
|
199
|
+
const b = button(label, touch, () => {});
|
|
200
|
+
b.dataset.action = action;
|
|
201
|
+
const source = `touch-${action}`;
|
|
202
|
+
let pointer: number | undefined;
|
|
203
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
204
|
+
const reset = (): void => {
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
timer = undefined;
|
|
207
|
+
const captured = pointer;
|
|
208
|
+
pointer = undefined;
|
|
209
|
+
if (captured !== undefined && b.hasPointerCapture(captured))
|
|
210
|
+
b.releasePointerCapture(captured);
|
|
211
|
+
input?.clearVirtual(source);
|
|
212
|
+
b.removeAttribute('data-held');
|
|
213
|
+
};
|
|
214
|
+
resets.push(reset);
|
|
215
|
+
b.addEventListener('pointerdown', (event) => {
|
|
216
|
+
if (playback.paused || pointer !== undefined || event.button !== 0) return;
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
canvas.focus({ preventScroll: true });
|
|
219
|
+
pointer = event.pointerId;
|
|
220
|
+
b.setPointerCapture(pointer);
|
|
221
|
+
input?.setVirtual(source, action, 1);
|
|
222
|
+
b.dataset.held = 'true';
|
|
223
|
+
});
|
|
224
|
+
for (const type of ['pointerup', 'pointercancel', 'lostpointercapture'])
|
|
225
|
+
b.addEventListener(type, (event) => {
|
|
226
|
+
if ((event as PointerEvent).pointerId === pointer) reset();
|
|
227
|
+
});
|
|
228
|
+
// Keyboard and assistive activation have no pointer sequence. A click is a short press.
|
|
229
|
+
b.addEventListener('click', (event) => {
|
|
230
|
+
if (event.detail !== 0 || playback.paused) return;
|
|
231
|
+
reset();
|
|
232
|
+
input?.setVirtual(source, action, 1);
|
|
233
|
+
timer = setTimeout(reset, 180);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
window.addEventListener('blur', clearTouch);
|
|
237
|
+
const hidden = (): void => {
|
|
238
|
+
if (document.hidden) clearTouch();
|
|
239
|
+
};
|
|
240
|
+
document.addEventListener('visibilitychange', hidden);
|
|
241
|
+
cleanups.push(
|
|
242
|
+
playback.onChange(() => {
|
|
243
|
+
clearTouch();
|
|
244
|
+
touch.disabled = playback.paused;
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
touch.disabled = playback.paused;
|
|
248
|
+
function send(commands: Command[]): void {
|
|
249
|
+
for (const [type, payload] of commands) client.command(type, payload);
|
|
250
|
+
}
|
|
251
|
+
async function advance(ticks: number): Promise<void> {
|
|
252
|
+
const start = client.tick;
|
|
253
|
+
if (start === undefined) throw new Error('The world is still loading. Try again shortly.');
|
|
254
|
+
client.control({ action: 'step', ticks });
|
|
255
|
+
const deadline = performance.now() + 10000;
|
|
256
|
+
while (!disposed && (client.tick ?? 0) < start + ticks) {
|
|
257
|
+
if (performance.now() > deadline)
|
|
258
|
+
throw new Error('The game did not respond. Reload to reconnect.');
|
|
259
|
+
await new Promise((resolve) => setTimeout(resolve, 16));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const fine = panel.querySelector('#fine-actions') as HTMLInputElement;
|
|
263
|
+
const actions = panel.querySelector('.text-actions') as HTMLElement;
|
|
264
|
+
async function take(action: Action): Promise<void> {
|
|
265
|
+
if (busy || !textMode || disposed) return;
|
|
266
|
+
busy = true;
|
|
267
|
+
actions.setAttribute('aria-busy', 'true');
|
|
268
|
+
for (const b of actions.querySelectorAll('button')) b.setAttribute('aria-disabled', 'true');
|
|
269
|
+
try {
|
|
270
|
+
send(neutral(kind));
|
|
271
|
+
send(action.commands);
|
|
272
|
+
await advance(fine.checked ? 1 : action.ticks);
|
|
273
|
+
if (disposed) return;
|
|
274
|
+
send(neutral(kind));
|
|
275
|
+
await advance(1);
|
|
276
|
+
if (!disposed) describe();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
summary.textContent = error instanceof Error ? error.message : String(error);
|
|
279
|
+
} finally {
|
|
280
|
+
busy = false;
|
|
281
|
+
actions.removeAttribute('aria-busy');
|
|
282
|
+
for (const b of actions.querySelectorAll('button')) b.removeAttribute('aria-disabled');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (const action of gameActions(kind)) button(action.label, actions, () => void take(action));
|
|
286
|
+
button('Describe surroundings', actions, () => {
|
|
287
|
+
if (!busy) describe();
|
|
288
|
+
});
|
|
289
|
+
button(
|
|
290
|
+
'Restart game',
|
|
291
|
+
actions,
|
|
292
|
+
() => void take({ label: 'Restart', commands: [cmd('restart')], ticks: 1 }),
|
|
293
|
+
);
|
|
294
|
+
if (kind === 'dungeon') {
|
|
295
|
+
const faceHeading = (desired: number): void => {
|
|
296
|
+
const rot = client.get('player', 'transform')?.rot as number[] | undefined;
|
|
297
|
+
if (!rot) return;
|
|
298
|
+
const yaw = 2 * Math.atan2(rot[1] ?? 0, rot[3] ?? 1);
|
|
299
|
+
const delta = -Math.atan2(Math.sin(desired - yaw), Math.cos(desired - yaw));
|
|
300
|
+
const count = Math.max(1, Math.ceil(Math.abs(delta)));
|
|
301
|
+
void take({
|
|
302
|
+
label: 'Face target',
|
|
303
|
+
ticks: 1,
|
|
304
|
+
commands: Array.from({ length: count }, () => cmd('look', { yaw: delta / count })),
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
const face = (id: string): void => {
|
|
308
|
+
const target = client.get(id, 'transform')?.pos as number[] | undefined;
|
|
309
|
+
const position = client.get('player', 'transform')?.pos as number[] | undefined;
|
|
310
|
+
if (!target || !position) return;
|
|
311
|
+
faceHeading(
|
|
312
|
+
Math.atan2(-(target[0] ?? 0) + (position[0] ?? 0), -(target[2] ?? 0) + (position[2] ?? 0)),
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
const directionLabel = document.createElement('label');
|
|
316
|
+
directionLabel.className = 'face-direction';
|
|
317
|
+
directionLabel.textContent = 'Compass direction ';
|
|
318
|
+
const direction = document.createElement('select');
|
|
319
|
+
for (const [name, value] of [
|
|
320
|
+
['North', 0],
|
|
321
|
+
['East', -Math.PI / 2],
|
|
322
|
+
['South', Math.PI],
|
|
323
|
+
['West', Math.PI / 2],
|
|
324
|
+
] as const) {
|
|
325
|
+
const option = document.createElement('option');
|
|
326
|
+
option.value = String(value);
|
|
327
|
+
option.textContent = name;
|
|
328
|
+
direction.append(option);
|
|
329
|
+
}
|
|
330
|
+
directionLabel.append(direction);
|
|
331
|
+
actions.append(directionLabel);
|
|
332
|
+
button('Face compass direction', actions, () => faceHeading(Number(direction.value)));
|
|
333
|
+
button('Face the key', actions, () => face('key'));
|
|
334
|
+
button('Face the north gate', actions, () => face('gate'));
|
|
335
|
+
button('Face nearest sentinel', actions, () => {
|
|
336
|
+
const p = client.get('player', 'transform')?.pos as number[] | undefined;
|
|
337
|
+
if (!p) return;
|
|
338
|
+
const enemies = client
|
|
339
|
+
.entities()
|
|
340
|
+
.filter((id) => client.get(id, 'sentinel')?.alive)
|
|
341
|
+
.map((id) => {
|
|
342
|
+
const q = client.get(id, 'transform')?.pos as number[] | undefined;
|
|
343
|
+
return {
|
|
344
|
+
id,
|
|
345
|
+
distance: q
|
|
346
|
+
? Math.hypot((q[0] ?? 0) - (p[0] ?? 0), (q[2] ?? 0) - (p[2] ?? 0))
|
|
347
|
+
: Infinity,
|
|
348
|
+
};
|
|
349
|
+
})
|
|
350
|
+
.sort((a, b) => a.distance - b.distance);
|
|
351
|
+
if (enemies[0]) face(enemies[0].id);
|
|
352
|
+
else summary.textContent = 'No sentinels remain.';
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
// Significant events only: reading position every frame would drown out screen-reader controls.
|
|
356
|
+
let announce: ReturnType<typeof setTimeout> | undefined;
|
|
357
|
+
const off = client.onEvent('*', (event) => {
|
|
358
|
+
if (
|
|
359
|
+
![
|
|
360
|
+
'seed-collected',
|
|
361
|
+
'checkpoint',
|
|
362
|
+
'respawn',
|
|
363
|
+
'victory',
|
|
364
|
+
'delivery',
|
|
365
|
+
'crash',
|
|
366
|
+
'hurt',
|
|
367
|
+
'heal',
|
|
368
|
+
'strike',
|
|
369
|
+
'key-found',
|
|
370
|
+
'gate-opened',
|
|
371
|
+
].includes(event.type)
|
|
372
|
+
)
|
|
373
|
+
return;
|
|
374
|
+
clearTimeout(announce);
|
|
375
|
+
announce = setTimeout(() => {
|
|
376
|
+
if (!disposed && !textMode) live.textContent = describeGame(kind, client).summary;
|
|
377
|
+
}, 100);
|
|
378
|
+
});
|
|
379
|
+
const startText = new URLSearchParams(location.search).get('text') === '1';
|
|
380
|
+
if (startText) textToggle.click();
|
|
381
|
+
return {
|
|
382
|
+
restart(): void {
|
|
383
|
+
client.command('restart');
|
|
384
|
+
if (playback.paused) {
|
|
385
|
+
client.control({ action: 'step', ticks: 1 });
|
|
386
|
+
setTimeout(playback.draw, 50);
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
dispose(): void {
|
|
390
|
+
disposed = true;
|
|
391
|
+
clearTimeout(announce);
|
|
392
|
+
off();
|
|
393
|
+
clearTouch();
|
|
394
|
+
for (const cleanup of cleanups) cleanup();
|
|
395
|
+
window.removeEventListener('blur', clearTouch);
|
|
396
|
+
document.removeEventListener('visibilitychange', hidden);
|
|
397
|
+
headerObserver.disconnect();
|
|
398
|
+
playback.dispose();
|
|
399
|
+
toolbar.remove();
|
|
400
|
+
panel.remove();
|
|
401
|
+
touch.remove();
|
|
402
|
+
live.remove();
|
|
403
|
+
document.body.classList.remove('text-play');
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export type GameKind = 'courier' | 'skybound' | 'dungeon';
|
|
2
|
+
export interface GameReader {
|
|
3
|
+
get(id: string, component: string): Record<string, unknown> | undefined;
|
|
4
|
+
entities(): string[];
|
|
5
|
+
}
|
|
6
|
+
export interface Description {
|
|
7
|
+
summary: string;
|
|
8
|
+
surroundings: string[];
|
|
9
|
+
}
|
|
10
|
+
const n = (v: unknown): number => Number(v ?? 0);
|
|
11
|
+
const point = (reader: GameReader, id: string): number[] =>
|
|
12
|
+
(reader.get(id, 'transform')?.pos as number[] | undefined) ?? [0, 0, 0];
|
|
13
|
+
const metres = (v: number): string => `${Math.abs(v).toFixed(1)} metres`;
|
|
14
|
+
function offset(from: number[], to: number[], side = false): string {
|
|
15
|
+
const x = (to[0] ?? 0) - (from[0] ?? 0);
|
|
16
|
+
const z = side ? (to[1] ?? 0) - (from[1] ?? 0) : (to[2] ?? 0) - (from[2] ?? 0);
|
|
17
|
+
return `${metres(x)} ${x >= 0 ? 'east' : 'west'}, ${metres(z)} ${side ? (z >= 0 ? 'above' : 'below') : z >= 0 ? 'south' : 'north'}`;
|
|
18
|
+
}
|
|
19
|
+
function heading(reader: GameReader): string {
|
|
20
|
+
const rot = reader.get('player', 'transform')?.rot as number[] | undefined;
|
|
21
|
+
const degrees =
|
|
22
|
+
((((-2 * Math.atan2(rot?.[1] ?? 0, rot?.[3] ?? 1) * 180) / Math.PI) % 360) + 360) % 360;
|
|
23
|
+
const compass = [
|
|
24
|
+
'north',
|
|
25
|
+
'northeast',
|
|
26
|
+
'east',
|
|
27
|
+
'southeast',
|
|
28
|
+
'south',
|
|
29
|
+
'southwest',
|
|
30
|
+
'west',
|
|
31
|
+
'northwest',
|
|
32
|
+
];
|
|
33
|
+
return `${compass[Math.round(degrees / 45) % 8]}, ${degrees.toFixed(0)} degrees clockwise from north`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Read the actual mirrored world, including dynamic enemies and collected/removed objects. */
|
|
37
|
+
export function describeGame(
|
|
38
|
+
kind: GameKind,
|
|
39
|
+
reader: GameReader,
|
|
40
|
+
textControls = false,
|
|
41
|
+
): Description {
|
|
42
|
+
const p = point(reader, 'player');
|
|
43
|
+
const component =
|
|
44
|
+
kind === 'courier' ? 'courierGame' : kind === 'skybound' ? 'skyGame' : 'dungeonGame';
|
|
45
|
+
const game = reader.get('game', component);
|
|
46
|
+
if (!game) return { summary: 'Loading the world.', surroundings: [] };
|
|
47
|
+
const message = textControls
|
|
48
|
+
? String(game.message)
|
|
49
|
+
.replace(/\bPress R[^.]*\./gi, 'Choose Restart game to begin again.')
|
|
50
|
+
.replace(/\bpress E\b/gi, 'choose Interact')
|
|
51
|
+
.replace(
|
|
52
|
+
'Space to attack. H drinks your potion.',
|
|
53
|
+
'Choose Strike to attack. Choose Drink potion to heal.',
|
|
54
|
+
)
|
|
55
|
+
: String(game.message);
|
|
56
|
+
const location = `Position: east ${p[0]?.toFixed(1)}, south ${p[2]?.toFixed(1)} metres.`;
|
|
57
|
+
if (kind === 'courier') {
|
|
58
|
+
const surroundings = [
|
|
59
|
+
`Roads run north–south at east −24, 0 and 24 metres, and east–west at south −24, 0 and 24 metres. Stay within about 3 metres of a road centre. Steer while accelerating; steering alone does not turn a stationary car.`,
|
|
60
|
+
];
|
|
61
|
+
if (game.status !== 'won')
|
|
62
|
+
surroundings.push(
|
|
63
|
+
`Next delivery beacon: ${offset(p, point(reader, 'beacon'))}. Drive within 3 metres to deliver.`,
|
|
64
|
+
);
|
|
65
|
+
const obstacles = reader
|
|
66
|
+
.entities()
|
|
67
|
+
.filter((id) => id !== 'player' && reader.get(id, 'collider'))
|
|
68
|
+
.map((id) => ({ id, pos: point(reader, id) }))
|
|
69
|
+
.filter((o) => Math.hypot((o.pos[0] ?? 0) - (p[0] ?? 0), (o.pos[2] ?? 0) - (p[2] ?? 0)) < 12)
|
|
70
|
+
.sort(
|
|
71
|
+
(a, b) =>
|
|
72
|
+
Math.hypot((a.pos[0] ?? 0) - (p[0] ?? 0), (a.pos[2] ?? 0) - (p[2] ?? 0)) -
|
|
73
|
+
Math.hypot((b.pos[0] ?? 0) - (p[0] ?? 0), (b.pos[2] ?? 0) - (p[2] ?? 0)),
|
|
74
|
+
);
|
|
75
|
+
for (const o of obstacles.slice(0, 6))
|
|
76
|
+
surroundings.push(`Obstacle ${o.id.replaceAll('-', ' ')}: ${offset(p, o.pos)}.`);
|
|
77
|
+
return {
|
|
78
|
+
summary: `${game.status}. ${message} ${location} Facing ${heading(reader)}. Speed ${n(game.speed).toFixed(1)} metres per second. ${game.delivered} of ${game.total} deliveries; condition ${game.health} percent; ${game.seconds} seconds of driving time left.`,
|
|
79
|
+
surroundings,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (kind === 'skybound') {
|
|
83
|
+
const body = reader.get('player', 'platformBody');
|
|
84
|
+
const velocity = body?.vel as number[] | undefined;
|
|
85
|
+
const surroundings: string[] = [];
|
|
86
|
+
for (const id of reader.entities()) {
|
|
87
|
+
const q = point(reader, id);
|
|
88
|
+
const solid = reader.get(id, 'platformSolid');
|
|
89
|
+
if (solid) {
|
|
90
|
+
const half = solid.halfExtents as number[];
|
|
91
|
+
const left = (q[0] ?? 0) - (half[0] ?? 0),
|
|
92
|
+
right = (q[0] ?? 0) + (half[0] ?? 0);
|
|
93
|
+
if (right < (p[0] ?? 0) - 10 || left > (p[0] ?? 0) + 15) continue;
|
|
94
|
+
surroundings.push(
|
|
95
|
+
`${solid.oneWay ? 'Raised ledge' : 'Island'} from east ${left.toFixed(1)} to ${right.toFixed(1)}, surface height ${((q[1] ?? 0) + (half[1] ?? 0)).toFixed(1)} metres. ${!solid.oneWay && (p[0] ?? 0) >= left && (p[0] ?? 0) <= right ? `Eastern edge ${metres(right - (p[0] ?? 0))} away; the space between islands is a gap.` : ''}`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (Math.abs((q[0] ?? 0) - (p[0] ?? 0)) > 12) continue;
|
|
99
|
+
if (reader.get(id, 'tag')?.name === 'hazard')
|
|
100
|
+
surroundings.push(`Thorns: ${offset(p, q, true)}. Jump over them.`);
|
|
101
|
+
if (reader.get(id, 'patrol')?.alive)
|
|
102
|
+
surroundings.push(
|
|
103
|
+
`Patrolling creature: ${offset(p, q, true)}. Jump over it or land on it while falling.`,
|
|
104
|
+
);
|
|
105
|
+
const seed = reader.get(id, 'seedPickup');
|
|
106
|
+
if (seed && !seed.collected) surroundings.push(`Seed: ${offset(p, q, true)}.`);
|
|
107
|
+
}
|
|
108
|
+
surroundings.push(
|
|
109
|
+
'Checkpoint at east 37 metres; lighthouse at east 75. Short steps travel up to 1.6 metres; long jumps travel up to 5.8 metres. Jump near an island edge to cross a gap.',
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
summary: `${game.status}. ${message} East ${p[0]?.toFixed(1)} metres, height ${p[1]?.toFixed(1)} metres. ${body?.grounded ? 'On ground' : n(velocity?.[1]) > 0 ? 'Rising' : 'Falling'}. ${game.lives} lives; ${game.coins} of ${game.total} seeds; checkpoint ${game.checkpoint ? 'saved' : 'not reached'}.`,
|
|
113
|
+
surroundings,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const surroundings = [
|
|
117
|
+
`Brass key ${game.key ? 'collected' : `at ${offset(p, point(reader, 'key'))}; walk within 1.2 metres to collect`}.`,
|
|
118
|
+
`North gate ${game.doorOpen ? 'open' : 'locked'}: ${offset(p, point(reader, 'gate'))}. Face it within 3 metres and interact after collecting the key.`,
|
|
119
|
+
`Lantern: ${offset(p, [0, 0, -12])}. Interact within 2.5 metres after opening the gate.`,
|
|
120
|
+
];
|
|
121
|
+
for (const id of reader.entities()) {
|
|
122
|
+
const q = point(reader, id);
|
|
123
|
+
const enemy = reader.get(id, 'sentinel');
|
|
124
|
+
if (enemy?.alive)
|
|
125
|
+
surroundings.push(
|
|
126
|
+
`Sentinel ${id.replaceAll('-', ' ')}: ${offset(p, q)}, ${enemy.hp} health. Face it within 2.6 metres to strike; a sentinel within 1.4 metres can attack.`,
|
|
127
|
+
);
|
|
128
|
+
const collider = reader.get(id, 'collider');
|
|
129
|
+
if (
|
|
130
|
+
collider?.isStatic &&
|
|
131
|
+
Math.hypot((q[0] ?? 0) - (p[0] ?? 0), (q[2] ?? 0) - (p[2] ?? 0)) < 5
|
|
132
|
+
) {
|
|
133
|
+
const half = collider.halfExtents as number[] | undefined;
|
|
134
|
+
surroundings.push(
|
|
135
|
+
`Wall or barrier ${id.replaceAll('-', ' ')}: ${offset(p, q)}${half ? `, ${n(half[0]) * 2} by ${n(half[1]) * 2} metres` : ''}.`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
summary: `${game.status}. ${message} ${location} Facing ${heading(reader)}. Vitality ${game.health}; ${game.potions} potion; ${game.kills} sentinels defeated.`,
|
|
141
|
+
surroundings,
|
|
142
|
+
};
|
|
143
|
+
}
|