/**
 * 游戏数据中心 
 */
import { Singleton } from "../Common/Utils/Singleton";
import { randArr } from "./../Common/Utils/util";


export class DCGame extends Singleton {
	private _data: ObjData; //配置数据
	//临时数据
	private m_nQuestionIdx = 0;	    //当前问题Idx
	private m_objOption: cc.Node;   //目标节点 

	//游戏数据
	private m_optionArr: Array<Option>;//选项列表  当前小题的所有选项

	//初始化数据
	initData() {
		this.questionIdx = 0;
		this.m_objOption = null;
		this.m_optionArr = [];
		this.setOptionArr();
	}

	//表单配置数据
	set data(value: any) {
		this._data = value;
	}
	get data(): ObjData {
		return this._data;
	}

	//设置游戏问题ID
	public get questionIdx() {
		return this.m_nQuestionIdx;
	}
	public set questionIdx(value) {
		this.m_nQuestionIdx = value;
	}

	//设置目标节点
	public get objOption() {
		return this.m_objOption;
	}
	public set objOption(value) {
		this.m_objOption = value;
	}

	//获得开始引导音频
	getAudioBegin() {
		if (!this.data.guideBegin_audio_url) return "";
		return this.data.guideBegin_audio_url;
	}

	// getAudioEnd() {
	// 	if (!this.data.guideEnd_audio_url) return "";
	// 	return this.data.guideEnd_audio_url;
	// }

	//获得重新开始音频
	getAudioReStart() {
		if (!this.data.guideRestart_audio_url) return "";
		return this.data.guideRestart_audio_url;
	}

	//获得题目
	getQuestionByIdx() {
		let Idx = this.m_nQuestionIdx
		return this.data.question_arr[Idx]
	}

	//获得题干音频
	getQuestionAudioUrl() {
		let Idx = this.m_nQuestionIdx
		return this.data.question_arr[Idx].question_audio_url
	}

	//获得题干结束音频
	getQuestionEndAudioUrl() {
		let Idx = this.m_nQuestionIdx
		return this.data.question_arr[Idx].question_audio_url_end;
	}

	//拿到组1数据
	getGroup1() {
		let question = this.getQuestionByIdx()
		return question.group_arr_1
	}

	//拿到组1数据
	getGroup2() {
		let question = this.getQuestionByIdx()
		return question.group_arr_2
	}

	//获得选项列表
	getOptionArr() {
		let Idx = this.m_nQuestionIdx
		let arr = JSON.parse(JSON.stringify(this.data.question_arr[Idx].option_arr));
		arr = randArr(arr)
		return arr
	}

	//设置选项列表
	setOptionArr() {
		this.m_optionArr = this.getOptionArr();
	}

	//从选项列表中抽一个出来
	getOption() {
		return this.m_optionArr.pop();
	}
}

export class ObjData {
	guideBegin_audio_url: string = "";
	// guideEnd_audio_url: string = "";
	guideRestart_audio_url: string = "";
	question_arr: Question[] = [];
}

export class Question {
	question_audio_url: string = "";
	question_audio_url_end: string = "";
	group_arr_1: Group = new Group();
	group_arr_2: Group = new Group();
	option_arr: Option[] = [];
}

export class Group {
	group_audio_url: string = "";
	group_text: string = ""
}

export class Option {
	option_text: string = "";
	option_pic_url: string = "";
	option_audio_url: string = "";
	option_Idx: number = 0;
}