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ACzB,EAAE,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC;IACpC,CAAC;IAFe,0BAAa,gBAE5B,CAAA;AAEL,CAAC,EA1FgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA0F5B","file":"","sourceRoot":"/","sourcesContent":["import { SettingEvents } from \"../../event/BaseEvents\";\nimport { GameBasicSettings } from \"../settings/GameBasicSettings\";\nimport { ResUtils } from \"../../utils/ResUtils\";\nimport { delay } from \"simba-utils\";\n\nexport namespace AudioManager {\n let _musicPathPrefix: string = \"\";\n let _voicePathPrefix: string = \"\";\n let _effectPathPrefix: string = \"\";\n\n export function init(musicPathPrefix = \"\", effectPathPrefix = \"\", voicePathPrefix = \"\") {\n _musicPathPrefix = musicPathPrefix;\n _voicePathPrefix = voicePathPrefix;\n _effectPathPrefix = effectPathPrefix;\n cc.audioEngine.setMusicVolume(GameBasicSettings.musicVolume);\n cc.audioEngine.setEffectsVolume(GameBasicSettings.soundVolume);\n SettingEvents.MusicVolumeChange.on((volume) => {\n cc.audioEngine.setMusicVolume(volume);\n if (volume === 0) {\n cc.audioEngine.pauseMusic();\n } else {\n cc.audioEngine.resumeMusic();\n }\n });\n SettingEvents.SoundVolumeChange.on((volume) => {\n cc.audioEngine.setEffectsVolume(volume);\n });\n }\n\n export async function playMusic(path: string) {\n if (path[0] !== \"/\") path = _musicPathPrefix + path;\n if (!GameBasicSettings.musicVolume) return;\n try {\n let clip = await ResUtils.loadRes<cc.AudioClip>(path, cc.AudioClip);\n cc.audioEngine.playMusic(clip, true);\n } catch (e) {\n console.error(e);\n }\n }\n\n export function pauseMusic() {\n cc.audioEngine.pauseMusic();\n }\n\n export function resumeMusic() {\n cc.audioEngine.resumeMusic();\n }\n\n export function stopMusic() {\n cc.audioEngine.stopMusic();\n }\n\n export async function playEffect(path: string, loopCount = 1) {\n if (path[0] !== \"/\") path = _effectPathPrefix + path;\n if (!GameBasicSettings.soundVolume) return NaN;\n try {\n let clip = await ResUtils.loadRes<cc.AudioClip>(path, cc.AudioClip);\n if (loopCount <= 0) {\n return cc.audioEngine.playEffect(clip, true);\n } else {\n for (let i = 0; i < loopCount; i++) {\n let id = cc.audioEngine.playEffect(clip, false);\n let time = cc.audioEngine.getDuration(id);\n await delay(time);\n }\n return NaN;\n }\n } catch (e) {\n console.error(e);\n }\n }\n\n export async function playVoice(path: string) {\n if (path[0] !== \"/\") path = _voicePathPrefix + path;\n stopAllEffect();\n try {\n let clip = await ResUtils.loadRes<cc.AudioClip>(path, cc.AudioClip);\n let id = cc.audioEngine.playEffect(clip, false);\n let time = cc.audioEngine.getDuration(id);\n await delay(time);\n } catch (e) {\n console.error(e);\n }\n }\n\n export function stopEffect(id: number) {\n if (!isNaN(id)) {\n cc.audioEngine.stopEffect(id);\n }\n }\n\n export function stopAllEffect() {\n cc.audioEngine.stopAllEffects();\n }\n\n}"]}