@adatechnology/game-weather 0.3.4 → 0.3.5

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.
@@ -962,6 +962,66 @@ var GameWeather = (() => {
962
962
  };
963
963
  }
964
964
  var sceneMany = (count, make) => Array.from({ length: count }, make);
965
+ var hz = (midi) => 440 * 2 ** ((midi - 69) / 12);
966
+ var layer = (note, beat, wave, level) => {
967
+ const [at, midi, beats] = note;
968
+ const length = beats * beat;
969
+ return {
970
+ at: at * beat,
971
+ duration: length,
972
+ source: { kind: "osc", wave, frequency: { set: hz(midi) } },
973
+ envelope: [[0, 1e-4, "set"], [0.01, level, "linear"], [Math.max(0.02, length * 0.9), level * 0.35, "linear"], [length, 1e-4, "exp", "fixed"]]
974
+ };
975
+ };
976
+ function radioTrack(spec) {
977
+ const beat = 60 / spec.bpm;
978
+ const recipes = Array.from({ length: spec.bars }, (_, bar) => {
979
+ const inBar = (notes) => notes.filter((n) => n[0] >= bar * 4 && n[0] < bar * 4 + 4).map((n) => [n[0] - bar * 4, n[1], n[2]]);
980
+ const layers = [
981
+ ...inBar(spec.bass).map((n) => layer(n, beat, "triangle", 0.16)),
982
+ ...inBar(spec.chords).map((n) => layer(n, beat, "sine", 0.05)),
983
+ ...inBar(spec.melody).map((n) => layer(n, beat, spec.wave, 0.07))
984
+ ];
985
+ return { id: `${spec.id}_${bar}`, bus: "world", duration: 4 * beat, layers, falloff: { model: "none" } };
986
+ });
987
+ return { song: { id: spec.id, barSeconds: 4 * beat, bars: recipes.map((r) => r.id) }, recipes };
988
+ }
989
+ var chord = (bar, root, minor = false) => [[bar * 4, root, 4], [bar * 4, root + (minor ? 3 : 4), 4], [bar * 4, root + 7, 4]];
990
+ var bassLine = (roots, pattern) => roots.flatMap((root, bar) => pattern.map((b) => [bar * 4 + b, root - 12, 0.9]));
991
+ var TRACKS = [
992
+ // a bright pop loop: I–V–vi–IV in C
993
+ radioTrack({
994
+ id: "radio_track_pop",
995
+ bpm: 112,
996
+ bars: 4,
997
+ wave: "square",
998
+ bass: bassLine([48, 55, 57, 53], [0, 1.5, 2, 3]),
999
+ chords: [...chord(0, 60), ...chord(1, 55), ...chord(2, 57, true), ...chord(3, 53)],
1000
+ melody: [[0, 76, 1], [1, 74, 0.5], [1.5, 72, 1.5], [4, 74, 1], [5, 76, 1], [6, 79, 2], [8, 76, 1], [9, 74, 1], [10, 72, 2], [12, 72, 1], [13, 74, 1], [14, 72, 2]]
1001
+ }),
1002
+ // a syncopated loop in A minor, the bass on the off-beats
1003
+ radioTrack({
1004
+ id: "radio_track_groove",
1005
+ bpm: 100,
1006
+ bars: 4,
1007
+ wave: "triangle",
1008
+ bass: bassLine([57, 62, 64, 57], [0, 0.75, 1.5, 2.5, 3.25]),
1009
+ chords: [...chord(0, 57, true), ...chord(1, 62, true), ...chord(2, 64), ...chord(3, 57, true)],
1010
+ melody: [[0.5, 72, 0.5], [1.25, 76, 0.75], [2.5, 74, 1], [4.5, 77, 0.5], [5.25, 74, 0.75], [6.5, 72, 1.5], [8.5, 71, 0.5], [9.25, 74, 0.75], [10.5, 76, 1.5], [12.5, 72, 0.5], [13.25, 69, 2]]
1011
+ }),
1012
+ // a slow blues-like loop in F with a swung melody
1013
+ radioTrack({
1014
+ id: "radio_track_slow",
1015
+ bpm: 76,
1016
+ bars: 4,
1017
+ wave: "sine",
1018
+ bass: bassLine([53, 58, 53, 60], [0, 2]),
1019
+ chords: [...chord(0, 65), ...chord(1, 58), ...chord(2, 65), ...chord(3, 60)],
1020
+ melody: [[0, 72, 1.5], [1.67, 75, 0.33], [2, 77, 2], [4, 74, 1], [5, 72, 1], [6, 70, 2], [8, 72, 1.5], [9.67, 69, 0.33], [10, 65, 2], [12, 67, 1], [13, 70, 1], [14, 72, 2]]
1021
+ })
1022
+ ];
1023
+ var RADIO_TRACKS = TRACKS.map((t) => t.song);
1024
+ var RADIO_BANK = { id: "vehicle_radio", sounds: TRACKS.flatMap((t) => t.recipes), loops: [] };
965
1025
  var FOLEY_FALLOFF = {
966
1026
  model: "inverse_square",
967
1027
  k: 0.02,
@@ -1568,11 +1628,11 @@ var GameWeather = (() => {
1568
1628
  ...s.splash ? [sceneNoise({ type: "bandpass", f: s.splash.f * take.f, f2: s.splash.f2 * take.f, q: 1.4, d: s.splash.d * take.t * weight ** 0.4, vol: s.splash.vol * gait.vol * take.v * weight ** 0.5 })] : []
1569
1629
  ];
1570
1630
  }
1571
- var quieter = (level, layers) => layers.map((layer) => {
1572
- const gain = layer.gain ?? 1;
1573
- if (typeof gain === "number") return { ...layer, gain: gain * level };
1574
- if (Array.isArray(gain)) return { ...layer, gain: [gain[0] * level, gain[1] * level] };
1575
- return layer;
1631
+ var quieter = (level, layers) => layers.map((layer2) => {
1632
+ const gain = layer2.gain ?? 1;
1633
+ if (typeof gain === "number") return { ...layer2, gain: gain * level };
1634
+ if (Array.isArray(gain)) return { ...layer2, gain: [gain[0] * level, gain[1] * level] };
1635
+ return layer2;
1576
1636
  });
1577
1637
  var recipe = (id, layers, falloff, bus = "world") => ({ id, bus, pan: true, layers, falloff, sources: ["sdk"] });
1578
1638
  var takeId = (id, index) => `${id}_${String(index + 1).padStart(2, "0")}`;
@@ -1588,7 +1648,7 @@ var GameWeather = (() => {
1588
1648
  (take) => quieter(LANDING_LEVEL, [
1589
1649
  // both feet, a hair apart, then the knees taking the weight (a low body thump) and the clothes settling
1590
1650
  ...footLayers(surface, take, GAITS.run, LANDINGS[landing2].weight),
1591
- ...footLayers(surface, { ...take, v: take.v * 0.6 }, GAITS.run, LANDINGS[landing2].weight * 0.6).map((layer) => ({ ...layer, at: (typeof layer.at === "number" ? layer.at : 0) + 0.018 * take.t })),
1651
+ ...footLayers(surface, { ...take, v: take.v * 0.6 }, GAITS.run, LANDINGS[landing2].weight * 0.6).map((layer2) => ({ ...layer2, at: (typeof layer2.at === "number" ? layer2.at : 0) + 0.018 * take.t })),
1592
1652
  sceneTone({ f: 60 * take.f, f2: 38, d: 0.14 * LANDINGS[landing2].weight * take.t, vol: 0.22 * LANDINGS[landing2].weight ** 0.7 * take.v, delay: 0.02 }),
1593
1653
  sceneNoise({ type: "bandpass", f: [1800, 2600], q: 0.8, d: 0.18, vol: LANDINGS[landing2].cloth * take.v, delay: 0.04 })
1594
1654
  ]),
@@ -1634,7 +1694,7 @@ var GameWeather = (() => {
1634
1694
  fall_damage: (take) => [
1635
1695
  ...BODY.body_fall(take),
1636
1696
  sceneNoise({ type: "highpass", f: 2800, d: 0.02, vol: 0.35 * take.v, delay: 0.01 }),
1637
- ...voice({ f0: 170, f1: 110, d: 0.32, fA: 650, fB: 1150, noise: 0.25, vol: 0.32 })(take).map((layer) => ({ ...layer, at: 0.08 }))
1697
+ ...voice({ f0: 170, f1: 110, d: 0.32, fA: 650, fB: 1150, noise: 0.25, vol: 0.32 })(take).map((layer2) => ({ ...layer2, at: 0.08 }))
1638
1698
  ],
1639
1699
  player_hurt: voice({ f0: 150, f1: 105, d: 0.26, fA: 620, fB: 1100, noise: 0.3, vol: 0.35 }),
1640
1700
  player_breath_run: (take) => [