import { AudioClip, AudioSource, error, _decorator, isValid } from 'cc';
import { resLoader } from '../res/ResLoader';
const { ccclass, menu } = _decorator;

export class AudioEffect extends AudioSource {
    private _effects: Map<string, AudioClip> = new Map<string, AudioClip>();

    load(bundle: string, url: string, callback?: Function) {
        resLoader.load(bundle, url, AudioClip, (error: Error, clip: AudioClip) => {
            if (error) {
                console.error(error);
            } else {
                if(isValid(this._effects)){
                    this._effects.set(url, clip);
                    this.playOneShot(clip, this.volume);
                    callback && callback();
                }
            }
        });
    }
}
