// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GameLogic from "../script/GameLogic_TXZS_G_001"

cc.Class({

	extends: cc.Component,

	properties: {
		bubble: {
			type: cc.Prefab,
			default: null,
		},
		star: {
			type: cc.Prefab,
			default: null,
		},
		score: {
			type: cc.Prefab,
			default: null,
		},
	},

	gameLogic: null,

	// 生命周期 onLoad
	onLoad() {
		this.initSceneData();
		this.initSize();
	},

	_imageResList: null,
	_audioResList: null,
	_animaResList: null,
	initSceneData() {
		this._imageResList = [];
		this._audioResList = [];
		this._animaResList = [];
	},

	_designSize: null,  // 设计分辨率
	_frameSize: null,  // 屏幕分辨率
	_mapScaleMin: null,  // 场景中常用缩放（取大值）
	_mapScaleMax: null,  // 场景中常用缩放（取小值）
	_cocosScale: null,  // cocos 自缩放 （较少用到）
	initSize() {

		// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
		let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
		let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height
		let f = screen_size >= design_size
		cc.Canvas.instance.fitHeight = f
		cc.Canvas.instance.fitWidth = !f

		const frameSize = cc.view.getFrameSize();
		this._frameSize = frameSize;

		this._designSize = cc.view.getDesignResolutionSize();

		let sx = cc.winSize.width / frameSize.width;
		let sy = cc.winSize.height / frameSize.height;
		this._cocosScale = Math.min(sx, sy);

		sx = frameSize.width / this._designSize.width;
		sy = frameSize.height / this._designSize.height;
		this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
		this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
	},


	// 生命周期 start
	start() {
		console.log("start")
		let getData = this.getData.bind(this);
		// if (window && window.courseware) {
		// 	getData = window.courseware.getData;
		// }

		getData((data) => {
			console.log('data:', data);
			if(data.rows) {
				this.data = this.translateData(data.rows)
			} else {
				this.data = this.getDefaultData();
			}
			
			this.data = JSON.parse(JSON.stringify(this.data));
			this.preloadItem()
			this.preloadItem(_=>{
				this.gameLogic = new GameLogic(this.data, {
					designSize: this._designSize,
					frameSize: this._frameSize,
					mapScaleMin: this._mapScaleMin,
					mapScaleMax: this._mapScaleMax,
					cocosScale: this._cocosScale,
					imageResList: this._imageResList,
					audioResList: this._audioResList,
					animaResList: this._animaResList,
					prefabs: {
						bubble: this.bubble,
						star: this.star,
						score: this.score
					},
					properties: {
						option: this.option,
						empty: this.empty
					}
				})
			})
		})
	},

	onDestroy() {
		this.gameLogic.onDestroy && this.gameLogic.onDestroy();
	},

	getData(cb) {

		let data;
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			const middleLayerComponent = middleLayer.getComponent('middleLayer');
			data = middleLayerComponent.getTempData('hw_dictation_data');
		} else {
			data = this.getDefaultData();
		}
		cb(data);
		// cb(this.getDefaultData());
	},

	getDefaultData() {
		// const dataJson = '{ "contentObj": { "version": "1.0", "key": "DataKey_dfzx_ppp", "question": {}, "dataArray": [ { "correct": [ { "type": "Text", "text": "Demo", "audio_url": "", "image_url": "" } ], "incorrect": [], "audio_url1": "" } ] } }'
		const data = [ { "id": 20, "pid": 19, "text_en": "what", "text_cn": "什么", "audio_url": "http://teach.cdn.ireadabc.com/36b5e5d9a5240bff453e95e2d74cece0.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/27a5b4d9525a299e3806ccd991a8e5f9.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/b9b759a25cafbadc3130201e50cf4f85.jpeg\"]", "phonetic": "[wɒt]", "description": null, "mlk": null, "data": null, "seq": 1, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 21, "pid": 19, "text_en": "is", "text_cn": "是", "audio_url": "http://teach.cdn.ireadabc.com/d7f9276c7ff13b734c74358d7580a193.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/45100afa502326955d0f03cac87f1a5b.mp3", "image_url": null, "phonetic": "[ɪz]", "description": null, "mlk": null, "data": null, "seq": 2, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 22, "pid": 19, "text_en": "what’s", "text_cn": "是什么", "audio_url": "http://teach.cdn.ireadabc.com/383082bc329464ae1580fffcd5e85d54.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/244d88fbd98972865959d1c0fe50bdac.mp3", "image_url": null, "phonetic": "[wɒts]", "description": null, "mlk": null, "data": null, "seq": 3, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 23, "pid": 19, "text_en": "your", "text_cn": "你的", "audio_url": "http://teach.cdn.ireadabc.com/09b268cd4e201e12f4f8af377308689b.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/f723a8c809b4c910b416a9a6c9e34eb8.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/808504438919f5d2849dff97f7fb0ffd.jpg\",\"http://teach.cdn.ireadabc.com/fc9d5a0d4eba960aecae0d88b0c39acd.jpg\"]", "phonetic": "[jɔː(r)]", "description": null, "mlk": null, "data": null, "seq": 4, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-14T01:48:59.000Z", "del": 0 }, { "id": 24, "pid": 19, "text_en": "name", "text_cn": "名字", "audio_url": "http://teach.cdn.ireadabc.com/60bf983a10741a0796a3a71d1c0b5907.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/0fa9f2cc4c971d870889d7b80976654f.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/a0d9907a44d617784b533dc920647dee.jpg\"]", "phonetic": "[neɪm]", "description": null, "mlk": null, "data": null, "seq": 5, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 25, "pid": 19, "text_en": "please", "text_cn": "请", "audio_url": "http://teach.cdn.ireadabc.com/ee1c7821c46b49ba850ebefc598cdb5b.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/ac372008acb6236b6a1428a334c7f0a5.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/a42594ef6c4fc5b1987d2b073ae675dd.webp\",\"http://teach.cdn.ireadabc.com/7fc1972331756f74dbcf7ae0215a809b.png\"]", "phonetic": "[pliːz]", "description": null, "mlk": null, "data": null, "seq": 6, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 26, "pid": 19, "text_en": "good", "text_cn": "好的", "audio_url": "http://teach.cdn.ireadabc.com/3aeaf5c3884ad3f00a92900ed478c77e.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/403ba0be9e118b5325e3ae8acbdd3743.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/42946cef3972cc2ddaded63ba0fc20c1.webp\"]", "phonetic": "[ɡʊd]", "description": null, "mlk": null, "data": null, "seq": 7, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-14T01:49:00.000Z", "del": 0 }, { "id": 27, "pid": 19, "text_en": "morning", "text_cn": "早晨,上午", "audio_url": "http://teach.cdn.ireadabc.com/382d219f6339f5e0980cb9b716dbac8d.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/2c9c57ed86a6ca438c486543bc8bcb88.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/ffbf1f05334754e42deff6f8f2f96d3e.jpg\",\"http://teach.cdn.ireadabc.com/b8e68519a23841f248a09293a879ffe9.jpg\",\"http://teach.cdn.ireadabc.com/d72d4b2d838e91570a3e777eaa5f9420.jpg\"]", "phonetic": "['mɔːnɪŋ]", "description": null, "mlk": null, "data": null, "seq": 8, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-14T01:49:00.000Z", "del": 0 }, { "id": 28, "pid": 19, "text_en": "Ms.", "text_cn": "女士", "audio_url": "http://teach.cdn.ireadabc.com/81c51b5b602e3687c6b220727c5e5f55.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/5476bff8440fc49bebad504a0bd86eba.mp3", "image_url": null, "phonetic": "[miz]", "description": null, "mlk": "Ms", "data": null, "seq": 9, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-14T07:46:34.000Z", "del": 0 }, { "id": 29, "pid": 19, "text_en": "my", "text_cn": "我的", "audio_url": "http://teach.cdn.ireadabc.com/d4463b448d966353c3c19ae9b9e6ca71.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/cfbc278fb514c0bc9ca690f1c4df0950.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/a2c2888111d4c18015a7d01d55fe93fb.jpg\",\"http://teach.cdn.ireadabc.com/98aa7a0d3243e8a361fd2973e4563f93.jpg\",\"http://teach.cdn.ireadabc.com/8a8b042372a3304b66495039eb7a92ff.jpg\",\"http://teach.cdn.ireadabc.com/da793b5cf93ae8915574f42d837dbae3.jpg\",\"http://teach.cdn.ireadabc.com/56857caeabb7b5bd49fa3054b2e45a52.webp\"]", "phonetic": "[maɪ]", "description": null, "mlk": null, "data": null, "seq": 10, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 30, "pid": 19, "text_en": "bird", "text_cn": "鸟", "audio_url": "http://teach.cdn.ireadabc.com/1ef04de98ddc59957edbc709901c60c7.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/fae76ae6e1bcb53d63d6f38838587ae0.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/7cf3efe3d56e7fe69d6a1809b567d1ae.jpeg\",\"http://teach.cdn.ireadabc.com/64b0eb3286053f0bf7672f61f9e5565a.jpeg\",\"http://teach.cdn.ireadabc.com/deb296c3696ee0940dc91ee18eb68d27.webp\"]", "phonetic": "[bɜːd]", "description": null, "mlk": null, "data": null, "seq": 11, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 31, "pid": 19, "text_en": "tweet", "text_cn": "小鸟啼叫", "audio_url": "http://teach.cdn.ireadabc.com/db4b0511e318b0725532aeba6181bd51.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/867865f1650f3512adba56c83bcb9f3e.mp3", "image_url": null, "phonetic": "[twi:t]", "description": null, "mlk": null, "data": null, "seq": 12, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 32, "pid": 19, "text_en": "a(n)", "text_cn": "一个", "audio_url": "http://teach.cdn.ireadabc.com/81eec7df521de5f8b0704fa114bc0aff.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/618b7d333097f2e96b35bb9135231918.mp3", "image_url": null, "phonetic": "[ə][ən]", "description": null, "mlk": null, "data": null, "seq": 13, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 33, "pid": 19, "text_en": "boy", "text_cn": "男孩", "audio_url": "http://teach.cdn.ireadabc.com/6c60ff7775afbb0b454f23151719e9d0.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/e27330597469d5e81f0037c5846aca48.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/1f042535eef57f88054d46f903d87e80.jpeg\"]", "phonetic": "[bɔɪ]", "description": null, "mlk": null, "data": null, "seq": 14, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 34, "pid": 19, "text_en": "girl", "text_cn": "女孩", "audio_url": "http://teach.cdn.ireadabc.com/d038b562b0c7781e718eb08550849143.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/9ad553f6e10ddc1bfeb851082f9f1d25.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/896d19830863cfc1561553ebf3b6ecbe.webp\",\"http://teach.cdn.ireadabc.com/92354ec729582b3bb2ea05851e9d0806.webp\"]", "phonetic": "[ɡɜːl]", "description": null, "mlk": null, "data": null, "seq": 15, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 35, "pid": 19, "text_en": "afternoon", "text_cn": "下午", "audio_url": "http://teach.cdn.ireadabc.com/1f70fe441cdca82832cdf7bc286796f7.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/0ab162e708e2ba9991398f10107504ab.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/e4b9c73c31c47a7441bb6ac04d558c02.jpg\",\"http://teach.cdn.ireadabc.com/d2914aad9ce834ebb057b04400609a17.jpg\",\"http://teach.cdn.ireadabc.com/0ad04d2a371a51af723a2fae92ebbf10.jpg\"]", "phonetic": "[ˌɑːftə'nuːn]", "description": null, "mlk": null, "data": null, "seq": 16, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 }, { "id": 36, "pid": 19, "text_en": "panda", "text_cn": "熊猫", "audio_url": "http://teach.cdn.ireadabc.com/99b59a21ea78955c7e593c2f38ef31de.mp3", "audio_cn_url": "http://teach.cdn.ireadabc.com/a30d8dc936cbe5e1324b293faaa6e3ce.mp3", "image_url": "[\"http://teach.cdn.ireadabc.com/e32c4771a53e118e25fc0c16de7deccb.jpg\",\"http://teach.cdn.ireadabc.com/e79e9d8a7b391b55aabeb54281ccf5a7.jpg\"]", "phonetic": "['pændə]", "description": null, "mlk": null, "data": null, "seq": 17, "has_child": 0, "depth": 4, "created_date": "2023-02-01T10:07:13.000Z", "updated_date": "2023-02-10T03:31:34.000Z", "del": 0 } ];
		// 数据转换 - 适配听写助手数据
		return this.translateData(data);
	},

	// 数据转换 - 把听写助手传进来的数据转换成这个模板需要的游戏数据
	translateData(data) {
		// 获取干扰项
		function getErrDataItem(arr, correctIndex, errNum) {
			if(correctIndex >= arr.length) {
				// 参数错误
				return;
			}

			//  深拷贝数组 防止后面splice破坏原数组
			let temp_arr = JSON.parse(JSON.stringify(arr));
			temp_arr.splice(correctIndex, 1);
			if(errNum >= temp_arr.length) {
				// 长度不够 - 返回全部数据
				return temp_arr;
			}

			// 打乱数组 - 取前errNum个元素返回
			temp_arr.sort(()=>Math.random()>0.5?-1:1)
			return temp_arr.splice(0, errNum);
		}

		// 按照需要的结构进行组装
		const tData = {
			"contentObj": {
				"version": "1.0", 
				"key": "DataKey_dfzx_ppp", 
				"question": {}, 
				"dataArray": []
			}
		}
		data.forEach((item, index)=>{
			const errItem = getErrDataItem(data, index, 5);
			const configItem = {
				"correct": [], 
				"incorrect": [], 
				"audio_url1": item.audio_cn_url
			}

			configItem.correct.push({
				"type": "Text", 
				"text": item.text_en, 
				"audio_url": item.audio_cn_url, 
				"image_url": ""
			})

			errItem.forEach(eItem=>{
				configItem.incorrect.push({
					"type": "Text", 
					"text": eItem.text_en, 
					"audio_url": eItem.audio_cn_url, 
					"image_url": ""
				})
			})
			
			tData.contentObj.dataArray.push(configItem);
		})
		return tData;
	},

	preloadItem(callback) {
		this.addPreloadImage();
		this.addPreloadAudio();
		this.addPreloadAnima();
		this.preload(()=>{if(callback) callback()});
	},


	addPreloadImage() {
		this.data.contentObj.dataArray.forEach(qItem => {
			qItem.correct.forEach(item=>{
				if(item.type == "Image" && item.image_url) {
					this._imageResList.push({ url: item.image_url });
				}
			})
			qItem.incorrect.forEach(item=>{
				if(item.type == "Image" && item.image_url) {
					this._imageResList.push({ url: item.image_url });
				}
			})
		})
		
		this._imageResList.push({ url: this.data.pic_url_2 });
	},

	addPreloadAudio() {
		this.data.contentObj.dataArray.forEach(qItem => {
			if(qItem.audio_url1) {
				this._audioResList.push({ url: qItem.audio_url1 });
			}
			qItem.correct.forEach(item=>{
				if(item.audio_url) {
					this._imageResList.push({ url: item.audio_url });
				}
			})
			qItem.incorrect.forEach(item=>{
				if(item.audio_url) {
					this._imageResList.push({ url: item.audio_url });
				}
			})
		})
	},

	addPreloadAnima() {

	},

	preload(callback) {

		const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
		cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {

			this.loadEnd();
			if (window && window["air"]) {
				window["air"].hideAirClassLoading();
			}
			if(callback) {
				callback();
			}
			cc.debug.setDisplayStats(false);
		});
	},


	loadEnd() {
		this.initData();
		this.initAudio();
		// this.initView();
		// this.initListener();
	},

	_cantouch: null,
	initData() {
		// 所有全局变量 默认都是null 
		this._cantouch = true;
	},

	audioBtn: null,
	initAudio() {
		const audioNode = cc.find('Canvas/res/audio');

		const getAudioByResName = (resName) => {
			return audioNode.getChildByName(resName).getComponent(cc.AudioSource);
		}

		this.audioBtn = getAudioByResName('btn');

	},


	// initView() {
	// 	// this.initBg();
	// 	// this.initPic();
	// 	// this.initBtn();
	// 	// this.initIcon();
	// },

	// initBg() {
	// 	const bgNode = cc.find('Canvas/bg');
	// 	bgNode.scale = this._mapScaleMax;
	// },

	// pic1: null,
	// pic2: null,
	// initPic() {
	// 	const canvas = cc.find('Canvas');
	// 	const maxW = canvas.width * 0.7;

	// 	this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
	// 		const picNode1 = sprNode;
	// 		picNode1.scale = maxW / picNode1.width;
	// 		picNode1.baseX = picNode1.x;
	// 		canvas.addChild(picNode1);
	// 		this.pic1 = picNode1;

	// 		const labelNode = new cc.Node();
	// 		labelNode.color = cc.Color.YELLOW;
	// 		const label = labelNode.addComponent(cc.Label);
	// 		label.string = this.data.text;
	// 		label.fontSize = 60;
	// 		label.lineHeight = 60;
	// 		label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
	// 		picNode1.addChild(labelNode);
	// 	});

	// 	this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
	// 		const picNode2 = sprNode;
	// 		picNode2.scale = maxW / picNode2.width;
	// 		canvas.addChild(picNode2);
	// 		picNode2.x = canvas.width;
	// 		picNode2.baseX = picNode2.x;
	// 		this.pic2 = picNode2;

	// 		const labelNode = new cc.Node();
	// 		const label = labelNode.addComponent(cc.RichText);
	// 		const size = 60
	// 		label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
	// 		label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
	// 		label.lineHeight = size;
	// 		picNode2.addChild(labelNode);
	// 	});

	// },

	// initIcon() {
	// 	const iconNode = this.getSprNode('icon');
	// 	iconNode.zIndex = 5;
	// 	iconNode.anchorX = 1;
	// 	iconNode.anchorY = 1;
	// 	iconNode.parent = cc.find('Canvas');
	// 	iconNode.x = iconNode.parent.width / 2 - 10;
	// 	iconNode.y = iconNode.parent.height / 2 - 10;

	// 	iconNode.on(cc.Node.EventType.TOUCH_START, () => {
	// 		this.playAudioByUrl(this.data.audio_url);
	// 	})
	// },

	// curPage: null,
	// initBtn() {

	// 	this.curPage = 0;
	// 	const bottomPart = cc.find('Canvas/bottomPart');
	// 	bottomPart.zIndex = 5; // 提高层级

	// 	bottomPart.x = bottomPart.parent.width / 2;
	// 	bottomPart.y = -bottomPart.parent.height / 2;

	// 	const leftBtnNode = bottomPart.getChildByName('btn_left');
	// 	//节点中添加了button组件 则可以添加click事件监听
	// 	leftBtnNode.on('click', () => {
	// 		if (!this._cantouch) {
	// 			return;
	// 		}
	// 		if (this.curPage == 0) {
	// 			return;
	// 		}
	// 		this.curPage = 0
	// 		this.leftMove();

	// 		cc.audioEngine.play(this.audioBtn.clip, false, 0.8)
	// 	})

	// 	const rightBtnNode = bottomPart.getChildByName('btn_right');
	// 	//节点中添加了button组件 则可以添加click事件监听
	// 	rightBtnNode.on('click', () => {
	// 		if (!this._cantouch) {
	// 			return;
	// 		}
	// 		if (this.curPage == 1) {
	// 			return;
	// 		}

	// 		this.curPage = 1
	// 		this.rightMove();

	// 		cc.audioEngine.play(this.audioBtn.clip, false, 0.5)
	// 	})
	// },

	// leftMove() {
	// 	this._cantouch = false;
	// 	const len = this.pic1.parent.width;
	// 	cc.tween(this.pic1)
	// 		.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
	// 		.start();

	// 	cc.tween(this.pic2)
	// 		.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
	// 		.call(() => {
	// 			this._cantouch = true;
	// 		})
	// 		.start();
	// },

	// rightMove() {
	// 	this._cantouch = false;
	// 	const len = this.pic1.parent.width;
	// 	cc.tween(this.pic1)
	// 		.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
	// 		.start();

	// 	cc.tween(this.pic2)
	// 		.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
	// 		.call(() => {
	// 			this._cantouch = true;
	// 		})
	// 		.start();
	// },
	// update (dt) {},
























	// ------------------------------------------------
	getSprNode(resName) {
		const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
		const node = new cc.Node();
		node.addComponent(cc.Sprite).spriteFrame = sf;
		return node;
	},


	getSpriteFrimeByUrl(url, cb) {
		cc.loader.load({ url }, (err, img) => {
			const spriteFrame = new cc.SpriteFrame(img)
			if (cb) {
				cb(spriteFrame);
			}
		})
	},

	getSprNodeByUrl(url, cb) {
		const node = new cc.Node();
		const spr = node.addComponent(cc.Sprite);
		this.getSpriteFrimeByUrl(url, (sf) => {
			spr.spriteFrame = sf;
			if (cb) {
				cb(node);
			}
		})
	},

	playAudioByUrl(audio_url, cb = null) {
		if (audio_url) {
			cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
				const audioId = cc.audioEngine.play(audioClip, false, 0.8);
				if (cb) {
					cc.audioEngine.setFinishCallback(audioId, () => {
						cb();
					});
				}
			});
		}
	},

	// ------------------------------------------

});
