@adatechnology/game-destruction-three 0.5.0 → 0.6.0

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 CHANGED
@@ -7,7 +7,7 @@ physics, loose pieces after a part comes off, and pooled particles (fire, smoke,
7
7
  - Nothing is changed in place: geometry and materials are cloned on the first visual change of a mesh, and `restore` / `clear` give the originals back.
8
8
  - Blasts and the fires of burning parts are drawn by the effects world of [`@adatechnology/game-vfx`](../game-vfx) (an `explode` event plays `ev.effect ?? 'generic'`, scaled by the radius when it names none). Pass the world the host shares in `vfx`; without it the renderer makes its own world and its own `game-vfx-three` layer and steps them in `update`. Debris, sparks, drips and leaks still use two pooled `THREE.Points` (additive and normal blending), with a soft sprite computed in the shader (no texture asset); they move to the shared sprite pool when `game-vfx` gets one.
9
9
  - `three` is a peer dependency used for types only: you pass your own `THREE` instance at runtime.
10
- - Sounds are not played: you get keys (`impact_metal`, `shatter_glass`, ...) through `onSound`.
10
+ - The renderer plays nothing: you get keys (`impact_metal`, `shatter_glass`, `burn_loop`, `burn_end`, ...) through `onSound`. `createDestructionSound(engine)` is the sound bank for them on a [`@adatechnology/game-audio`](../game-audio) engine: the Cena de Arte's material sounds (clang, wood, glass, crumble, thud, boom...) and the game's explosion thump, a fire loop that follows how many parts burn, and a key table (`style: 'art_scene' | 'game'`, `keys` to replace) so a game changes what each key plays.
11
11
 
12
12
  Contracts live in [`@adatechnology/game-contracts`](../game-contracts); the types are re-exported here, so existing imports keep working.
13
13
 
@@ -155,7 +155,7 @@ heatColor(temperatureC: number): number // 0xRRGGBB, 0 below ~450 C, dark red ~5
155
155
  Renderizador three.js para o `@adatechnology/game-destruction`. O núcleo decide o que cada golpe faz e devolve eventos; este pacote desenha: amassados
156
156
  nos vértices, furos de bala e rachaduras, carbonização e brilho de calor, derretimento e poças, fragmentos com física leve, peças soltas e partículas
157
157
  em pool (fogo, fumaça, faíscas, poeira, cacos, lascas). Geometria e materiais só são clonados na primeira mudança visual de uma malha, e `restore` /
158
- `clear` devolvem os originais. Os sons não são tocados: o jogo recebe chaves (`impact_metal`, `shatter_glass`, ...) em `onSound`.
158
+ `clear` devolvem os originais. O renderer não toca nada: o jogo recebe chaves (`impact_metal`, `shatter_glass`, `burn_loop`, `burn_end`, ...) em `onSound`; `createDestructionSound(engine)` é o banco de sons delas no `game-audio` (sons dos materiais da Cena de Arte, o estouro do jogo, o laço de fogo e a tabela chave → som, trocável).
159
159
 
160
160
  Uso: `specFromObject3D(THREE, modelo)` gera a especificação e o mapa parte -> malhas; registre no mundo com `world.add(spec)`, ligue com
161
161
  `renderer.bind(id, modelo, { parts })` e chame `world.update(dt)` e `renderer.update(dt)` a cada quadro. Com `quality: 'low'` os orçamentos de
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import * as THREE_NS from 'three';
2
2
  import { Vec3, DebrisKind, DestructionWorld, MaterialId, DestructibleSpec } from '@adatechnology/game-destruction';
3
3
  export { Quat, Vec3 } from '@adatechnology/game-destruction';
4
4
  import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
5
+ import { LoopRecipe, SoundBank, SoundRecipe, AudioEngine } from '@adatechnology/game-audio';
6
+ import { Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
5
7
 
6
8
  /**
7
9
  * Public types of @adatechnology/game-destruction-three.
@@ -34,7 +36,7 @@ interface RendererOptions {
34
36
  autoSplit?: boolean;
35
37
  /** Called when a loose piece is created (the bench registers it as grabbable). */
36
38
  onPiece?: (piece: Piece) => void;
37
- /** Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). */
39
+ /** Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). `burn_loop` is sent when a part starts to burn and `burn_end` when it burns out or is put out. */
38
40
  onSound?: (key: string, point: Vec3, volume: number) => void;
39
41
  /**
40
42
  * The effects world that draws blasts and fires. Pass the one the host shares with the other renderers (and step it, through its
@@ -187,7 +189,70 @@ declare function specFromObject3D(THREE: ThreeNamespace, root: Object3D, options
187
189
  */
188
190
  declare function heatColor(temperatureC: number): number;
189
191
 
192
+ /** The art scene's destruction sounds, each with the team name in its `sources`. */
193
+ declare const SCENE_SOUNDS: readonly SoundRecipe[];
194
+ /** The game's explosion thump: a sine from 70 to 28 Hz over 1.2 s, `1.4 / (1 + d² × 0.002)` (jogo L68278). */
195
+ declare const EXPLOSION_BOOM: SoundRecipe;
196
+ /**
197
+ * The fire loop of the art scene (cena L1316): noise through a 1800 Hz bandpass (Q 0.6) into a gain that starts at 0. The page never raises it, so it is
198
+ * silent there; here `createDestructionSound` raises it while something burns (the level is the kit's, in `fire`).
199
+ */
200
+ declare const BURN_LOOP: LoopRecipe;
201
+ declare const DESTRUCTION_SOUND_BANK: SoundBank;
202
+
203
+ /**
204
+ * What a sound key plays: the recipe, its params, a scale on the volume the renderer gives, and (optionally) a louder recipe above a volume
205
+ * (a big blast gets the long boom).
206
+ */
207
+ type SoundKeyRule = {
208
+ readonly sound: string;
209
+ readonly params?: Readonly<Record<string, number>>;
210
+ readonly volumeScale?: number;
211
+ readonly above?: {
212
+ readonly volume: number;
213
+ readonly sound: string;
214
+ };
215
+ };
216
+ type DestructionSoundStyle = 'art_scene' | 'game';
217
+ /**
218
+ * The keys `createDestructionRenderer` sends to `onSound`, mapped to the sounds the teams delivered. The Cena de Arte has a sound for every material
219
+ * (clang, wood, glass, crumble, thud...); the game has four classes (impact, glass, wood, explosion) and its own explosion thump. Which team sound answers
220
+ * which key is the kit's choice (the teams call the sounds, not the renderer's keys), so it is data: `keys` replaces any entry.
221
+ */
222
+ declare const DESTRUCTION_SOUND_KEYS: Readonly<Record<DestructionSoundStyle, Readonly<Record<string, SoundKeyRule>>>>;
223
+ type DestructionSoundOptions = {
224
+ /** Which team answers the keys (default `art_scene`, the kit mix). `game` falls back to the art scene for the keys the game has no sound for. */
225
+ readonly style?: DestructionSoundStyle;
226
+ /** Replaces or adds a key's rule; `null` silences it. */
227
+ readonly keys?: Readonly<Record<string, SoundKeyRule | null>>;
228
+ /** The fire loop: the volume each burning part adds and the most it reaches (the page never raises it, so these are the kit's). */
229
+ readonly fire?: {
230
+ readonly perFire?: number;
231
+ readonly max?: number;
232
+ };
233
+ /** Burn loop on or off (default on). */
234
+ readonly burnLoop?: boolean;
235
+ };
236
+ type DestructionSound = {
237
+ /** Pass to `createDestructionRenderer({ onSound })`. */
238
+ readonly onSound: (key: string, point: Vec3$1, volume: number) => void;
239
+ /** The rule a key resolves to, if any. */
240
+ rule(key: string): SoundKeyRule | undefined;
241
+ /** Parts burning now. */
242
+ readonly burning: () => number;
243
+ dispose(): void;
244
+ };
245
+ declare const DEFAULT_FIRE: {
246
+ readonly perFire: 0.05;
247
+ readonly max: 0.2;
248
+ };
249
+ /**
250
+ * Plays the renderer's sound keys on a game-audio engine: the bank is registered in the engine, a key becomes a positional sound at the point, and
251
+ * `burn_loop` / `burn_end` (a part starts to burn, a part burns out or is put out) drive one fire loop whose volume follows how many parts burn.
252
+ */
253
+ declare function createDestructionSound(engine: AudioEngine, options?: DestructionSoundOptions): DestructionSound;
254
+
190
255
  /** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
191
256
  type ParticleKind = SpriteKind;
192
257
 
193
- export { type BindOptions, type DestructionRenderer, type ExplodeOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, heatColor, specFromObject3D };
258
+ export { BURN_LOOP, type BindOptions, DEFAULT_FIRE, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, SCENE_SOUNDS, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, createDestructionSound, heatColor, specFromObject3D };
@@ -23,7 +23,14 @@ var GameDestructionThree = (() => {
23
23
  // src/index.ts
24
24
  var index_exports = {};
25
25
  __export(index_exports, {
26
+ BURN_LOOP: () => BURN_LOOP,
27
+ DEFAULT_FIRE: () => DEFAULT_FIRE,
28
+ DESTRUCTION_SOUND_BANK: () => DESTRUCTION_SOUND_BANK,
29
+ DESTRUCTION_SOUND_KEYS: () => DESTRUCTION_SOUND_KEYS,
30
+ EXPLOSION_BOOM: () => EXPLOSION_BOOM,
31
+ SCENE_SOUNDS: () => SCENE_SOUNDS,
26
32
  createDestructionRenderer: () => createDestructionRenderer,
33
+ createDestructionSound: () => createDestructionSound,
27
34
  heatColor: () => heatColor,
28
35
  specFromObject3D: () => specFromObject3D
29
36
  });
@@ -5284,9 +5291,9 @@ var GameDestructionThree = (() => {
5284
5291
  this.color[i3] = lerp4(this.rgbStart[i3], this.rgbEnd[i3], t);
5285
5292
  this.color[i3 + 1] = lerp4(this.rgbStart[i3 + 1], this.rgbEnd[i3 + 1], t);
5286
5293
  this.color[i3 + 2] = lerp4(this.rgbStart[i3 + 2], this.rgbEnd[i3 + 2], t);
5287
- let envelope = t < def.fadeIn ? t / def.fadeIn : 1 - (t - def.fadeIn) / (1 - def.fadeIn);
5288
- if (def.flicker) envelope *= 1 - def.flicker * (0.5 + 0.5 * Math.sin(age * 38 + this.seed[i] * 50));
5289
- this.alpha[i] = clamp4(envelope, 0, 1) * def.alpha * this.alphaMul[i];
5294
+ let envelope2 = t < def.fadeIn ? t / def.fadeIn : 1 - (t - def.fadeIn) / (1 - def.fadeIn);
5295
+ if (def.flicker) envelope2 *= 1 - def.flicker * (0.5 + 0.5 * Math.sin(age * 38 + this.seed[i] * 50));
5296
+ this.alpha[i] = clamp4(envelope2, 0, 1) * def.alpha * this.alphaMul[i];
5290
5297
  top = i + 1;
5291
5298
  }
5292
5299
  this.high = top;
@@ -8143,9 +8150,9 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
8143
8150
  // src/ground.ts
8144
8151
  var MAX_RADIUS = 1.2;
8145
8152
  var GroundSpots = class {
8146
- constructor(THREE, scene, groundAt, cap) {
8153
+ constructor(THREE, scene2, groundAt, cap) {
8147
8154
  __publicField(this, "THREE", THREE);
8148
- __publicField(this, "scene", scene);
8155
+ __publicField(this, "scene", scene2);
8149
8156
  __publicField(this, "groundAt", groundAt);
8150
8157
  __publicField(this, "cap", cap);
8151
8158
  __publicField(this, "spots", []);
@@ -8547,9 +8554,9 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
8547
8554
 
8548
8555
  // src/rebar.ts
8549
8556
  var RebarCages = class {
8550
- constructor(THREE, scene, radius = 4e-3) {
8557
+ constructor(THREE, scene2, radius = 4e-3) {
8551
8558
  __publicField(this, "THREE", THREE);
8552
- __publicField(this, "scene", scene);
8559
+ __publicField(this, "scene", scene2);
8553
8560
  __publicField(this, "cages", /* @__PURE__ */ new Map());
8554
8561
  __publicField(this, "geometry");
8555
8562
  __publicField(this, "material");
@@ -10413,10 +10420,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10413
10420
  const sy = lerp5(1, 0.25, melt);
10414
10421
  const sxz = 1 + 0.18 * melt;
10415
10422
  for (let i = range[0] * 3, v = 0; i < range[1] * 3; i += 3, v++) {
10416
- const noise = (Math.imul(v + 1, 2654435761) >>> 0) % 1e3 / 1e3;
10423
+ const noise2 = (Math.imul(v + 1, 2654435761) >>> 0) % 1e3 / 1e3;
10417
10424
  arr[i] = cx + (work[i] - cx) * sxz;
10418
10425
  arr[i + 2] = cz + (work[i + 2] - cz) * sxz;
10419
- arr[i + 1] = Math.max(minY, minY + (work[i + 1] - minY) * sy - noise * melt * h * 0.04);
10426
+ arr[i + 1] = Math.max(minY, minY + (work[i + 1] - minY) * sy - noise2 * melt * h * 0.04);
10420
10427
  }
10421
10428
  }
