Files

3 lines
12 KiB
JavaScript
Raw Permalink Normal View History

2026-07-28 10:47:32 -04:00
var gdjs;(function(h){const d=new h.Logger("Audio manager"),f=["audio"],_={preload:!0,onplayerror:(l,e)=>d.error("Can't play an audio file: "+e),onloaderror:(l,e)=>d.error("Error while loading an audio file: "+e)},c=l=>l>1?1:l<0?0:l,u=(l,e)=>{if(l instanceof Error&&l.message&&typeof l.message=="string"&&l.message.startsWith("Maximum call stack size exceeded"))console.warn(`An error occurred when call method "${e}":`,l);else throw l};class m{constructor(e,t,s,i,a){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=c(t),this._loop=s,this._rate=i,this._audioResourceName=a}isActualId(){return!!this._howl._soundById(this._id)}isLoaded(){return this._howl.state()==="loaded"}play(){try{if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(h.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(t=>{this.on("play",t),t(e)}),this._oncePlay.forEach(t=>t(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play())}catch(e){u(e,"play")}return this}pause(){try{this._id!==null&&this.isActualId()&&this._howl.pause(this._id)}catch(e){u(e,"pause")}return this}stop(){try{this._id!==null&&this.isActualId()&&this._howl.stop(this._id)}catch(e){u(e,"stop")}return this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){try{this._rate=e,this._id!==null&&this.isActualId()&&(e=h.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id))}catch(t){u(t,"rate")}return this}getLoop(){return this._loop}setLoop(e){try{this._loop=e,this._id!==null&&this.isActualId()&&this._howl.loop(e,this._id)}catch(t){u(t,"loop")}return this}getVolume(){try{return this._id===null||!this.isActualId()?this._initialVolume:this._howl.volume(this._id)}catch(e){u(e,"getVolume")}return this._initialVolume}setVolume(e){try{this._initialVolume=c(e),this._id!==null&&this.isActualId()&&this._howl.volume(this._initialVolume,this._id)}catch(t){u(t,"volume")}return this}getMute(){return this._id===null||!this.isActualId()?!1:this._howl.mute(this._id)}setMute(e){try{this._id!==null&&this.isActualId()&&this._howl.mute(e,this._id)}catch(t){u(t,"mute")}return this}getSeek(){return this._id===null||!this.isActualId()?0:this._howl.seek(this._id)}setSeek(e){try{this._id!==null&&this.isActualId()&&this._howl.seek(e,this._id)}catch(t){u(t,"seek")}return this}getSpatialPosition(e){return this._id===null||!this.isActualId()?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,t,s){return this._id!==null&&this.isActualId()&&this._howl.pos(e,t,s,this._id),this}fade(e,t,s){try{this._id!==null&&this.isActualId()&&this._howl.fade(c(e),c(t),s,this._id)}catch(i){u(i,"fade")}return this}on(e,t){return e==="play"?this._id===null?this._onPlay.push(t):this._howl.on(e,t,this._id):this._id===null?this.once("play",()=>this.on(e,t)):this._howl.on(e,t,this._id),this}once(e,t){return e==="play"?this._id===null?this._oncePlay.push(t):this.playing()?t(this._id):this._howl.once(e,t,this._id):this._id===null?this.once("play",()=>this.once(e,t)):this._howl.once(e,t,this._id),this}off(e,t){return this._id!==null&&this._howl.off(e,t,this._id),this}getNetworkSyncData(){if(this.paused()||!this.isLoaded()||this.stopped())return;const e=this.getSeek(),t=typeof e!="number"?0:e,s=this.isLoaded()?this.getVolume():this._initialVolume;return{resourceName:this._audioResourceName,loop:this._loop,volume:s,rate:this._rate,seek:t}}}h.HowlerSound=m;class p{constructor(e){this._loadedMusics=new h.ResourceCache;this._loadedSounds=new h.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._cachedSpatialPosition={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._muteEverythingReasons=new Set;this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const t=this._resourceLoader.getResource(e);return t&&this.getResourceKinds().i
//# sourceMappingURL=howler-sound-manager.js.map