@bendyline/molen-tooling 0.0.2 → 0.0.3

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.
Files changed (76) hide show
  1. package/dist/capture/harness.js +216 -216
  2. package/dist/capture/worldgen-preview.js +288 -288
  3. package/dist/cli.mjs +110 -10
  4. package/dist/docs-src/guide/3d-model-assets.md +35 -3
  5. package/dist/docs-src/guide/adaptive-performance.md +4 -0
  6. package/dist/docs-src/guide/agent-loop.md +6 -6
  7. package/dist/docs-src/guide/aircraft.md +16 -7
  8. package/dist/docs-src/guide/audio.md +247 -0
  9. package/dist/docs-src/guide/browser-mount.md +3 -1
  10. package/dist/docs-src/guide/building-interiors.md +5 -4
  11. package/dist/docs-src/guide/determinism.md +12 -12
  12. package/dist/docs-src/guide/earth-view.md +444 -0
  13. package/dist/docs-src/guide/entities.md +1 -1
  14. package/dist/docs-src/guide/examples.md +2 -1
  15. package/dist/docs-src/guide/game-samples.md +21 -4
  16. package/dist/docs-src/guide/graphics-performance.md +40 -8
  17. package/dist/docs-src/guide/input.md +9 -0
  18. package/dist/docs-src/guide/markers.md +52 -0
  19. package/dist/docs-src/guide/materials.md +10 -3
  20. package/dist/docs-src/guide/navigation.md +144 -0
  21. package/dist/docs-src/guide/project.md +1 -1
  22. package/dist/docs-src/guide/quickstart.md +2 -2
  23. package/dist/docs-src/guide/recognizable-places.md +3 -2
  24. package/dist/docs-src/guide/scripting.md +4 -2
  25. package/dist/docs-src/guide/sky.md +16 -0
  26. package/dist/docs-src/guide/source-bundles.md +0 -1
  27. package/dist/docs-src/guide/structure-library.md +2 -2
  28. package/dist/docs-src/guide/terrain.md +45 -2
  29. package/dist/docs-src/guide/vehicles.md +18 -9
  30. package/dist/docs-src/guide/worldgen.md +3 -3
  31. package/dist/docs-src/llms.txt +10 -4
  32. package/dist/docs-src/schemas/README.md +3 -0
  33. package/dist/docs-src/schemas/archive-set.md +175 -0
  34. package/dist/docs-src/schemas/components.md +1104 -1
  35. package/dist/docs-src/schemas/matgraph.md +6 -0
  36. package/dist/docs-src/schemas/soundbank.md +251 -0
  37. package/dist/docs-src/schemas/structure-placements.md +496 -0
  38. package/dist/docs-src/schemas/terrain-package.md +120 -0
  39. package/dist/index.d.mts +5 -1
  40. package/dist/index.mjs +1 -1
  41. package/dist/{mcp-AOfIp89b.mjs → mcp-BTVwVKFb.mjs} +67 -3
  42. package/dist/{ops-C4BvDgP-.mjs → ops-BPdHodFR.mjs} +915 -29
  43. package/dist/templates/city-courier/README.md +13 -0
  44. package/dist/templates/city-courier/delivery-run.replay.json +151 -151
  45. package/dist/templates/city-courier/gen/molen-types.ts +142 -4
  46. package/dist/templates/city-courier/package.json +1 -0
  47. package/dist/templates/city-courier/scene.json +79 -0
  48. package/dist/templates/city-courier/scripts/game.ts +5 -1
  49. package/dist/templates/city-courier/scripts/molen-scripts.d.ts +167 -4
  50. package/dist/templates/city-courier/src/audio.ts +96 -0
  51. package/dist/templates/city-courier/src/game-shell.css +8 -0
  52. package/dist/templates/city-courier/src/main.ts +3 -0
  53. package/dist/templates/city-courier/test/headless.test.ts +1 -1
  54. package/dist/templates/index.json +3 -0
  55. package/dist/templates/skybound/README.md +13 -0
  56. package/dist/templates/skybound/first-leap.replay.json +152 -152
  57. package/dist/templates/skybound/gen/molen-types.ts +142 -4
  58. package/dist/templates/skybound/package.json +1 -0
  59. package/dist/templates/skybound/scene.json +40 -0
  60. package/dist/templates/skybound/scripts/game.ts +8 -5
  61. package/dist/templates/skybound/scripts/molen-scripts.d.ts +167 -4
  62. package/dist/templates/skybound/src/audio.ts +96 -0
  63. package/dist/templates/skybound/src/game-shell.css +8 -0
  64. package/dist/templates/skybound/src/main.ts +3 -0
  65. package/dist/templates/skybound/test/headless.test.ts +1 -1
  66. package/dist/templates/top-down-arena/README.md +14 -1
  67. package/dist/templates/top-down-arena/arena-skirmish.replay.json +152 -152
  68. package/dist/templates/top-down-arena/package.json +1 -0
  69. package/dist/templates/top-down-arena/scene.json +20 -0
  70. package/dist/templates/top-down-arena/scripts/combat.ts +1 -0
  71. package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +167 -4
  72. package/dist/templates/top-down-arena/src/audio.ts +96 -0
  73. package/dist/templates/top-down-arena/src/gen/molen-types.ts +142 -4
  74. package/dist/templates/top-down-arena/src/main.ts +3 -0
  75. package/dist/templates/top-down-arena/test/headless.test.ts +1 -1
  76. package/package.json +11 -11