10422
10429
  /** The colour attribute of the host's current geometry (created white when there is none) with vertex colours switched on in its material. */
@@ -10741,6 +10748,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10741
10748
  __publicField(this, "cages");
10742
10749
  __publicField(this, "active", /* @__PURE__ */ new Map());
10743
10750
  __publicField(this, "fires", /* @__PURE__ */ new Map());
10751
+ /** Primed parts burning in the effects world until they go off: their burn loop ends when they are put out. */
10752
+ __publicField(this, "primedBurning", /* @__PURE__ */ new Set());
10744
10753
  __publicField(this, "leaks", []);
10745
10754
  __publicField(this, "homeTags", []);
10746
10755
  __publicField(this, "throttles", /* @__PURE__ */ new Map());
@@ -11082,8 +11091,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
11082
11091
  case "primed":
11083
11092
  if (ev.trigger !== "explosion") {
11084
11093
  this.vfx.fire({ point: ev.point, radius: PRIMED_FIRE_RADIUS, life: ev.delay });
11094
+ this.primedBurning.add(`${ev.object}|${ev.part}`);
11085
11095
  this.activate(ev.object, ev.part);
11086
11096
  this.sound("ignite", ev.point, 0.7);
11097
+ this.sound("burn_loop", ev.point, 0.5);
11087
11098
  }
