@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
@@ -231,6 +231,36 @@
231
231
  }
232
232
  }
233
233
  },
234
+ {
235
+ "id": "audio",
236
+ "components": {
237
+ "audioEnvironment": {
238
+ "buses": {
239
+ "music": 0.55,
240
+ "ambience": 0.7
241
+ },
242
+ "ambience": [
243
+ {
244
+ "sound": "ambience.city.traffic",
245
+ "gain": 0.4
246
+ }
247
+ ],
248
+ "music": {
249
+ "playlist": ["music.racing"],
250
+ "gain": 0.8
251
+ },
252
+ "events": {
253
+ "crash": {
254
+ "sound": "impact.metal.heavy"
255
+ },
256
+ "delivery": {
257
+ "sound": "game.pickup",
258
+ "bus": "ui"
259
+ }
260
+ }
261
+ }
262
+ }
263
+ },
234
264
  {
235
265
  "id": "ground",
236
266
  "components": {
@@ -2941,6 +2971,19 @@
2941
2971
  "components": {
2942
2972
  "transform": {
2943
2973
  "pos": [0, 0.55, 12]
2974
+ },
2975
+ "audioSource": {
2976
+ "sound": "vehicle.engine.car",
2977
+ "spatial": false,
2978
+ "gain": 0.7,
2979
+ "pitchFrom": {
2980
+ "signal": "self.speed",
2981
+ "curve": [[0, 0.75], [16, 1.6]]
2982
+ },
2983
+ "gainFrom": {
2984
+ "signal": "self.speed",
2985
+ "curve": [[0, 0.55], [16, 1]]
2986
+ }
2944
2987
  }
2945
2988
  },
2946
2989
  "prefab": "vehicle"
@@ -3104,6 +3147,15 @@
3104
3147
  "to": 32,
3105
3148
  "speed": 5,
3106
3149
  "start": -26
3150
+ },
3151
+ "audioSource": {
3152
+ "sound": "vehicle.engine.car",
3153
+ "gain": 0.6,
3154
+ "pitch": 0.85,
3155
+ "spatial": {
3156
+ "refDistance": 14,
3157
+ "maxDistance": 70
3158
+ }
3107
3159
  }
3108
3160
  },
3109
3161
  "prefab": "vehicle"
@@ -3157,6 +3209,15 @@
3157
3209
  "to": 32,
3158
3210
  "speed": -6,
3159
3211
  "start": 23
3212
+ },
3213
+ "audioSource": {
3214
+ "sound": "vehicle.engine.car",
3215
+ "gain": 0.6,
3216
+ "pitch": 0.85,
3217
+ "spatial": {
3218
+ "refDistance": 14,
3219
+ "maxDistance": 70
3220
+ }
3160
3221
  }
3161
3222
  },
3162
3223
  "prefab": "vehicle"
@@ -3210,6 +3271,15 @@
3210
3271
  "to": 32,
3211
3272
  "speed": 5,
3212
3273
  "start": 9
3274
+ },
3275
+ "audioSource": {
3276
+ "sound": "vehicle.engine.car",
3277
+ "gain": 0.6,
3278
+ "pitch": 0.85,
3279
+ "spatial": {
3280
+ "refDistance": 14,
3281
+ "maxDistance": 70
3282
+ }
3213
3283
  }
3214
3284
  },
3215
3285
  "prefab": "vehicle"
@@ -3263,6 +3333,15 @@
3263
3333
  "to": 32,
3264
3334
  "speed": 6,
3265
3335
  "start": -5
3336
+ },
3337
+ "audioSource": {
3338
+ "sound": "vehicle.engine.car",
3339
+ "gain": 0.6,
3340
+ "pitch": 0.85,
3341
+ "spatial": {
3342
+ "refDistance": 14,
3343
+ "maxDistance": 70
3344
+ }
3266
3345
  }
3267
3346
  },
3268
3347
  "prefab": "vehicle"
@@ -63,6 +63,7 @@ molen.on('collision', (p) => {
63
63
  : 'Collision! Ease off and use the handbrake.',
64
64
  });
65
65
  molen.emit('crash', { health });
66
+ if (health === 0) molen.audio.play('ui.error');
66
67
  });