@@ -137,7 +137,7 @@ type MolenAircraftData = {
137
137
  nodes: string[];
138
138
  sources?: Record<string, {
139
139
  component: string;
140
- path: string | number[];
140
+ path: (string | number)[];
141
141
  }>;
142
142
  bindings: {
143
143
  node: string;
@@ -194,6 +194,138 @@ type MolenAircraftStateData = {
194
194
  crashed: boolean;
195
195
  waitingForTerrain: boolean;
196
196
  };
197
+ /** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
198
+ type MolenAudioEnvironmentData = {
199
+ buses?: Record<string, number>;
200
+ ambience?: {
201
+ sound: string;
202
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
203
+ min?: number;
204
+ max?: number;
205
+ } | {
206
+ exists: boolean;
207
+ }>;
208
+ gain?: number;
209
+ gainFrom?: {
210
+ signal: string;
211
+ curve: [number, number][];
212
+ smoothS?: number;
213
+ } | {
214
+ signal: string;
215
+ curve: [number, number][];
216
+ smoothS?: number;
217
+ }[];
218
+ pitchFrom?: {
219
+ signal: string;
220
+ curve: [number, number][];
221
+ smoothS?: number;
222
+ } | {
223
+ signal: string;
224
+ curve: [number, number][];
225
+ smoothS?: number;
226
+ }[];
227
+ fadeS?: number;
228
+ }[];
229
+ music?: {
230
+ playlist: string[];
231
+ mode?: 'sequence' | 'shuffle';
232
+ crossfadeS?: number;
233
+ gain?: number;
234
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
235
+ min?: number;
236
+ max?: number;
237
+ } | {
238
+ exists: boolean;
239
+ }>;
240
+ };
241
+ events?: Record<string, {
242
+ sound: string;
243
+ at?: string;
244
+ gain?: number;
245
+ pitch?: number;
246
+ bus?: string;
247
+ }>;
248
+ footsteps?: {
249
+ sound: string;
250
+ surfaces?: Record<string, string>;
251
+ strideM?: number;
252
+ gain?: number;
253
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
254
+ min?: number;
255
+ max?: number;
256
+ } | {
257
+ exists: boolean;
258
+ }>;
259
+ };
260
+ listenerEntity?: string;
261
+ maxVoices?: number;
262
+ };
263
+ /** Sound emitter on an entity: a sound-bank id, loop/autoplay, gain and pitch driven by signals (vehicleState.speed, listener.distance…), and one-shot triggers. Positional when the entity has a transform. Render-side only; see guide/audio.md. */
264
+ type MolenAudioSourceData = {
265
+ sound: string;
266
+ loop?: boolean;
267
+ autoplay?: boolean;
268
+ gain?: number;
269
+ pitch?: number;
270
+ bus?: string;
271
+ spatial?: false | {
272
+ refDistance?: number;
273
+ maxDistance?: number;
274
+ rolloff?: number;
275
+ model?: 'linear' | 'inverse' | 'exponential';
276
+ };
277
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
278
+ min?: number;
279
+ max?: number;
280
+ } | {
281
+ exists: boolean;
282
+ }>;
283
+ gainFrom?: {
284
+ signal: string;
285
+ curve: [number, number][];
286
+ smoothS?: number;
287
+ } | {
288
+ signal: string;
289
+ curve: [number, number][];
290
+ smoothS?: number;
291
+ }[];
292
+ pitchFrom?: {
293
+ signal: string;
294
+ curve: [number, number][];
295
+ smoothS?: number;
296
+ } | {
297
+ signal: string;
298
+ curve: [number, number][];
299
+ smoothS?: number;
300
+ }[];
301
+ triggerFrom?: {
302
+ signal: string;
303
+ every?: number;
304
+ onChange?: boolean;
305
+ sound?: string;
306
+ };
307
+ startTick?: number;
308
+ };
309
+ /** Area ambience: a looping sound that fades in as the listener enters a sphere or box around the entity (a waterfall, a machine room, a market). */
310
+ type MolenAudioZoneData = {
311
+ sound: string;
312
+ shape: {
313
+ kind: 'sphere';
314
+ radius: number;
315
+ } | {
316
+ kind: 'box';
317
+ halfExtents: [number, number, number];
318
+ };
319
+ fade?: number;
320
+ gain?: number;
321
+ bus?: string;
322
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
323
+ min?: number;
324
+ max?: number;
325
+ } | {
326
+ exists: boolean;
327
+ }>;
328
+ };
197
329
  /** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
198
330
  type MolenCharacterData = {
199
331
  speed: number;
@@ -515,7 +647,7 @@ type MolenLocalTransformData = {
515
647
  type MolenModel_signalsData = {
516
648
  sources: Record<string, {
517
649
  component: string;
518
- path: string | number[];
650
+ path: (string | number)[];
519
651
  }>;
520
652
  bindings: {
521
653
  node: string;
@@ -712,7 +844,7 @@ type MolenVehicleData = {
712
844
  nodes: string[];
713
845
  sources?: Record<string, {
714
846
  component: string;
715
- path: string | number[];
847
+ path: (string | number)[];
716
848
  }>;
717
849
  bindings: {
718
850
  node: string;
@@ -807,6 +939,12 @@ interface MolenComponentData {
807
939
  'aircraftInput': MolenAircraftInputData;
808
940
  /** Deterministic flight state, including rotor phase and engine spool, preserved by keyframes. */