11088
11099
  break;
11089
11100
  case "spall":
@@ -11101,16 +11112,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
11101
11112
  break;
11102
11113
  case "extinguish": {
11103
11114
  const f = this.fires.get(`${ev.object}|${ev.part}`);
11115
+ const primed = this.primedBurning.delete(`${ev.object}|${ev.part}`);
11104
11116
  if (f) {
11105
11117
  this.stopFire(`${ev.object}|${ev.part}`);
11106
11118
  this.vfx.burst("steam", f.point, [0, 1, 0], 14, 1.2);
11107
11119
  }
11120
+ if (f || primed) this.sound("burn_end", f?.point ?? this.rootPoint(ev.object), 0.5);
11108
11121
  this.activate(ev.object, ev.part);
11109
11122
  this.sound("extinguish", f?.point ?? this.rootPoint(ev.object), 0.6);
11110
11123
  break;
11111
11124
  }
11112
11125
  case "burnout": {
11113
11126
  this.stopFire(`${ev.object}|${ev.part}`);
11127
+ this.primedBurning.delete(`${ev.object}|${ev.part}`);
11128
+ this.sound("burn_end", ev.point, 0.5);
11114
11129
  this.vfx.burst("ash", ev.point, [0, 1, 0], 16, 1);
11115
11130
  this.vfx.burst("smoke", ev.point, [0, 1, 0], 6, 0.8, { color: SMOKE_TONES.grey });
11116
11131
  const pv = this.partVis(ev.object, ev.part);
@@ -11152,6 +11167,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
11152
11167
  break;
11153
11168
  }