67
68
  molen.on('tick', () => {
68
69
  const g = game();
@@ -76,8 +77,10 @@ molen.on('tick', () => {
76
77
  );
77
78
  if (g.status !== 'playing' || seconds === 0) {
78
79
  molen.patch('player', 'kinematicBody', { vel: [0, 0, 0] });
79
- if (seconds === 0 && g.status === 'playing')
80
+ if (seconds === 0 && g.status === 'playing') {
80
81
  update({ status: 'lost', seconds: 0, message: 'Time is up. Press R to retry the route.' });
82
+ molen.audio.play('ui.error');
83
+ }
81
84
  return;
82
85
  }
83
86
  const v = body.vel;
@@ -114,6 +117,7 @@ molen.on('tick', () => {
114
117
  });
115
118
  placeBeacon(delivered);
116
119
  molen.emit('delivery', { delivered });
120
+ if (delivered === g.total) molen.audio.play('sting.win');
117
121
  }
118
122
  for (const [id, t, car] of molen.query('transform', 'trafficCar')) {
119
123
  if (t.pos[2] > car.to || t.pos[2] < car.from)
@@ -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;
@@ -525,7 +657,7 @@ type MolenLocalTransformData = {
525
657
  type MolenModel_signalsData = {
526
658
  sources: Record<string, {
527
659
  component: string;
528
- path: string | number[];
660
+ path: (string | number)[];
529
661
  }>;
530
662
  bindings: {
531
663
  node: string;
@@ -710,7 +842,7 @@ type MolenVehicleData = {
710
842
  nodes: string[];
711
843
  sources?: Record<string, {
712
844
  component: string;
713
- path: string | number[];
845
+ path: (string | number)[];
714
846
  }>;
715
847
  bindings: {
716
848
  node: string;
@@ -805,6 +937,12 @@ interface MolenComponentData {
805
937
  'aircraftInput': MolenAircraftInputData;
806
938
  /** Deterministic flight state, including rotor phase and engine spool, preserved by keyframes. */
807
939
  'aircraftState': MolenAircraftStateData;
940
+ /** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
941
+ 'audioEnvironment': MolenAudioEnvironmentData;
942
+ /** 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. */
943
+ 'audioSource': MolenAudioSourceData;
944
+ /** 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). */
945
+ 'audioZone': MolenAudioZoneData;
808
946
  /** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
809
947
  'character': MolenCharacterData;
810
948
  /** 2.5D kinematic collider (circle or XZ AABB) with layer/mask bitmasks. */
@@ -891,7 +1029,7 @@ type MolenComponentName = keyof MolenComponentData;
891
1029
  type MolenComponentPatch = { [K in MolenComponentName]?: MolenComponentData[K] };
892
1030
 
893
1031
  /** 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 & {});
1032
+ 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' | '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 & {});
895
1033
  /** Prefab names declared in the scene. */
896
1034
  type MolenPrefabName = 'box' | 'cylinder' | 'sphere' | 'vehicle' | (string & {});
897
1035
  /** Registry type ids this project declares (`molen.spawnType`). */
@@ -1024,6 +1162,29 @@ interface MolenMath {
1024
1162
  cbrt(...args: number[]): number;
1025
1163
  }
1026
1164
 
1165
+ /** Options for `molen.audio.play`. Omit entity and position for a non-positional sound. */
1166
+ interface MolenAudioPlayOptions {
1167
+ /** Play at (and follow) this entity's transform. */
1168
+ entity?: MolenEntityId;
1169
+ /** Play at a fixed world position. */
1170
+ position?: MolenVec3;
1171
+ gain?: number;
1172
+ pitch?: number;
1173
+ bus?: string;
1174
+ /** Loop until stopped; default the sound's own loop flag. */
1175
+ loop?: boolean;
1176
+ }
1177
+
1178
+ /** `molen.audio`: each call emits an `audio.*` event the client plays (guide/audio.md). */
1179
+ interface MolenAudioApi {
1180
+ /** Play a sound-bank id; returns a handle for `stop`. */
1181
+ play(sound: string, opts?: MolenAudioPlayOptions): string;
1182
+ /** Stop by handle, or every voice matching an entity and/or sound. */
1183
+ stop(target: string | { entity?: MolenEntityId; sound?: string }, fadeS?: number): void;
1184
+ /** Switch background music to a track or playlist; null stops it. */
1185
+ music(playlist: string | string[] | null, opts?: { crossfadeS?: number }): void;
1186
+ }
1187
+
1027
1188
  /** The verb set injected into every scene-data script as `molen`. */
1028
1189
  interface MolenApi {
1029
1190
  /** Spawn from a component map. */
@@ -1080,6 +1241,8 @@ interface MolenApi {
1080
1241
  handler: (payload: MolenCommands[T], ctx: MolenTickContext, command: MolenCommand) => void,
1081
1242
  ): MolenUnsubscribe;
1082
1243
  emit(type: string, payload?: MolenJsonValue): void;
1244
+ /** Sound: play/stop one-shots and loops, switch music. Never affects the simulation. */
1245
+ readonly audio: MolenAudioApi;
1083
1246
  raycast(origin: MolenVec3, dir: MolenVec3, maxDist: number, mask?: number): MolenRayHit | null;
1084
1247
  overlapCircle(center: MolenVec3, radius: number, mask?: number): string[];
1085
1248
  /** 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}`);
@@ -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
  }
@@ -37,7 +37,7 @@ describe('city-courier: authored scene + scripts', () => {
37
37
  command(w, 'drive', { dir: [0, -1] });
38
38
  w.stepN(90);
39
39
  expect(stateHash(w)).toBe(
40
- 'sha256:d5bb47f21578dd28540e1027fd1acfb282bebd1e26aa03ecba155ff87d16d6ef',
40
+ 'sha256:d82352ff8a1969ea1f702d38a963b09efe7b9c6d00a2f067fed247b239451fdb',
41
41
  );
42
42
  });
43
43
 
@@ -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",
@@ -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: