System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  "use strict";

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, assetManager, AudioClip, AudioSource, constants, settingData, audioManager, _crd;

  function _reportPossibleCrUseOfconstants(extras) {
    _reporterNs.report("constants", "../data/constants", _context.meta, extras);
  }

  function _reportPossibleCrUseOfsettingData(extras) {
    _reporterNs.report("settingData", "../data/settingData", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      assetManager = _cc.assetManager;
      AudioClip = _cc.AudioClip;
      AudioSource = _cc.AudioSource;
    }, function (_unresolved_2) {
      constants = _unresolved_2.constants;
    }, function (_unresolved_3) {
      settingData = _unresolved_3.default;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "9d41fnOFEtCvYwlsO6f1fZZ", "audioManager", undefined);

      __checkObsolete__(['AssetManager', 'assetManager', 'AudioClip', 'AudioSource']);

      audioManager = class audioManager {
        constructor() {
          this.cachedAudioArr = [];
          this.bundleAudios = null;
          this.bgVolumeMax = 0.8;
        }

        //单例
        static ins() {
          if (!this.instance) {
            this.instance = new audioManager();
          }

          return this.instance;
        }
        /**
         * 预加载音乐
         */


        async initialize() {
          this.bundleAudios = await new Promise((resolve, reject) => {
            assetManager.loadBundle('audios', (err, bundle) => {
              if (err) {
                reject(err);
              } else {
                resolve(bundle);
              }
            });
          });

          for (let path of Object.values((_crd && constants === void 0 ? (_reportPossibleCrUseOfconstants({
            error: Error()
          }), constants) : constants).audios)) {
            if (path == "") continue;
            let audioClip = await new Promise((resolve, reject) => {
              this.bundleAudios.load(path, AudioClip, (err, clip) => {
                if (err) {
                  reject(err);
                } else {
                  resolve(clip);
                }
              });
            });
            this.cachedAudioArr.push({
              clip: audioClip,
              audioSource: null,
              path: path,
              playStatus: false,
              totalTime: audioClip.getDuration(),
              time_id: -1,
              t: 0
            });
          }

          window["youxi"] = {
            SoundManager: {
              pauseAll: () => {
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).data.bg_music_status = false;
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).data.sound_status = false;
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).saveToCache();

                if ((_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).data.bg_music_status) {
                  this.play((_crd && constants === void 0 ? (_reportPossibleCrUseOfconstants({
                    error: Error()
                  }), constants) : constants).audios.bg_music, true);
                } else {
                  this.stop((_crd && constants === void 0 ? (_reportPossibleCrUseOfconstants({
                    error: Error()
                  }), constants) : constants).audios.bg_music);
                }
              },
              resumeAll: () => {
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).data.bg_music_status = true;
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).data.sound_status = true;
                (_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
                  error: Error()
                }), settingData) : settingData).saveToCache();
              }
            },
            TargetedAds: {
              open: () => {},
              clos: () => {}
            },
            Fps: {
              setfps: value => {}
            }
          };
        }
        /**
         * 播放音效 不会两个相同的音乐重复播放 可以停止
         * @param path 播放音乐的路径
         * @param loop 是否循环播放
         * @param s 如果为-1则最大音量立即播放 如果为其他则慢慢音量递增起来播放
         * @returns 
         */


        play(path, loop = false, s = -1) {
          if (!(_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
            error: Error()
          }), settingData) : settingData).data.bg_music_status) return;

          const fun = audio => {
            if (audio.audioSource == null) {
              audio.audioSource = this.audioSourceLoop(loop);
            }

            if (audio.playStatus) return;
            audio.audioSource.clip = a.clip;

            if (audio.time_id) {
              clearInterval(audio.time_id);

              if (audio.audioSource.playing) {
                audio.audioSource.pause();
              }
            }

            audio.audioSource.play();

            if (s == -1) {
              audio.audioSource.volume = this.bgVolumeMax;
            } else {
              audio.t = 0;
              audio.audioSource.volume = 0;
              let interval = 1 / s / 10;
              audio.time_id = setInterval(() => {
                audio.t += interval;
                let volume = audio.t / s;

                if (volume >= this.bgVolumeMax) {
                  clearInterval(audio.time_id);
                } else {
                  audio.audioSource.volume = volume;
                }
              }, interval * 1000);
            }

            audio.playStatus = true;
          };

          let a = this.cachedAudioArr.find(e => e.path == path);

          if (a) {
            fun(a);
          } else {
            this.bundleAudios.load(path, AudioClip, (err, clip) => {
              if (err) {
                console.warn(err);
              } else {
                let data = {
                  path: path,
                  clip: clip,
                  audioSource: null,
                  playStatus: false,
                  totalTime: clip.getDuration(),
                  time_id: -1,
                  t: 0
                };
                fun(data);
              }
            });
          }
        }
        /**
         * 单次播放一次的音效 可以停止
         * @param path 音乐路径
         * @param overlap 是否可以重复两个同一个音效连续播放
         * @returns 
         */


        playOneShot(path, overlap = true) {
          if (!(_crd && settingData === void 0 ? (_reportPossibleCrUseOfsettingData({
            error: Error()
          }), settingData) : settingData).data.sound_status) return;

          const fun = audio => {
            if (overlap || !audio.playStatus) {
              if (audio.audioSource == null) {
                audio.audioSource = this.audioSourceLoop(false);
              }

              audio.audioSource.clip = audio.clip;
              audio.audioSource.play();
              audio.audioSource.volume = 1;
              audio.playStatus = true;
            }
          };

          let a = this.cachedAudioArr.find(e => e.path == path);

          if (a) {
            fun(a);
          } else {
            this.bundleAudios.load(path, AudioClip, (err, clip) => {
              if (err) {
                console.warn(err);
              } else {
                let data = {
                  path: path,
                  clip: clip,
                  audioSource: null,
                  playStatus: false,
                  totalTime: clip.getDuration(),
                  time_id: -1,
                  t: 0
                };
                this.cachedAudioArr.push(data);
                fun(data);
              }
            });
          }
        }
        /**
         * 停止播放音效
         * @param path 音效路径名称
         * @param s 为-1立即停止播放 非-1则是慢慢的声音越来越小的停止播放
         * @returns 
         */


        stop(path, s = -1) {
          let audio = this.cachedAudioArr.find(e => e.path == path);

          if (audio) {
            if (!audio.audioSource) return;
            if (!audio.audioSource.playing) return;

            if (audio.time_id) {
              clearInterval(audio.time_id);
            }

            let audioSource = audio.audioSource;

            if (s == -1) {
              audioSource == null ? void 0 : audioSource.pause();
            } else {
              audio.t = 0;
              let interval = 1 / s / 10;
              audio.time_id = setInterval(() => {
                if (audioSource) {
                  audio.t += interval;
                  let volume = this.bgVolumeMax - audio.t / s;

                  if (volume <= 0) {
                    clearInterval(audio.time_id);
                    audioSource == null ? void 0 : audioSource.pause();
                  } else {
                    audioSource.volume = volume <= 0 ? 0 : volume;
                  }
                }
              }, interval * 1000);
            }

            audio.playStatus = false;
          }
        }
        /**
         * 加载音效
         * @param loop 是否循环
         */


        audioSourceLoop(loop) {
          let audioSource = null;

          if (loop) {
            //播放单次的时候具柄
            audioSource = this.getAudioSource(null, true, this.bgVolumeMax);
          } else {
            //循环播放的时候具柄
            audioSource = this.getAudioSource(null, false, 1);
          }

          return audioSource;
        }
        /**
         * 得到一个播放音乐的控制类
         * @param clip 音效片段
         * @param loop 是否循环
         * @param volume 音量
         * @returns 播放类
         */


        getAudioSource(clip = null, loop = false, volume = 1) {
          let audioSource = new AudioSource();

          if (clip) {
            audioSource.clip = clip;
          }

          audioSource.loop = loop;
          audioSource.volume = volume;
          return audioSource;
        }

      };
      audioManager.instance = null;

      _export("default", audioManager.ins());

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=087929fdb2c1d7a6108b29fbc7588d5611018e23.js.map