@adatechnology/game-animals-three 0.1.3 → 0.2.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/dist/index.js CHANGED
@@ -698,6 +698,84 @@ var updateSplit = (rig, delta) => {
698
698
  });
699
699
  };
700
700
 
701
+ // src/audio/recipes.ts
702
+ import { DISTANCE_CURVES } from "@adatechnology/game-audio";
703
+ var call = (o) => ({
704
+ id: o.id,
705
+ bus: "world",
706
+ order: "calls",
707
+ duration: o.seconds,
708
+ tail: 0.02,
709
+ // the page makes its gain and filter before it looks at the level
710
+ keepSilent: true,
711
+ layers: [
712
+ {
713
+ repeat: { count: o.count, spacing: o.spacing },
714
+ source: { kind: "osc", wave: o.wave, frequency: { from: o.frequency, to: o.frequency * o.drop, curve: "exp", over: "duration" } },
715
+ filters: { mode: "serial", bank: [{ type: "bandpass", frequency: { set: o.frequency * 1.2 }, q: 3 }] },
716
+ envelope: [
717
+ [0, 1e-4, "set", "fixed"],
718
+ [0.015, 1, "exp"],
719
+ ["1d", 1e-4, "exp", "fixed"]
720
+ ]
721
+ }
722
+ ],
723
+ falloff: DISTANCE_CURVES.animals,
724
+ sources: [`jogo:L66625-66639 bichoSom('${o.team}')`]
725
+ });
726
+ var DOG_BARK = call({ id: "dog_bark", team: "latido", count: 2, spacing: 0.22, seconds: 0.12, wave: "square", frequency: 520, drop: 0.6 });
727
+ var LAPWING_CALL = call({ id: "lapwing_call", team: "queroquero", count: 3, spacing: 0.14, seconds: 0.09, wave: "square", frequency: 2400, drop: 0.6 });
728
+ var HEN_CLUCK = call({ id: "hen_cluck", team: "cacarejo", count: 4, spacing: 0.14, seconds: 0.09, wave: "square", frequency: 900, drop: 0.6 });
729
+ var COW_MOO = call({ id: "cow_moo", team: "mugido", count: 1, spacing: 0.14, seconds: 1.2, wave: "sawtooth", frequency: 140, drop: 0.8 });
730
+ var ANIMAL_SOUNDS = [DOG_BARK, LAPWING_CALL, HEN_CLUCK, COW_MOO];
731
+ var ANIMAL_SOUND_BANK = { id: "animals_three", sounds: ANIMAL_SOUNDS };
732
+
733
+ // src/audio/calls.json
734
+ var calls_default = {
735
+ sources: [
736
+ "jogo:L66677 galinha: cacarejo, 6 s between calls, noise 30 m",
737
+ "jogo:L66680 quero-quero: queroquero when the player is near (alarme), 8 s, noise 40 m",
738
+ "jogo:L66681 vaca: mugido, 30 s, noise 80 m",
739
+ "jogo:L66683 cachorro: latido when a zombie is within 12 m, 3 s, noise 60 m"
740
+ ],
741
+ species: {
742
+ chicken: { sound: "hen_cluck", cooldown: 6, noiseMetres: 30 },
743
+ southern_lapwing: { sound: "lapwing_call", cooldown: 8, noiseMetres: 40 },
744
+ cow: { sound: "cow_moo", cooldown: 30, noiseMetres: 80 },
745
+ dog: { sound: "dog_bark", cooldown: 3, noiseMetres: 60 }
746
+ }
747
+ };
748
+
749
+ // src/audio/sound.ts
750
+ var DATA = calls_default;
751
+ var ANIMAL_CALLS = DATA.species;
752
+ var ANIMAL_CALL_SOURCES = DATA.sources;
753
+ function createAnimalSound(sink, options = {}) {
754
+ sink.register?.(ANIMAL_SOUND_BANK);
755
+ const calls = { ...ANIMAL_CALLS, ...options.calls };
756
+ const waiting = /* @__PURE__ */ new Map();
757
+ const callOf = (speciesId) => calls[speciesId] ?? void 0;
758
+ return {
759
+ callOf,
760
+ call(speciesId, position, o = {}) {
761
+ const found = callOf(speciesId);
762
+ if (!found) return false;
763
+ const key = o.key ?? speciesId;
764
+ if ((waiting.get(key) ?? 0) > 0) return false;
765
+ waiting.set(key, found.cooldown);
766
+ sink.play({ sound: found.sound, position, ...o.volume === void 0 ? {} : { volume: o.volume } });
767
+ return true;
768
+ },
769
+ update(dt) {
770
+ for (const [key, seconds] of waiting) {
771
+ if (seconds - dt <= 0) waiting.delete(key);
772
+ else waiting.set(key, seconds - dt);
773
+ }
774
+ },
775
+ dispose: () => waiting.clear()
776
+ };
777
+ }
778
+
701
779
  // src/line-up.ts
702
780
  import { lineUpLength } from "@adatechnology/game-animals";