11154
11169
  case "explode":
11170
+ this.primedBurning.delete(`${ev.object}|${ev.part}`);
11155
11171
  this.onExplode(ev);
11156
11172
  break;
11157
11173
  case "destroyed":
@@ -11642,6 +11658,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
11642
11658
  this.fragments.clear();
11643
11659
  this.ground.clear();
11644
11660
  this.cages.clear();
11661
+ this.primedBurning.clear();
11645
11662
  this.vfx.sprites().clear();
11646
11663
  this.ownVfx?.world.clear();
11647
11664
  }
@@ -11670,6 +11687,325 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
11670
11687
  this.disposed = true;
11671
11688
  }
11672
11689
  };
11690
+
11691
+ // ../game-audio/dist/index.js
11692
+ var DISTANCE_CURVES = {
11693
+ /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
11694
+ game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
11695
+ /** The game's `grito`: `1 / (1 + d² × 0.006)`, silent below 0.02 (jogo L62129–62130). */
11696
+ game_scream: { model: "inverse_square", k: 6e-3, minGain: 0.02 },
11697
+ /** The game's `voz`: `1 / (1 + d² × 0.01)`, silent below 0.02 (jogo L62146–62147). */
11698
+ game_voice: { model: "inverse_square", k: 0.01, minGain: 0.02 },
11699
+ /** The game's `boom`: `1.4 / (1 + d² × 0.002)`, never silent (jogo L68280). */
11700
+ game_boom: { model: "inverse_square", k: 2e-3, scale: 1.4 },
11701
+ /** The art scene's `outAt`: `vol / (1 + d² × 0.008)` (cena L1320). */
11702
+ art_scene: { model: "inverse_square", k: 8e-3 },
11703
+ /** The game's animal calls: `max(0, 1 − d / 70) × 0.25`, silent at or below 0.005 (jogo L66627–66628). */
11704
+ animals: { model: "linear", range: 70, scale: 0.25, minGain: 5e-3 }
11705
+ };
11706
+ var mix_profiles_default = [
11707
+ {
11708
+ id: "game",
11709
+ master: 0.5,
11710
+ noise: { seconds: 1.5, create: "lazy" },
11711
+ sources: ["jogo:L62077-62081 master 0.5 to the output", "jogo:L62082-62088 noise 1.5 s made by the first sound that needs it"]
11712
+ },
11713
+ {
11714
+ id: "art_scene",
11715
+ master: 0.85,
11716
+ compressor: { threshold: -12, ratio: 5 },
11717
+ reverb: { seconds: 2.2, decay: 3.4, wet: 0.4 },
11718
+ noise: { seconds: 2, create: "eager" },
11719
+ sources: [
11720
+ "cena:L1308 compressor -12 dB, ratio 5",
11721
+ "cena:L1309 master 0.85",
11722
+ "cena:L1310 convolver, impulse 2.2 s of (1 - i/len)^3.4",
11723
+ "cena:L1311 wet 0.4",
11724
+ "cena:L1312 noise 2 s made with the chain"
11725
+ ]
11726
+ }
11727
+ ];
11728
+ var MIX_PROFILES = Object.fromEntries(
11729
+ mix_profiles_default.map((profile) => [profile.id, profile])
11730
+ );
11731
+ var game_sfx_default = {
11732
+ sources: ["jogo:L62089-62107"],
11733
+ note: "The game's sfx table P: [lowpass cutoff Hz, peak gain, seconds]. Played as a noise burst with the game's distance curve (falloff game_sfx) and a 0.05 s tail. Team names in `team`.",
11734
+ classes: [
11735
+ { id: "pistol", team: "pistola", bus: "weapons", cutoff: 1800, gain: 0.9, seconds: 0.18 },
11736
+ { id: "shotgun", team: "escopeta", bus: "weapons", cutoff: 900, gain: 1.2, seconds: 0.35 },
11737
+ { id: "rifle", team: "fuzil", bus: "weapons", cutoff: 1400, gain: 1.1, seconds: 0.28 },
11738
+ { id: "long_rifle", team: "rifle", bus: "weapons", cutoff: 1100, gain: 1.3, seconds: 0.45 },
11739
+ { id: "impact", team: "impacto", bus: "world", cutoff: 2500, gain: 0.25, seconds: 0.05 },
11740
+ { id: "flesh", team: "carne", bus: "world", cutoff: 600, gain: 0.35, seconds: 0.08 },
11741
+ { id: "step", team: "passo", bus: "world", cutoff: 400, gain: 0.08, seconds: 0.05 },
11742
+ { id: "glass", team: "vidro", bus: "world", cutoff: 5e3, gain: 0.5, seconds: 0.3 },
11743
+ { id: "wood", team: "madeira", bus: "world", cutoff: 700, gain: 0.5, seconds: 0.2 },
11744
+ { id: "reload", team: "recarga", bus: "weapons", cutoff: 3e3, gain: 0.15, seconds: 0.06 },
11745
+ { id: "empty", team: "vazio", bus: "weapons", cutoff: 4e3, gain: 0.12, seconds: 0.03 },
11746
+ { id: "explosion", team: "explosao", bus: "world", cutoff: 200, gain: 1.6, seconds: 1.4 }
11747
+ ],
11748
+ fallback: { id: "unknown", team: "(any other name)", bus: "world", cutoff: 1e3, gain: 0.5, seconds: 0.1 }
11749
+ };
11750
+ var GAME_SFX = game_sfx_default;
11751
+ var GAME_SFX_CLASSES = GAME_SFX.classes;
11752
+ var GAME_SFX_FALLBACK = GAME_SFX.fallback;
11753
+ function noiseClassRecipe(row, id = `sfx_${row.id}`) {
11754
+ return {
11755
+ id,
11756
+ bus: row.bus,
11757
+ order: "burst",
11758
+ duration: row.seconds,
11759
+ tail: 0.05,
11760
+ layers: [
11761
+ {
11762
+ source: { kind: "noise", offset: "random" },
11763
+ filters: { mode: "serial", bank: [{ type: "lowpass", frequency: { set: row.cutoff } }] },
11764
+ envelope: [
11765
+ [0, row.gain, "set"],
11766
+ ["1d", 1e-3, "exp", "fixed"]
11767
+ ]
11768
+ }
11769
+ ],
11770
+ falloff: DISTANCE_CURVES.game_sfx,
11771
+ sources: [...GAME_SFX.sources.map((source) => `${source} ${row.team}`)]
11772
+ };
11773
+ }
11774
+ var GAME_SFX_BANK = { id: "game_sfx", sounds: [...GAME_SFX_CLASSES, GAME_SFX_FALLBACK].map((row) => noiseClassRecipe(row)) };
11775
+ var BENCH_BANK = {
11776
+ id: "audio_bench",
11777
+ sounds: [
11778
+ {
11779
+ id: "bench_ping",
11780
+ bus: "ui",
11781
+ pan: true,
11782
+ duration: 0.25,
11783
+ layers: [
11784
+ {
11785
+ gain: 0.5,
11786
+ wet: 0.3,
11787
+ source: { kind: "osc", wave: "sine", frequency: { from: 880 } },
11788
+ envelope: [
11789
+ [0, 1e-4, "set", "fixed"],
11790
+ [2e-3, 1, "exp"],
11791
+ ["1d", 1e-4, "exp", "fixed"]
11792
+ ]
11793
+ }
11794
+ ],
11795
+ falloff: DISTANCE_CURVES.art_scene,
11796
+ sources: ["sdk: bench probe, a 880 Hz ping through the art scene output stage"]
11797
+ },
11798
+ {
11799
+ id: "bench_hiss",
11800
+ bus: "ui",
11801
+ pan: true,
11802
+ duration: [0.3, 0.9],
11803
+ layers: [
11804
+ {
11805
+ gain: 0.4,
11806
+ source: { kind: "noise", offset: "random", offsetScale: 1.5, loop: true },
11807
+ filters: { mode: "serial", bank: [{ type: "highpass", frequency: { set: 3e3 }, q: 0.7 }] },
11808
+ envelope: [
11809
+ [0, 1e-4, "set", "fixed"],
11810
+ [2e-3, 1, "exp"],
11811
+ ["1d", 1e-4, "exp", "fixed"]
11812
+ ]
11813
+ }
11814
+ ],
11815
+ falloff: DISTANCE_CURVES.art_scene,
11816
+ sources: ["sdk: bench probe, a highpass hiss of random length"]
11817
+ }
11818
+ ]
11819
+ };
11820
+
11821
+ // src/audio/recipes.ts
11822
+ var ATTACK = 2e-3;
11823
+ var lengthOf = (d, attack) => {
11824
+ if (typeof d === "number") return attack + d;
11825
+ if (Array.isArray(d)) return [attack + d[0], attack + d[1]];
11826
+ return { ...d, add: (d.add ?? 0) + attack };
11827
+ };
11828
+ var envelope = (attack) => [
11829
+ [0, 1e-4, "set", "fixed"],
11830
+ [attack, 1, "exp"],
11831
+ ["1d", 1e-4, "exp", "fixed"]
11832
+ ];
11833
+ function noise(o) {
11834
+ const a = o.a ?? ATTACK;
11835
+ const over = typeof o.d === "number" ? o.d : 0;
11836
+ return {
11837
+ filters: {
11838
+ mode: "serial",
11839
+ bank: [{ type: o.type ?? "lowpass", frequency: o.f2 === void 0 ? { set: o.f } : { set: o.f, to: o.f2, curve: "exp", over }, q: o.q ?? 0.7 }]
11840
+ },
11841
+ duration: lengthOf(o.d, a),
11842
+ gain: o.vol,
11843
+ ...o.delay === void 0 ? {} : { at: o.delay },
11844
+ ...o.wet === void 0 ? {} : { wet: o.wet },
11845
+ source: { kind: "noise", offset: "random", offsetScale: 1.5, loop: true },
11846
+ envelope: envelope(a)
11847
+ };
11848
+ }
11849
+ function tone(o) {
11850
+ return {
11851
+ source: { kind: "osc", wave: o.wave ?? "sine", frequency: { from: o.f, to: o.f2 ?? "from", curve: "exp", over: "duration" } },
11852
+ duration: lengthOf(o.d, ATTACK),
11853
+ gain: o.vol,
11854
+ ...o.delay === void 0 ? {} : { at: o.delay },
11855
+ ...o.wet === void 0 ? {} : { wet: o.wet },
11856
+ envelope: envelope(ATTACK)
11857
+ };
11858
+ }
11859
+ var many = (count, make) => Array.from({ length: count }, make);
11860
+ var scene = (id, layers, line, vars) => ({
11861
+ id,
11862
+ bus: "world",
11863
+ pan: true,
11864
+ layers,
11865
+ falloff: DISTANCE_CURVES.art_scene,
11866
+ ...vars ? { vars } : {},
11867
+ sources: [`cena:${line}`]
11868
+ });
11869
+ var boomLayers = (big) => [
11870
+ noise({ f: 1200, f2: 120, d: 1.8, vol: 2, wet: 1.2 }),
11871
+ tone({ f: 65, f2: 24, d: 1, vol: 1.8 }),
11872
+ noise({ type: "highpass", f: 1500, d: 0.2, vol: 0.8 }),
11873
+ ...big ? [noise({ f: 500, f2: 90, a: 0.2, d: 2.4, vol: 1.2, wet: 1, delay: 0.15 })] : [],
11874
+ ...many(8, () => tone({ f: [2600, 5600], d: 0.05, vol: 0.08, delay: [0.4, 1.6] }))
11875
+ ];
11876
+ var SCENE_SOUNDS = [
11877
+ scene(
11878
+ "glass_shatter",
11879
+ [noise({ type: "highpass", f: 2800, d: 0.45, vol: 0.9, wet: 0.5 }), ...many(12, () => tone({ f: [3e3, 7500], d: [0.06, 0.14], vol: 0.18, delay: [0, 0.55] }))],
11880
+ "L1359 glass"
11881
+ ),
11882
+ scene(
11883
+ "wood_hit",
11884
+ [noise({ type: "bandpass", f: 850, q: 1, d: 0.25, vol: 0.9, wet: 0.3 }), tone({ f: 210, f2: 90, d: 0.1, vol: 0.6 }), noise({ type: "highpass", f: 2e3, d: 0.04, vol: 0.5 })],
11885
+ "L1360 wood"
11886
+ ),
11887
+ scene("thunk", [noise({ type: "bandpass", f: 700, q: 2, d: 0.07, vol: 0.4 })], "L1361 thunk"),
11888
+ scene("ping", [tone({ f: [2600, 3500], f2: 1400, d: 0.14, vol: 0.18, wet: 0.3 })], "L1362 ping"),
11889
+ scene("clang", [tone({ f: [520, 720], f2: 480, d: 0.5, vol: 0.35, wet: 0.4 }), tone({ f: 1370, f2: 1300, d: 0.3, vol: 0.15 }), noise({ type: "highpass", f: 2e3, d: 0.05, vol: 0.5 })], "L1363 clang"),
11890
+ scene("chip", [noise({ type: "bandpass", f: 1600, q: 1.2, d: 0.06, vol: 0.5 })], "L1364 chip"),
11891
+ scene(
11892
+ "crumble",
11893
+ [noise({ f: 900, f2: 200, d: 0.6, vol: 0.9, wet: 0.3 }), ...many(5, () => noise({ type: "bandpass", f: [500, 1400], q: 2, d: 0.05, vol: 0.4, delay: [0.1, 0.5] }))],
11894
+ "L1365 crumble"
11895
+ ),
11896
+ // `thud(x, z, v)`: `v` is the `scale` param (default 1)
11897
+ scene("thud", [tone({ f: 75, f2: 38, d: 0.22, vol: { param: "scale", scale: 0.6 } }), noise({ f: 420, d: 0.16, vol: { param: "scale", scale: 0.45 } })], "L1358 thud", { scale: 1 }),
11898
+ // `hiss(x, z, d)`: `seconds` is the param `d` (default 1.2)
11899
+ scene("hiss", [noise({ type: "highpass", f: 3500, a: 0.05, d: { param: "seconds" }, vol: 0.35 })], "L1366 hiss", { seconds: 1.2 }),
11900
+ scene("boom", boomLayers(false), "L1367 boom"),
11901
+ scene("boom_big", boomLayers(true), "L1367 boom (big)"),
11902
+ scene("burst", [noise({ f: 700, f2: 120, d: 0.7, vol: 1.4, wet: 0.5 }), noise({ type: "highpass", f: 3e3, a: 0.05, d: 1.2, vol: 0.4, delay: 0.1 })], "L1357 burst"),
11903
+ scene("crack", [noise({ type: "highpass", f: 1800, d: 0.05, vol: 0.8 }), tone({ f: 420, f2: 180, d: 0.06, vol: 0.4 })], "L1354 crack")
11904
+ ];
11905
+ var EXPLOSION_BOOM = {
11906
+ id: "explosion_boom",
11907
+ bus: "world",
11908
+ order: "boom",
11909
+ duration: 1.6,
11910
+ tail: 0.1,
11911
+ layers: [
11912
+ {
11913
+ source: { kind: "osc", wave: "sine", frequency: { from: 70, to: 28, curve: "exp", over: 1.2 } },
11914
+ envelope: [
11915
+ [0, 1, "set"],
11916
+ ["1d", 1e-3, "exp", "fixed"]
11917
+ ]
11918
+ }
11919
+ ],
11920
+ falloff: DISTANCE_CURVES.game_boom,
11921
+ sources: ["jogo:L68278-68285 boom"]
11922
+ };
11923
+ var BURN_LOOP = {
11924
+ id: "burn_loop",
11925
+ bus: "world",
11926
+ order: "chain_loop",
11927
+ source: { kind: "noise", loop: true },
11928
+ filters: { mode: "serial", bank: [{ type: "bandpass", frequency: { set: 1800 }, q: 0.6 }] },
11929
+ volume: 0,
11930
+ sources: ["cena:L1316 fire loop (silent in the page: its gain is never raised)", "sdk: the level while burning"]
11931
+ };
11932
+ var DESTRUCTION_SOUND_BANK = { id: "destruction_three", sounds: [...SCENE_SOUNDS, EXPLOSION_BOOM], loops: [BURN_LOOP] };
11933
+
11934
+ // src/audio/sound.ts
11935
+ var DESTRUCTION_SOUND_KEYS = {
11936
+ art_scene: {
11937
+ impact_metal: { sound: "clang" },
11938
+ impact_wood: { sound: "wood_hit" },
11939
+ impact_glass: { sound: "ping" },
11940
+ impact_masonry: { sound: "chip" },
11941
+ impact_soft: { sound: "thud" },
11942
+ shatter_glass: { sound: "glass_shatter" },
11943
+ crumble: { sound: "crumble" },
11944
+ splinter: { sound: "crack" },
11945
+ ricochet: { sound: "ping" },
11946
+ unscrew: { sound: "chip" },
11947
+ detach: { sound: "thunk" },
11948
+ ignite: { sound: "hiss", params: { seconds: 0.5 } },
11949
+ extinguish: { sound: "hiss" },
11950
+ melt_sizzle: { sound: "hiss", params: { seconds: 0.6 } },
11951
+ explode: { sound: "boom", above: { volume: 0.9, sound: "boom_big" } }
11952
+ },
11953
+ game: {
11954
+ impact_metal: { sound: "sfx_impact" },
11955
+ impact_wood: { sound: "sfx_wood" },
11956
+ impact_glass: { sound: "sfx_glass" },
11957
+ impact_masonry: { sound: "sfx_impact" },
11958
+ impact_soft: { sound: "sfx_flesh" },
11959
+ shatter_glass: { sound: "sfx_glass" },
11960
+ crumble: { sound: "sfx_impact" },
11961
+ splinter: { sound: "sfx_wood" },
11962
+ explode: { sound: "explosion_boom" }
11963
+ }
11964
+ };
11965
+ var DEFAULT_FIRE = { perFire: 0.05, max: 0.2 };
11966
+ function createDestructionSound(engine, options = {}) {
11967
+ engine.register(DESTRUCTION_SOUND_BANK);
11968
+ engine.register(GAME_SFX_BANK);
11969
+ const fire = { ...DEFAULT_FIRE, ...options.fire };
11970
+ const rules = { ...DESTRUCTION_SOUND_KEYS.art_scene, ...options.style === "game" ? DESTRUCTION_SOUND_KEYS.game : {}, ...options.keys };
11971
+ let loop;
11972
+ let burning = 0;
11973
+ const setFire = () => {
11974
+ if (options.burnLoop === false) return;
11975
+ if (burning <= 0) {
11976
+ loop?.stop();
11977
+ loop = void 0;
11978
+ return;
11979
+ }
11980
+ loop ?? (loop = engine.loop("burn_loop"));
11981
+ loop.set({ volume: Math.min(fire.max, fire.perFire * burning) });
11982
+ };
11983
+ return {
11984
+ onSound(key, point, volume) {
11985
+ if (key === "burn_loop") {
11986
+ burning += 1;
11987
+ setFire();
11988
+ return;
11989
+ }
11990
+ if (key === "burn_end") {
11991
+ if (burning > 0) burning -= 1;
11992
+ setFire();
11993
+ return;
11994
+ }
11995
+ const rule = rules[key];
11996
+ if (!rule) return;
11997
+ const sound = rule.above && volume >= rule.above.volume ? rule.above.sound : rule.sound;
11998
+ engine.play(sound, { position: point, volume: volume * (rule.volumeScale ?? 1), ...rule.params ? { params: rule.params } : {} });
11999
+ },
12000
+ rule: (key) => rules[key] ?? void 0,
12001
+ burning: () => burning,
12002
+ dispose() {
12003
+ loop?.stop();
12004
+ loop = void 0;
12005
+ burning = 0;
12006
+ }
12007
+ };
12008
+ }
11673
12009
  return __toCommonJS(index_exports);
11674
12010
  })();
11675
12011
  //# sourceMappingURL=index.global.js.map