/**
 * 数据管理器
 */
LWD_3.data_mgr = {
	data: null,//表所有数据
	quesId: 0,//题目id
	nowNum: 0,//剩余正确数量

	gameState: 1,//游戏状态1可操作 2不可操作

	//获得默认数据
	getDefaultData() {
		const dataJson = {
			"maxWrongNumber": 4,
			"question_arr": [{
				"question_audio_url": "http://staging-teach.cdn.ireadabc.com/25432da42768ff9681946ea7fc7ee272.mp3",
				"option_arr": [{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "a" },
				{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/58eec304909298176bde6c408c9dac1b.mp3", "is_right": false, "text": "b" },
				{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "c" }],
				"audio_url": "http://staging-teach.cdn.ireadabc.com/25432da42768ff9681946ea7fc7ee272.mp3"
			},
			{
				"question_audio_url": "http://staging-teach.cdn.ireadabc.com/25432da42768ff9681946ea7fc7ee272.mp3",
				"option_arr": [{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "a" },
				{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/58eec304909298176bde6c408c9dac1b.mp3", "is_right": false, "text": "b" },
				{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "c" },
				{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/58eec304909298176bde6c408c9dac1b.mp3", "is_right": false, "text": "d" }]
			},
			{
				"question_audio_url": "http://staging-teach.cdn.ireadabc.com/25432da42768ff9681946ea7fc7ee272.mp3",
				"option_arr": [{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "a" }]
			},
			{
				"question_audio_url": "http://staging-teach.cdn.ireadabc.com/25432da42768ff9681946ea7fc7ee272.mp3",
				"option_arr": [
					{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "is_right": true, "text": "a" },
					{ "pic_url": "http://staging-teach.cdn.ireadabc.com/3134325b66d1b8ecf2f83db853195da5.png", "audio_url": "http://staging-teach.cdn.ireadabc.com/58eec304909298176bde6c408c9dac1b.mp3", "is_right": false, "text": "b" }]
			}],
			"ske_json": "http://staging-teach.cdn.ireadabc.com/343192141e9dfca91571a7208c68d365.json",
			"ske_json_name": "queen_ske.json",
			"tex_json": "http://staging-teach.cdn.ireadabc.com/e53670138a8dc28727528948bffe0854.json",
			"tex_json_name": "queen_tex.json",
			"tex_png": "http://staging-teach.cdn.ireadabc.com/9bde7212f4aa705a52e73a23d2902023.png",
			"tex_png_name": "queen_tex.png",
			"guideBegin_audio_url": "http://staging-teach.cdn.ireadabc.com/bd6e2b3a870ef3f9ee9ad9c0fda79228.mp3",
			"guideEnd_audio_url": "http://staging-teach.cdn.ireadabc.com/bd6e2b3a870ef3f9ee9ad9c0fda79228.mp3",
			"guideRestart_audio_url": "http://staging-teach.cdn.ireadabc.com/bd6e2b3a870ef3f9ee9ad9c0fda79228.mp3",
		}
		const data1 = dataJson;
		// const data = JSON.parse(dataJson);
		// const data = [];
		const data = {
			"question_arr": [
				{
					"question_audio_url": "https://teach.cdn.ireadabc.com/a5a335d362c47064f34aa6988dcaa3a4.mp3",
					"option_arr": [
						{
							"text": "a_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/ef4aec311cf6349aac0251fefea51495.mp3",
							"is_right": false
						},
						{
							"text": "u_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/9b4d5a7d58dd29fe3983a3e1ed723488.mp3",
							"is_right": false
						},
						{
							"text": "o_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/aad3b9ddff6a712ebdebfaad5c6d8c4c.mp3",
							"is_right": false
						},
						{
							"text": "i_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/18d60942e3f1f2d4a0bfa850e1764ff4.mp3",
							"is_right": true
						},
						{
							"text": "ave",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/d5a82cfd83a443694682b8dd90e8883b.mp3",
							"is_right": false
						}
					]
				},
				{
					"question_audio_url": "https://teach.cdn.ireadabc.com/a5a335d362c47064f34aa6988dcaa3a4.mp3",
					"option_arr": [
						{
							"text": "ake",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/7aa7ae7a3693fe7faad4f3203e5e0470.mp3",
							"is_right": false
						},
						{
							"text": "ave",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/d5a82cfd83a443694682b8dd90e8883b.mp3",
							"is_right": false
						},
						{
							"text": "ate",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/219a7220c0372e856601306f6b5af22c.mp3",
							"is_right": false
						},
						{
							"text": "i_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/18d60942e3f1f2d4a0bfa850e1764ff4.mp3",
							"is_right": true
						},
						{
							"text": "u_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/9b4d5a7d58dd29fe3983a3e1ed723488.mp3",
							"is_right": false
						}
					]
				},
				{
					"question_audio_url": "https://teach.cdn.ireadabc.com/a5a335d362c47064f34aa6988dcaa3a4.mp3",
					"option_arr": [
						{
							"text": "ake",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/7aa7ae7a3693fe7faad4f3203e5e0470.mp3",
							"is_right": false
						},
						{
							"text": "i_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/18d60942e3f1f2d4a0bfa850e1764ff4.mp3",
							"is_right": true
						},
						{
							"text": "o_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/aad3b9ddff6a712ebdebfaad5c6d8c4c.mp3",
							"is_right": false
						},
						{
							"text": "ate",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/219a7220c0372e856601306f6b5af22c.mp3",
							"is_right": false
						},
						{
							"text": "u_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/9b4d5a7d58dd29fe3983a3e1ed723488.mp3",
							"is_right": false
						}
					]
				},
				{
					"question_audio_url": "https://teach.cdn.ireadabc.com/a5a335d362c47064f34aa6988dcaa3a4.mp3",
					"option_arr": [
						{
							"text": "a_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/ef4aec311cf6349aac0251fefea51495.mp3",
							"is_right": false
						},
						{
							"text": "ame",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/905dd2c3db170630ef50556e68a43dd6.mp3",
							"is_right": false
						},
						{
							"text": "u_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/9b4d5a7d58dd29fe3983a3e1ed723488.mp3",
							"is_right": false
						},
						{
							"text": "i_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/18d60942e3f1f2d4a0bfa850e1764ff4.mp3",
							"is_right": true
						},
						{
							"text": "o_e",
							"pic_url": "https://teach.cdn.ireadabc.com/10304dad1e1302839bcf3946448cb044.png",
							"audio_url": "https://teach.cdn.ireadabc.com/aad3b9ddff6a712ebdebfaad5c6d8c4c.mp3",
							"is_right": false
						}
					]
				}
			],
			"ske_json": "https://teach.cdn.ireadabc.com/e1f754e6541015ac2af531aaee21647d.json",
			"ske_json_name": "bear_2_ske.json",
			"tex_json": "https://teach.cdn.ireadabc.com/74817f63b8f00d89e7994d6e75660ced.json",
			"tex_json_name": "bear_2_tex.json",
			"tex_png": "https://teach.cdn.ireadabc.com/29812ad5d439658dd872d51dfd6eeb27.png",
			"tex_png_name": "bear_2_tex.png",
			"guideRestart_audio_url": "https://teach.cdn.ireadabc.com/545f8544641d2423783604c9f6802f1c.mp3",
			"guideEnd_audio_url": "https://teach.cdn.ireadabc.com/ef8b1264fa40981cd16a3c7b003a6cdf.mp3",
			"guideBegin_audio_url": "https://teach.cdn.ireadabc.com/e41dd233aab5b09a3d48fc82e9991ad6.mp3"
		}
		return data;
	},

	getAudioBegin() {
		if (!this.data.guideBegin_audio_url) return -1;
		return this.data.guideBegin_audio_url;
	},
	getAudioEnd() {
		if (!this.data.guideEnd_audio_url) return -1;
		return this.data.guideEnd_audio_url
	},
	getAudioReStart() {
		if (!this.data.guideRestart_audio_url) return -1;
		return this.data.guideRestart_audio_url
	},

	//数据处理
	resetQuestion() {
		for (var i in this.data.question_arr) {
			if (i % 2 == 0) {
				let num = LWD_3.utils.randFromTo_Int(0, 1);
				if (num == 0 && this.data.question_arr[~~i + 1]) {
					let swap = (arr, i, j) => {
						[arr[i], arr[j]] = [arr[j], arr[i]];
					}
					//交换
					swap(this.data.question_arr, ~~i, ~~i + 1)
				};
			}
		}
	},

	//获取问题列表
	getQuestionArr() {
		return this.data.question_arr;
	},

	//获得表单信息
	getQuestion(num) {
		return this.data.question_arr[num];
	},

	//获得单题列表
	getQuestionOneList(num) {
		return this.data.question_arr[num].option_arr;
	},

	//获得题干
	getQuestionStem(num) {
		return this.data.question_arr[num].question_audio_url;
	},


	//获得标题
	getTitle() {
		return this.data.title;
	},

	//获得表单信息
	getSheepfoldArr() {
		return this.data.sheepfoldArr;
	},

	//获得表单信息
	getSheepfold(num) {
		return this.data.sheepfoldArr[num];
	},

	//获得所有选项
	getSheepArr() {
		return this.data.sheepArr;
	},

	//获得单项信息
	getSheep(num) {
		return this.data.sheepArr[num];
	},

	//获取当前整页数据
	getPageInfo: function () {
		return this.data.contentObj.pageArr[this.pageId].pageInfo;
	},

	//获得整条数据
	getResultInfo: function (id) {
		var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
		return pageInfo[id];
	},

	//处理数据
	proGameData: function () {
		this.resetQuestion();
		this.preload();
		console.log("数据处理完毕:");
	},

	preload() {
		cc.assetManager.loadAny(null, null, null, (err, data) => {
			if (window && window["air"]) {
				cc.find('Canvas').opacity = 0;
				window.air.onCourseInScreen = (next) => {
					cc.find('Canvas').opacity = 255;
					this.loadEnd();
					next();
				}
				window.air.hideAirClassLoading();
			} else {
				this.loadEnd();
			}
			cc.debug.setDisplayStats(false);
		});
	},

	loadEnd() {
		//更新游戏界面信息
		LWD_3.game.inst.guideGame();
		LWD_3.game.inst.isLoadEnd = true;
	},
}