703
781
  var lineUpAnimals = (rigs, options = {}) => {
@@ -805,7 +883,7 @@ var TEXT = {
805
883
  time_scale: "Game seconds per real second for the bite timers (60: ten minutes pass in ten seconds)"
806
884
  },
807
885
  options: { visual_state: { alive: "Alive", infected: "Infected", dead: "Dead" }, gait: { idle: "Idle", walk: "Walk", run: "Run" } },
808
- actions: { bite_all: "Bite every animal", recover: "Heal every animal", skin_40: "Add 40 animals as node skins", clear_skins: "Remove the skins" },
886
+ actions: { bite_all: "Bite every animal", recover: "Heal every animal", call: "Make the animals with a call call (hen, lapwing, cow, dog)", skin_40: "Add 40 animals as node skins", clear_skins: "Remove the skins" },
809
887
  layers: { joints: "Joints", split: "Split view", sound_range: "Sound range", carcass_lure: "Carcass lure radius" },
810
888
  metrics: { animals: "Animals", draw_calls: "Draw calls", triangles: "Triangles", nodes_per_skin: "Nodes per skin", incubating: "Incubating", turned: "Turned", dead: "Dead" },
811
889
  scenarios: {
@@ -828,7 +906,7 @@ var TEXT = {
828
906
  time_scale: "Segundos de jogo por segundo real nos prazos da mordida (60: dez minutos passam em dez segundos)"
829
907
  },
830
908
  options: { visual_state: { alive: "Vivo", infected: "Infectado", dead: "Morto" }, gait: { idle: "Parado", walk: "Andando", run: "Correndo" } },
831
- actions: { bite_all: "Morder todos os bichos", recover: "Curar todos os bichos", skin_40: "P\xF4r 40 bichos como pele de n\xF3s", clear_skins: "Tirar as peles" },
909
+ actions: { bite_all: "Morder todos os bichos", recover: "Curar todos os bichos", call: "Fazer os bichos com chamado chamarem (galinha, quero-quero, vaca, cachorro)", skin_40: "P\xF4r 40 bichos como pele de n\xF3s", clear_skins: "Tirar as peles" },
832
910
  layers: { joints: "Juntas", split: "Vista aberta", sound_range: "Alcance do som", carcass_lure: "Raio de atra\xE7\xE3o da carca\xE7a" },
833
911
  metrics: { animals: "Bichos", draw_calls: "Chamadas de desenho", triangles: "Tri\xE2ngulos", nodes_per_skin: "N\xF3s por pele", incubating: "Incubando", turned: "Viraram", dead: "Morreram" },
834
912
  scenarios: {
@@ -857,6 +935,7 @@ function createAnimalsTestModule(options = {}) {
857
935
  let animals = null;
858
936
  let host = null;
859
937
  let outbreak = null;
938
+ let sound = null;
860
939
  let time = 0;
861
940
  let clock = 0;
862
941
  let skinGroup = null;
@@ -959,6 +1038,11 @@ function createAnimalsTestModule(options = {}) {
959
1038
  delete entry.counted;
960
1039
  animals?.setVisualState(entry.rig, settings.visual);
961
1040
  }
1041
+ } else if (change.id === "call" && sound) {
1042
+ for (const [id, entry] of placed) {
1043
+ const at = entry.rig.root.getWorldPosition(new three.Vector3());
1044
+ sound.call(entry.rig.species.id, [at.x, at.y + 0.5, at.z], { key: id });
1045
+ }
962
1046
  } else if (change.id === "skin_40") addSkins();
963
1047
  else if (change.id === "clear_skins") clearSkins();
964
1048
  return;
@@ -989,6 +1073,7 @@ function createAnimalsTestModule(options = {}) {
989
1073
  const frame = (dt) => {
990
1074
  time += dt * settings.speed;
991
1075
  clock += dt;
1076
+ sound?.update(dt);
992
1077
  for (const [id, entry] of placed) {
993
1078
  if (!entry.rig.root.parent) {
994
1079
  placed.delete(id);
@@ -1066,6 +1151,7 @@ function createAnimalsTestModule(options = {}) {
1066
1151
  { kind: "number", id: "time_scale", name: text.controls.time_scale, hint: text.hints.time_scale, min: 1, max: 600, step: 1, default: DEFAULT_TIME_SCALE },
1067
1152
  { kind: "action", id: "bite_all", name: text.actions.bite_all },
1068
1153
  { kind: "action", id: "recover", name: text.actions.recover },
1154
+ { kind: "action", id: "call", name: text.actions.call },
1069
1155
  { kind: "action", id: "skin_40", name: text.actions.skin_40 },
1070
1156
  { kind: "action", id: "clear_skins", name: text.actions.clear_skins }
1071
1157
  ],
@@ -1083,6 +1169,7 @@ function createAnimalsTestModule(options = {}) {
1083
1169
  attach(lent) {
1084
1170
  host = lent;
1085
1171
  ensure(lent.THREE);
1172
+ sound = lent.audio && options.sound !== false ? createAnimalSound(lent.audio, options.sound ?? {}) : null;
1086
1173
  const stopChange = lent.bench?.onChange(onChange);
1087
1174
  const stopFrame = lent.onFrame(frame);
1088
1175
  return () => {
@@ -1090,6 +1177,8 @@ function createAnimalsTestModule(options = {}) {
1090
1177
  stopFrame();
1091
1178
  clearRings();
1092
1179
  clearSkins();
1180
+ sound?.dispose();
1181
+ sound = null;
1093
1182
  host = null;
1094
1183
  };
1095
1184
  }
@@ -1144,10 +1233,19 @@ var createAnimalsThree = (THREE, options = {}) => {
1144
1233
  };
1145
1234
  export {
1146
1235
  ANIMALS_AREA_ID,
1236
+ ANIMAL_CALLS,
1237
+ ANIMAL_CALL_SOURCES,
1147
1238
  ANIMAL_ITEM_PREFIX,
1239
+ ANIMAL_SOUNDS,
1240
+ ANIMAL_SOUND_BANK,
1148
1241
  BIRD_EXTRAS,
1242
+ COW_MOO,
1243
+ DOG_BARK,
1244
+ HEN_CLUCK,
1245
+ LAPWING_CALL,
1149
1246
  QUADRUPED_EXTRAS,
1150
1247
  applyVisualState,
1248
+ createAnimalSound,
1151
1249
  createAnimalsTestModule,
1152
1250
  createAnimalsThree,
1153
1251
  createCoatTexture,