const { ccclass, property } = cc._decorator;

@ccclass
export default class SoundController extends cc.Component {
  static instance: SoundController;

  @property(Array(cc.AudioClip)) sounds: Array<cc.AudioClip> =
    new Array<cc.AudioClip>();

  protected onLoad(): void {
    SoundController.instance = this;
  }

  public static playLoopSound(sound: cc.AudioClip, delayTime: number) {
    const audioId = cc.audioEngine.playEffect(sound, false);

    this.instance.scheduleOnce(() => {
      cc.audioEngine.stopEffect(audioId);
      cc.audioEngine.playEffect(sound, true);
    }, delayTime);
  }

  public static playNoLoopSound(sound: cc.AudioClip) {
    cc.audioEngine.playEffect(sound, false);
  }
}
