@bendyline/molen-tooling 0.0.2 → 0.0.4

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 (86) hide show
  1. package/README.md +4 -4
  2. package/dist/capture/harness.js +222 -222
  3. package/dist/capture/worldgen-preview.js +288 -288
  4. package/dist/cli.mjs +162 -10
  5. package/dist/docs-src/guide/3d-model-assets.md +35 -3
  6. package/dist/docs-src/guide/adaptive-performance.md +4 -0
  7. package/dist/docs-src/guide/agent-loop.md +6 -6
  8. package/dist/docs-src/guide/aircraft.md +28 -7
  9. package/dist/docs-src/guide/ambient-life.md +389 -0
  10. package/dist/docs-src/guide/audio.md +247 -0
  11. package/dist/docs-src/guide/browser-mount.md +8 -1
  12. package/dist/docs-src/guide/building-interiors.md +5 -4
  13. package/dist/docs-src/guide/capability-authoring.md +5 -0
  14. package/dist/docs-src/guide/determinism.md +35 -27
  15. package/dist/docs-src/guide/earth-view.md +492 -0
  16. package/dist/docs-src/guide/entities.md +9 -1
  17. package/dist/docs-src/guide/examples.md +6 -2
  18. package/dist/docs-src/guide/figures.md +3 -0
  19. package/dist/docs-src/guide/game-samples.md +22 -5
  20. package/dist/docs-src/guide/graphics-performance.md +40 -8
  21. package/dist/docs-src/guide/input.md +9 -0
  22. package/dist/docs-src/guide/markers.md +55 -0
  23. package/dist/docs-src/guide/materials.md +10 -3
  24. package/dist/docs-src/guide/navigation.md +150 -0
  25. package/dist/docs-src/guide/project.md +1 -1
  26. package/dist/docs-src/guide/quickstart.md +2 -2
  27. package/dist/docs-src/guide/recognizable-places.md +3 -2
  28. package/dist/docs-src/guide/scripting.md +4 -2
  29. package/dist/docs-src/guide/sky.md +16 -0
  30. package/dist/docs-src/guide/source-bundles.md +0 -1
  31. package/dist/docs-src/guide/structure-library.md +2 -2
  32. package/dist/docs-src/guide/surface-rendering.md +4 -3
  33. package/dist/docs-src/guide/terrain.md +52 -2
  34. package/dist/docs-src/guide/vehicles.md +32 -10
  35. package/dist/docs-src/guide/worldgen.md +3 -3
  36. package/dist/docs-src/llms.txt +14 -5
  37. package/dist/docs-src/schemas/README.md +4 -0
  38. package/dist/docs-src/schemas/archive-set.md +175 -0
  39. package/dist/docs-src/schemas/components.md +1634 -2
  40. package/dist/docs-src/schemas/matgraph.md +6 -0
  41. package/dist/docs-src/schemas/scene.md +105 -0
  42. package/dist/docs-src/schemas/soundbank.md +251 -0
  43. package/dist/docs-src/schemas/structure-placements.md +496 -0
  44. package/dist/docs-src/schemas/terrain-package.md +120 -0
  45. package/dist/docs-src/schemas/transport-network.md +351 -0
  46. package/dist/index.d.mts +49 -2
  47. package/dist/index.mjs +81 -4
  48. package/dist/{mcp-AOfIp89b.mjs → mcp-BtuworIW.mjs} +88 -3
  49. package/dist/{ops-C4BvDgP-.mjs → ops-DMGcWoL2.mjs} +1204 -93
  50. package/dist/templates/city-courier/README.md +14 -1
  51. package/dist/templates/city-courier/delivery-run.replay.json +151 -151
  52. package/dist/templates/city-courier/gen/molen-types.ts +223 -5
  53. package/dist/templates/city-courier/package.json +2 -0
  54. package/dist/templates/city-courier/scene.json +142 -246
  55. package/dist/templates/city-courier/scripts/game.ts +7 -15
  56. package/dist/templates/city-courier/scripts/molen-scripts.d.ts +252 -16
  57. package/dist/templates/city-courier/src/audio.ts +96 -0
  58. package/dist/templates/city-courier/src/game-shell.css +8 -0
  59. package/dist/templates/city-courier/src/main.ts +3 -0
  60. package/dist/templates/city-courier/src/worker.ts +3 -1
  61. package/dist/templates/city-courier/test/headless.test.ts +3 -2
  62. package/dist/templates/data-viz/README.md +1 -1
  63. package/dist/templates/index.json +22 -1
  64. package/dist/templates/skybound/README.md +13 -0
  65. package/dist/templates/skybound/first-leap.replay.json +152 -152
  66. package/dist/templates/skybound/gen/molen-types.ts +223 -5
  67. package/dist/templates/skybound/package.json +1 -0
  68. package/dist/templates/skybound/scene.json +40 -0
  69. package/dist/templates/skybound/scripts/game.ts +8 -5
  70. package/dist/templates/skybound/scripts/molen-scripts.d.ts +248 -5
  71. package/dist/templates/skybound/src/audio.ts +96 -0
  72. package/dist/templates/skybound/src/game-shell.css +8 -0
  73. package/dist/templates/skybound/src/main.ts +3 -0
  74. package/dist/templates/skybound/test/headless.test.ts +1 -1
  75. package/dist/templates/terrain-flyover/README.md +2 -2
  76. package/dist/templates/top-down-arena/README.md +15 -2
  77. package/dist/templates/top-down-arena/arena-skirmish.replay.json +152 -152
  78. package/dist/templates/top-down-arena/package.json +1 -0
  79. package/dist/templates/top-down-arena/scene.json +20 -0
  80. package/dist/templates/top-down-arena/scripts/combat.ts +1 -0
  81. package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +248 -5
  82. package/dist/templates/top-down-arena/src/audio.ts +96 -0
  83. package/dist/templates/top-down-arena/src/gen/molen-types.ts +223 -5
  84. package/dist/templates/top-down-arena/src/main.ts +3 -0
  85. package/dist/templates/top-down-arena/test/headless.test.ts +1 -1
  86. package/package.json +13 -12
