import { asyncDelay, delayCall, getSprNode, getSprNodeByUrl, onHomeworkFinish, playAudio, playAudioByUrl } from "../script/util";
import { defaultData } from "../script/defaultData";

cc.Class({

	extends: cc.Component,

	properties: {
	},

	// 生命周期 onLoad
	onLoad() {
		this._timeoutIds = [];
		this._intervalIds = [];
		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;

		this.canvas = cc.find('Canvas');
	},


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

		getData((data) => {
			console.log('data:', data);
			this.data = data || this.getDefaultData();

			console.log('this.data:', this.data);

			this.data = JSON.parse(JSON.stringify(this.data))
			this.preloadItem()
		})
	},

	getData(func) {
		// if (window && window.courseware) {
		// 	window.courseware.getData(func, 'scene');
		// 	return;
		// }

		// const middleLayer = cc.find('middleLayer');
		// if (middleLayer) {
		// 	const middleLayerComponent = middleLayer.getComponent('middleLayer');
		// 	middleLayerComponent.getData(func);
		// 	return;
		// }

		func(this.getDefaultData());
	},

	getDefaultData() {

		return {"animArr":[{"key":"letter_big_0","title":"大写彩色动画","skeJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/3854b249ba08fe0d7f7be94308eda238.json","name":"D大彩_ske.json"},"texJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/047c4030ce0956e7fa491bb10efa99d0.json","name":"D大彩_tex.json"},"texPngData":{"url":"https://staging-teach.cdn.ireadabc.com/fdeefde6344de8b50de4c1e97532de46.png","name":"D大彩_tex.png"}},{"key":"letter_big_1","title":"大写黑色动画","skeJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/4a73aa0ed1abe9fe59cbc9396164ab0b.json","name":"D大黑_ske.json"},"texJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/264182a83f00f862662611adde7afc05.json","name":"D大黑_tex.json"},"texPngData":{"url":"https://staging-teach.cdn.ireadabc.com/444b96de33fb48ab6a488b058d81449d.png","name":"D大黑_tex.png"}},{"key":"letter_small_0","title":"小写彩色动画","skeJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/4fbe3832ff08127bb2899c525f3c0918.json","name":"D小彩_ske.json"},"texJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/958bfb6722f4bf5f2b5d975e420cf23c.json","name":"D小彩_tex.json"},"texPngData":{"url":"https://staging-teach.cdn.ireadabc.com/489483bb7b433044f5736ac1f05d4bf2.png","name":"D小彩_tex.png"}},{"key":"letter_small_1","title":"小写黑色动画","skeJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/f88764f49c73d2bdc7ab21d3f3f3c4bc.json","name":"D小黑_ske.json"},"texJsonData":{"url":"https://staging-teach.cdn.ireadabc.com/403916dcfd80ce24069eddce10e0124c.json","name":"D小黑_tex.json"},"texPngData":{"url":"https://staging-teach.cdn.ireadabc.com/840b55ebf6ae75ec7cf011c48f3189ec.png","name":"D小黑_tex.png"}}],"write_big_0_audio_url":"https://staging-teach.cdn.ireadabc.com/d4c2f72fd4238c48c1b19d747d0ce382.mp3","write_big_1_audio_url":"https://staging-teach.cdn.ireadabc.com/4c5a39defde0e90f3a53bf50db6943f4.mp3","write_big_2_audio_url":"https://staging-teach.cdn.ireadabc.com/a5652eadaf165869b2b551530921bb0d.mp3","write_small_0_audio_url":"https://staging-teach.cdn.ireadabc.com/d099918c85ac7afc33f169c9038f46d4.mp3","write_small_1_audio_url":"https://staging-teach.cdn.ireadabc.com/2f1ea180fb4d17dce34e8d7cc6cf9159.mp3","write_small_2_audio_url":"https://staging-teach.cdn.ireadabc.com/15147c1c4ae733303566baf84fae2840.mp3","finish_audio_url":"https://staging-teach.cdn.ireadabc.com/7fb349c67a76d2112a0604e624acaa97.mp3","tip_audio_url":"https://staging-teach.cdn.ireadabc.com/d5cdef3f02abe29b14ca8c16ad4e7543.mp3","letter":"A","dot_small_2_url":"https://staging-teach.cdn.ireadabc.com/8a8cbc71ad861b372418f36aef32a8cd.png","dot_small_1_url":"https://staging-teach.cdn.ireadabc.com/80221b2a4b62f57c33c7e6491f372077.png","dot_big_1_url":"https://staging-teach.cdn.ireadabc.com/e2b74edc1520bc2001d82b4e8aaba5d7.png","dot_big_2_url":"https://staging-teach.cdn.ireadabc.com/e2b74edc1520bc2001d82b4e8aaba5d7.png","bg_pic_url":"http://staging-teach.cdn.ireadabc.com/7e2e266a6e2e596103ac973e0a22d3ac.jpg","bgItem2":{"url":"http://staging-teach.cdn.ireadabc.com/e94766af9c75bcdc8308a914929afc74.png","rect":{"x":172.26,"y":0,"width":1367.48,"height":1769}},"hotZoneItemArr2":[{"id":"1666840073802","index":0,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"3","labelText":"rac w a say","posX":803.5,"posY":249.5,"rect":{"x":182.53,"y":152.34,"width":391.64,"height":42.43}},{"id":"1666840147464","index":1,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"5","labelText":"A","posX":522.5,"posY":398.5,"rect":{"x":138.71,"y":220.52,"width":88.35,"height":113.39}},{"id":"1666840195993","index":2,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_0_b","posX":899.5,"posY":401.5,"rect":{"x":403.75,"y":223.99,"width":82.78,"height":110.61}},{"id":"1666840237362","index":3,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_1_b","posX":1082.4997014371008,"posY":398.5003494839767,"rect":{"x":531.05,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840289442","index":4,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_2_b","posX":"1265","posY":398.5003494839767,"rect":{"x":658,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840378939","index":5,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_3_b","posX":"1448","posY":398.5003494839767,"rect":{"x":785.3,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840417298","index":6,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_4_b","posX":"1632","posY":398.5003494839767,"rect":{"x":913.3,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840451040","index":7,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_5_b","posX":1814.0003364272902,"posY":398.5003468726394,"rect":{"x":1039.91,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840547094","index":8,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"A_6_b","posX":1999.0004974597578,"posY":398.5003468726394,"rect":{"x":1168.6,"y":221.91,"width":82.78,"height":110.61}},{"id":"1666840559646","index":9,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_0_s","posX":901.000658492225,"posY":683.5003468726394,"rect":{"x":412.79,"y":445.21,"width":66.78,"height":60.52}},{"id":"1666840588967","index":10,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_1_s","posX":1082.9997027427694,"posY":682.500594949684,"rect":{"x":539.4,"y":444.51,"width":66.78,"height":60.52}},{"id":"1666840599411","index":11,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_2_s","posX":1260.9998611638996,"posY":683.5005940792382,"rect":{"x":663.22,"y":445.21,"width":66.78,"height":60.52}},{"id":"1666840612277","index":12,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_3_s","posX":1444.0000161032467,"posY":684.500594949684,"rect":{"x":790.52,"y":445.9,"width":66.78,"height":60.52}},{"id":"1666840622998","index":13,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_4_s","posX":1631.0001753948227,"posY":682.5005958201295,"rect":{"x":920.6,"y":444.51,"width":66.78,"height":60.52}},{"id":"1666840636543","index":14,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_5_s","posX":1811.0003381681818,"posY":682.5005940792382,"rect":{"x":1045.82,"y":444.51,"width":66.78,"height":60.52}},{"id":"1666840652074","index":15,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"1","labelText":"a_6_s","posX":1993.0004948484204,"posY":684.5005940792382,"rect":{"x":1172.42,"y":445.9,"width":66.78,"height":60.52}},{"id":"1666840663151","index":16,"itemType":"rect","fontScale":1.3375,"imgScale":1,"imgSizeW":0,"imgSizeH":0,"mapScale":1.3375,"dragDot":{"x":856,"y":875.97907444668},"gIdx":"2","posX":1249.5,"posY":520.5,"rect":{"x":59.41,"y":134.26,"width":1258.4,"height":455.64}}]}
		// return {"write_big_0_audio_url":"https://teach.cdn.ireadabc.com/d1dc9853d03d0237f0d2206dcf7f62e9.mp3","write_big_1_audio_url":"https://teach.cdn.ireadabc.com/eb0054aa1415046dfa35ed31a3a7e35c.mp3","tip_audio_url":"https://teach.cdn.ireadabc.com/52824b6c66664de8ee7b3bef3af5593f.mp3","finish_audio_url":"https://staging-teach.cdn.ireadabc.com/750a7079ea924a9260cebf649645b87c.mp3","write_small_0_audio_url":"https://teach.cdn.ireadabc.com/b2ce05a59cbdcaef5d85e56c6ffdcc20.mp3","write_small_1_audio_url":"https://teach.cdn.ireadabc.com/eb0054aa1415046dfa35ed31a3a7e35c.mp3","write_small_2_audio_url":"https://teach.cdn.ireadabc.com/908269df525600b866042ab473a0b879.mp3","write_big_2_audio_url":"https://teach.cdn.ireadabc.com/0fd3a090c37a2c11bb8503908a1326f2.mp3","letter":"A","animArr":[{"key":"letter_big_0","title":"大写彩色动画","skeJsonData":{"url":"https://teach.cdn.ireadabc.com/cdee11a12d4bf498bd3f0931bfe858cf.json","name":"A大彩_ske.json"},"texJsonData":{"url":"https://teach.cdn.ireadabc.com/ae2b83555093e3a739fcef9f107f52bb.json","name":"A大彩_tex.json"},"texPngData":{"url":"https://teach.cdn.ireadabc.com/db4a8c0d718e998f8fd3983aaf39e8d5.png","name":"A大彩_tex.png"}},{"key":"letter_big_1","title":"大写黑色动画","skeJsonData":{"url":"https://teach.cdn.ireadabc.com/14c5231012b4a1f3ac898ca6f83bc213.json","name":"A大黑_ske.json"},"texJsonData":{"url":"https://teach.cdn.ireadabc.com/a9e874a147023e0944cf89c351661218.json","name":"A大黑_tex.json"},"texPngData":{"url":"https://teach.cdn.ireadabc.com/8e12ae87d2c1a7bb6fc320272a930d9b.png","name":"A大黑_tex.png"}},{"key":"letter_small_0","title":"小写彩色动画","skeJsonData":{"url":"https://teach.cdn.ireadabc.com/8c0ccddb1d49eb555846c006244b27dc.json","name":"A小彩_ske.json"},"texJsonData":{"url":"https://teach.cdn.ireadabc.com/667e32080f139a09ab434a698dccc18b.json","name":"A小彩_tex.json"},"texPngData":{"url":"https://teach.cdn.ireadabc.com/65abc1cc2e73a2b9bbaffa497d81e5a4.png","name":"A小彩_tex.png"}},{"key":"letter_small_1","title":"小写黑色动画","skeJsonData":{"url":"https://teach.cdn.ireadabc.com/356e9e26a2a74c57791fff7471142d54.json","name":"A小黑_ske.json"},"texJsonData":{"url":"https://teach.cdn.ireadabc.com/9a262fdad701a170994510e1562baa76.json","name":"A小黑_tex.json"},"texPngData":{"url":"https://teach.cdn.ireadabc.com/500b883b3c0c0613a6de963f3deb7f72.png","name":"A小黑_tex.png"}}],"bg_pic_url":"https://teach.cdn.ireadabc.com/520b8785f6b253aef7ced8941711c1cf.png","dot_big_1_url":"https://teach.cdn.ireadabc.com/125b10277b51185a8238f0ad2d399e3e.png","dot_big_2_url":"https://teach.cdn.ireadabc.com/e61ae4cb1ce8dfbec37f153980233d6b.png","dot_small_1_url":"https://teach.cdn.ireadabc.com/9b5c4f22242cff975aa6189235e4caf9.png","dot_small_2_url":"https://teach.cdn.ireadabc.com/cd32e56db4dc9fadea2ad52aa0c93066.png"};
	},

	preloadItem() {
		this.addPreloadImage();
		this.addPreloadAudio();
		this.addPreloadAnima();
		this.preload();
	},


	addPreloadImage() {

		this._imageResList.push({ url: this.data.dot_big_1_url || '' });
		this._imageResList.push({ url: this.data.dot_big_2_url || '' });
		this._imageResList.push({ url: this.data.dot_small_1_url || '' });
		this._imageResList.push({ url: this.data.dot_small_2_url || '' });
		this._imageResList.push({ url: this.data.bg_pic_url || '' });



	},

	addPreloadAudio() {

		if (this.data) {
			this._audioResList.push({ url: this.data.write_big_0_audio_url || '' });
			this._audioResList.push({ url: this.data.write_big_1_audio_url || '' });
			this._audioResList.push({ url: this.data.write_big_2_audio_url || '' });
			this._audioResList.push({ url: this.data.write_small_0_audio_url || '' });
			this._audioResList.push({ url: this.data.write_small_1_audio_url || '' });
			this._audioResList.push({ url: this.data.write_small_2_audio_url || '' });
			this._audioResList.push({ url: this.data.finish_audio_url || '' });
			this._audioResList.push({ url: this.data.tip_audio_url || '' });
		}
	},

	addPreloadAnima() {

		const animArr = this.data.animArr;
		for (let i=0; i<animArr.length; i++) {
			this._animaResList.push({ url: animArr[i]?.skeJsonData?.url || '' });
			this._animaResList.push({ url: animArr[i]?.texJsonData?.url || '' });
			this._animaResList.push({ url: animArr[i]?.texPngData?.url || '' });
		}
	},

	preload() {

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

			this.addServerListener();


			cc.debug.setDisplayStats(false);
		});
	},

	addServerListener() {

		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();
		}


		if (window.air) {
			window.air.osmoHandwritingCallback = (data) => {

				if (!data) {
					console.log('data is not exist!!!');
					return;
				}

				console.log('osmoHandwritingCallback data: ', data);

				if (typeof (data) == 'string') {
					console.log('data is string ');
					const dataObj = JSON.parse(data);

					this.photoEnd(dataObj);
					return;
				}

				// 哲学逻辑
				this.photoEnd(data);

			}
		}

	},

	loadEnd() {

		console.log('loadEnd')

		this.initData();
		this.initAudio();
		this.initView();


		const node = cc.find('middleLayer/ConsoleNode/BtnOpen');
		if (node) {
			node.opacity = 0;
		}
		// this.initListener();
	},


	step: null,
	canTouch: null,
	dataPool: null,
	initData() {
		// 所有全局变量 默认都是null 

		console.log(' canTouch = fasle  0');

		this.canTouch = false;
		this.step = 1;
		this.dataPool = [];




		this.centerItemArr = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, '1');
		this.benchmark1Data = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, '3')[0];
		this.benchmark2Data = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, '4')[0];
		this.firstItemData = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, '5')[0];

		this.initCheckBase();
		this.initQuesRegion();
		// this.initTestPointArr();
	},


	ques_region: null,
	initQuesRegion() {
		const regionItem = this.data.hotZoneItemArr2.find(hzItem => {
			return hzItem.gIdx == '2'
		})

		const bgRect = this.data.bgItem2.rect;
		const regionRect = regionItem.rect;

		const left = Math.round( (regionRect.x ) / bgRect.width  * 1000 ) / 1000;
		const right =  Math.round( (regionRect.x + regionRect.width) / bgRect.width * 1000 ) / 1000;
		const top =  Math.round( (regionRect.y ) / bgRect.height * 1000 ) / 1000;
		const bottom =  Math.round( (regionRect.y + regionRect.height) / bgRect.height * 1000 ) / 1000;

		this.ques_region = [
			left, top,
			right, top,
			right, bottom,
			left, bottom
		]

		console.log(' this.ques_region: ' , this.ques_region);

		console.log('regionItem: ', regionItem);
	},

	initTestPointArr() {
		
		const linkeItemArr = this.data.hotZoneItemArr.filter(hzItem => {
			return hzItem.gIdx == '0';
		})

		const bgRect = this.data.bgItem2.rect;

		const setDebugCenterPos = (hzItem) => {

			const debugItemIndex = (Number(hzItem.pointItem) - 1) 
			const debugItem = this.data.hotZoneItemArr2[debugItemIndex];
			const {rect} = debugItem

			const left = Math.round( (rect.x ) / bgRect.width  * 1000 ) / 1000;
			const right =  Math.round( (rect.x + rect.width) / bgRect.width * 1000 ) / 1000;
			const top =  Math.round( (rect.y ) / bgRect.height * 1000 ) / 1000;
			const bottom =  Math.round( (rect.y + rect.height) / bgRect.height * 1000 ) / 1000;
	
			
			const x = left + (right - left) / 2;
			const y = bottom - (bottom - top) / 2;

			// console.log('~~x: ', x);
			// console.log('~~y: ', y);
			hzItem.debugCenterPos = [x, y];
		}

		console.log('linkeItemArr: ', linkeItemArr);

		linkeItemArr.forEach(hzItem => {
			return setDebugCenterPos(hzItem);
		})

		const startPosObj = {};
		const endPosObj = {};

		for (let i=0; i<linkeItemArr.length; i++) {
			const index = this.data.hotZoneItemArr.indexOf(linkeItemArr[i]);
			const key = (index + 1).toString();
			if (!startPosObj[key] && !endPosObj[key]) {
				startPosObj[key] = linkeItemArr[i];


				const endKey = linkeItemArr[i].linkItem.toString();
				const endIndex = Number(endKey) - 1;
				const endItem = this.data.hotZoneItemArr[endIndex];
				endPosObj[endKey] = endItem;
			}
		}

		console.log('startPosObj: ', startPosObj);
		console.log('endPosObj: ', endPosObj);

		this.start_points = [];
		for (let key in startPosObj) {
			const item = startPosObj[key];
			this.start_points = this.start_points.concat(item.debugCenterPos);
		}

		console.log('this.start_points: ', this.start_points);

		this.end_points = [];
		for (let key in endPosObj) {
			const item = endPosObj[key];
			this.end_points = this.end_points.concat(item.debugCenterPos);
		}
		
		console.log('this.end_points: ', this.end_points);

	},

	initCheckBase() {

		console.log('benchmark1Data: ', this.benchmark1Data);
		console.log('benchmark2Data: ', this.benchmark2Data);
		console.log('centerItemArr: ', this.centerItemArr);

		const benchmark1Rect = this.benchmark1Data.rect;
		const benchmark1CenterY = (benchmark1Rect.y + benchmark1Rect.height / 2);

		let unitH;
		let unitW;
		let baseX;
		let baseY;

		if (this.benchmark2Data) {
			const benchmark2Rect = this.benchmark2Data.rect;
			const benchmark2CenterY = (benchmark2Rect.y + benchmark2Rect.height / 2);
			
			unitH = benchmark2CenterY - benchmark1CenterY;
			unitW = benchmark2Rect.x + benchmark2Rect.width - benchmark1Rect.x;
			baseX = benchmark1Rect.x;
			baseY = benchmark1CenterY;
		}

		if (this.firstItemData) {
			const firstItemRect = this.firstItemData.rect;
			baseX = firstItemRect.x + firstItemRect.width / 2;
			baseY = firstItemRect.y + firstItemRect.height / 2;
			unitW = benchmark1Rect.x + benchmark1Rect.width - (firstItemRect.x + firstItemRect.width / 2);
			unitH = (firstItemRect.y + firstItemRect.height / 2) - benchmark1CenterY;
		}


		for(let i=0; i<this.centerItemArr.length; i++) {

			const itemRect = this.centerItemArr[i].rect;
			const x = itemRect.x + itemRect.width / 2;
			const y = itemRect.y + itemRect.height / 2;

			const unitX = (x - baseX) / unitW;
			const unitY = (y - baseY) / unitH;
			const unitW2 = itemRect.width / unitW;
			const unitH2 = itemRect.height / unitH;


			this.centerItemArr[i].unitX = unitX;
			this.centerItemArr[i].unitY = unitY;
			this.centerItemArr[i].unitW = unitW2;
			this.centerItemArr[i].unitH = unitH2;

			this.initCheckLetter(this.centerItemArr[i]);

			// console.log('unitX: ', unitX)
			// console.log('unitY: ', unitY)
		}

		console.log('unitH: ', unitH)
		console.log('unitW: ', unitW)
		console.log('baseX: ', baseX)
		console.log('baseY: ', baseY)
	
		const centerX = this.data.bgItem2.rect.width / 2;
		this.centerUnitW = (centerX - baseX) / unitW;

	},


	getGroupArrByGIdx(arr, gIdx) {
		const groupArr = [];
		for (let i=0; i<arr.length; i++) {
			if (arr[i].gIdx == gIdx) {
				groupArr.push(arr[i]);
			}
		}

		return groupArr;
	},

	initCheckLetter(checkLetter) {
		console.log('checkLetter: ' ,checkLetter);
		const tempTextArr = checkLetter.labelText.split("_");
		console.log('tempTextArr: ' ,tempTextArr);
		if (tempTextArr.length > 1) {

			checkLetter.labelText = tempTextArr[0];
			checkLetter.index = tempTextArr[1];
			checkLetter.sizeType = tempTextArr[2];
			checkLetter.key = tempTextArr[1] + '_' + tempTextArr[2];
		}
	},



	audioBtn: null,
	audioBegin: null,
	audioTipArea: null,
	audioTipLetter: null,
	audioTipIcon: null,
	audioTipSuccess: null,

	audioTipError: null,
	audioTipNotFill: null,
	audioTipFillWrong: null,
	audioOsmoTip: null,
	audioRight: null,
	initAudio() {
		const audioNode = cc.find('Canvas/res/audio');

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

		this.audioBtn = getAudioByResName('btn');

		this.audioBegin = getAudioByResName('begin');



		this.audioTip1 = getAudioByResName('tip_1');
		this.audioTip2 = getAudioByResName('tip_2');
		this.audioTip3 = getAudioByResName('tip_3');

		this.audioOsmoTip = getAudioByResName('osmo_tip');
		this.audioRight = getAudioByResName('right');

		this.audioDefault = getAudioByResName('default');


	},



	//调起检测
	startTesting() {


		
		// this.getPhotoData((data) => {
		// 	this.photoEnd(data);
		// });     
		// return;

		const cw = window.courseware;
		if (!cw || !cw.openOsmoHandwriting) {

			console.log('cw.openOsmoHandwriting not exist');
			return;
		}



		const para = {
			"library_id": "iplayabc",
			"page_id": this.data.page_id, //27,
			"book_id": this.data.book_id,//"opw1",
			"part_name": this.data.part_name, //"d",
			"is_hand_writing": true,
			"is_line_link": false,
	
			'ques_region' : this.ques_region
		}
		cw.openOsmoHandwriting(para);


	},

	//结束检测
	endTesting() {
		const cw = window.courseware;
		if (!cw || !cw.closeOsmoHandwriting) {

			return;
		}
		cw.closeOsmoHandwriting();
		// this.isTesting = false;
	},

	isTesting: null,
	initTestingListener() {

		if (window.air) {
			window.air.osmoCallback = (res) => {
				// 哲学逻辑
				console.log('initTestingListener res: ', res);
				this.photoEnd(res);
			}
		}

	},


	initView() {

		this.initBg();

		this.initLetterItem();



		this.initWriteArea(false);
		this.initWriteArea(true);

		this.initDebugLayer();


		this.initCatListener();

		this.gameStart();





	},



	initCatListener() {

		const content = cc.find("Canvas/content");
		content.zIndex = 10;

		const catBox = cc.find("Canvas/content/catFrame/catBox")
		catBox.on('touchstart', () => {
			if (this.isPlayTip) {
				return;
			}

			if (!this.canTouch) {
				return;
			}


			if (!this.data.tip_audio_url) {
				return;
			}


			this.isPlayTip = true;

			this.playAni('begin', 0)
			//播放引导音频1
	
			playAudioByUrl(this.data.tip_audio_url, () => {
	
				this.isPlayTip = false;
				this.playAni('normal', 0);
	
			})

		})
	},


	writeNodeArr: null,
	initWriteArea(isSmall) {

		let writeBg;
		if (isSmall) {
			writeBg = this.itemBgSmall;
		} else {
			writeBg = this.itemBgBig;
		}


		const num = 7;

		const edge = 0.05;
		const baseW = 132
		const baseX = 250;
		const baseH = writeBg.height * 0.9;

		
		const writeNodeArr = [];

		for (let i = 0; i < num; i++) {

			const writeNode = new cc.Node();
			writeNode.x = baseX + baseW * i;
			// writeNode.y = -baseH / 2;
			writeNode.width = baseW;
			writeNode.height = baseH;
			writeBg.addChild(writeNode);

			writeNode.hitCount = 0;



			writeNodeArr.push(writeNode);
		}

		if (isSmall) {
			this.writeNodeArr2 = writeNodeArr;
		} else {
			this.writeNodeArr1 = writeNodeArr;
		}
	},



	maskNode: null,
	initMask() {

		const maskNode = new cc.Node();
		maskNode.width = this.canvas.width;
		maskNode.height = this.canvas.height;
		maskNode.anchorX = 0.5;
		maskNode.anchorY = 0.5;
		const mask = maskNode.addComponent(cc.Graphics);
		mask.fillColor = cc.Color.BLACK.setA(100);
		mask.fillRect(-this.canvas.width / 2, -this.canvas.height / 2, this.canvas.width, this.canvas.height);
		this.canvas.addChild(maskNode, 9);

		maskNode.addComponent(cc.BlockInputEvents);
		maskNode.active = false;
		this.maskNode = maskNode;
	},

	addDefaultMusic() {
		// console.log(' in ')
		// playAudio(this.audioDefault.clip, () => {
		// 	console.log(' wusheng end');
		// })
		cc.audioEngine.play(this.audioDefault.clip, true, 0.8);

	},


	initBg() {

		const bg = new cc.Node();
		this.canvas.addChild(bg);

		getSprNodeByUrl(this.data.bg_pic_url, (spr) => {
			// spr.node.parent = animNode.parent;
			// spr.node.x = animNode.x;
			// spr.node.y = animNode.y;
			// spr.node.scale = animNode.scale;

			// console.log('	spr.node.width: ', spr.node.width)
			// console.log('	spr.node.height: ', spr.node.height)
			bg.width = spr.node.width;
			bg.height = spr.node.height;

			spr.node.anchorX = 1;
			spr.node.anchorY = 0;
			bg.anchorX = 1;
			bg.anchorY = 0;
			bg.addChild(spr.node);

			const canvas = cc.find('Canvas');
			bg.scale = Math.max((canvas.width / bg.width), (canvas.height / bg.height));
			bg.y = -this.canvas.height / 2;
			bg.x = this.canvas.width / 2;
		})

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

		// const canvas = cc.find('Canvas');
		// bgNode.scale = Math.max((canvas.width / bgNode.width), (canvas.height / bgNode.height));
	},


	letterItemArr: null,
	initLetterItem() {

		this.addLetterItemBig();
		this.addLetterItemSmall();
	
		
	},

	addLetterItemBig() {

		const itemBgBig = getSprNode('item_bg');
		itemBgBig.scale = this._mapScaleMin;
		itemBgBig.anchorX = 0;
		this.canvas.addChild(itemBgBig);
		this.itemBgBig = itemBgBig;

	
			
		const letterW = 50 * this._mapScaleMin;
		itemBgBig.x = -itemBgBig.width / 2 * itemBgBig.scaleX + letterW;
		itemBgBig.y =  200 * this._mapScaleMin;
		// itemLetterBig.x = itemBgBig.x - letterW;
		// itemLetterBig.y = itemBgBig.y;

		// getSprNodeByUrl(this.data.letter_big_pic_url, (spr) => {
		// 	const itemLetterBig = spr.node;
		// 	this.canvas.addChild(itemLetterBig);

		// 	itemLetterBig.scale = itemBgBig.height / itemLetterBig.height;

		// 	itemLetterBig.x = itemBgBig.x - letterW;
		// 	itemLetterBig.y = itemBgBig.y;
		// })

		

		let animColor;
		let animBlack;
		const checkShowOneLineAnim = () => {
			if (animColor && animBlack) {
				this.setOneLineAllAnimBig(animColor, animBlack, itemBgBig)
				this.showLetterAnim(1000,	this.letterAnimBig);
				this.addColorLetterListener( this.letterAnimBig );
			}
		}

		const bigColorData = this.getAnimData('letter_big_0');
		const bigBlackData = this.getAnimData('letter_big_1');

		this.getOneAnim(bigColorData, (animNode) => {

			animColor = animNode;
			animColor.x = 100;
			animColor.name = 'daxie_yanse'
			this.letterAnimBig = animColor;
			itemBgBig.addChild(animColor);
			checkShowOneLineAnim();			

		})

		this.getOneAnim(bigBlackData, (animNode) => {
			animBlack = animNode;
			checkShowOneLineAnim();

			const itemLetterBig = cc.instantiate(animNode);
			this.canvas.addChild(itemLetterBig);
			itemLetterBig.animationNames = animNode.animationNames;



			this.showLetterAnim(1000, itemLetterBig);

			itemLetterBig.x = itemBgBig.x - letterW;
			itemLetterBig.y = itemBgBig.y;


			// itemLetterBig.scale = 0.614;

			// itemLetterBig.y += itemBgBig.height / 6;

		})


		

		// const letterAnim0 = this.getLetterAnimBig0(letterS.toUpperCase());
		// letterAnim0.x = 100;
		// this.letterAnimBig = letterAnim0;
		// itemBgBig.addChild(letterAnim0);

		// const baseX = letterAnim0.x + 150;
		// const baseY = letterAnim0.y + 32;
		// const disW = 132;
		// for (let i=0; i<7; i++) {
		// 	const letterAnim1 = this.getLetterAnimBig1(letterS);
		// 	letterAnim1.x = baseX + i * disW;
		// 	letterAnim1.y = baseY;
		// 	itemBgBig.addChild(letterAnim1);

		// 	if (i < 2) {
		// 		letterAnim1.opacity = 255 * 0.5;
		// 	} else {
		// 		letterAnim1.active = false;
		// 	}
		// }
	},

	setLetterDot(animNode, key) {
		const url = this.data[key + '_url'];
		if (url) {
			getSprNodeByUrl(url, (spr) => {
				spr.node.parent = animNode.parent;
				spr.node.x = animNode.x;
				spr.node.y = animNode.y;
				spr.node.scale = animNode.scale;

				console.log('	spr.node.width: ', spr.node.width)
				console.log('	spr.node.height: ', spr.node.height)
			})
		}
	},


	addColorLetterListener(letter) {

		console.log(' in addColorLetterListener 1', letter.name || '')


		const nodeW = 258;
		const nodeH = 138;
		letter.width = nodeW;
		letter.height = nodeH;
		
		letter.on('touchstart', ()=> {

			console.log( ' in addColorLetterListener 2')

			if (!this.canTouch) {
				return;
			}

			console.log(' canTouch = fasle  1');

			this.canTouch = false;

			this.showLetterAnim(1, 	letter, () => {
				this.checkShowDataPool();
			});

		})
	},

	getAnimData(key) {
		const animArr = this.data.animArr;
		for (let i=0; i<animArr.length; i++) {
			if (animArr[i].key == key) {
				return animArr[i];
			}
		}
	},

	setOneLineAllAnimBig(animColor, animBlack, animBg) {

		this.lineLetterBigArr = [];
		const baseX = animColor.x + 150;
		// const baseY = animColor.y + 32;
		const disW = 132;
		for (let i=0; i<7; i++) {
			const anim = cc.instantiate(animBlack);
			anim.animationNames = animBlack.animationNames;
			anim.x = baseX + i * disW;

			// anim.scale = animBg.height / anim.height;
			
			if (anim.height) {
				// anim.scale = 0.614;
				// if(animBg != this.itemBgSmall) {
				// 	anim.y += animBg.height / 6;
				// }
			} else {
				
				// anim.scale = 0.614;
				// if(animBg != this.itemBgSmall) {
				// 	anim.y += animBg.height / 6;
				// }
			}

			// console.log('	anim.scale ~ ', 	anim.scale);

			animBg.addChild(anim, 1);

			this.showLetterAnim(1000, anim);
			// const dragonDisplay = anim.getComponent(dragonBones.ArmatureDisplay);
			// dragonDisplay.timeScale = 1000;
			// dragonDisplay.playAnimation(anim.animationNames[0], 1);

			if (i < 2) {
				anim.opacity = 255 * 0.3;
				if (i == 0) {
					this.setLetterDot(anim, 'dot_big_1');
				}

			} else {
				anim.active = false;
				this.setLetterDot(anim, 'dot_big_2');
			}

			this.lineLetterBigArr.push(anim);
		}
	},


	setOneLineAllAnimSmall(animColor, animBlack, animBg) {

		this.lineLetterSmallArr = [];
		const baseX = animColor.x + 150;
		const disW = 132;
		for (let i=0; i<7; i++) {
			const anim = cc.instantiate(animBlack);
			anim.animationNames = animBlack.animationNames;
			anim.x = baseX + i * disW;
				
			// anim.scale = 0.614;

			// console.log('	anim.scale ~ ', 	anim.scale);

			animBg.addChild(anim, 1);

			this.showLetterAnim(1000, anim);
			// const dragonDisplay = anim.getComponent(dragonBones.ArmatureDisplay);
			// dragonDisplay.timeScale = 1000;
			// dragonDisplay.playAnimation(anim.animationNames[0], 1);

			if (i < 2) {
				anim.opacity = 255 * 0.3;

				if (i == 0) {
					this.setLetterDot(anim, 'dot_small_1');
				}

			} else {
				anim.active = false;

				this.setLetterDot(anim, 'dot_small_2');
			}


			this.lineLetterSmallArr.push(anim);
		}
	},

	addLetterItemSmall() {


		const itemBgSmall = getSprNode('item_bg');
		itemBgSmall.scale = this._mapScaleMin;
		itemBgSmall.anchorX = 0;
		this.canvas.addChild(itemBgSmall);
		this.itemBgSmall = itemBgSmall;

			
		const letterW = 50 * this._mapScaleMin;
		itemBgSmall.x = -itemBgSmall.width / 2 * itemBgSmall.scaleX + letterW;
		itemBgSmall.y =  -30 * this._mapScaleMin;
	

		let animColor;
		let animBlack;
		const checkShowOneLineAnim = () => {
			if (animColor && animBlack) {
				this.setOneLineAllAnimSmall(animColor, animBlack, itemBgSmall)
				this.showLetterAnim(1000, this.letterAnimSmall);
				this.addColorLetterListener( this.letterAnimSmall );
			}
		}

		const smallColorData = this.getAnimData('letter_small_0');
		const smallBlackData = this.getAnimData('letter_small_1');

		this.getOneAnim(smallColorData, (animNode) => {

			animColor = animNode;
			animColor.x = 100;
			this.letterAnimSmall = animColor;
			itemBgSmall.addChild(animColor);
			checkShowOneLineAnim();			

		})

		this.getOneAnim(smallBlackData, (animNode) => {
			animBlack = animNode;
			checkShowOneLineAnim();

			const itemLetterSmall = cc.instantiate(animNode);
			this.canvas.addChild(itemLetterSmall);
			itemLetterSmall.animationNames = animNode.animationNames;

			this.showLetterAnim(1000, itemLetterSmall);

			itemLetterSmall.x = itemBgSmall.x - letterW;
			itemLetterSmall.y = itemBgSmall.y;

			// itemLetterSmall.scale = 0.614;

			// itemLetterSmall.y += itemBgSmall.height / 6;
		})


		// const letterS = this.data.letter.toLowerCase();

		// const itemLetterSmall = getSprNode('letter/' + letterS + '_0_1');
		// // itemLetterSmall.x = -this.canvas.width / 2 + 70 * this._mapScaleMin;
		// // itemLetterSmall.y = -30 * this._mapScaleMin;
		// itemLetterSmall.scale = this._mapScaleMin;
		// this.canvas.addChild(itemLetterSmall);

		// const itemBgSmall = getSprNode('item_bg');
		// itemBgSmall.scale = this._mapScaleMin;
		// // itemBgSmall.x = itemLetterSmall.x + 70 * this._mapScaleMin;
		// // itemBgSmall.y = itemLetterSmall.y;
		// itemBgSmall.anchorX = 0;
		// this.canvas.addChild(itemBgSmall);
		// this.itemBgSmall = itemBgSmall;


		// const letterW = 50 * this._mapScaleMin;
		// itemBgSmall.x = -itemBgSmall.width / 2 * itemBgSmall.scaleX + letterW;
		// itemBgSmall.y =  -30 * this._mapScaleMin;
		// itemLetterSmall.x = itemBgSmall.x - letterW;
		// itemLetterSmall.y = itemBgSmall.y;


		// const letterAnim0 = this.getLetterAnimSmall0(letterS.toLowerCase());
		// letterAnim0.x = 100;
		// letterAnim0.y = 7;
		// letterAnim0.opacity = 160;
		// this.letterAnimSmall = letterAnim0;

		// itemBgSmall.addChild(letterAnim0);

		// const baseX = letterAnim0.x + 150;
		// const baseY = 4;
		// const disW = 132;
		// for (let i=0; i<7; i++) {
		// 	const letterAnim1 = this.getLetterAnimSmall1(letterS);
		// 	letterAnim1.x = baseX + i * disW;
		// 	letterAnim1.y = baseY;

		// 	if (i < 2) {
		// 		letterAnim1.opacity = 255 * 0.5;
		// 	} else {
		// 		letterAnim1.active = false;
		// 	}

		// 	itemBgSmall.addChild(letterAnim1);
		// }
	},

	getLetterAnimBig0(resName) {

		const anim = cc.find("Canvas/res/anim/" + resName + "_0")
		const letter = cc.instantiate(anim);
		// letter.scale *= 0.588;
		letter.name = resName;

		letter.on('touchstart', ()=> {

			if (!this.canTouch) {
				return;
			}

			console.log(' canTouch = fasle  2');

			this.canTouch = false;
			// const letterAnim = letter.getComponent(cc.Animation);
			// letterAnim.play('anim_A_0');

			// const cb = () => {
			// 	// this.canTouch = true;
			// 	this.checkShowDataPool();
			// 	letterAnim.off('finished', cb)
			// }
			// letterAnim.on('finished', cb);


			this.showLetterAnim(1, letter, () => {
				this.checkShowDataPool();
			});

		})


		return letter;

	},

	getLetterAnimBig1(letter) {
		const sprNode = getSprNode('letter/' + letter + '_1_1');
		return sprNode;
	},

	getLetterAnimSmall0(resName) {

		const anim = cc.find("Canvas/res/anim/" + resName + "_0")
		const letter = cc.instantiate(anim);
		// letter.scale *= 0.588;
		letter.name = resName;


		letter.on('touchstart', ()=> {

			if (!this.canTouch) {
				return;
			}

			console.log(' canTouch = fasle  3');

			this.canTouch = false;
			// const letterAnim = letter.getComponent(cc.Animation);
			// letterAnim.play('anim_a_0');

			// const cb = () => {
			// 	// this.canTouch = true;
			// 	this.checkShowDataPool();
			// 	letterAnim.off('finished', cb)
			// }
			// letterAnim.on('finished', cb);

			this.showLetterAnim(1, letter, () => {
				this.checkShowDataPool();
			});
		})


		return letter;

		// const sprNode = getSprNode('letter/' + letter + '_0_0');
		// return sprNode;
	},

	getLetterAnimSmall1(letter) {
		const sprNode = getSprNode('letter/' + letter + '_0_1');
		return sprNode;
	},


	debugLayer: null,
	initDebugLayer() {


		console.log(' in initDebugLayer');
		const layer = new cc.Node();

		if (this.data.isDebug || true) {
			layer.parent = cc.find('Canvas');
		}


		layer.width = this.canvas.width / 2;
		layer.height = this.canvas.height / 2;

		layer.zIndex = 100;
		layer.anchorX = 0;
		layer.anchorY = 1;


		if (!this.data.bgItem2) {
			return;
		}


		cc.loader.load({url: this.data.bgItem2.url}, (err, img) => {

			this.debugBgImg = img;
			this.checkBg = img;
			layer.width = img.width;
			layer.height = img.height;

			const sprNode = layer;
	
			var sf = new cc.SpriteFrame(img);

			const spr = sprNode.addComponent(cc.Sprite);
			spr.spriteFrame = sf			

			const sx = this.canvas.width / 2 / layer.width;
			const sy = (this.canvas.height) / 2 / layer.height;
			const s = Math.min(sx, sy);
			layer.scale = s;

			this.startTesting();
	
		});

		layer.x = -this.canvas.width / 2 + 10;
		layer.y = this.canvas.height / 2 - this.canvas.height / 3;
		layer.opacity = 150;

		this.debugLayer = layer;

		const drawLayer = new cc.Node();
    this.debugLayer.addChild(drawLayer, 2);

    this.debugDrawLayer = drawLayer;

	},




	getColorRectByPos(posArr, color='red') {
		const topLeft = posArr[0];
		const bottomRight = posArr[2];

		const sample = this.sample;
		const x = topLeft.x1 * sample.width;
		const y = topLeft.y1 * sample.height;
		const width = (bottomRight.x3 - topLeft.x1) * sample.width;
		const height = (bottomRight.y3 - topLeft.y1) * sample.height;
		const rect = {x, y: -y - height, width, height};

		// console.log('rect ', rect);
		const colorRect = this.getColorRect(rect, color);
		colorRect.opacity = 100;
		return colorRect;
	},


	gameStart() {

		this.beginShowAudio();
	},

	beginShowAudio() {


		console.log(' canTouch = fasle 4');

		this.canTouch = false;

		const playEnd = () => {

			this.isPlayTip = false;
			this.playAni('normal', 0);
			// this.startTesting();

			this.showLetterAnim(1, this.letterAnimBig, () => {
				this.showBigLetter1Audio();
			});
		}


		if (!this.data.write_big_0_audio_url) {
			playEnd();
			return;
		}

		this.isPlayTip = true;
		this.playAni('begin', 0)
		//播放引导音频1
		playAudioByUrl(this.data.write_big_0_audio_url, () => {
			if (this.isDestroy) {
				return;
			}
			playEnd();
		})
	},

	showLetterAnim(timeScale = 1, animNode, cb=null) {
		console.log(' in showLetterAnim')

		const dragonDisplay = animNode.getComponent(dragonBones.ArmatureDisplay);
		dragonDisplay.timeScale = timeScale;
		dragonDisplay.playAnimation(animNode.animationNames[0], 1);

		dragonDisplay.once(	dragonBones.EventObject.LOOP_COMPLETE , () => {
			cb && cb();
		})

	

		// const anim = this.letterAnimBig.getComponent(cc.Animation);

		// anim.play('anim_A_0');
		// const cb = () => {
		// 	console.log('in finished');
		// 	this.showBigLetter1Audio();
		// 	anim.off('finished', cb)
		// }

		// anim.on('finished', cb);



	},

	showBigLetter1Audio() {

		const playEnd = () => {

			this.playAni('normal', 0);

			console.log( 'this.canTouch = true  1 ');
			this.canTouch = true;
			this.startTesting();

			// this.showLetterAnim();
		}


		if (!this.data.write_big_1_audio_url) {
			playEnd();
			return;
		}

		this.playAni('begin', 0)
		//播放引导音频1
		playAudioByUrl(this.data.write_big_1_audio_url, () => {
			if (this.isDestroy) {
				return;
			}
			playEnd();
		})
	},






	showSecondLetter() {
		this.showLetter(1, () => {

			playAudio(this.audioTip3.clip, () => {

				if (this.isDestroy) {
					return;
				}
				// })
				//播放引导音频3
				// this.playAudioByUrl(this.data.guideAudioUrl3, () => {

				// state.stop();

				// this.playAni('normal', 0);

				// this.showPhotoBtn();

				this.showAllSound();
				this.showPhotoBtn();

				this.playAni('normal', 0);

			});

		})
	},

	showLetter(index, cb, isSmall) {


		let writeRect;

		if (isSmall) {
			writeRect = this.writeNodeArr2[Number(index)];

			console.log('show Letter small 1 :' , index)
		} else {
			writeRect = this.writeNodeArr1[Number(index)];
		}

		writeRect.hitCount++;
		if (writeRect.hitCount < 1) {
			return;
		}

		if (writeRect.isShowEnd) {
			return;
		}
		writeRect.isShowEnd = true;


		playAudio(this.audioRight.clip);

		if (!isSmall) {
			const animNode = this.lineLetterBigArr[index];
			animNode.active = true;
			animNode.opacity = 255;
			this.showLetterAnim(1, animNode, () => {

			});

		} else {

			const animNode = this.lineLetterSmallArr[index];
			animNode.active = true;
			animNode.opacity = 255;
			this.showLetterAnim(1, animNode, () => {

			});

		}
		return;



		console.log('show Letter small 2 :' , index)

		const letterAnim = this.getLetterAnim(isSmall);

		letterAnim.parent = writeRect;
		letterAnim.y = 4;

		// letterAnim.x = writeRect.width / 2;
		// letterAnim.y = writeRect.height / 2;

		this.showItemAniNew(letterAnim, () => {

			if (!this.isGameEnd) {
				this.checkGameEnd();

			}
		})

		playAudio(this.audioRight.clip);

	},

	checkGameEnd() {
		return;
		const writeNodeArr = this.writeNodeArr;
		const isEnd = writeNodeArr.every(node => {
			return node.isShowEnd;
		})

		if (isEnd) {
			this.gameEnd();
		} else {


			this.endTesting();

			setTimeout(() => {
				this.startTesting();
			}, 8000);

		}
	},

	isGameEnd: null,
	gameEnd() {

		this.isGameEnd = true;
		console.log('in gameEnd');
		this.endTesting();
	},

	getLetterAnim(isSmall) {

		let resName;
		if (isSmall) {
			resName = this.data.letter.toLowerCase();
		} else {
			resName = this.data.letter.toUpperCase();
		}
		const anim = cc.find("Canvas/res/anim/" + resName)
		const letter = cc.instantiate(anim);
		letter.scale *= 0.588;
		letter.name = resName;

		if (!isSmall) {
			letter.anchorY = 0.28
		}

		return letter;
	},

	showItemAniNew(item, cb) {
		if (item.isShow) {
			return;
		}
		item.isShow = true;
		item.active = true;

		// const anim = item.getComponent(cc.Animation);
		// console.log(' showItemAniNew  item: ', item);

		// anim.play(item.name);

		// anim.on('finished', () => {
		// 	console.log('in finished');
		// 	if (cb) {
		// 		cb();
		// 	}
		// });


		this.showLetterAnim(1, item, () => {
			cb && cb();
		});


	},

	showItemAni(item, cb) {
		if (item.isShow) {
			return;
		}
		item.isShow = true;

		item.opacity = 0;
		item.active = true;
		cc.tween(item)
			.to(1, { opacity: 255 })
			.call(() => {
				if (cb) {
					cb();
				}
			})
			.start();
	},

	showAllSound() {
		const letterItemArr = this.letterItemArr;
		for (let i = 0; i < letterItemArr.length; i++) {
			const item = letterItemArr[i];
			this.showItemAni(item.btnSound);
		}
	},




	playAni(name, times = 1) {

		const cat = cc.find('Canvas/content/catFrame/cat');

		var dragonDisplay = cat.getComponent(dragonBones.ArmatureDisplay);

		const state = dragonDisplay.playAnimation(name, times);
		return state;
	},

	playTipAni(name, times = 1, cb = null) {

		const tip = cc.find('Canvas/tipFrame/tip');
		tip.parent.zIndex = 10;
		tip.active = true;

		var dragonDisplay = tip.getComponent(dragonBones.ArmatureDisplay);

		const state = dragonDisplay.playAnimation(name, times);

		dragonDisplay.on(dragonBones.EventObject.COMPLETE, () => {
			tip.active = false;
			if (cb) {
				cb();
			}
		})

		return state;
	},

	moveHand(index, callback = null) {

		let textNode = cc.find("Canvas/content/bg_green/bg_word-background/text");

		let wordNodeArr = textNode.wordNodeArr

		let wordNode = wordNodeArr[2 * index];

		if (!wordNode) {

			if (callback) {
				callback();
			}
			return;
		}

		let handNode = cc.find("Canvas/content/bg_green/bg_word-background/text/icon_hand");
		handNode.x = wordNode.x;

		this.handAni();

		if (callback) {
			callback();
		}
	},

	/**
	 * 播放文本音频
	 * @param {*} callback 
	 */
	playTextAutio(callback = null) {

		this.playAudioByUrl(this.data.exercises.audioUrl, () => {

			if (this.isDestroy) {
				return;
			}
			//停止监听动画
			this._stopAni = true;

			if (callback) {
				callback();
			}
		}, (audioId) => {

			//显示完成，不再播放动画
			if (this._shown) {
				return;
			}

			//设置可播放动画
			this._stopAni = false;

			//隐藏手指
			let handNode = cc.find("Canvas/content/bg_green/bg_word-background/text/icon_hand");
			handNode.opacity = 0;

			let lyrics = this.data.exercises.lrcData.lyrics;

			//临时音频打点数组
			let arr = JSON.parse(JSON.stringify(lyrics));
			console.log(arr);

			this.monitor(audioId, arr);
		})
	},

	/**
	 * 重新设置文字位置
	 */
	resetTextPosition() {

		let textNode = cc.find("Canvas/content/bg_green/bg_word-background/text");

		let wordNodeArr = textNode.wordNodeArr;

		//间隔
		let space = 40;

		let tW = 0;

		for (let i = 0; i < wordNodeArr.length; ++i) {

			let wordNode = wordNodeArr[i];
			wordNode.removeFromParent();
			wordNode.parent = textNode;
			tW += wordNode.width;

			let widget = wordNode.getComponent(cc.Widget);
			widget.bottom = - wordNode.getComponent(cc.Label).fontSize / 2;
			widget.updateAlignment();

			wordNode.initScale = wordNode.scale;
		}

		tW += (this.data.exercises.wordArr.length - 1) * space;

		let startX = -  tW / 2;

		for (let i = 0; i < wordNodeArr.length; ++i) {
			let width = wordNodeArr[i].width;
			wordNodeArr[i].x = startX + width / 2;
			startX += width;

			if (wordNodeArr[i].isInitial) {
				continue;
			}
			startX += space;
		}

		if (tW > textNode.width) {
			const sx = textNode.width / tW;

			textNode.scale = Math.round(sx * 1000) / 1000;

			textNode.initScale = textNode.scale;
		}
	},


	/**
	 * 显示结束
	 */
	_shown: null,
	showEnd() {

		console.log(' in showEnd');

		if (this._curIndex < this.data.exercises.wordArr.length) {
			return;
		}

		if (this._shown) {
			return;
		}

		this._shown = true;

		let handNode = cc.find("Canvas/content/bg_green/bg_word-background/text/icon_hand");
		handNode.opacity = 0;
		this._stop = true;

		//播放动画
		const state = this.playAni('finish', 0);

		//播放引导音频2
		this.playAudioByUrl(this.data.guideAudioUrl2, () => {

			if (this.isDestroy) {
				return;
			}

			state.stop();

			this.playAni('normal', 0);

			this.showPhotoBtn();
		});


	},

	_stop: null,
	_tween: null,
	handAni() {

		let handNode = cc.find("Canvas/content/bg_green/bg_word-background/text/icon_hand");

		handNode.opacity = 255;
		handNode.y = handNode.initY;
		const move = () => {
			this._tween = cc.tween(handNode)
				.to(0.5, { y: handNode.initY + 50 })
				.to(0.5, { y: handNode.initY })
				.call(() => {

					if (!this._stop) {
						move()
					}
				})
				.start();
		}

		this._stop = false;

		move();
	},

	_stopAni: null,
	monitor(audioId, arr) {

		if (this._stopAni) {
			return;
		}

		this._stopAni = false;

		let currentTime = cc.audioEngine.getCurrentTime(audioId);

		let len = arr.length;

		for (let i = len - 1; i >= 0; --i) {

			let time = arr[i].time;

			time = Math.round(time * 1000) / 1000;

			currentTime = Math.round(currentTime * 1000) / 1000;

			if (time < currentTime) {

				//如果是最后一个匹配，则播放内容动画
				if (len == 1) {
					this.contentAni();
				}
				else {
					this.textAni();
				}

				//移除匹配上的元素
				arr.splice(i, 1);

				break;
			}

		}

		requestAnimationFrame(() => {

			this.monitor(audioId, arr);
		})
	},

	/**
	 * 文本动画
	 */
	_playText: null,
	textAni() {

		if (this._playText) {
			return;
		}

		this._playText = true;

		console.log(' canTouch = fasle  5');

		this.canTouch = false;

		const twinkle = (node) => {
			cc.tween(node)
				.to(0.3, { scale: node.initScale * 1.5 })
				.to(0.3, { scale: node.initScale })
				.call(() => {
					this._playText = false;
				})
				.start();
		};

		let textNode = cc.find("Canvas/content/bg_green/bg_word-background/text");

		let wordNodeArr = textNode.wordNodeArr;

		for (let i = 0; i < wordNodeArr.length; ++i) {
			let wordNode = wordNodeArr[i];

			//如果是首字母，则执行动画
			if (wordNode.isInitial) {
				twinkle(wordNode);
			}
		}

	},


	/**
	 * 内容动画
	 */
	contentAni() {

		let handNode = cc.find("Canvas/content/bg_green/bg_word-background/text/icon_hand");
		handNode.opacity = 0;

		const twinkle = (node) => {
			cc.tween(node)
				.to(0.5, { scale: node.initScale * 1.1 })
				.to(0.5, { scale: node.initScale })
				.to(0.5, { scale: node.initScale * 1.1 })
				.to(0.5, { scale: node.initScale })
				.call(() => {
					this.canTouch = true;
				})
				.start();
		};

		let textNode = cc.find("Canvas/content/bg_green/bg_word-background/text");

		twinkle(textNode);
	},



	photoBtn: null,
	initPhotoBtn() {

		const canvas = cc.find('Canvas');

		const photoBtn = this.getSprNode('btn_photo');
		photoBtn.active = false;
		canvas.addChild(photoBtn);
		photoBtn.scale = this._mapScaleMin;
		// photoBtn.x = 100;
		photoBtn.y = -canvas.height / 2 + photoBtn.height / 2 * photoBtn.scaleY;
		photoBtn.addComponent(cc.Button);
		photoBtn.on('click', () => {
			this.showPhotoTip();
		})

		this.photoBtn = photoBtn;
	},

	showPhotoBtn() {
		if (!this.photoBtn) {
			this.initPhotoBtn();
		}
		this.photoBtn.active = true;
	},

	hidePhotoBtn() {
		if (!this.photoBtn) {
			return;
		}
		this.photoBtn.active = false;
	},

	showPhotoTip() {

		this.maskNode.active = true;
		playAudio(this.audioOsmoTip.clip);
		this.playAni('begin', 0)
		this.playTipAni('normal', 1, () => {
			console.log('play ani end');

			this.playAni('normal', 0)


			this.photoBtnClick();

		})


	},

	isOpenPhotoCheck: null,
	openPhotoData() {
		this.isOpenPhotoCheck = true;
	},

	closePhotoData() {
		this.isOpenPhotoCheck = true;
	},


	photoBtnClick() {
		console.log(' in photoBtnClick')

		if (!window || !window.courseware) {
			console.log('window.courseware not found')
			return;
		}


		// window.courseware.openRecognitionCamera = this.getPhotoData.bind(this);

		const openRecognitionCamera = window.courseware.openRecognitionCamera;
		if (!openRecognitionCamera) {
			console.log('openRecognitionCamera not found')
			return;
		}
		openRecognitionCamera((data) => {
			console.log('openRecognitionCamera data: ', data)

			this._timeoutIds.push(setTimeout(() => {

				if (typeof data == 'string') {
					data = JSON.parse(data);
				}

				const { result } = data;
				this.photoEnd(result);

				this.maskNode.active = false;
			}, 100));



		})

	},


	photoEnd(data, isPool=false) {
		
		console.log(' this.photo end ', data);

		if (!this.canTouch && isPool == false) {
			this.dataPool.push(data);
			console.log('! cantouch')
			return;
		}
		
		this.changeBboxPos(data);

		const isRightArea = this.checkIsRightArea(data);
		if (!isRightArea) {
			console.log('没有检测到区域')
			return;
		}



		if (this.isCanDraw) {
			return;
		}
		this.isCanDraw = true;


		delayCall(0.01, () => {
			this.isCanDraw = false;
		})



		this.debugDrawLayer.removeAllChildren();


		const answerData = this.getAnswerData(data);

		// return;

		this.showUserRight(answerData, data);

		return;

		const answerWrongData = this.getAnswerWrongData(data);
		let isShowWrong = false;
		if (this.oldAnswerWrongData) {
		
			for (let key in answerWrongData) {
				const wrongData = answerWrongData[key];
				const oldWrongData = this.oldAnswerWrongData[key];
				if (oldWrongData && oldWrongData.sentence == wrongData.sentence) {
					wrongData.count += oldWrongData.count;

					if (wrongData.count >= 3) {
						isShowWrong = true;
					}
				}
			}
		}

		if (isShowWrong) {
			this.showUserWrong(answerWrongData);
		}

		this.oldAnswerWrongData = answerWrongData;

		console.log('answerWrongData: ', JSON.stringify( answerWrongData) );
	},



	photoEndOld(data, isPool = false) {

		console.log(' this.photo end');

		if (!this.canTouch && isPool == false) {
			this.dataPool.push(data);
			console.log('! cantouch')
			return;
		}


		this.changeWriteDataToBboxData(data.result)

		console.log("data.result: ", data.result);

		// const result = data.result;
		// for (let i=0; i<result.length; i++) {
		// 	result[i].top *= 400;
		// 	result[i].bottom *= 400;
		// 	result[i].left *= 400;
		// 	result[i].right *= 400;
		// }

			
		// this.topTitleData = null;
		// this.bottomTitleData = null;


		// const isRightArea1 = this.checkIsRightArea(data, false);
		// const isRightArea2 = this.checkIsRightArea(data, true);
		// if (!isRightArea1 && !isRightArea2) {
		// 	// playAudio(this.audioTipArea.clip)
		// 	console.log('没有检测到此题的区域')
		// 	return;
		// }


		// this.debugLayer.removeAllChildren();

		this.sample.removeAllChildren();
		for (let i=0; i<this.dotArr1.length; i++) {
			this.dotArr1[i].parent = this.sample;
		}
		for (let i=0; i<this.dotArr2.length; i++) {
			this.dotArr2[i].parent = this.sample;
		}
		
		// this.colorRectTop = null;


		const answerData1 = this.getAnswerDataNew(data, false);
		const answerData2 = this.getAnswerDataNew(data, true);



		this.showUserRight(answerData1, false);
		this.showUserRight(answerData2, true);


		const oldStep = this.step;
		this.checkShowStepAudio();
		if (oldStep != this.step) {

			console.log(' canTouch = fasle  6');

			this.canTouch = false;
			this.showStepAudio();
		} else {
			// this.canTouch = true;
			this.checkShowDataPool();
		}

		// const isFillAll = this.checkIsFillAll(answerData);
		// if (!isFillAll) {
		// 	// playAudio(this.audioTipNotFill.clip)
		// 	// playAudio(this.audioTipFillWrong.clip)

		// 	// console.log('这道题还有空没填哦')
		// 	return;
		// }

		// // const isFillWrong = this.checkIsFillWrong(answerData);
		// // if (!isFillWrong) {
		// // 	playAudio(this.audioTipFillWrong.clip)

		// // 	console.log('这道题有空填错了哦')
		// // 	return;
		// // }

		// this.showPhotoSuccess();

	},

	async showStepAudio() {
		console.log(' in showStepAudio: ', this.step);
		await asyncDelay(0.5);

		switch(this.step) {
			case 2:
				this.playAudioStep2();
				break;
			case 3:
				this.playAudioStep3();
				break;
			case 4:
				this.playAudioStep4();
				break;
			case 5:
				this.playAudioStep5();
				break;
		}
	},

	playAudioStep2() {
		playAudioByUrl(this.data.write_big_2_audio_url, () => {
			// this.canTouch = true;
			this.checkShowDataPool();
		});
	},

	playAudioStep3() {
		if (this.isDestroy) {
			return;
		}
		this.beginShowAudioSmall();
	},

	playAudioStep4() {
		playAudioByUrl(this.data.write_small_2_audio_url, () => {
			this.checkShowDataPool();
			// this.canTouch = true;
		});
	},

	playAudioStep5() {
		setTimeout(() => {
			if (this.isDestroy ) {
				return;
			}

			console.log(' play finish_audio_url:' , this.data.finish_audio_url)
			playAudioByUrl(this.data.finish_audio_url, () => {
							// 结束位置
			onHomeworkFinish();
			});
		}, 500);

	},

	checkShowDataPool() {

		if (this.dataPool.length == 0) {
			console.log('	this.canTouch = true  6')
			this.canTouch = true;
			return;
		}

		const data = this.dataPool.shift();
		this.photoEnd(data, true);

	},


	checkShowStepAudio() {


		switch(this.step) {
			case 1:
				this.checkStep1();
				break;
			case 2:
				this.checkStep2();
				break;
			case 3:
				this.checkStep3();
				break;			
			case 4:
				this.checkStep4();
				break;

			case 5:
				break;

			case 6:
				break;
		}
	},

	checkStep1() {
		let writeNodeArr = this.writeNodeArr1;

		let isShowEnd = true;
		for (let i = 0; i < 2; i++) {

			if (!writeNodeArr[i].isShowEnd) {
				isShowEnd = false;
				break;
			}
		}

		if (isShowEnd) {
			this.step ++;
			this.checkShowStepAudio();
		} 
	},

	checkStep2() {
		let writeNodeArr = this.writeNodeArr1;

		let isShowEnd = true;
		for (let i = 2; i < 7; i++) {

			if (!writeNodeArr[i].isShowEnd) {
				isShowEnd = false;
				break;
			}
		}

		if (isShowEnd) {
			this.step ++;
			this.checkShowStepAudio();
		} 
	},

	checkStep3() {
		let writeNodeArr = this.writeNodeArr2;

		let isShowEnd = true;
		for (let i = 0; i < 2; i++) {

			if (!writeNodeArr[i].isShowEnd) {
				isShowEnd = false;
				break;
			}
		}

		if (isShowEnd) {
			this.step ++;
			this.checkShowStepAudio();
		} 
	},

	checkStep4() {
		let writeNodeArr = this.writeNodeArr2;

		let isShowEnd = true;
		for (let i = 2; i < 7; i++) {

			if (!writeNodeArr[i].isShowEnd) {
				isShowEnd = false;
				break;
			}
		}

		if (isShowEnd) {
			this.step ++;
			this.checkShowStepAudio();
		} 
	},



	beginShowAudioSmall() {
		const playEnd = () => {
			this.playAni('normal', 0);
			this.showSmallLetterAnim();
			// this.checkShowDataPool();
			// this.canTouch = true;
		}

		console.log('')
		if (!this.data.write_small_0_audio_url) {
			playEnd();
			return;
		}

		this.playAni('begin', 0)
		playAudioByUrl(this.data.write_small_0_audio_url, () => {
			if (this.isDestroy) {
				return;
			}
			playEnd();
		})
	},

	showSmallLetterAnim() {
		console.log(' in showSmallLetterAnim')
		// const anim = this.letterAnimSmall.getComponent(cc.Animation);

		// anim.play('anim_a_0');
		// const cb = () => {
		// 	console.log('in finished');
		// 	this.showSmallLetter1Audio();
		// 	anim.off('finished', cb)
		// }

		// anim.on('finished', cb);


		this.showLetterAnim(1, this.letterAnimSmall, () => {
			this.showSmallLetter1Audio();
		});
	},

	showSmallLetter1Audio() {
		console.log(' in showSmallLetter1Audio')
		const playEnd = () => {

			console.log(' in playEnd ~')
			this.playAni('normal', 0);
			// this.canTouch = true;
			this.checkShowDataPool();
			// this.startTesting();

		}


		if (!this.data.write_small_1_audio_url) {
			playEnd();
			return;
		}

		this.playAni('begin', 0)
		//播放引导音频1
		playAudioByUrl(this.data.write_small_1_audio_url, () => {
			if (this.isDestroy) {
				return;
			}
			playEnd();
		})
	},


	showUserRightNew(answerData, isSmall) {

		console.log('answerData: ', answerData.toString());

		if (!answerData || Object.keys(answerData).length == 0) {
			return;
		}

		let writeNodeArr;
		if (isSmall) {
			writeNodeArr = this.writeNodeArr2
		} else {
			writeNodeArr = this.writeNodeArr1
		}

		for (let i = 0; i < 7; i++) {
			const key = i.toString();
			if (answerData[key]) {
				this.showLetter(i, null, isSmall);

			} else {
				let writeRect = writeNodeArr[i];
				writeRect.hitCount = 0;
			}
		}
	},

	showUserRight(answerData, data) {

		const text = data?.result?.text
		if (!text) {
			return false;
		}


		console.log('answerData: ', answerData);
		// console.log('this.picNodeArr: ', this.picNodeArr);

		if (Object.keys(answerData).length == 0) {
			return;
		}

		// let writeNodeArr;
		// if (isSmall) {
		// 	writeNodeArr = this.writeNodeArr2
		// } else {
		// 	writeNodeArr = this.writeNodeArr1
		// }

		// for (let i = 0; i < 7; i++) {
		// 	const key = i.toString();
		// 	if (answerData[key]) {
		// 		this.showLetter(i, null, isSmall);

		// 	} else {
		// 		let writeRect = writeNodeArr[i];
		// 		writeRect.hitCount = 0;
		// 	}
		// }


		const bigNodeArr = this.writeNodeArr1;
		const smallNodeArr = this.writeNodeArr2;
		
		console.log('bigNodeArr: ', bigNodeArr);
		console.log('smallNodeArr: ', smallNodeArr);

		for (let i = 0; i < 7; i++) {
			const keyB = i + '_' + 'b';
			const keyS = i + '_' + 's';

			if (answerData[keyB]) {

				this.showLetter(i, null, false);
			} else {

				let writeRect = bigNodeArr[i];
				writeRect.hitCount = 0;
			}
			
			if (answerData[keyS]) {

				this.showLetter(i, null, true);
			}  else {

				let writeRect = smallNodeArr[i];
				writeRect.hitCount = 0;
			}
		
		}


	},



	

	checkIsFillAll(answerData) {

		const letterArr = this.data.letter_arr;
		for (let i = 0; i < letterArr.length; i++) {
			const key = i.toString();
			const letterData = letterArr[i];

			const item = this.letterItemArr[i];
			if (!item.isShow) {
				if (letterData.is_right && !answerData[key]) {
					console.log("没有看到第" + (i + 1) + "个空的答案哦")
					return false;
				}
			}



		}

		return true;

	},


	checkIsFillWrong(answerData) {

		const letterArr = this.data.letter_arr;
		for (let i = 0; i < letterArr.length; i++) {
			const key = i.toString();
			const letterData = letterArr[i];

			const item = this.letterItemArr[i];
			if (!item.isShow) {
				if (!letterData.is_right && answerData[key]) {
					console.log("第" + (i + 1) + "个空填错了哦")
					return false;
				}
			}


		}

		return true;

	},

	getTopLeftLetter(text, block, topLabelData, bottomLabelData) {

		// const titleTopLeft = topLabelData.location.top_left;
		// const titleRightBottom = topLabelData.location.right_bottom;
		// const checkX = titleTopLeft.x + (titleRightBottom.x - titleTopLeft.x) / 3;
		// const checkY = titleRightBottom.y;

		console.log('topLabelData:', topLabelData);
		console.log('bottomLabelData:', bottomLabelData);

		const topY = -topLabelData.word[0].location.top;
		const bottomY = -bottomLabelData.word[0].location.bottom;


		text = text.trim();

		let topLeftLetter;

		for (let j = 0; j < block.length; j++) {

			const line = block[j].line;
			if (!line) {
				continue;
			}


			for (let i = 0; i < line.length; i++) {

				// const {word, location} = line[i];
				const word = line[i].word;
				const location = line[i].word[0].location;

				const curTop = -location.top;
				if (curTop >= topY || curTop <= bottomY) {
					continue;
				}

				console.log(' center line: ', line[i]);


				let sentence = ''
				word.forEach(item => {
					sentence += item.content + ' ';
				});

				sentence.trim();

				line[i].sentence = sentence;
				console.log('sentence: ', sentence);
				if (sentence.indexOf(text) != -1) {

					line[i].tmpLen = this.getToZeroLen(location)
					if (!topLeftLetter) {
						topLeftLetter = line[i];
					} else {
						if (topLeftLetter.tmpLen > line[i].tmpLen) {
							topLeftLetter = line[i];
						}
					}
				}
			}
		}

		return topLeftLetter;
	},

	getToZeroLen(location) {
		const { top, left } = location;
		const len = Math.sqrt(Math.pow(left, 2) + Math.pow(top, 2));
		return len;
	},

	getPhotoLabelData(textArr, block, isShow=true) {


		for(let j=0; j<block.length; j++) {

			const line = block[j];
			if (!line) {
				continue;
			}

			const sentence = line.content;


			if (isShow) {
				const label = this.getLabel(sentence, 150);
				label.x = line.left * this.debugBgImg.width;
				label.y = -(line.top + (line.bottom - line.top) / 2) * this.debugBgImg.height;
				label.parent = this.debugDrawLayer;
				label.zIndex = 200;
				// label.color = cc.Color.RED;
				const l = label.getComponent(cc.Label);
				label.anchorX = 0;
				console.log(' sentence~:  ', sentence);
			}




			if (this.checkIsInsert(textArr, sentence)) {
				return line;
			}

		}

		return false;

	},

	checkIsInsert(textArr, sentence) {
		console.log('textArr: ', textArr);
		console.log('sentence: ', sentence);

		let index = -1;
		for (let i = 0; i < textArr.length; i++) {
			index = sentence.indexOf(textArr[i], index);
			console.log('index: ', index);
			if (index == -1) {
				return false;
			}
		}

		return true;
	},

	getTempWordArr(line, splitText) {

		const lineBox = {left: line.left, top: line.top, right: line.right, bottom: line.bottom};
		const baseX = lineBox.left;

		let textIndex = 0;
		const oneDisW = (lineBox.right - lineBox.left) / line.content.length;

		const arr = line.content.split(splitText);
		const wordArr = [];
		for (let i=0; i<arr.length; i++) {
			const content = arr[i];
			const location = {}
			location.left = baseX + textIndex * oneDisW;
			location.right = location.left + oneDisW * content.length;
			location.top = lineBox.top;
			location.bottom = lineBox.bottom;
			
			wordArr.push({content, location});

			textIndex += content.length;
		}

		return wordArr;
	},

	getPhotoWordArr(text, block, benchmark1Data) {

		const wordArr = [];
		// const maxLen = 10;

		text = text.trim();

		const topY = -benchmark1Data.top;

		for(let j=0; j<block.length; j++) {

			const line = block[j];
			if (!line) {
				continue;
			}


			const sentence = line.content;
			if (sentence.indexOf(text) != -1 ) {
				wordArr.push( line );
			}

		}

		return wordArr;
	},



	checkCutWordData(wordArr) {

		let newWordArr = [];
		for (let i = 0; i < wordArr.length; i++) {

			let wordObj = wordArr[i];

			wordObj.content = wordObj.content.trim();

			if (wordObj.content.length > 1) {

				const tmpArr = [];
				const w = wordObj.location.right - wordObj.location.left
				const subW = w / wordObj.content.length;
				for (let j = 0; j < wordObj.content.length; j++) {

					const subWordObj = {};
					subWordObj.content = wordObj.content[j];
					subWordObj.location = {
						top: wordObj.location.top,
						bottom: wordObj.location.bottom,
						left: wordObj.location.left + subW * j,
						right: wordObj.location.left + subW * (j + 1)
					}

					tmpArr.push(subWordObj);
				}
				newWordArr = newWordArr.concat(tmpArr)


			} else {
				newWordArr.push(wordObj)
			}

		}

		console.log('newWordArr: ', newWordArr);
		return newWordArr;
	},





	getOneAnim(data ,cb) {

		if (!data.texPngData) {
			cb && cb();
			return
		}

		const animaNode = new cc.Node();

		const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
		
		const image = data.texPngData.url//"http://staging-teach.cdn.ireadabc.com/5a0c5af3e952acd0ac83a6e5c6f03ff1.png";
		const ske = data.skeJsonData.url//"http://staging-teach.cdn.ireadabc.com/bd825dcceea298d1146be8067ae3d17f.json";
		const atlas = data.texJsonData.url//"http://staging-teach.cdn.ireadabc.com/246f8991b729fa3e5a7f4802de828efa.json";
		cc.loader.load(image, (error, texture) => {

			cc.loader.load({url: atlas, type: 'txt'}, (error, atlasJson) => {

				cc.loader.load({url: ske, type: 'txt'}, (error, dragonBonesJson) => {

					const atlas = new dragonBones.DragonBonesAtlasAsset();
					atlas.atlasJson = atlasJson;
					atlas.texture = texture;

					const asset = new dragonBones.DragonBonesAsset();
					asset.dragonBonesJson = dragonBonesJson;

					dragonDisplay.dragonAtlasAsset = atlas;
					dragonDisplay.dragonAsset = asset;

					let json = JSON.parse(asset.dragonBonesJson);
					let armatures = json["armature"];
					let armatureNames = [];
					for (let i = 0; i < armatures.length; i++) {
						armatureNames.push(armatures[i].name);
					}

					if (armatureNames.length > 0) {
						let defaultArmatureName = armatureNames[0];
						dragonDisplay.armatureName = defaultArmatureName;

						let defaultArmature = armatures[0];
						let animations = defaultArmature.animation;
						let animationNames = [];
						for (let i = 0; i < animations.length; i++) {
							animationNames.push(animations[i].name);
						}

						animaNode.animationNames = animationNames;
					}

					cb(animaNode);

				});
			});
		});

	},


	checkIsRightArea(data) {

		const text = data?.result?.text
		if (!text) {
			return false;
		}

		const benchmark1Text = this.benchmark1Data.labelText
		const benchmark1TextArr = benchmark1Text.split(' ');
		console.log('benchmark1TextArr: ', benchmark1TextArr);
		// const letter = this.data.letter || 'Aa';

		const benchmark1LabelData = this.getPhotoLabelData(benchmark1TextArr, text, false);
		if (!benchmark1LabelData) {
			console.log('!benchmark1LabelData')
			return false;
		}
		this.benchmark1LabelData = benchmark1LabelData;
		console.log('benchmark1LabelData: ', benchmark1LabelData);

		

		if ( this.firstItemData ) {

			const firstText = this.firstItemData.labelText
			const firstTextArr = firstText.split(' ');

			const firstItemLabelData = this.getTopLeftLetter2(firstText, text, this.benchmark1LabelData);

			if (!firstItemLabelData) {
				return false;
			}
			this.firstItemLabelData = firstItemLabelData;

			console.log('firstItemLabelData: ', firstItemLabelData);
			return true

		} else if (this.benchmark2Data) {
		
			const benchmark2Text = this.benchmark2Data.labelText
			const benchmark2TextArr = benchmark2Text.split(' ');
			const benchmark2LabelData = this.getPhotoLabelData(benchmark2TextArr, text, false);
			if (!benchmark2LabelData) {
				return false;
			}
			this.benchmark2LabelData = benchmark2LabelData;
			return true;
		}

		return false;

	
	
	},


	getTopLeftLetter2(text, block, topLabelData) {

		const benchmark1Rect = this.benchmark1Data.rect;

		const rect = {
			x: topLabelData.left, 
			y: -topLabelData.bottom, 
			width: Math.abs( topLabelData.right - topLabelData.left ), 
			height: Math.abs( topLabelData.bottom - topLabelData.top ), 
		}                        
		const colorRect = this.getColorRect(rect, "green");
		this.debugDrawLayer.addChild(colorRect);
		


		const tempUnitW = benchmark1Rect.x + benchmark1Rect.width;
		const tempUnitH = benchmark1Rect.y + benchmark1Rect.height;
		const tempBaseX = benchmark1Rect.x + benchmark1Rect.width / 2;
		const tempBaseY = benchmark1Rect.y + benchmark1Rect.height / 2;


		const firstItemData = this.firstItemData;		
		const firstItemRect = this.firstItemData.rect;

	
		const firstItemX = firstItemRect.x + firstItemRect.width / 2;
		const firstItemY = firstItemRect.y + firstItemRect.height / 2;

		const unitX = (firstItemX - tempBaseX) / tempUnitW;
		const unitY = (firstItemY - tempBaseY) / tempUnitH;
		const unitW2 = firstItemRect.width / tempUnitW;
		const unitH2 = firstItemRect.height / tempUnitH;



		console.log('tempUnitW: ', tempUnitW);
		console.log('tempUnitH: ', tempUnitH);
		console.log('tempBaseX: ', tempBaseX);
		console.log('tempBaseY: ', tempBaseY);

		console.log('firstItemY: ', firstItemY);
		console.log('tempBaseY: ', tempBaseY);
		console.log('tempUnitH: ', tempUnitH);

		firstItemData.unitX = unitX;
		firstItemData.unitY = unitY;
		firstItemData.unitW = unitW2;
		firstItemData.unitH = unitH2;



		const topLocationLeft = topLabelData.left;
		const topLocationTop = topLabelData.top;
		const topLocationRight = topLabelData.right;
		const topLocationBottom = topLabelData.bottom;

		const baseX = topLocationLeft + (topLocationRight - topLocationLeft) / 2;
		const baseY =	topLocationTop + (topLocationBottom - topLocationTop) / 2;
		const unitW = topLocationRight;
		const unitH = topLocationTop + (topLocationBottom - topLocationTop);
		

		const checkLetter = firstItemData;

		console.log('baseY: ', baseY);
		console.log('checkLetter.unitY: ', checkLetter.unitY);
		console.log('unitH: ', unitH);


		let x = baseX + checkLetter.unitX * unitW;
		const y = baseY + checkLetter.unitY * unitH;
		const w = checkLetter.unitW * unitW;
		const h = checkLetter.unitH * unitH;
		const r = Math.min(w, h) / 2;


		console.log(' baseX:  ', baseX);
		console.log(' checkLetter.unitX:  ', checkLetter.unitX);
		console.log(' unitW:  ', unitW);
		console.log(' x:  ', x);
		console.log(' y:  ', y);
		console.log(' r:  ', r);
		console.log(' checkLetter:  ', checkLetter);

		const dot = this.getColorDot(x, -y, r, r, 'blue');
		this.debugDrawLayer.addChild(dot, 5);

		dot.labelText = checkLetter.labelText;


		const wordDataArr =  this.getPhotoWordArr(text, block, topLabelData);
		let topLeftLetterData;


		const {dotRect, labelText} = dot
		


		for (let i=0; i<wordDataArr.length; i++) {

			// const tempWordArr = wordDataArr[i].word;
			const tempWordArr = this.getTempWordArr(wordDataArr[i],['']);



			for (let k=0; k<tempWordArr.length; k++) {
					
				const {location , content} = tempWordArr[k];

				const rect = {
					x: location.left, 
					y: -location.bottom, 
					width: Math.abs( location.right - location.left ), 
					height: Math.abs( location.bottom - location.top ), 
				}                        
				const colorRect = this.getColorRect(rect, "purple");
				colorRect.labelText = content;
				this.debugDrawLayer.addChild(colorRect);

				// console.log('colorRect: ', colorRect);

				const label = this.getLabel(content);
				label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
				label.y = colorRect.y - colorRect.height / 2 //* colorRect.scaleY;
				label.color = cc.Color.GREEN;
				this.debugDrawLayer.addChild(label);




				///------

				const checkRect = colorRect.ccRect;
				const targetLabelText = colorRect.labelText;

				const {dotRect, labelText, key} = dot;

				if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && checkRect.intersects(dotRect)) {
					return tempWordArr[k];
				}

				///------
				
			}

		}
			
		return null;

	},


	
	getTopLeftLetterData(result, identifier, topTitleData, bottomTitleData) {
		
		const identifierArr = this.getIdentifierArr(result, identifier);

		identifierArr.forEach(item => {
			const len = Math.sqrt(Math.pow(item.left, 2) + Math.pow(item.top, 2));
			item.minLen = len;
		})

		identifierArr.sort((a, b) => {
			return a.minLen - b.minLen
		})

		const topLeftLetter = identifierArr[0];
		if (-topLeftLetter.bottom > -topTitleData.bottom || -topLeftLetter.bottom < -bottomTitleData.bottom ) {
			return;
		}

		const unit = bottomTitleData.bottom - bottomTitleData.top;
		const targetX = bottomTitleData.left + unit * 1;
		if (topLeftLetter.left > targetX) {
			return;
		}

		return topLeftLetter;
	},

	getIdentifierArr(data, identifier) {

		const result = data.result;

		const identifierArr = [];
		for (let i = 0; i < result.length; i++) {

			const data = result[i];
			const { classIdentifier } = data;

			if (classIdentifier == identifier) {
				identifierArr.push(data)
			}
		}
		return identifierArr;
	},

	getAnswerDataNew(data, isSmall) {

		let letter = this.data.letter || 'a';

		let checkLetter, dotArr;
		if (isSmall) {
			checkLetter = letter.toLowerCase();
			dotArr = this.dotArr2;
		} else {
			checkLetter = letter.toUpperCase();
			dotArr = this.dotArr1;
		}



		const answerData = {};

		const resultTextArr = data.result.text;
		for (let i=0; i<resultTextArr.length; i++) {

			const wordData = resultTextArr[i];

			if (wordData.content != checkLetter) {
				continue;
			}

			const colorRect =	this.getColorRectByPos(wordData.bbox)
			colorRect.data = wordData;

			this.sample.addChild(colorRect);
			this.setOneAnswerDataNew(colorRect, dotArr, answerData);
	
		}

		return answerData;
	},


	
	getAnswerData(data) {
		
		const text = data?.result?.text
		if (!text) {
			return false;
		}

		console.log(' in getAnswerData: ', text);

		const benchmark1LabelData = this.benchmark1LabelData;
		let benchmark2LabelData ;

		const centerItemArr = this.centerItemArr;

		const benchmark1Left = benchmark1LabelData.left;
		const benchmark1Top = benchmark1LabelData.top;
		const benchmark1Right = benchmark1LabelData.right;
		const benchmark1Bottom = benchmark1LabelData.bottom;

		let baseX;
		let baseY;
		let unitW;
		let unitH;

		if (this.benchmark2LabelData) {
			benchmark2LabelData = this.benchmark2LabelData;


			const benchmark2Left = benchmark2LabelData.left;
			const benchmark2Top = benchmark2LabelData.top;
			const benchmark2Right = benchmark2LabelData.right;
			const benchmark2Bottom = benchmark2LabelData.bottom;


			const bottomLocation = benchmark2LabelData;

			baseX = benchmark1Left;
			baseY =	benchmark1Top + (benchmark1Bottom - benchmark1Top) / 2;
			unitW = benchmark2Right - benchmark1Left;
			unitH = bottomLocation.top + (bottomLocation.bottom - bottomLocation.top) / 2 - baseY;


			const benchmark2Rect = {
				x: benchmark2Left, 
				y: -benchmark2Bottom,
				width: Math.abs( benchmark2Left - benchmark2Right ), 
				height: Math.abs( benchmark2Top - benchmark2Bottom ), 
			}
			
			const colorbenchmark2Rect = this.getColorRect(benchmark2Rect, 'green');
			this.debugDrawLayer.addChild(colorbenchmark2Rect);
		} 


		if (this.firstItemLabelData) {
			const {location} = this.firstItemLabelData;
			const firstItemLeft = location.left;
			const firstItemRight = location.right;
			const firstItemTop = location.top;
			const firstItemBottom = location.bottom;

			console.log(' location: ', location);
			console.log(' firstItemLeft: ', firstItemLeft);
			console.log(' firstItemRight: ', firstItemRight);
			console.log(' firstItemTop: ', firstItemTop);
			console.log(' firstItemBottom: ', firstItemBottom);

			baseX = firstItemLeft + (firstItemRight - firstItemLeft) / 2;
			baseY =	firstItemTop + (firstItemBottom - firstItemTop) / 2;
			unitW = benchmark1Left + (benchmark1Right -  benchmark1Left) - ( firstItemLeft + (firstItemRight - firstItemLeft) / 2 );
			unitH = ( firstItemTop + (firstItemBottom - firstItemTop) / 2 ) - (benchmark1Top + (benchmark1Bottom -  benchmark1Top) / 2);
		}

		console.log(' baseX ~~~ ', baseX);
		console.log(' baseY ~~~ ', baseY);
		console.log(' unitW ~~~ ', unitW);
		console.log(' unitH ~~~ ', unitH);


		const dotArr = [];
		for (let i=0; i<this.centerItemArr.length; i++) {
			const checkLetter = this.centerItemArr[i];

			let x = baseX + checkLetter.unitX * unitW;
			const y = baseY + checkLetter.unitY * unitH;
			const w = checkLetter.unitW * unitW;
			const h = checkLetter.unitH * unitH;
			const r = Math.min(w, h)

			const dot = this.getColorDot(x, -y, w / 2, h / 2);


			this.debugDrawLayer.addChild(dot, 5);

			// dot.key = centerItemArr[i].index + 1;

	
			dot.key = checkLetter.key;
			dot.labelText = checkLetter.labelText;


			dotArr.push(dot);


		}



		// console.log('dotArr: ', dotArr);
		console.log('benchmark1LabelData: ', benchmark1LabelData);

		const answerData = {};

		for (let j=0; j<this.centerItemArr.length; j++) {
			const checkLetter = this.centerItemArr[j];

			const wordDataArr = this.getPhotoWordArr(checkLetter.labelText, text, benchmark1LabelData);

			console.log('~~~wordDataArr: ', wordDataArr);


			for (let i=0; i<wordDataArr.length; i++) {

				const tempWordArr = this.getTempWordArr(wordDataArr[i],['']); // wordDataArr[i].word;

				for (let k=0; k<tempWordArr.length; k++) {
					
					const {location , content} = tempWordArr[k];

					const rect = {
						x: location.left, 
						y: -location.bottom, 
						width: Math.abs( location.right - location.left ), 
						height: Math.abs( location.bottom - location.top ), 
					}                        
					const colorRect = this.getColorRect(rect, "purple");
					colorRect.labelText = content;
					this.debugDrawLayer.addChild(colorRect);

					// console.log('colorRect: ', colorRect);

					const label = this.getLabel(content, colorRect.scaleX *  colorRect.width);
					label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
					label.y = colorRect.y + colorRect.height / 2 * colorRect.scaleY;
					label.color = cc.Color.BLACK;

					this.debugDrawLayer.addChild(label);
					
	
					this.setOneAnswerData(colorRect, dotArr, answerData, wordDataArr[i]);
	
				}
				
			}

		}



		const benchmark1Rect = {
			x: benchmark1Left, 
			y: -benchmark1Bottom,
			width: Math.abs( benchmark1Left - benchmark1Right ), 
			height: Math.abs( benchmark1Top - benchmark1Bottom ), 
		}

		console.log('benchmark1Rect: ', benchmark1Rect);
		
		const colorbenchmark1Rect = this.getColorRect(benchmark1Rect, 'green');
		this.debugDrawLayer.addChild(colorbenchmark1Rect);

		return answerData;

	},

	changeWriteDataToBboxData(result) {
		const curTextArr = result.text;
		const bboxTextArr = [];
		for (let i=0; i<curTextArr.length; i++) {

			const score = curTextArr[i].score;

			const {left, right, top, bottom} = curTextArr[i];
			const text = curTextArr[i].content;

			console.log('text..', JSON.stringify( curTextArr[i] ));
			console.log('text..', text);
			const disW = (right - left) / text.length;
			const disH = (bottom - top);
			for (let j=0; j<text.length; j++) {

				const x1 = left + j * disW;
				const y1 = top;

				const x2 = x1 + disW;
				const y2 = y1;

				const x3 = x2;
				const y3 = y2 + disH;

				const x4 = x1;
				const y4 = y3;

				const bbox = [{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}]


				this.changeBboxPos(bbox);

				const content = text[j];
				bboxTextArr.push({bbox, content, score});
			}

		}

		result.text = bboxTextArr;

	},

	changeBboxPos(data) {

		const text = data?.result?.text;
		if (!text) {
			return;
		}


		for (let i=0; i<text.length; i++) {

			let {left, top, right, bottom} = text[i];

			const q_left = this.ques_region[0];
			const q_top = this.ques_region[1];
			const q_right = this.ques_region[2];
			const q_bottom = this.ques_region[7];

			const rect = {x: q_left, y: q_top, width: q_right - q_left, height: q_bottom - q_top};

			text[i].left = q_left + left * rect.width;
			text[i].top = q_top + top * rect.height;
			text[i].right = q_left + right * rect.width;
			text[i].bottom = q_top + bottom * rect.height;

		}

	
	},



	setTestLabel(labelData) {

		if (!this.debugLayer.parent || !this.debugLayer.active) {
			return;
		}

		console.log('labelData: ', labelData)
		const location = labelData.word[0].location;
		const label = this.getLabel(labelData.sentence);
		label.anchorX = 0;
		// label.anchorY = 1;
		label.x = location.left;
		label.y = -location.top
		label.zIndex = 50;


		// const rect = {};
		// rect.width = location.right - location.left;
		// rect.height = location.bottom - location.top;
		// rect.x = location.left;
		// rect.y = -location.top;
		// const colorRect = this.getColorRect(rect, cc.Color.YELLOW);
		// this.debugLayer.addChild(colorRect);

		this.debugLayer.addChild(label);
	},

	setTestRectDot(topLabelData, bottomLabelData, topLeftLetter, wordDataArr) {


		const topLeftPosX = topLeftLetter.left;
		const topLeftPosY = topLeftLetter.top;

		const totalH = -topLabelData.top + bottomLabelData.top;
	
		const unitH = -topLabelData.top + bottomLabelData.bottom;
		const rate = 0.26;

		console.log('unitH: ', unitH);


		let rectH;
		let rectW;
		let disW;

		let unit;
		if (-topLeftPosY > -topLabelData.top - totalH / 3) {

			unit = topLeftLetter.bottom - topLabelData.bottom;
			console.log('unit: ', unit);

			// 50

			rectH = 0.88 *rate * unitH; //44  
			rectW = 0.5 *rate * unitH; //27;
			disW = 0.66 *rate * unitH; //55;
		
		} else {

			unit = bottomLabelData.top - topLeftLetter.top;
			// 50

			rectH = 0.5 *rate * unitH; //25  
			rectW = 0.54 *rate * unitH; //27;
			disW = 0.6 *rate * unitH; //46;

			console.log('unit: ', unit);


		}



		const baseX = topLeftPosX + rectW / 2;
		let baseY = -(topLeftPosY - rectH / 2);


		let col = 0;

		const dotArr = [];
		for (let i = 0; i < 9; i++) {
			const x = baseX + col * disW;
			const y = baseY;
			const dot = this.getColorDot(x, y, rectW * 0.1);
			this.debugLayer.addChild(dot,5);
			dotArr.push(dot);
			col++;


		}

		return dotArr;







		// const topLeftPosX = topLeftLetter.word[0].location.left;
		// const topLeftPosY = topLeftLetter.word[0].location.top;

		// const totalH = -topLabelData.word[0].location.top + bottomLabelData.word[0].location.top;


		// const unitH = -topLeftLetter.word[0].location.top + topLeftLetter.word[0].location.bottom;


		// console.log('unitH: ', unitH);



		// let rectH = 1 * unitH; //21  
		// let rectW = 1.476 * unitH; //31;
		// let disW = 2.08 * unitH; //45;


		// const letterLocation = topLeftLetter.word[0].location;
		// const bottomLocation = bottomLabelData.word[0].location;
		// const topLocation = topLabelData.word[0].location;
		// let unit;
		// if (-topLeftPosY > -topLabelData.word[0].location.top - totalH / 3 ) {

		// 	unit = letterLocation.bottom - topLocation.bottom;
		// 	// 50

		// 	rectH = 0.88 * unit; //44  
		// 	rectW = 0.54 * unit; //27;
		// 	disW = 1.07 * unit; //55;

		// } else {

		// 	unit = bottomLocation.top - letterLocation.top;
		// 	// 50

		// 	rectH = 0.5 * unit; //25  
		// 	rectW = 0.54 * unit; //27;
		// 	disW = 1.13 * unit; //46;

		// }





		// const baseX = topLeftPosX + rectW / 2;
		// let baseY = -(topLeftPosY - rectH / 2 );


		// let col = 0;

		// const dotArr = [];
		// for (let i=0; i<9; i++) {
		// 	const x = baseX + col * disW;
		// 	const y = baseY;
		// 	const dot = this.getColorDot(x, y, rectW * 0.6);
		// 	this.debugLayer.addChild(dot,5);
		// 	dotArr.push(dot);
		// 	col ++;


		// }

		// return dotArr;

	},

	


	setOneAnswerData(colorRect, dotArr, answerData, line) {

		console.log(' in setOneAnswerData')
		console.log('colorRect: ', colorRect)
		console.log('dotArr: ', dotArr)
		console.log('answerData: ', answerData)

		
		const rect = colorRect.ccRect;
		const targetLabelText = colorRect.labelText;

		for (let i=0; i<dotArr.length; i++) {

			const {dotRect, labelText, key} = dotArr[i];

				console.log('targetLabelText.toLowerCase() : ', targetLabelText.toLowerCase() );
				console.log('labelText.toLowerCase()  : ', labelText.toLowerCase()  );
				console.log('rect.intersects(dotRect) : ', rect.intersects(dotRect) );

			if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && rect.intersects(dotRect)) {
				const len = targetLabelText.trim().length;

				console.log('len: ', len);

				if (!answerData[key]) {
					answerData[key] = {colorRect, count: len};
				} else {
					answerData[key].count += len;

					// console.log('len: ', len);
					// console.log('	answerData[key].count: ', 	answerData[key].count);

				}

				if ( labelText.length <= 1) {
					answerData[key].isFinish = true;
					answerData[key].line = line;

				} else {
					if (answerData[key].count >= labelText.length) {
						answerData[key].isFinish = true;
						answerData[key].line = line;
					}
				}

			
				// return;
			}

		}

	},

	

	getLabel(text, fontSize = 20) {
		const labelNode = new cc.Node();
		const label = labelNode.addComponent(cc.Label);
		label.string = text;
		labelNode.color = cc.Color.BLACK;
		label.fontSize = fontSize;
		label.lineHeight = fontSize;
		return labelNode;
	},

	getColorRect(rect, color=null) {

		if (!color) {
			color = 'red'
		}


		rect.x *= this.debugBgImg.width;
		rect.y *= this.debugBgImg.height;
		rect.width *= this.debugBgImg.width;
		rect.height *= this.debugBgImg.height;

		const node = getSprNode(color);
		node.anchorX = 0;
		node.anchorY = 0;
		node.x = rect.x;
		node.y = rect.y;
		node.scaleX = rect.width / node.width;
		node.scaleY = rect.height / node.height;

		node.ccRect = new cc.Rect(rect.x, rect.y, rect.width, rect.height);


		return node;
	},


	

	
	getColorDot(x, y, w=100, h=100, color='red') {
		const node = new cc.Node();

		if (!h) {
			h = w;
		}

		x *= this.debugBgImg.width;
		y *= this.debugBgImg.height;
		w *= this.debugBgImg.width;
		h *= this.debugBgImg.height;

		if (this.debugLayer.parent && this.debugLayer.active) {

			const rect = {
				x:- w/2,
				y: - h/ 2, 
				width:w, 
				height:h
			}


			const colorDot = getSprNode(color);

		
			colorDot.scaleX = rect.width / colorDot.width;
			colorDot.scaleY = rect.height / colorDot.height;
			node.addChild(colorDot);


		}

		node.x = x;
		node.y = y;


		const rect = new cc.Rect(node.x -w/2, node.y -h/2, w, h);
		node.dotRect = rect;
		return node;
	},


	checkIsRightLetter(result) {
		const block = result?.data?.block
		if (!block) {
			return false;
		}
		return false;

		const letter = this.data.letter;
		const letterLabelData = this.getPhotoLabelData(letter, block);

		return letterLabelData;
	},

	checkIsRightPos(result) {
		const block = result?.data?.block
		if (!block) {
			return false;
		}

		return false;

		const iconLabelData = this.getPhotoLabelData('I like', block);
		const topLabelData = this.getPhotoLabelData('n and repeat', block);
		const bottomLabelData = this.getPhotoLabelData('n, point, and repeat', block);
		if (!iconLabelData) {
			return false;
		}

		const topY = topLabelData.location.top_left.y;
		const bottomY = bottomLabelData.location.top_left.y;
		const iconY = iconLabelData.location.top_left.y;
		if (bottomY <= iconY <= topY) {
			return true;
		}
	},

	showPhotoSuccess() {
		console.log(' in showPhotoSuccess')

		if (!this.data.finish_audio_url) {
			return;
		}

		playAudio(this.data.finish_audio_url)

	},

	getPhotoData(cb) {

		const tmpData1 = {"result":{"text":[{"left":0.08800879865884781,"right":0.42794278264045715,"top":0.010067113675177097,"bottom":0.16778524219989777,"score":1,"content":"CTrace,write,and say."},{"left":0.09350935369729996,"right":0.48184818029403687,"top":0.1845637559890747,"bottom":0.46644294261932373,"score":0.9882554411888123,"content":"AAAA"},{"left":0.5731573104858398,"right":0.6347634792327881,"top":0.20469798147678375,"bottom":0.463087260723114,"score":0.9638504385948181,"content":"A"},{"left":0.751375138759613,"right":0.8129813075065613,"top":0.20134228467941284,"bottom":0.4563758373260498,"score":0.8285241723060608,"content":"A"},{"left":0.5665566325187683,"right":0.6281628012657166,"top":0.6677852272987366,"bottom":0.8791946172714233,"score":0.8251835703849792,"content":"a"}]}}
		// const tmpData1 = {"result":{"text":[{"left":0,"right":0.33299797773361206,"top":0.0971250981092453,"bottom":0.12354312092065811,"content":1,"text":"race,write,and say."},{"left":0.14084507524967194,"right":0.9476861357688904,"top":0.13131313025951385,"bottom":0.21445220708847046,"content":0.9066159129142761,"text":"AAAA-A-AA"},{"left":0.28470826148986816,"right":0.9315895438194275,"top":0.2735042870044708,"bottom":0.32867133617401123,"content":0.9610617756843567,"text":"aaaq qa"},{"left":0.03018108569085598,"right":0.6438632011413574,"top":0.37995338439941406,"bottom":0.41025641560554504,"content":1,"text":"Listen. Then write Aa or cross it out. o5"},{"left":0.636820912361145,"right":0.7655935883522034,"top":0.4755244851112366,"bottom":0.5314685106277466,"content":0.8729087710380554,"text":"Aa"},{"left":0.10663983970880508,"right":0.11167001724243164,"top":0.5788655877113342,"bottom":0.6021755933761597,"content":0.7464486360549927,"text":"4"},{"left":0.1589537262916565,"right":0.29074445366859436,"top":0.5936285853385925,"bottom":0.6596736311912537,"content":0.8887001872062683,"text":"Aa"},{"left":0.6549295783042908,"right":0.7786720395088196,"top":0.5920745730400085,"bottom":0.6643356680870056,"content":0.9307805895805359,"text":"Aa"},{"left":0.11267605423927307,"right":0.4034205377101898,"top":0.7700077891349792,"bottom":0.807303786277771,"content":1,"text":"Lusten and chant, bd"},{"left":0.28973841667175293,"right":0.7162978053092957,"top":0.9254079461097717,"bottom":0.9712509512901306,"content":0.9342746138572693,"text":"户藤미 Ow"},{"left":0.8158953785896301,"right":0.7203219532966614,"top":0.9611499905586243,"bottom":0.9370629191398621,"content":0.7845855951309204,"text":"0章"}]}}
		cb(tmpData1);
		return;
		const tmpData = 
		{
			"code":200000,
			"message":"success",
			"result":{
					"homography":{
							"matrix":[
									[
											1.4966796485557876,
											0.5865544493734395,
											46.43280157429157
									],
									[
											-0.01005137610702238,
											1.4984154182794625,
											96.67508554672378
									],
									[
											0.000019639357377687945,
											0.001378134169965562,
											1
									]
							],
							"query_size":[
									640,
									832
							],
							"support_size":[
									640,
									480
							]
					},
					"support_results":[
							[
									[
											0.2924,
											0.1243,
											0.3488,
											0.1873,
											"A",
											0.9908210039138794
									],
									[
											0.3907,
											0.1245,
											0.4472,
											0.1909,
											"A",
											0.9895601272583008
									],
									[
											0.7505,
											0.1161,
											0.8179,
											0.1909,
											"A",
											0.9865421056747437
									],
									[
											0.8503,
											0.1128,
											0.9112,
											0.1917,
											"A",
											0.9810258150100708
									],
									[
											0.6587,
											0.1186,
											0.719,
											0.186,
											"A",
											0.9783920049667358
									],
									[
											0.4766,
											0.1212,
											0.5328,
											0.1916,
											"A",
											0.9687917828559875
									],
									[
											0.5683,
											0.1199,
											0.6217,
											0.1859,
											"A",
											0.9639236927032471
									],
									[
											0.7852,
											0.2524,
											0.8253,
											0.288,
											"a",
											0.9914705753326416
									],
									[
											0.5002,
											0.2517,
											0.5432,
											0.2862,
											"a",
											0.9906148314476013
									],
									[
											0.6927,
											0.2471,
											0.7312,
											0.2832,
											"a",
											0.9835354089736938
									],
									[
											0.5963,
											0.2489,
											0.6354,
											0.2856,
											"a",
											0.9809314608573914
									],
									[
											0.4034,
											0.2494,
											0.4504,
											0.2877,
											"a",
											0.9800149202346802
									],
									[
											0.8807,
											0.248,
											0.9223,
											0.2903,
											"a",
											0.9736253023147583
									],
									[
											0.3024,
											0.2486,
											0.3559,
											0.2896,
											"a",
											0.9720337986946106
									]
							]
					],
					"text":[
							{
									"bbox":[
											{
													"x1":0.2924,
													"y1":0.1243
											},
											{
													"x2":0.3488,
													"y2":0.1243
											},
											{
													"x3":0.3488,
													"y3":0.1873
											},
											{
													"x4":0.2924,
													"y4":0.1873
											}
									],
									"content":"A",
									"score":0.9908210039138794
							},
							{
									"bbox":[
											{
													"x1":0.3907,
													"y1":0.1245
											},
											{
													"x2":0.4472,
													"y2":0.1245
											},
											{
													"x3":0.4472,
													"y3":0.1909
											},
											{
													"x4":0.3907,
													"y4":0.1909
											}
									],
									"content":"A",
									"score":0.9895601272583008
							},
							{
									"bbox":[
											{
													"x1":0.7505,
													"y1":0.1161
											},
											{
													"x2":0.8179,
													"y2":0.1161
											},
											{
													"x3":0.8179,
													"y3":0.1909
											},
											{
													"x4":0.7505,
													"y4":0.1909
											}
									],
									"content":"A",
									"score":0.9865421056747437
							},
							{
									"bbox":[
											{
													"x1":0.8503,
													"y1":0.1128
											},
											{
													"x2":0.9112,
													"y2":0.1128
											},
											{
													"x3":0.9112,
													"y3":0.1917
											},
											{
													"x4":0.8503,
													"y4":0.1917
											}
									],
									"content":"A",
									"score":0.9810258150100708
							},
							{
									"bbox":[
											{
													"x1":0.6587,
													"y1":0.1186
											},
											{
													"x2":0.719,
													"y2":0.1186
											},
											{
													"x3":0.719,
													"y3":0.186
											},
											{
													"x4":0.6587,
													"y4":0.186
											}
									],
									"content":"A",
									"score":0.9783920049667358
							},
							{
									"bbox":[
											{
													"x1":0.4766,
													"y1":0.1212
											},
											{
													"x2":0.5328,
													"y2":0.1212
											},
											{
													"x3":0.5328,
													"y3":0.1916
											},
											{
													"x4":0.4766,
													"y4":0.1916
											}
									],
									"content":"A",
									"score":0.9687917828559875
							},
							{
									"bbox":[
											{
													"x1":0.5683,
													"y1":0.1199
											},
											{
													"x2":0.6217,
													"y2":0.1199
											},
											{
													"x3":0.6217,
													"y3":0.1859
											},
											{
													"x4":0.5683,
													"y4":0.1859
											}
									],
									"content":"A",
									"score":0.9639236927032471
							},
							{
									"bbox":[
											{
													"x1":0.7852,
													"y1":0.2524
											},
											{
													"x2":0.8253,
													"y2":0.2524
											},
											{
													"x3":0.8253,
													"y3":0.288
											},
											{
													"x4":0.7852,
													"y4":0.288
											}
									],
									"content":"a",
									"score":0.9914705753326416
							},
							{
									"bbox":[
											{
													"x1":0.5002,
													"y1":0.2517
											},
											{
													"x2":0.5432,
													"y2":0.2517
											},
											{
													"x3":0.5432,
													"y3":0.2862
											},
											{
													"x4":0.5002,
													"y4":0.2862
											}
									],
									"content":"a",
									"score":0.9906148314476013
							},
							{
									"bbox":[
											{
													"x1":0.6927,
													"y1":0.2471
											},
											{
													"x2":0.7312,
													"y2":0.2471
											},
											{
													"x3":0.7312,
													"y3":0.2832
											},
											{
													"x4":0.6927,
													"y4":0.2832
											}
									],
									"content":"a",
									"score":0.9835354089736938
							},
							{
									"bbox":[
											{
													"x1":0.5963,
													"y1":0.2489
											},
											{
													"x2":0.6354,
													"y2":0.2489
											},
											{
													"x3":0.6354,
													"y3":0.2856
											},
											{
													"x4":0.5963,
													"y4":0.2856
											}
									],
									"content":"a",
									"score":0.9809314608573914
							},
							{
									"bbox":[
											{
													"x1":0.8807,
													"y1":0.248
											},
											{
													"x2":0.9223,
													"y2":0.248
											},
											{
													"x3":0.9223,
													"y3":0.2903
											},
											{
													"x4":0.8807,
													"y4":0.2903
											}
									],
									"content":"a",
									"score":0.9736253023147583
							},
							{
									"bbox":[
											{
													"x1":0.3024,
													"y1":0.2486
											},
											{
													"x2":0.3559,
													"y2":0.2486
											},
											{
													"x3":0.3559,
													"y3":0.2896
											},
											{
													"x4":0.3024,
													"y4":0.2896
											}
									],
									"content":"a",
									"score":0.9720337986946106
							}
					]
			}
	}
		// {
		// 	"code": 200000,
		// 	"message": "success",
		// 	"result": {
		// 		"support_results": [
		// 			[
		// 				[
		// 					0.49317359924316406,
		// 					0.25097235652010197,
		// 					0.5522325038909912,
		// 					0.288081715131967,
		// 					"a",
		// 					0.990108072757721
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.7815923094749451,
		// 					0.2423561773522615,
		// 					0.8420042395591736,
		// 					0.2829396176165032,
		// 					"a",
		// 					0.9900233745574951
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.5897714495658875,
		// 					0.24693736438131567,
		// 					0.6457504034042358,
		// 					0.2819446122459721,
		// 					"a",
		// 					0.9894896745681763
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.2031928449869156,
		// 					0.25154209940460914,
		// 					0.26929566264152527,
		// 					0.29193248868186233,
		// 					"a",
		// 					0.983356773853302
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.39285269379615784,
		// 					0.24877103711543316,
		// 					0.45319148898124695,
		// 					0.2872285145969844,
		// 					"a",
		// 					0.9817916750907898
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.30443957448005676,
		// 					0.2532131404780602,
		// 					0.3565950095653534,
		// 					0.2885934469473862,
		// 					"a",
		// 					0.9796608090400696
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.8672714233398438,
		// 					0.24161506162136312,
		// 					0.9294711947441101,
		// 					0.2848689417255425,
		// 					"a",
		// 					0.9749398231506348
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.680833101272583,
		// 					0.24406777752747533,
		// 					0.7436296343803406,
		// 					0.28508718252948045,
		// 					"a",
		// 					0.9576545357704163
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.48491987586021423,
		// 					0.12172665519367754,
		// 					0.5459403395652771,
		// 					0.19091845712618705,
		// 					"A",
		// 					0.9131966829299927
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.5817452669143677,
		// 					0.12464039263645885,
		// 					0.6427905559539795,
		// 					0.18670312292435287,
		// 					"A",
		// 					0.8777841925621033
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.6734722256660461,
		// 					0.12392509000705718,
		// 					0.7303305864334106,
		// 					0.18485528186833022,
		// 					"A",
		// 					0.8367360234260559
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.8564218282699585,
		// 					0.1192738632772547,
		// 					0.9225841164588928,
		// 					0.19054701754113432,
		// 					"A",
		// 					0.7801001071929932
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.7687476277351379,
		// 					0.12338259301840243,
		// 					0.8205023407936096,
		// 					0.18305307740282176,
		// 					"A",
		// 					0.6130796670913696
		// 				]
		// 			],
		// 			[
		// 				[
		// 					0.3863550126552582,
		// 					0.1285817704766488,
		// 					0.4408574104309082,
		// 					0.18449943199799176,
		// 					"A",
		// 					0.5841907858848572
		// 				]
		// 			]
		// 		],
		// 		"text": [
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.49317359924316406,
		// 						"y1": 0.25097235652010197
		// 					},
		// 					{
		// 						"x2": 0.5522325038909912,
		// 						"y2": 0.25097235652010197
		// 					},
		// 					{
		// 						"x3": 0.5522325038909912,
		// 						"y3": 0.288081715131967
		// 					},
		// 					{
		// 						"x4": 0.49317359924316406,
		// 						"y4": 0.288081715131967
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.990108072757721
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.7815923094749451,
		// 						"y1": 0.2423561773522615
		// 					},
		// 					{
		// 						"x2": 0.8420042395591736,
		// 						"y2": 0.2423561773522615
		// 					},
		// 					{
		// 						"x3": 0.8420042395591736,
		// 						"y3": 0.2829396176165032
		// 					},
		// 					{
		// 						"x4": 0.7815923094749451,
		// 						"y4": 0.2829396176165032
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9900233745574951
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.5897714495658875,
		// 						"y1": 0.24693736438131567
		// 					},
		// 					{
		// 						"x2": 0.6457504034042358,
		// 						"y2": 0.24693736438131567
		// 					},
		// 					{
		// 						"x3": 0.6457504034042358,
		// 						"y3": 0.2819446122459721
		// 					},
		// 					{
		// 						"x4": 0.5897714495658875,
		// 						"y4": 0.2819446122459721
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9894896745681763
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.2031928449869156,
		// 						"y1": 0.25154209940460914
		// 					},
		// 					{
		// 						"x2": 0.26929566264152527,
		// 						"y2": 0.25154209940460914
		// 					},
		// 					{
		// 						"x3": 0.26929566264152527,
		// 						"y3": 0.29193248868186233
		// 					},
		// 					{
		// 						"x4": 0.2031928449869156,
		// 						"y4": 0.29193248868186233
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.983356773853302
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.39285269379615784,
		// 						"y1": 0.24877103711543316
		// 					},
		// 					{
		// 						"x2": 0.45319148898124695,
		// 						"y2": 0.24877103711543316
		// 					},
		// 					{
		// 						"x3": 0.45319148898124695,
		// 						"y3": 0.2872285145969844
		// 					},
		// 					{
		// 						"x4": 0.39285269379615784,
		// 						"y4": 0.2872285145969844
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9817916750907898
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.30443957448005676,
		// 						"y1": 0.2532131404780602
		// 					},
		// 					{
		// 						"x2": 0.3565950095653534,
		// 						"y2": 0.2532131404780602
		// 					},
		// 					{
		// 						"x3": 0.3565950095653534,
		// 						"y3": 0.2885934469473862
		// 					},
		// 					{
		// 						"x4": 0.30443957448005676,
		// 						"y4": 0.2885934469473862
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9796608090400696
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.8672714233398438,
		// 						"y1": 0.24161506162136312
		// 					},
		// 					{
		// 						"x2": 0.9294711947441101,
		// 						"y2": 0.24161506162136312
		// 					},
		// 					{
		// 						"x3": 0.9294711947441101,
		// 						"y3": 0.2848689417255425
		// 					},
		// 					{
		// 						"x4": 0.8672714233398438,
		// 						"y4": 0.2848689417255425
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9749398231506348
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.680833101272583,
		// 						"y1": 0.24406777752747533
		// 					},
		// 					{
		// 						"x2": 0.7436296343803406,
		// 						"y2": 0.24406777752747533
		// 					},
		// 					{
		// 						"x3": 0.7436296343803406,
		// 						"y3": 0.28508718252948045
		// 					},
		// 					{
		// 						"x4": 0.680833101272583,
		// 						"y4": 0.28508718252948045
		// 					}
		// 				],
		// 				"content": "a",
		// 				"score": 0.9576545357704163
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.48491987586021423,
		// 						"y1": 0.12172665519367754
		// 					},
		// 					{
		// 						"x2": 0.5459403395652771,
		// 						"y2": 0.12172665519367754
		// 					},
		// 					{
		// 						"x3": 0.5459403395652771,
		// 						"y3": 0.19091845712618705
		// 					},
		// 					{
		// 						"x4": 0.48491987586021423,
		// 						"y4": 0.19091845712618705
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.9131966829299927
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.5817452669143677,
		// 						"y1": 0.12464039263645885
		// 					},
		// 					{
		// 						"x2": 0.6427905559539795,
		// 						"y2": 0.12464039263645885
		// 					},
		// 					{
		// 						"x3": 0.6427905559539795,
		// 						"y3": 0.18670312292435287
		// 					},
		// 					{
		// 						"x4": 0.5817452669143677,
		// 						"y4": 0.18670312292435287
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.8777841925621033
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.6734722256660461,
		// 						"y1": 0.12392509000705718
		// 					},
		// 					{
		// 						"x2": 0.7303305864334106,
		// 						"y2": 0.12392509000705718
		// 					},
		// 					{
		// 						"x3": 0.7303305864334106,
		// 						"y3": 0.18485528186833022
		// 					},
		// 					{
		// 						"x4": 0.6734722256660461,
		// 						"y4": 0.18485528186833022
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.8367360234260559
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.8564218282699585,
		// 						"y1": 0.1192738632772547
		// 					},
		// 					{
		// 						"x2": 0.9225841164588928,
		// 						"y2": 0.1192738632772547
		// 					},
		// 					{
		// 						"x3": 0.9225841164588928,
		// 						"y3": 0.19054701754113432
		// 					},
		// 					{
		// 						"x4": 0.8564218282699585,
		// 						"y4": 0.19054701754113432
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.7801001071929932
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.7687476277351379,
		// 						"y1": 0.12338259301840243
		// 					},
		// 					{
		// 						"x2": 0.8205023407936096,
		// 						"y2": 0.12338259301840243
		// 					},
		// 					{
		// 						"x3": 0.8205023407936096,
		// 						"y3": 0.18305307740282176
		// 					},
		// 					{
		// 						"x4": 0.7687476277351379,
		// 						"y4": 0.18305307740282176
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.6130796670913696
		// 			},
		// 			{
		// 				"bbox": [
		// 					{
		// 						"x1": 0.3863550126552582,
		// 						"y1": 0.1285817704766488
		// 					},
		// 					{
		// 						"x2": 0.4408574104309082,
		// 						"y2": 0.1285817704766488
		// 					},
		// 					{
		// 						"x3": 0.4408574104309082,
		// 						"y3": 0.18449943199799176
		// 					},
		// 					{
		// 						"x4": 0.3863550126552582,
		// 						"y4": 0.18449943199799176
		// 					}
		// 				],
		// 				"content": "A",
		// 				"score": 0.5841907858848572
		// 			}
		// 		]
		// 	}
		// }

		cb(tmpData);
	},


	photoCheckStart() {
		this.getPhotoData((data) => {
			this.photoEnd(data);
		})
	},


	updatePhotoCheck() {
		if (this.isOpenPhotoCheck) {

			this.photoCheckStart();

			this.isOpenPhotoCheck = false;
		}
	},


	update() {
		this.updatePhotoCheck();
	},


	// ------------------------------------------------
	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);
			}
		})
	},

	_audioId: null,
	playAudioByUrl(audio_url, cb = null, loadcb = null, loop = false) {

		if (this._audioId) {
			cc.audioEngine.pause(this._audioId);
		}

		let audioId;

		if (audio_url) {
			cc.assetManager.loadRemote(audio_url, (err, audioClip) => {

				audioId = cc.audioEngine.play(audioClip, loop, 0.8);
				this._audioId = audioId;

				if (cb) {
					cc.audioEngine.setFinishCallback(audioId, () => {
						cb();
					});
				}

				if (loadcb) {
					loadcb(audioId);
				}

			});
		}
	},
	_timeoutIds: null,
	_intervalIds: null,
	// 生命周期
	onDestroy() {
		this.isDestroy = true;
		this._timeoutIds.forEach(id => {
			clearTimeout(id);
		});
		this._intervalIds.forEach(id => {
			clearInterval(id);
		});
	},


	onDestroy() {

		clearTimeout(this.timer_1);
	}

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

});

