import AssetMgr from "../Common/Module/AssetMgr/AssetMgr";
import AudioMgr from "../Common/Module/AudioMgr/AudioMgr";
import { randFromTo_Int } from "../Common/Utils/util";

/**
 * 音效使用
 */

//游戏音效枚举
export enum E_AudioName {
	BTN = "btn",
	ENDEFFECT = "endEffect"
}

export class Speaker {
	//播放音效
	// public static playEffect(name) {
	// 	AssetMgr.loadAudio("Audios", name).then((clip) => {
	// 		AudioMgr.playEffect(clip, false);
	// 	})
	// 	let clip = this.getClip();
	// }

	//播放正确音效
	public static playRightEffect(cb?: Function) {
		//随机
		let name = "right" + randFromTo_Int(0, 2);
		this.playEffect(name, cb);
		// AssetMgr.loadAudio("Audios", name).then((clip) => {
		// 	AudioMgr.playEffect(clip, false, cb);
		// })
	}

	//播放失败音效
	public static playErrorEffect(cb?: Function) {
		//随机
		let name = "wrong" + randFromTo_Int(0, 2);
		this.playEffect(name, cb);
		// AssetMgr.loadAudio("Audios", name).then((clip) => {
		// 	AudioMgr.playEffect(clip, false, cb);
		// })
	}

	public static playEffect(audioName, cb?) {
		const audio = cc.find(`Canvas/nodRes/audio/${audioName}`).getComponent(cc.AudioSource);
		AudioMgr.playEffect(audio.clip, false, cb)
	}
}