@@ -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,210 @@ type MolenAircraftStateData = {
194
194
  crashed: boolean;
195
195
  waitingForTerrain: boolean;
196
196
  };
197
+ /** Kernel-owned state of an ambient NPC (car, pedestrian, train car or aircraft): its lane, position along it, speed and routing. Read it; the ambient systems write it. */
198
+ type MolenAmbientAgentData = {
199
+ kind: 'car' | 'pedestrian' | 'train' | 'aircraft';
200
+ type: string;
201
+ color?: string;
202
+ lane: string;
203
+ s: number;
204
+ speed: number;
205
+ prev?: string;
206
+ next?: string;
207
+ seed: number;
208
+ length: number;
209
+ width: number;
210
+ state: 'move' | 'wait' | 'dwell' | 'idle';
211
+ since: number;
212
+ hops: number;
213
+ hidden?: boolean;
214
+ consist?: string;
215
+ carIndex?: number;
216
+ trail?: string[];
217
+ served?: string;
218
+ air?: {
219
+ x: number;
220
+ z: number;
221
+ dx: number;
222
+ dz: number;
223
+ y0: number;
224
+ y1: number;
225
+ length: number;
226
+ };
227
+ spawnedTick: number;
228
+ };
229
+ /** Marks the entity ambient NPCs spawn around (usually the player or camera rig), with optional radius and density overrides. */
230
+ type MolenAmbientObserverData = {
231
+ radius?: number;
232
+ despawnRadius?: number;
233
+ density?: number;
234
+ };
235
+ /** On an entity type: makes it an ambient NPC candidate (car, bus, rail car or aircraft) with dimensions, speeds and spawn weight. */
236
+ type MolenAmbientRoleData = {
237
+ role: 'car' | 'bus' | 'rail' | 'aircraft';
238
+ length?: number;
239
+ width?: number;
240
+ height?: number;
241
+ cruise?: number;
242
+ max?: number;
243
+ weight?: number;
244
+ cars?: number;
245
+ colors?: string[];
246
+ visual?: {
247
+ wheelNodes?: string[];
248
+ frontWheelNodes?: string[];
249
+ paintMaterial?: string;
250
+ wheelRadius?: number;
251
+ wheelbase?: number;
252
+ rotors?: string[];
253
+ gearNodes?: string[];
254
+ };
255
+ };
256
+ /** Kernel-owned ambient bookkeeping on the `$ambient` entity: observer, spawn sequence and policy overrides. */
257
+ type MolenAmbientStateData = {
258
+ observer?: {
259
+ pos?: [number, number, number];
260
+ forward?: [number, number];
261
+ entity?: string;
262
+ setAtTick: number;
263
+ };
264
+ nextSeq: number;
265
+ spawned: number;
266
+ despawned: number;
267
+ policy?: Record<string, unknown>;
268
+ };
269
+ /** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
270
+ type MolenAudioEnvironmentData = {
271
+ buses?: Record<string, number>;
272
+ ambience?: {
273
+ sound: string;
274
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
275
+ min?: number;
276
+ max?: number;
277
+ } | {
278
+ exists: boolean;
279
+ }>;
280
+ gain?: number;
281
+ gainFrom?: {
282
+ signal: string;
283
+ curve: [number, number][];
284
+ smoothS?: number;
285
+ } | {
286
+ signal: string;
287
+ curve: [number, number][];
288
+ smoothS?: number;
289
+ }[];
290
+ pitchFrom?: {
291
+ signal: string;
292
+ curve: [number, number][];
293
+ smoothS?: number;
294
+ } | {
295
+ signal: string;
296
+ curve: [number, number][];
297
+ smoothS?: number;
298
+ }[];
299
+ fadeS?: number;
300
+ }[];
301
+ music?: {
302
+ playlist: string[];
303
+ mode?: 'sequence' | 'shuffle';
304
+ crossfadeS?: number;
305
+ gain?: number;
306
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
307
+ min?: number;
308
+ max?: number;
309
+ } | {
310
+ exists: boolean;
311
+ }>;
312
+ };
313
+ events?: Record<string, {
314
+ sound: string;
315
+ at?: string;
316
+ gain?: number;
317
+ pitch?: number;
318
+ bus?: string;
319
+ }>;
320
+ footsteps?: {
321
+ sound: string;
322
+ surfaces?: Record<string, string>;
323
+ strideM?: number;
324
+ gain?: number;
325
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
326
+ min?: number;
327
+ max?: number;
328
+ } | {
329
+ exists: boolean;
330
+ }>;
331
+ };
332
+ listenerEntity?: string;
333
+ maxVoices?: number;
334
+ };
335
+ /** 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. */
336
+ type MolenAudioSourceData = {
337
+ sound: string;
338
+ loop?: boolean;
339
+ autoplay?: boolean;
340
+ gain?: number;
341
+ pitch?: number;
342
+ bus?: string;
343
+ spatial?: false | {
344
+ refDistance?: number;
345
+ maxDistance?: number;
346
+ rolloff?: number;
347
+ model?: 'linear' | 'inverse' | 'exponential';
348
+ };
349
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
350
+ min?: number;
351
+ max?: number;
352
+ } | {
353
+ exists: boolean;
354
+ }>;
355
+ gainFrom?: {
356
+ signal: string;
357
+ curve: [number, number][];
358
+ smoothS?: number;
359
+ } | {
360
+ signal: string;
361
+ curve: [number, number][];
362
+ smoothS?: number;
363
+ }[];
364
+ pitchFrom?: {
365
+ signal: string;
366
+ curve: [number, number][];
367
+ smoothS?: number;
368
+ } | {
369
+ signal: string;
370
+ curve: [number, number][];
371
+ smoothS?: number;
372
+ }[];
373
+ triggerFrom?: {
374
+ signal: string;
375
+ every?: number;
376
+ onChange?: boolean;
377
+ sound?: string;
378
+ };
379
+ startTick?: number;
380
+ };
381
+ /** 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). */
382
+ type MolenAudioZoneData = {
383
+ sound: string;
384
+ shape: {
385
+ kind: 'sphere';
386
+ radius: number;
387
+ } | {
388
+ kind: 'box';
389
+ halfExtents: [number, number, number];
390
+ };
391
+ fade?: number;
392
+ gain?: number;
393
+ bus?: string;
394
+ when?: Record<string, string | number | boolean | (string | number | boolean)[] | {
395
+ min?: number;
396
+ max?: number;
397
+ } | {
398
+ exists: boolean;
399
+ }>;
400
+ };
197
401
  /** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
198
402
  type MolenCharacterData = {
199
403
  speed: number;
@@ -525,7 +729,7 @@ type MolenLocalTransformData = {
525
729
  type MolenModel_signalsData = {
526
730
  sources: Record<string, {
527
731
  component: string;
528
- path: string | number[];
732
+ path: (string | number)[];
529
733
  }>;
530
734
  bindings: {
531
735
  node: string;
@@ -590,7 +794,7 @@ type MolenPlatformSolidData = {
590
794
  };
591
795
  /** Client render contract: a primitive, a gltf asset (by project asset id) with optional sub-node, material override, shadows, and clip playback, or a capability-registered kind. */
