add SoundPlayers to SoundBank

- SoundBank may not create SoundPlayers (but it can call .take if need)
- All SoundPlayers SoundBank plays are given to it
This commit is contained in:
Michael "Z" Goddard 2018-06-18 12:03:20 -04:00 committed by Corey Frang
parent d40564d61a
commit 5177dd5c85

View file

@ -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);