809
941
  'aircraftState': MolenAircraftStateData;
942
+ /** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
943
+ 'audioEnvironment': MolenAudioEnvironmentData;
944
+ /** Sound emitter on an entity: a sound-bank id, loop/autoplay, gain and pitch driven by signals (vehicleState.speed, listener.distance…), and one-shot triggers. Positional when the entity has a transform. Render-side only; see guide/audio.md. */
945
+ 'audioSource': MolenAudioSourceData;
946
+ /** Area ambience: a looping sound that fades in as the listener enters a sphere or box around the entity (a waterfall, a machine room, a market). */
947
+ 'audioZone': MolenAudioZoneData;
810
948
  /** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
811
949
  'character': MolenCharacterData;
812
950
  /** 2.5D kinematic collider (circle or XZ AABB) with layer/mask bitmasks. */
@@ -895,7 +1033,7 @@ type MolenComponentName = keyof MolenComponentData;
895
1033
  type MolenComponentPatch = { [K in MolenComponentName]?: MolenComponentData[K] };
896
1034
 
897
1035
  /** Entity ids declared in the scene. Ids of spawned entities are plain strings. */
898
- type MolenEntityId = 'camera-target' | 'checkpoint' | 'checkpoint-flag' | 'cloud0' | 'cloud1' | 'cloud10' | 'cloud2' | 'cloud3' | 'cloud4' | 'cloud5' | 'cloud6' | 'cloud7' | 'cloud8' | 'cloud9' | 'critter0' | 'critter1' | 'environment' | 'game' | 'grass0' | 'grass1' | 'grass2' | 'grass3' | 'grass4' | 'hazard0' | 'hazard3' | 'hero-eye' | 'hero-hat' | 'hero-head' | 'hero-pack' | 'hill0' | 'hill1' | 'hill10' | 'hill2' | 'hill3' | 'hill4' | 'hill5' | 'hill6' | 'hill7' | 'hill8' | 'hill9' | 'island0' | 'island1' | 'island2' | 'island3' | 'island4' | 'lamp' | 'ledge0' | 'ledge1' | 'ledge2' | 'ledge3' | 'ledge4' | 'ledge5' | 'lighthouse' | 'lighthouse-top' | 'player' | 'root0--3' | 'root0--6' | 'root0-0' | 'root0-3' | 'root0-6' | 'root1-12' | 'root1-15' | 'root1-18' | 'root1-21' | 'root2-26' | 'root2-29' | 'root2-32' | 'root2-35' | 'root2-38' | 'root3-44' | 'root3-47' | 'root3-50' | 'root3-53' | 'root3-56' | 'root4-61' | 'root4-64' | 'root4-67' | 'root4-70' | 'root4-73' | 'root4-76' | 'root4-79' | 'seed0' | 'seed1' | 'seed10' | 'seed11' | 'seed12' | 'seed13' | 'seed14' | 'seed2' | 'seed3' | 'seed4' | 'seed5' | 'seed6' | 'seed7' | 'seed8' | 'seed9' | (string & {});
1036
+ type MolenEntityId = 'audio' | 'camera-target' | 'checkpoint' | 'checkpoint-flag' | 'cloud0' | 'cloud1' | 'cloud10' | 'cloud2' | 'cloud3' | 'cloud4' | 'cloud5' | 'cloud6' | 'cloud7' | 'cloud8' | 'cloud9' | 'critter0' | 'critter1' | 'environment' | 'game' | 'grass0' | 'grass1' | 'grass2' | 'grass3' | 'grass4' | 'hazard0' | 'hazard3' | 'hero-eye' | 'hero-hat' | 'hero-head' | 'hero-pack' | 'hill0' | 'hill1' | 'hill10' | 'hill2' | 'hill3' | 'hill4' | 'hill5' | 'hill6' | 'hill7' | 'hill8' | 'hill9' | 'island0' | 'island1' | 'island2' | 'island3' | 'island4' | 'lamp' | 'ledge0' | 'ledge1' | 'ledge2' | 'ledge3' | 'ledge4' | 'ledge5' | 'lighthouse' | 'lighthouse-top' | 'player' | 'root0--3' | 'root0--6' | 'root0-0' | 'root0-3' | 'root0-6' | 'root1-12' | 'root1-15' | 'root1-18' | 'root1-21' | 'root2-26' | 'root2-29' | 'root2-32' | 'root2-35' | 'root2-38' | 'root3-44' | 'root3-47' | 'root3-50' | 'root3-53' | 'root3-56' | 'root4-61' | 'root4-64' | 'root4-67' | 'root4-70' | 'root4-73' | 'root4-76' | 'root4-79' | 'seed0' | 'seed1' | 'seed10' | 'seed11' | 'seed12' | 'seed13' | 'seed14' | 'seed2' | 'seed3' | 'seed4' | 'seed5' | 'seed6' | 'seed7' | 'seed8' | 'seed9' | (string & {});
899
1037
  /** Prefab names declared in the scene. */
