@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.
- package/README.md +4 -4
- package/dist/capture/harness.js +222 -222
- package/dist/capture/worldgen-preview.js +288 -288
- package/dist/cli.mjs +162 -10
- package/dist/docs-src/guide/3d-model-assets.md +35 -3
- package/dist/docs-src/guide/adaptive-performance.md +4 -0
- package/dist/docs-src/guide/agent-loop.md +6 -6
- package/dist/docs-src/guide/aircraft.md +28 -7
- package/dist/docs-src/guide/ambient-life.md +389 -0
- package/dist/docs-src/guide/audio.md +247 -0
- package/dist/docs-src/guide/browser-mount.md +8 -1
- package/dist/docs-src/guide/building-interiors.md +5 -4
- package/dist/docs-src/guide/capability-authoring.md +5 -0
- package/dist/docs-src/guide/determinism.md +35 -27
- package/dist/docs-src/guide/earth-view.md +492 -0
- package/dist/docs-src/guide/entities.md +9 -1
- package/dist/docs-src/guide/examples.md +6 -2
- package/dist/docs-src/guide/figures.md +3 -0
- package/dist/docs-src/guide/game-samples.md +22 -5
- package/dist/docs-src/guide/graphics-performance.md +40 -8
- package/dist/docs-src/guide/input.md +9 -0
- package/dist/docs-src/guide/markers.md +55 -0
- package/dist/docs-src/guide/materials.md +10 -3
- package/dist/docs-src/guide/navigation.md +150 -0
- package/dist/docs-src/guide/project.md +1 -1
- package/dist/docs-src/guide/quickstart.md +2 -2
- package/dist/docs-src/guide/recognizable-places.md +3 -2
- package/dist/docs-src/guide/scripting.md +4 -2
- package/dist/docs-src/guide/sky.md +16 -0
- package/dist/docs-src/guide/source-bundles.md +0 -1
- package/dist/docs-src/guide/structure-library.md +2 -2
- package/dist/docs-src/guide/surface-rendering.md +4 -3
- package/dist/docs-src/guide/terrain.md +52 -2
- package/dist/docs-src/guide/vehicles.md +32 -10
- package/dist/docs-src/guide/worldgen.md +3 -3
- package/dist/docs-src/llms.txt +14 -5
- package/dist/docs-src/schemas/README.md +4 -0
- package/dist/docs-src/schemas/archive-set.md +175 -0
- package/dist/docs-src/schemas/components.md +1634 -2
- package/dist/docs-src/schemas/matgraph.md +6 -0
- package/dist/docs-src/schemas/scene.md +105 -0
- package/dist/docs-src/schemas/soundbank.md +251 -0
- package/dist/docs-src/schemas/structure-placements.md +496 -0
- package/dist/docs-src/schemas/terrain-package.md +120 -0
- package/dist/docs-src/schemas/transport-network.md +351 -0
- package/dist/index.d.mts +49 -2
- package/dist/index.mjs +81 -4
- package/dist/{mcp-AOfIp89b.mjs → mcp-BtuworIW.mjs} +88 -3
- package/dist/{ops-C4BvDgP-.mjs → ops-DMGcWoL2.mjs} +1204 -93
- package/dist/templates/city-courier/README.md +14 -1
- package/dist/templates/city-courier/delivery-run.replay.json +151 -151
- package/dist/templates/city-courier/gen/molen-types.ts +223 -5
- package/dist/templates/city-courier/package.json +2 -0
- package/dist/templates/city-courier/scene.json +142 -246
- package/dist/templates/city-courier/scripts/game.ts +7 -15
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +252 -16
- package/dist/templates/city-courier/src/audio.ts +96 -0
- package/dist/templates/city-courier/src/game-shell.css +8 -0
- package/dist/templates/city-courier/src/main.ts +3 -0
- package/dist/templates/city-courier/src/worker.ts +3 -1
- package/dist/templates/city-courier/test/headless.test.ts +3 -2
- package/dist/templates/data-viz/README.md +1 -1
- package/dist/templates/index.json +22 -1
- package/dist/templates/skybound/README.md +13 -0
- package/dist/templates/skybound/first-leap.replay.json +152 -152
- package/dist/templates/skybound/gen/molen-types.ts +223 -5
- package/dist/templates/skybound/package.json +1 -0
- package/dist/templates/skybound/scene.json +40 -0
- package/dist/templates/skybound/scripts/game.ts +8 -5
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +248 -5
- package/dist/templates/skybound/src/audio.ts +96 -0
- package/dist/templates/skybound/src/game-shell.css +8 -0
- package/dist/templates/skybound/src/main.ts +3 -0
- package/dist/templates/skybound/test/headless.test.ts +1 -1
- package/dist/templates/terrain-flyover/README.md +2 -2
- package/dist/templates/top-down-arena/README.md +15 -2
- package/dist/templates/top-down-arena/arena-skirmish.replay.json +152 -152
- package/dist/templates/top-down-arena/package.json +1 -0
- package/dist/templates/top-down-arena/scene.json +20 -0
- package/dist/templates/top-down-arena/scripts/combat.ts +1 -0
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +248 -5
- package/dist/templates/top-down-arena/src/audio.ts +96 -0
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +223 -5
- package/dist/templates/top-down-arena/src/main.ts +3 -0
- package/dist/templates/top-down-arena/test/headless.test.ts +1 -1
- package/package.json +13 -12
|
@@ -238,6 +238,46 @@
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
|
+
{
|
|
242
|
+
"id": "audio",
|
|
243
|
+
"components": {
|
|
244
|
+
"audioEnvironment": {
|
|
245
|
+
"buses": {
|
|
246
|
+
"music": 0.55
|
|
247
|
+
},
|
|
248
|
+
"ambience": [
|
|
249
|
+
{
|
|
250
|
+
"sound": "ambience.wind",
|
|
251
|
+
"gainFrom": {
|
|
252
|
+
"signal": "listener.y",
|
|
253
|
+
"curve": [[0, 0.15], [30, 0.7]]
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
"music": {
|
|
258
|
+
"playlist": ["music.hero"],
|
|
259
|
+
"gain": 0.8
|
|
260
|
+
},
|
|
261
|
+
"events": {
|
|
262
|
+
"seed-collected": {
|
|
263
|
+
"sound": "game.pickup"
|
|
264
|
+
},
|
|
265
|
+
"stomp": {
|
|
266
|
+
"sound": "impact.soft"
|
|
267
|
+
},
|
|
268
|
+
"checkpoint": {
|
|
269
|
+
"sound": "sting.checkpoint"
|
|
270
|
+
},
|
|
271
|
+
"respawn": {
|
|
272
|
+
"sound": "ui.error"
|
|
273
|
+
},
|
|
274
|
+
"victory": {
|
|
275
|
+
"sound": "sting.win"
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
241
281
|
{
|
|
242
282
|
"id": "camera-target",
|
|
243
283
|
"components": {
|
|
@@ -10,11 +10,14 @@ molen.onCommand('move', (p) => {
|
|
|
10
10
|
if (game()?.status === 'playing') molen.patch('player', 'platformIntent', { move: p.dir[0] });
|
|
11
11
|
});
|
|
12
12
|
molen.onCommand('jump', (p) => {
|
|
13
|
-
if (game()?.status
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
if (game()?.status !== 'playing') return;
|
|
14
|
+
molen.patch('player', 'platformIntent', {
|
|
15
|
+
...(p.held ? { jump: true } : {}),
|
|
16
|
+
jumpHeld: p.held,
|
|
17
|
+
});
|
|
18
|
+
// Only a jump that can happen (on the ground, or within coyote time) makes a sound.
|
|
19
|
+
const body = molen.get('player', 'platformBody');
|
|
20
|
+
if (p.held && (body?.grounded || (body?.grace ?? 0) > 0)) molen.audio.play('game.jump');
|
|
18
21
|
});
|
|
19
22
|
molen.onCommand('restart', () => {
|
|
20
23
|
placePlayer(config.spawn);
|
|
@@ -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;
|
|
@@ -515,7 +719,7 @@ type MolenLocalTransformData = {
|
|
|
515
719
|
type MolenModel_signalsData = {
|
|
516
720
|
sources: Record<string, {
|
|
517
721
|
component: string;
|
|
518
|
-
path: string | number[];
|
|
722
|
+
path: (string | number)[];
|
|
519
723
|
}>;
|
|
520
724
|
bindings: {
|
|
521
725
|
node: string;
|
|
@@ -587,7 +791,7 @@ type MolenPlatformSolidData = {
|
|
|
587
791
|
};
|
|
588
792
|
/** 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. */
|
|
589
793
|
type MolenRenderableData = {
|
|
590
|
-
kind: 'primitive' | 'gltf' | 'figure';
|
|
794
|
+
kind: 'primitive' | 'gltf' | 'ambient-vehicle' | 'figure';
|
|
591
795
|
ref: string;
|
|
592
796
|
materialRef?: string;
|
|
593
797
|
primitive?: {
|
|
@@ -712,7 +916,7 @@ type MolenVehicleData = {
|
|
|
712
916
|
nodes: string[];
|
|
713
917
|
sources?: Record<string, {
|
|
714
918
|
component: string;
|
|
715
|
-
path: string | number[];
|
|
919
|
+
path: (string | number)[];
|
|
716
920
|
}>;
|
|
717
921
|
bindings: {
|
|
718
922
|
node: string;
|
|
@@ -807,6 +1011,20 @@ interface MolenComponentData {
|
|
|
807
1011
|
'aircraftInput': MolenAircraftInputData;
|
|
808
1012
|
/** Deterministic flight state, including rotor phase and engine spool, preserved by keyframes. */
|
|
809
1013
|
'aircraftState': MolenAircraftStateData;
|
|
1014
|
+
/** 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. */
|
|
1015
|
+
'ambientAgent': MolenAmbientAgentData;
|
|
1016
|
+
/** Marks the entity ambient NPCs spawn around (usually the player or camera rig), with optional radius and density overrides. */
|
|
1017
|
+
'ambientObserver': MolenAmbientObserverData;
|
|
1018
|
+
/** On an entity type: makes it an ambient NPC candidate (car, bus, rail car or aircraft) with dimensions, speeds and spawn weight. */
|
|
1019
|
+
'ambientRole': MolenAmbientRoleData;
|
|
1020
|
+
/** Kernel-owned ambient bookkeeping on the `$ambient` entity: observer, spawn sequence and policy overrides. */
|
|
1021
|
+
'ambientState': MolenAmbientStateData;
|
|
1022
|
+
/** Singleton soundscape rules: bus gains, ambience layers gated on weather/sky/listener signals, music playlist, event → sound mappings and listener footsteps. */
|
|
1023
|
+
'audioEnvironment': MolenAudioEnvironmentData;
|
|
1024
|
+
/** 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. */
|
|
1025
|
+
'audioSource': MolenAudioSourceData;
|
|
1026
|
+
/** 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). */
|
|
1027
|
+
'audioZone': MolenAudioZoneData;
|
|
810
1028
|
/** Kinematic character controller state (speed/jump/gravity + kernel-owned vy/grounded). */
|
|
811
1029
|
'character': MolenCharacterData;
|
|
812
1030
|
/** 2.5D kinematic collider (circle or XZ AABB) with layer/mask bitmasks. */
|
|
@@ -895,7 +1113,7 @@ type MolenComponentName = keyof MolenComponentData;
|
|
|
895
1113
|
type MolenComponentPatch = { [K in MolenComponentName]?: MolenComponentData[K] };
|
|
896
1114
|
|
|
897
1115
|
/** 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 & {});
|
|
1116
|
+
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
1117
|
/** Prefab names declared in the scene. */
|
|
900
1118
|
type MolenPrefabName = 'box' | 'cylinder' | 'seed' | 'sphere' | (string & {});
|
|
901
1119
|
/** Registry type ids this project declares (`molen.spawnType`). */
|
|
@@ -1028,6 +1246,29 @@ interface MolenMath {
|
|
|
1028
1246
|
cbrt(...args: number[]): number;
|
|
1029
1247
|
}
|
|
1030
1248
|
|
|
1249
|
+
/** Options for `molen.audio.play`. Omit entity and position for a non-positional sound. */
|
|
1250
|
+
interface MolenAudioPlayOptions {
|
|
1251
|
+
/** Play at (and follow) this entity's transform. */
|
|
1252
|
+
entity?: MolenEntityId;
|
|
1253
|
+
/** Play at a fixed world position. */
|
|
1254
|
+
position?: MolenVec3;
|
|
1255
|
+
gain?: number;
|
|
1256
|
+
pitch?: number;
|
|
1257
|
+
bus?: string;
|
|
1258
|
+
/** Loop until stopped; default the sound's own loop flag. */
|
|
1259
|
+
loop?: boolean;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/** `molen.audio`: each call emits an `audio.*` event the client plays (guide/audio.md). */
|
|
1263
|
+
interface MolenAudioApi {
|
|
1264
|
+
/** Play a sound-bank id; returns a handle for `stop`. */
|
|
1265
|
+
play(sound: string, opts?: MolenAudioPlayOptions): string;
|
|
1266
|
+
/** Stop by handle, or every voice matching an entity and/or sound. */
|
|
1267
|
+
stop(target: string | { entity?: MolenEntityId; sound?: string }, fadeS?: number): void;
|
|
1268
|
+
/** Switch background music to a track or playlist; null stops it. */
|
|
1269
|
+
music(playlist: string | string[] | null, opts?: { crossfadeS?: number }): void;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1031
1272
|
/** The verb set injected into every scene-data script as `molen`. */
|
|
1032
1273
|
interface MolenApi {
|
|
1033
1274
|
/** Spawn from a component map. */
|
|
@@ -1084,6 +1325,8 @@ interface MolenApi {
|
|
|
1084
1325
|
handler: (payload: MolenCommands[T], ctx: MolenTickContext, command: MolenCommand) => void,
|
|
1085
1326
|
): MolenUnsubscribe;
|
|
1086
1327
|
emit(type: string, payload?: MolenJsonValue): void;
|
|
1328
|
+
/** Sound: play/stop one-shots and loops, switch music. Never affects the simulation. */
|
|
1329
|
+
readonly audio: MolenAudioApi;
|
|
1087
1330
|
raycast(origin: MolenVec3, dir: MolenVec3, maxDist: number, mask?: number): MolenRayHit | null;
|
|
1088
1331
|
overlapCircle(center: MolenVec3, radius: number, mask?: number): string[];
|
|
1089
1332
|
/** 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
|
+
}
|
|
@@ -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:
|
|
41
|
+
'sha256:cb40e56449dcc4916b0f80b3dd33fe2783f4105f87259f5d47f70642cb91c58e',
|
|
42
42
|
);
|
|
43
43
|
});
|
|
44
44
|
|
|
@@ -37,9 +37,9 @@ npm test
|
|
|
37
37
|
|
|
38
38
|
`test/headless.test.ts` proves the seed is deterministic (identical heightmap twice), walks a 9x9 grid of `raycastDown` samples that must all sit inside the declared height range with the island centre above its edge, and meshes all sixteen chunks through `buildChunkGeometry` to more than 10,000 triangles.
|
|
39
39
|
|
|
40
|
-
In the engine repository, `test/golden/flyover.golden.test.ts` renders the island with `screenshotScene` and a `terrain: { descriptor, heightmapPng }` input — zero entities, 512x288, `FLYOVER_CAMERA`, more than 50,000 triangles after distance LOD — and
|
|
40
|
+
In the engine repository, `test/golden/flyover.golden.test.ts` renders the island with `screenshotScene` and a `terrain: { descriptor, heightmapPng }` input — zero entities, 512x288, `FLYOVER_CAMERA`, more than 50,000 triangles after distance LOD — and checks the frame with `frameStats` rather than a reference image: open sky across the top, the island's lit green slopes filling the lower middle.
|
|
41
41
|
|
|
42
|
-
There is no pinned state hash and no replay fixture: nothing in this sample is simulated. `molen shot` can render it too, but it needs both a scene to hang the terrain on and a heightmap already on disk (`--terrain terrain.json --heightmap <png>`), which is why the
|
|
42
|
+
There is no pinned state hash and no replay fixture: nothing in this sample is simulated. `molen shot` can render it too, but it needs both a scene to hang the terrain on and a heightmap already on disk (`--terrain terrain.json --heightmap <png>`), which is why the render test generates the PNG in process instead.
|
|
43
43
|
|
|
44
44
|
In the engine repository this sample lives in `examples/terrain-flyover/`. The same commands run from
|
|
45
45
|
that directory, and `pnpm --filter @bendyline/molen-examples-terrain-flyover test:unit` (or `test:golden`) runs its tests from the
|
|
@@ -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
|
|
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:
|
|
@@ -45,7 +58,7 @@ npm test
|
|
|
45
58
|
|
|
46
59
|
This sample carries **both** determinism artifacts, and they do different jobs. `test/headless.test.ts` pins a state hash at 90 ticks (through `runHeadless`, which is not the hash `sim run` prints) next to spawn, movement-stopped-by-wall, payload-rejection and contact-damage checks. `arena-skirmish.replay.json` freezes a recorded run — four `move` commands, 150 ticks, 45 events, per-tick reference hashes — and `test/replay.test.ts` replays it as part of `npm test`, so a behaviour drift reports the first divergent tick instead of only "the hash moved". Re-record an intentional change with `molen replay <fixture> --record`.
|
|
47
60
|
|
|
48
|
-
In the engine repository, three
|
|
61
|
+
In the engine repository, three render tests cover the visuals (golden tests stay there; a template copy does not include them): the scene's own ortho camera block (`arena-ortho`), an angled top-down camera (`arena`), and a **played** scenario (`drive`) that walks the player east through `driveScene` while enemies spawn, asserting on the outcome and on two captured frames. None compares against a reference image: `frameStats` checks that the green player sits in the middle of the view (and has left it after the drive) and that walls and enemies surround it.
|
|
49
62
|
|
|
50
63
|
In the engine repository this sample lives in `examples/top-down-arena/`. The same commands run from
|
|
51
64
|
that directory, and `pnpm --filter @bendyline/molen-examples-top-down-arena test:unit` (or `test:golden`) runs its tests from the
|