From 5177dd5c851edb30bf638518775d9b20f9d2b973 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Mon, 18 Jun 2018 12:03:20 -0400 Subject: [PATCH] add SoundPlayers to SoundBank - SoundBank may not create SoundPlayers (but it can call .take if need) - All SoundPlayers SoundBank plays are given to it --- src/SoundBank.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/SoundBank.js b/src/SoundBank.js index d83b7d0..ecbb1c4 100644 --- a/src/SoundBank.js +++ b/src/SoundBank.js @@ -1,22 +1,24 @@ -const SoundPlayer = require('./GreenPlayer'); -const EffectsChain = require('./effects/EffectChain'); +const log = require('./log'); const ALL_TARGETS = '*'; class SoundBank { - constructor (audioEngine) { + constructor (audioEngine, effectChainPrime) { this.audioEngine = audioEngine; this.soundPlayers = {}; this.playerTargets = new Map(); this.soundEffects = new Map(); + this.effectChainPrime = effectChainPrime; + } + + addSoundPlayer (soundPlayer) { + this.soundPlayers[soundPlayer.id] = soundPlayer; } getSoundPlayer (soundId) { if (!this.soundPlayers[soundId]) { - this.soundPlayers[soundId] = new SoundPlayer(this.audioEngine, { - id: soundId, buffer: this.audioEngine.audioBuffers[soundId] - }); + log.error(`SoundBank.getSoundPlayer(${soundId}): called missing sound in bank`); } return this.soundPlayers[soundId]; @@ -24,7 +26,7 @@ class SoundBank { getSoundEffects (sound) { if (!this.soundEffects.has(sound)) { - this.soundEffects.set(sound, new EffectsChain(this.audioEngine)); + this.soundEffects.set(sound, this.effectChainPrime.clone()); } return this.soundEffects.get(sound);