900
1038
  type MolenPrefabName = 'box' | 'cylinder' | 'seed' | 'sphere' | (string & {});
901
1039
  /** Registry type ids this project declares (`molen.spawnType`). */
@@ -1028,6 +1166,29 @@ interface MolenMath {
1028
1166
  cbrt(...args: number[]): number;
1029
1167
  }
1030
1168
 
1169
+ /** Options for `molen.audio.play`. Omit entity and position for a non-positional sound. */
1170
+ interface MolenAudioPlayOptions {
1171
+ /** Play at (and follow) this entity's transform. */
1172
+ entity?: MolenEntityId;
1173
+ /** Play at a fixed world position. */
1174
+ position?: MolenVec3;
1175
+ gain?: number;
1176
+ pitch?: number;
1177
+ bus?: string;
1178
+ /** Loop until stopped; default the sound's own loop flag. */
1179
+ loop?: boolean;
1180
+ }
1181
+
1182
+ /** `molen.audio`: each call emits an `audio.*` event the client plays (guide/audio.md). */
1183
+ interface MolenAudioApi {
1184
+ /** Play a sound-bank id; returns a handle for `stop`. */
1185
+ play(sound: string, opts?: MolenAudioPlayOptions): string;
1186
+ /** Stop by handle, or every voice matching an entity and/or sound. */
1187
+ stop(target: string | { entity?: MolenEntityId; sound?: string }, fadeS?: number): void;
1188
+ /** Switch background music to a track or playlist; null stops it. */
1189
+ music(playlist: string | string[] | null, opts?: { crossfadeS?: number }): void;
1190
+ }
1191
+
1031
1192
  /** The verb set injected into every scene-data script as `molen`. */