592
796
  type MolenRenderableData = {
593
- kind: 'primitive' | 'gltf' | 'figure';
797
+ kind: 'primitive' | 'gltf' | 'ambient-vehicle' | 'figure';
594
798
  ref: string;
595
799
  materialRef?: string;
596
800
  primitive?: {
@@ -641,14 +845,6 @@ type MolenTimerData = {
641
845
  repeatEvery?: number;
642
846
  }[];
643
847
  };
644
- /** Traffic route along one north/south street. */
645
- type MolenTrafficCarData = {
646
- lane: number;
647
- from: number;
648
- to: number;
649
- speed: number;
650
- start: number;
651
- };
652
848
  /** World position + orientation. pos is required; rot defaults to identity. */
653
849
  type MolenTransformData = {
654
850
  pos: [number, number, number];
@@ -710,7 +906,7 @@ type MolenVehicleData = {
710
906
  nodes: string[];
711
907
  sources?: Record<string, {
712
908
  component: string;
713
- path: string | number[];
909
+ path: (string | number)[];
714
910
  }>;
715
911
  bindings: {
716
912
  node: string;
@@ -805,6 +1001,20 @@ interface MolenComponentData {
805
1001
  'aircraftInput': MolenAircraftInputData;
806
1002
  /** Deterministic flight state, including rotor phase and engine spool, preserved by keyframes. */
807
1003
  'aircraftState': MolenAircraftStateData;
1004
+ /** Kernel-owned state of an ambient NPC (car, pedestrian, train car or aircraft): its lane, position along it, speed and routing. Read it; the ambient systems write it. */
1005
+ 'ambientAgent': MolenAmbientAgentData;
1006
+ /** Marks the entity ambient NPCs spawn around (usually the player or camera rig), with optional radius and density overrides. */
1007
+ 'ambientObserver': MolenAmbientObserverData;
1008
+ /** On an entity type: makes it an ambient NPC candidate (car, bus, rail car or aircraft) with dimensions, speeds and spawn weight. */
1009
+ 'ambientRole': MolenAmbientRoleData;
1010
+ /** Kernel-owned ambient bookkeeping on the `$ambient` entity: observer, spawn sequence and policy overrides. */
1011
+ 'ambientState': MolenAmbientStateData;
1012
+ /** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
1013
+ 'audioEnvironment': MolenAudioEnvironmentData;
1014
+ /** 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. */
1015
+ 'audioSource': MolenAudioSourceData;
1016
+ /** 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). */
1017
+ 'audioZone': MolenAudioZoneData;
808
1018
  /** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
809
1019
  'character': MolenCharacterData;
810
1020
  /** 2.5D kinematic collider (circle or XZ AABB) with layer/mask bitmasks. */
@@ -867,8 +1077,6 @@ interface MolenComponentData {
867
1077
  'tag': MolenTagData;
868
1078
  /** Snapshot-safe countdown timers that emit events (one-shot or repeating). Replaces callbacks. */
869
1079
  'timer': MolenTimerData;
870
- /** Traffic route along one north/south street. */
871
- 'trafficCar': MolenTrafficCarData;
872
1080
  /** World position + orientation. pos is required; rot defaults to identity. */
873
1081
  'transform': MolenTransformData;
874
1082
  /** Data-driven value animation over ticks: component + select-style path, lerp with easing. */
@@ -891,9 +1099,9 @@ type MolenComponentName = keyof MolenComponentData;
891
1099
  type MolenComponentPatch = { [K in MolenComponentName]?: MolenComponentData[K] };
892
1100
 
893
1101
  /** Entity ids declared in the scene. Ids of spawned entities are plain strings. */
894
- type MolenEntityId = 'beacon' | 'beacon-pillar' | 'block--16--16' | 'block--16--16-entry' | 'block--16--16-roof' | 'block--16--16-window1.5--1.5' | 'block--16--16-window1.5-1.5' | 'block--16--16-window3--1.5' | 'block--16--16-window3-1.5' | 'block--16--8' | 'block--16--8-entry' | 'block--16--8-roof' | 'block--16--8-window1.5--1.5' | 'block--16--8-window1.5-1.5' | 'block--16--8-window3--1.5' | 'block--16--8-window3-1.5' | 'block--16-16' | 'block--16-16-entry' | 'block--16-16-roof' | 'block--16-16-window1.5--1.5' | 'block--16-16-window1.5-1.5' | 'block--16-16-window3--1.5' | 'block--16-16-window3-1.5' | 'block--16-8' | 'block--16-8-entry' | 'block--16-8-roof' | 'block--16-8-window1.5--1.5' | 'block--16-8-window1.5-1.5' | 'block--16-8-window3--1.5' | 'block--16-8-window3-1.5' | 'block--8--16' | 'block--8--16-entry' | 'block--8--16-roof' | 'block--8--16-window1.5--1.5' | 'block--8--16-window1.5-1.5' | 'block--8--16-window3--1.5' | 'block--8--16-window3-1.5' | 'block--8--8' | 'block--8--8-entry' | 'block--8--8-roof' | 'block--8--8-window1.5--1.5' | 'block--8--8-window1.5-1.5' | 'block--8--8-window3--1.5' | 'block--8--8-window3-1.5' | 'block--8-16' | 'block--8-16-entry' | 'block--8-16-roof' | 'block--8-16-window1.5--1.5' | 'block--8-16-window1.5-1.5' | 'block--8-16-window3--1.5' | 'block--8-16-window3-1.5' | 'block--8-8' | 'block--8-8-entry' | 'block--8-8-roof' | 'block--8-8-window1.5--1.5' | 'block--8-8-window1.5-1.5' | 'block--8-8-window3--1.5' | 'block--8-8-window3-1.5' | 'block-16--16' | 'block-16--16-entry' | 'block-16--16-roof' | 'block-16--16-window1.5--1.5' | 'block-16--16-window1.5-1.5' | 'block-16--16-window3--1.5' | 'block-16--16-window3-1.5' | 'block-16--8' | 'block-16--8-entry' | 'block-16--8-roof' | 'block-16--8-window1.5--1.5' | 'block-16--8-window1.5-1.5' | 'block-16--8-window3--1.5' | 'block-16--8-window3-1.5' | 'block-16-16' | 'block-16-16-entry' | 'block-16-16-roof' | 'block-16-16-window1.5--1.5' | 'block-16-16-window1.5-1.5' | 'block-16-16-window3--1.5' | 'block-16-16-window3-1.5' | 'block-16-8' | 'block-16-8-entry' | 'block-16-8-roof' | 'block-16-8-window1.5--1.5' | 'block-16-8-window1.5-1.5' | 'block-16-8-window3--1.5' | 'block-16-8-window3-1.5' | 'block-8--16' | 'block-8--16-entry' | 'block-8--16-roof' | 'block-8--16-window1.5--1.5' | 'block-8--16-window1.5-1.5' | 'block-8--16-window3--1.5' | 'block-8--16-window3-1.5' | 'block-8--8' | 'block-8--8-entry' | 'block-8--8-roof' | 'block-8--8-window1.5--1.5' | 'block-8--8-window1.5-1.5' | 'block-8--8-window3--1.5' | 'block-8--8-window3-1.5' | 'block-8-16' | 'block-8-16-entry' | 'block-8-16-roof' | 'block-8-16-window1.5--1.5' | 'block-8-16-window1.5-1.5' | 'block-8-16-window3--1.5' | 'block-8-16-window3-1.5' | 'block-8-8' | 'block-8-8-entry' | 'block-8-8-roof' | 'block-8-8-window1.5--1.5' | 'block-8-8-window1.5-1.5' | 'block-8-8-window3--1.5' | 'block-8-8-window3-1.5' | 'boundary0' | 'boundary1' | 'boundary2' | 'boundary3' | 'car-cabin' | 'car-stripe' | 'dash-x-24--12' | 'dash-x-24--16' | 'dash-x-24--32' | 'dash-x-24--8' | 'dash-x-24-12' | 'dash-x-24-16' | 'dash-x-24-32' | 'dash-x-24-8' | 'dash-x0--12' | 'dash-x0--16' | 'dash-x0--32' | 'dash-x0--8' | 'dash-x0-12' | 'dash-x0-16' | 'dash-x0-32' | 'dash-x0-8' | 'dash-x24--12' | 'dash-x24--16' | 'dash-x24--32' | 'dash-x24--8' | 'dash-x24-12' | 'dash-x24-16' | 'dash-x24-32' | 'dash-x24-8' | 'dash-z-24--12' | 'dash-z-24--16' | 'dash-z-24--32' | 'dash-z-24--8' | 'dash-z-24-12' | 'dash-z-24-16' | 'dash-z-24-32' | 'dash-z-24-8' | 'dash-z0--12' | 'dash-z0--16' | 'dash-z0--32' | 'dash-z0--8' | 'dash-z0-12' | 'dash-z0-16' | 'dash-z0-32' | 'dash-z0-8' | 'dash-z24--12' | 'dash-z24--16' | 'dash-z24--32' | 'dash-z24--8' | 'dash-z24-12' | 'dash-z24-16' | 'dash-z24-32' | 'dash-z24-8' | 'environment' | 'game' | 'ground' | 'player' | 'road-x-24' | 'road-x0' | 'road-x24' | 'road-z-24' | 'road-z0' | 'road-z24' | 'traffic0' | 'traffic0-roof' | 'traffic1' | 'traffic1-roof' | 'traffic2' | 'traffic2-roof' | 'traffic3' | 'traffic3-roof' | 'wheel-0.8-0.85' | 'wheel-0.80.85' | 'wheel0.8-0.85' | 'wheel0.80.85' | (string & {});
1102
+ type MolenEntityId = 'audio' | 'beacon' | 'beacon-pillar' | 'block--16--16' | 'block--16--16-entry' | 'block--16--16-roof' | 'block--16--16-window1.5--1.5' | 'block--16--16-window1.5-1.5' | 'block--16--16-window3--1.5' | 'block--16--16-window3-1.5' | 'block--16--8' | 'block--16--8-entry' | 'block--16--8-roof' | 'block--16--8-window1.5--1.5' | 'block--16--8-window1.5-1.5' | 'block--16--8-window3--1.5' | 'block--16--8-window3-1.5' | 'block--16-16' | 'block--16-16-entry' | 'block--16-16-roof' | 'block--16-16-window1.5--1.5' | 'block--16-16-window1.5-1.5' | 'block--16-16-window3--1.5' | 'block--16-16-window3-1.5' | 'block--16-8' | 'block--16-8-entry' | 'block--16-8-roof' | 'block--16-8-window1.5--1.5' | 'block--16-8-window1.5-1.5' | 'block--16-8-window3--1.5' | 'block--16-8-window3-1.5' | 'block--8--16' | 'block--8--16-entry' | 'block--8--16-roof' | 'block--8--16-window1.5--1.5' | 'block--8--16-window1.5-1.5' | 'block--8--16-window3--1.5' | 'block--8--16-window3-1.5' | 'block--8--8' | 'block--8--8-entry' | 'block--8--8-roof' | 'block--8--8-window1.5--1.5' | 'block--8--8-window1.5-1.5' | 'block--8--8-window3--1.5' | 'block--8--8-window3-1.5' | 'block--8-16' | 'block--8-16-entry' | 'block--8-16-roof' | 'block--8-16-window1.5--1.5' | 'block--8-16-window1.5-1.5' | 'block--8-16-window3--1.5' | 'block--8-16-window3-1.5' | 'block--8-8' | 'block--8-8-entry' | 'block--8-8-roof' | 'block--8-8-window1.5--1.5' | 'block--8-8-window1.5-1.5' | 'block--8-8-window3--1.5' | 'block--8-8-window3-1.5' | 'block-16--16' | 'block-16--16-entry' | 'block-16--16-roof' | 'block-16--16-window1.5--1.5' | 'block-16--16-window1.5-1.5' | 'block-16--16-window3--1.5' | 'block-16--16-window3-1.5' | 'block-16--8' | 'block-16--8-entry' | 'block-16--8-roof' | 'block-16--8-window1.5--1.5' | 'block-16--8-window1.5-1.5' | 'block-16--8-window3--1.5' | 'block-16--8-window3-1.5' | 'block-16-16' | 'block-16-16-entry' | 'block-16-16-roof' | 'block-16-16-window1.5--1.5' | 'block-16-16-window1.5-1.5' | 'block-16-16-window3--1.5' | 'block-16-16-window3-1.5' | 'block-16-8' | 'block-16-8-entry' | 'block-16-8-roof' | 'block-16-8-window1.5--1.5' | 'block-16-8-window1.5-1.5' | 'block-16-8-window3--1.5' | 'block-16-8-window3-1.5' | 'block-8--16' | 'block-8--16-entry' | 'block-8--16-roof' | 'block-8--16-window1.5--1.5' | 'block-8--16-window1.5-1.5' | 'block-8--16-window3--1.5' | 'block-8--16-window3-1.5' | 'block-8--8' | 'block-8--8-entry' | 'block-8--8-roof' | 'block-8--8-window1.5--1.5' | 'block-8--8-window1.5-1.5' | 'block-8--8-window3--1.5' | 'block-8--8-window3-1.5' | 'block-8-16' | 'block-8-16-entry' | 'block-8-16-roof' | 'block-8-16-window1.5--1.5' | 'block-8-16-window1.5-1.5' | 'block-8-16-window3--1.5' | 'block-8-16-window3-1.5' | 'block-8-8' | 'block-8-8-entry' | 'block-8-8-roof' | 'block-8-8-window1.5--1.5' | 'block-8-8-window1.5-1.5' | 'block-8-8-window3--1.5' | 'block-8-8-window3-1.5' | 'boundary0' | 'boundary1' | 'boundary2' | 'boundary3' | 'car-cabin' | 'car-stripe' | 'dash-x-24--12' | 'dash-x-24--16' | 'dash-x-24--32' | 'dash-x-24--8' | 'dash-x-24-12' | 'dash-x-24-16' | 'dash-x-24-32' | 'dash-x-24-8' | 'dash-x0--12' | 'dash-x0--16' | 'dash-x0--32' | 'dash-x0--8' | 'dash-x0-12' | 'dash-x0-16' | 'dash-x0-32' | 'dash-x0-8' | 'dash-x24--12' | 'dash-x24--16' | 'dash-x24--32' | 'dash-x24--8' | 'dash-x24-12' | 'dash-x24-16' | 'dash-x24-32' | 'dash-x24-8' | 'dash-z-24--12' | 'dash-z-24--16' | 'dash-z-24--32' | 'dash-z-24--8' | 'dash-z-24-12' | 'dash-z-24-16' | 'dash-z-24-32' | 'dash-z-24-8' | 'dash-z0--12' | 'dash-z0--16' | 'dash-z0--32' | 'dash-z0--8' | 'dash-z0-12' | 'dash-z0-16' | 'dash-z0-32' | 'dash-z0-8' | 'dash-z24--12' | 'dash-z24--16' | 'dash-z24--32' | 'dash-z24--8' | 'dash-z24-12' | 'dash-z24-16' | 'dash-z24-32' | 'dash-z24-8' | 'environment' | 'game' | 'ground' | 'player' | 'road-x-24' | 'road-x0' | 'road-x24' | 'road-z-24' | 'road-z0' | 'road-z24' | 'wheel-0.8-0.85' | 'wheel-0.80.85' | 'wheel0.8-0.85' | 'wheel0.80.85' | (string & {});
895
1103
  /** Prefab names declared in the scene. */
896
- type MolenPrefabName = 'box' | 'cylinder' | 'sphere' | 'vehicle' | (string & {});
1104
+ type MolenPrefabName = 'box' | 'cylinder' | 'npc-car' | 'sphere' | 'vehicle' | (string & {});
897
1105
  /** Registry type ids this project declares (`molen.spawnType`). */
898
1106
  type MolenTypeId = string;
899
1107
 
@@ -1024,6 +1232,29 @@ interface MolenMath {
1024
1232
  cbrt(...args: number[]): number;
1025
1233
  }
1026
1234
 
1235
+ /** Options for `molen.audio.play`. Omit entity and position for a non-positional sound. */
1236
+ interface MolenAudioPlayOptions {
1237
+ /** Play at (and follow) this entity's transform. */
1238
+ entity?: MolenEntityId;
1239
+ /** Play at a fixed world position. */
1240
+ position?: MolenVec3;
1241
+ gain?: number;
1242
+ pitch?: number;
1243
+ bus?: string;
1244
+ /** Loop until stopped; default the sound's own loop flag. */
1245
+ loop?: boolean;
1246
+ }
1247
+
1248
+ /** `molen.audio`: each call emits an `audio.*` event the client plays (guide/audio.md). */
1249
+ interface MolenAudioApi {
1250
+ /** Play a sound-bank id; returns a handle for `stop`. */
1251
+ play(sound: string, opts?: MolenAudioPlayOptions): string;
1252
+ /** Stop by handle, or every voice matching an entity and/or sound. */
1253
+ stop(target: string | { entity?: MolenEntityId; sound?: string }, fadeS?: number): void;
1254
+ /** Switch background music to a track or playlist; null stops it. */
1255
+ music(playlist: string | string[] | null, opts?: { crossfadeS?: number }): void;
1256
+ }
1257
+
1027
1258
  /** The verb set injected into every scene-data script as `molen`. */
1028
1259
  interface MolenApi {
1029
1260
  /** Spawn from a component map. */
@@ -1080,6 +1311,8 @@ interface MolenApi {
1080
1311
  handler: (payload: MolenCommands[T], ctx: MolenTickContext, command: MolenCommand) => void,
1081
1312
  ): MolenUnsubscribe;
1082
1313
  emit(type: string, payload?: MolenJsonValue): void;
1314
+ /** Sound: play/stop one-shots and loops, switch music. Never affects the simulation. */
1315
+ readonly audio: MolenAudioApi;
1083
1316
  raycast(origin: MolenVec3, dir: MolenVec3, maxDist: number, mask?: number): MolenRayHit | null;
1084
1317
  overlapCircle(center: MolenVec3, radius: number, mask?: number): string[];
1085
1318
  /** Emit `event` after `ticks` ticks (snapshot-safe world timer). Returns the timer id. */
@@ -1096,6 +1329,9 @@ interface MolenApi {
1096
1329
  readonly tick: number;
1097
1330
  readonly dt: number;
1098
1331
  readonly math: MolenMath;
1332
+ /** Ambient life: stats / laneAt / agentsNear / setObserver / addRoad / … (see guide/ambient-life.md). Installed as a scripting extension, so its verbs are not checked here. */
1333
+ // biome-ignore lint/suspicious/noExplicitAny: capability signatures are owned by their extensions
1334
+ readonly ambient: Record<string, (...args: any[]) => any>;
1099
1335
  /** Figure verbs: mount / dismount / socket / … (see guide/figures.md). Installed as a scripting extension, so its verbs are not checked here. */
1100
1336
  // biome-ignore lint/suspicious/noExplicitAny: capability signatures are owned by their extensions
1101
1337
  readonly figures: Record<string, (...args: any[]) => any>;
@@ -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}`);
@@ -74,6 +76,7 @@ const timer = setInterval(() => {
74
76
  }, 80);
75
77
  function dispose(): void {
76
78
  clearInterval(timer);
79
+ void stopAudio.then((stop) => stop());
77
80
  mounted.dispose();
78
81
  worker.terminate();
79
82
  }
@@ -1,5 +1,7 @@
1
1
  /// <reference lib="webworker" />
2
+ import { ambientCapability } from '@bendyline/molen-ambient/kernel';
2
3
  import { startKernelWorker } from '@bendyline/molen-kernel';
3
4
  import { scene } from './scene';
4
5
 
5
- startKernelWorker({ scene: scene() });
6
+ // The scene's `ambient` block (traffic on the street grid) needs the ambient capability.
7
+ startKernelWorker({ scene: scene(), capabilities: [ambientCapability()] });
@@ -1,3 +1,4 @@
1
+ import { ambientCapability } from '@bendyline/molen-ambient/kernel';
1
2
  import {
2
3
  applyKeyframeTo,
3
4
  buildWorld,
@@ -10,7 +11,7 @@ import type { JsonObject } from '@bendyline/molen-schema';
10
11
  import { describe, expect, it } from 'vitest';
11
12
  import { scene } from '../src/scene';
12
13
 
13
- const build = (): World => buildWorld(scene());
14
+ const build = (): World => buildWorld(scene(), undefined, { capabilities: [ambientCapability()] });
14
15
  function command(w: World, type: string, payload: JsonObject = {}): void {
15
16
  const result = w.submitCommand({
16
17
  kind: 'command',
@@ -37,7 +38,7 @@ describe('city-courier: authored scene + scripts', () => {
37
38
  command(w, 'drive', { dir: [0, -1] });
38
39
  w.stepN(90);
39
40
  expect(stateHash(w)).toBe(
40
- 'sha256:d5bb47f21578dd28540e1027fd1acfb282bebd1e26aa03ecba155ff87d16d6ef',
41
+ 'sha256:88442f1752f6ba13ea11913128b5ce351dff6f998a98658c7624cafd258effc1',
41
42
  );
42
43
  });
43
44
 
@@ -38,7 +38,7 @@ npm test
38
38
 
39
39
  `test/headless.test.ts` checks one bar per datum, growth over time toward `value * heightScale`, height ordering (taller means bigger), the camera track validating and actually moving, and a **pinned state hash** at 60 ticks alongside run-to-run equality.
40
40
 
41
- In the engine repository, `test/golden/viz.golden.test.ts` is the render half (golden tests stay there; a template copy does not include them): `screenshotScene` at tick 40 from the track's own pose at tick 40, 512x320, asserting seven rendered entities and comparing against the committed `test/golden/__goldens__/viz.png`. It then runs `exportFrames` from tick 0 to 60 in steps of 30 along the same track and asserts three PNGs — the machinima sequence in miniature. There is no replay fixture: nothing here takes commands.
41
+ In the engine repository, `test/golden/viz.golden.test.ts` is the render half (golden tests stay there; a template copy does not include them): `screenshotScene` at tick 40 from the track's own pose at tick 40, 512x320, asserting seven rendered entities and, with `frameStats` rather than a reference image, that the bars cover part of the dark frame in several shades. It then runs `exportFrames` from tick 0 to 60 in steps of 30 along the same track and asserts three PNGs whose first and last frames differ — the machinima sequence in miniature. There is no replay fixture: nothing here takes commands.
42
42
 
43
43
  One wrinkle worth knowing: `src/viz.ts` imports `data.json` without an import attribute, which Vite and Vitest supply and plain Node does not. Passing `--setup src/viz.ts` to `molen sim run` or `molen shot` therefore fails to load the module, which is why the headless render and the frame export run inside Vitest rather than from the CLI.
44
44
 
@@ -61,6 +61,7 @@
61
61
  "scripts/spawner.ts",
62
62
  "scripts/tsconfig.json",
63
63
  "src/arena.ts",
64
+ "src/audio.ts",
64
65
  "src/gen/molen-types.ts",
65
66
  "src/main.ts",
66
67
  "src/scene.ts",
@@ -134,6 +135,7 @@
134
135
  "scripts/game.ts",
135
136
  "scripts/molen-scripts.d.ts",
136
137
  "scripts/tsconfig.json",
138
+ "src/audio.ts",
137
139
  "src/game-shell.css",
138
140
  "src/main.ts",
139
141
  "src/scene.ts",
@@ -167,6 +169,7 @@
167
169
  "scripts/game.ts",
168
170
  "scripts/molen-scripts.d.ts",
169
171
  "scripts/tsconfig.json",
172
+ "src/audio.ts",
170
173
  "src/game-shell.css",
171
174
  "src/main.ts",
172
175
  "src/scene.ts",
@@ -184,5 +187,23 @@
184
187
  "replays": ["first-leap.replay.json"],
185
188
  "tests": true
186
189
  }
187
- ]
190
+ ],
191
+ "versions": {
192
+ "@bendyline/molen-ambient": "0.0.4",
193
+ "@bendyline/molen-client": "0.0.4",
194
+ "@bendyline/molen-earth": "0.0.4",
195
+ "@bendyline/molen-entities": "0.0.4",
196
+ "@bendyline/molen-figures": "0.0.4",
197
+ "@bendyline/molen-input-react": "0.0.4",
198
+ "@bendyline/molen-kernel": "0.0.4",
199
+ "@bendyline/molen-materials": "0.0.4",
200
+ "@bendyline/molen-pack": "0.0.4",
201
+ "@bendyline/molen-pathfinding": "0.0.4",
202
+ "@bendyline/molen-physics-rapier": "0.0.4",
203
+ "@bendyline/molen-schema": "0.0.4",
204
+ "@bendyline/molen-terrain": "0.0.4",
205
+ "@bendyline/molen-tooling": "0.0.4",
206
+ "@bendyline/molen-worldgen": "0.0.4",
207
+ "@bendyline/molen-worldgen-earth": "0.0.4"
208
+ }
188
209
  }
@@ -29,6 +29,19 @@ A/D or Left/Right: run. Space: jump; hold for a full jump, release for a short h
29
29
 
30
30
  The shared `physics.engine: "platformer"` service owns swept XY box collision, gravity, coyote time, jump buffering, and variable jump height. `platformSolid` boxes are static and axis-aligned; `oneWay` ledges only catch descending bodies. Moving-platform carry, slopes, and rigid-body interactions are outside this small controller. Use Rapier for those needs. Edit `platformBody` tuning and authored level entities; scripts never implement wall or floor collision.
31
31
 
32
+ ## Sound
33
+
34
+ The `audio` entity's `audioEnvironment` plays wind that rises with the camera (`listener.y`) and heroic music, and maps pickups, stomps, the checkpoint, respawns and the finish to sounds. `scripts/game.ts` calls `molen.audio.play('game.jump')` for a jump that can happen. `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: