@excaliburjs/plugin-jsfxr
Version:
excalibur-jsfxr provides sound effect generation utilizing a wrapper around jsfxr
1 lines • 825 B
JavaScript
class JsfxrResource{sounds={};jsfxrModule;jsfxr;async init(){this.jsfxrModule=await import("./sfxr.mjs"),this.jsfxr=this.jsfxrModule.default}loadSoundConfig(s,o){this.sounds[s]=o}rangeValue(s,o){return Math.random()*(o-s)+s}deleteSoundConfig(s){delete this.sounds[s]}playConfig(s){void 0!==this.jsfxr&&void 0!==this.jsfxrModule&&(s=this.resolveValues(s),this.jsfxr.toAudio(s).play())}resolveValues(s){var o,r,e,t={};for(o in s)"oldParams"!==o&&("number"==typeof(e=s[o])?t[o]=e:(r=e.min,e=e.max,t[o]=this.rangeValue(r,e),console.log("set ",o," to ",t[o]," from ",r," to ",e)));return t}playSound(s){if(void 0!==this.jsfxr&&void 0!==this.jsfxrModule){var o=this.sounds[s];if(!o)throw new Error(`Sound ${s} not found`);s=this.resolveValues(o);this.jsfxr.toAudio(s).play()}}getConfigs(){return this.sounds}}export{JsfxrResource};