1032
1193
  interface MolenApi {
1033
1194
  /** Spawn from a component map. */
@@ -1084,6 +1245,8 @@ interface MolenApi {
1084
1245
  handler: (payload: MolenCommands[T], ctx: MolenTickContext, command: MolenCommand) => void,
1085
1246
  ): MolenUnsubscribe;
1086
1247
  emit(type: string, payload?: MolenJsonValue): void;
1248
+ /** Sound: play/stop one-shots and loops, switch music. Never affects the simulation. */
1249
+ readonly audio: MolenAudioApi;
1087
1250
  raycast(origin: MolenVec3, dir: MolenVec3, maxDist: number, mask?: number): MolenRayHit | null;
1088
1251
  overlapCircle(center: MolenVec3, radius: number, mask?: number): string[];
1089
1252
  /** Emit `event` after `ticks` ticks (snapshot-safe world timer). Returns the timer id. */
@@ -0,0 +1,96 @@
1
+ import type { MolenClient } from '@bendyline/molen-client';
2
+ import {
3
+ attachAutoplayUnlock,
4
+ createAudioLayer,
5
+ loadPackSoundbanks,
6
+ } from '@bendyline/molen-client/audio';
7
+ import { createPackSet, openPack, type PackIndex } from '@bendyline/molen-pack';
8
+
9
+ // Sound for this sample. The rules live in scene.json (the `audioEnvironment` entity and the
10
+ // `audioSource` components) and in the scripts (`molen.audio.play`); this file only loads the
11
+ // `molen.sounds` content pack and plays what the rules ask for. Without the pack the game is
12
+ // silent: fetch it with `npx molen pack fetch https://molen.dev/packs/index.json molen.sounds
13
+ // --out-dir public/packs`.
14
+
15
+ const SOUND_PACK = 'molen.sounds';
16
+ const MUTED_KEY = 'molen.samples.muted';
17
+
18
+ /** This app's packs/index.json first, then the site-wide one (molen.dev hosts it at /packs/). */
19
+ async function openSoundPack() {
20
+ const candidates = [new URL(`${import.meta.env.BASE_URL}packs/index.json`, location.href)];
21
+ const site = new URL('/packs/index.json', location.href);
22
+ if (site.href !== candidates[0]?.href) candidates.push(site);
23
+ for (const indexUrl of candidates) {
24
+ const response = await fetch(indexUrl).catch(() => undefined);
25
+ if (!response?.ok) continue;
26
+ const index = (await response.json().catch(() => undefined)) as PackIndex | undefined;
27
+ const entry = index?.packs?.[SOUND_PACK];
28
+ if (!entry) continue;
29
+ return openPack(new URL(entry.file, indexUrl).href, {
30
+ sizeHint: entry.size,
31
+ expect: { contentHash: entry.contentHash },
32
+ });
33
+ }
34
+ return undefined;
35
+ }
36
+
37
+ function readMuted(): boolean {
38
+ try {
39
+ return localStorage.getItem(MUTED_KEY) === '1';
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ /** Start the sample's audio; resolves to a stop function (a no-op when there is no sound pack). */
46
+ export async function startAudio(client: MolenClient, tickRate: number): Promise<() => void> {
47
+ const pack = await openSoundPack().catch((error: unknown) => {
48
+ console.warn('audio unavailable', error);
49
+ return undefined;
50
+ });
51
+ if (!pack) return () => {};
52
+ const packs = createPackSet([pack]);
53
+ const layer = createAudioLayer({
54
+ banks: await loadPackSoundbanks(packs),
55
+ provider: packs.assetProvider(),
56
+ renderer: client.renderer,
57
+ muted: readMuted(),
58
+ onWarning: (message) => console.warn(`audio: ${message}`),
59
+ });
60
+ const detachClient = layer.attachClient(client, { tickRate });
61
+ const detachUnlock = attachAutoplayUnlock(layer);
62
+
63
+ const toggle = document.createElement('button');
64
+ toggle.type = 'button';
65
+ toggle.className = 'sound-toggle';
66
+ toggle.textContent = 'Sound';
67
+ toggle.setAttribute('aria-pressed', String(!layer.muted));
68
+ toggle.addEventListener('click', () => {
69
+ layer.setMuted(!layer.muted);
70
+ toggle.setAttribute('aria-pressed', String(!layer.muted));
71
+ try {
72
+ localStorage.setItem(MUTED_KEY, layer.muted ? '1' : '0');
73
+ } catch {
74
+ // Storage can be unavailable (private windows); the choice just is not remembered.
75
+ }
76
+ });
77
+ const shell = document.getElementById('interface');
78
+ if (shell) shell.append(toggle);
79
+ else {
80
+ // Pages without the shared game shell get a plain corner button.
81
+ toggle.style.cssText = 'position:fixed;right:12px;bottom:10px;font:13px system-ui';
82
+ document.body.append(toggle);
83
+ }
84
+
85
+ let frame = requestAnimationFrame(function loop(now) {
86
+ layer.update(now);
87
+ frame = requestAnimationFrame(loop);
88
+ });
89
+ return () => {
90
+ cancelAnimationFrame(frame);
91
+ toggle.remove();
92
+ detachUnlock();
93
+ detachClient();
94
+ layer.dispose();
95
+ };
96
+ }
@@ -307,3 +307,11 @@ body[data-game="skybound"] h1 {
307
307
  font-size: 29px;
308
308
  }
309
309
  }
310
+ .sound-toggle {
311
+ position: absolute;
312
+ right: 34px;
313
+ bottom: 28px;
314
+ }
315
+ .sound-toggle[aria-pressed="false"] {
316
+ opacity: 0.6;
317
+ }
@@ -1,4 +1,5 @@
1
1
  import { mountExperience } from '@bendyline/molen-client';
2
+ import { startAudio } from './audio';
2
3
  import { scene } from './scene';
3
4
  import './game-shell.css';
4
5
 
@@ -10,6 +11,7 @@ const canvas = document.getElementById('view') as HTMLCanvasElement;
10
11
  const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
11
12
  const mounted = await mountExperience({ link: worker, scene: scene(), canvas, antialias: true });
12
13
  const { client } = mounted;
14
+ const stopAudio = startAudio(client, scene().tickRate ?? 30);
13
15
  function element(id: string): HTMLElement {
14
16
  const node = document.getElementById(id);
15
17
  if (node === null) throw new Error(`Missing UI element: ${id}`);
@@ -53,6 +55,7 @@ const timer = setInterval(() => {
53
55
  }, 80);
54
56
  function dispose(): void {
55
57
  clearInterval(timer);
58
+ void stopAudio.then((stop) => stop());
56
59
  mounted.dispose();
57
60
  worker.terminate();
58
61
  }
@@ -38,7 +38,7 @@ describe('skybound: authored scene + scripts', () => {
38
38
  command(w, 'move', { dir: [1, 0] });
39
39
  w.stepN(90);
40
40
  expect(stateHash(w)).toBe(
41
- 'sha256:e0632b2ae9a5ba9d279e6706949f7adfa5295a5e54c63845f9cb00e7e94e2653',
41
+ 'sha256:cb40e56449dcc4916b0f80b3dd33fe2783f4105f87259f5d47f70642cb91c58e',
42
42
  );
43
43
  });
44
44
 
@@ -20,7 +20,7 @@ W/A/S/D: move. The scene folds the four keys into a single `axis2d` rule that em
20
20
 
21
21
  ## Authoring map
22
22
 
23
- - `scene.json`: `physics.engine: "kinematics"`, a `top-down-ortho` camera at `viewHeight` 26, the `move` command, the WASD `axis2d` rule, four script refs with their `config`, and five entities — the player plus four walls.
23
+ - `scene.json`: `physics.engine: "kinematics"`, a `top-down-ortho` camera at `viewHeight` 26, the `move` command, the WASD `axis2d` rule, four script refs with their `config`, and six entities — the player, four walls, and an `audio` entity whose `audioEnvironment` holds the sound rules.
24
24
  - `types/arena.types.json`: the `arena` namespace (`arena.wall`, `arena.player`, `arena.enemy`). Entities instantiate a `type` and override only what differs, and the spawner script spawns the same type by name. `project.json` binds the doc and points codegen at `src/gen/molen-types.ts`.
25
25
  - `scripts/control.ts`: `molen.onCommand('move', ...)` writes the player's `kinematicBody.vel`.
26
26
  - `scripts/spawner.ts`: one `arena.enemy` on a random edge every `config.interval` ticks, through `molen.rng`.
@@ -29,6 +29,19 @@ W/A/S/D: move. The scene folds the four keys into a single `axis2d` rule that em
29
29
  - `scripts/molen-scripts.d.ts` and `scripts/tsconfig.json` are generated by `molen types gen` — never hand-edit them.
30
30
  - `src/scene.ts`: inlines the script files so the Worker, Vitest and the CLI all build an identical manifest. `src/main.ts` adds a HUD from mirrored state only.
31
31
 
32
+ ## Sound
33
+
34
+ The `audio` entity's `audioEnvironment` plays arena music and maps the `player-hit` event, which `scripts/combat.ts` emits on contact, to a hit sound. `src/audio.ts` loads the CC0 `molen.sounds` content pack and plays the rules; without it the
35
+ game is silent. In your own copy, fetch the pack once:
36
+
37
+ ```sh
38
+ npx molen pack fetch https://molen.dev/packs/index.json molen.sounds --out-dir public/packs
39
+ npx molen audio plan scene.json --ticks 300
40
+ ```
41
+
42
+ `molen audio plan` lists the loops and one-shots the scene would play, without a browser. See
43
+ [Sound and music](https://molen.dev/guide/audio).
44
+
32
45
  ## Verify
33
46
 
34
47
  From this directory: