Commit e4f06908 authored by limingzhe's avatar limingzhe

fix: debug

parent 2dd312e2
import { asyncDelay, delayCall, getSprNode, getSprNodeByUrl, onHomeworkFinish, playAudio, playAudioByUrl } from "../script/util";
import { defaultData } from "../script/defaultData";
import { asyncDelay, delayCall, getSprNode, getSprNodeByUrl, onHomeworkFinish, playAudio, playAudioByUrl } from "../script/OP_18_util";
cc.Class({
......
import { asyncDelay, 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 defaultData;
},
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 = [];
},
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;
}
this.ques_region = [
0, 0.077,
1, 0.077,
1, 0.331,
0, 0.331,
]
const para = {
"library_id": "iplayabc",
'page_id': 5,
'book_id': 'opw1',
'part_name': 'c',
'is_hand_writing': true,
'is_line_link': false,
'ques_region' : [
0, 0.077,
1, 0.077,
1, 0.331,
0, 0.331,
]
}
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() {
const layer = new cc.Node();
layer.x = -this.canvas.width / 2 + 10;
layer.y = this.canvas.height / 2 - 10;
// layer.active = false;
const sample = getSprNode('sample');
sample.anchorX = 0;
sample.anchorY = 1;
this.sample = sample;
sample.scale = 0.7;
layer.addChild(sample);
const topLeftRect = [
{x1: 0.28, y1:0.127},
{x2: 0.373, y2:0.127},
{x3: 0.373, y3:0.215},
{x4: 0.28, y4:0.215},
]
this.dotArr1 = [];
const disW = 0.093;// * sample.width;
// const disH = 0.13;// * sample.height;
// let row = 0;
let col = 0;
for (let i=0; i<7; i++) {
const posArr = JSON.parse(JSON.stringify(topLeftRect))
posArr[0].x1 += col * disW;
posArr[1].x2 += col * disW;
posArr[2].x3 += col * disW;
posArr[3].x4 += col * disW;
let color = 'blue';
if (i % 2 == 0) {
color = 'yellow'
}
const colorRect = this.getColorRectByPos(posArr, color)
sample.addChild(colorRect);
this.dotArr1.push(colorRect);
col ++;
}
const topLeftRect2 = [
{x1: 0.28, y1:0.227},
{x2: 0.373, y2:0.227},
{x3: 0.373, y3:0.315},
{x4: 0.28, y4:0.315},
]
this.dotArr2 = [];
// const disW = 0.093;// * sample.width;
// const disH = 0.13;// * sample.height;
// let row = 0;
col = 0;
for (let i=0; i<7; i++) {
const posArr = JSON.parse(JSON.stringify(topLeftRect2))
posArr[0].x1 += col * disW;
posArr[1].x2 += col * disW;
posArr[2].x3 += col * disW;
posArr[3].x4 += col * disW;
let color = 'yellow';
if (i % 2 == 0) {
color = 'blue'
}
const colorRect = this.getColorRectByPos(posArr, color)
sample.addChild(colorRect);
this.dotArr2.push(colorRect);
col ++;
}
this.canvas.addChild(layer, 10)
this.debugLayer = layer;
},
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');
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();
})
},
showUserRight(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;
}
}
},
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) {
// text = text.trim();
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 = line[i].word;
let sentence = ''
word.forEach(item => {
sentence += item.content + ' ';
});
sentence.trim();
sentence = sentence.toLowerCase();
line[i].sentence = sentence;
if (this.checkIsInsert(textArr, sentence)) {
return line[i];
}
// if (sentence.indexOf(text) != -1 ) {
// return line[i];
// }
}
}
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;
},
getPhotoWordArr(identifier, data, topLabelData, bottomLabelData) {
const identifierArr = this.getIdentifierArr(data, identifier)
const wordArr = [];
const topY = -topLabelData.top
const bottomY = -bottomLabelData.bottom;
for (let i = 0; i < identifierArr.length; i++) {
const curTop = -identifierArr[i].top;
if (curTop >= topY || curTop <= bottomY) {
continue;
}
wordArr.push(identifierArr[i]);
}
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);
});
});
});
},
topLabelData: null,
bottomLabelData: null,
topLeftLetter: null,
checkIsRightArea(data, isSmall) {
let letter = this.data.letter || 'a';
letter = letter.toUpperCase();
let checkLetter;
if (isSmall) {
checkLetter = 'x' + letter + '1'
} else {
checkLetter = letter + '1'
}
if (!this.topTitleData) {
const topTitleData = this.getIdentifierArr(data, 'originC')[0];
if (!topTitleData) {
return false;
}
this.topTitleData = topTitleData;
}
if (!this.bottomTitleData) {
const bottomTitleData = this.getIdentifierArr(data, 'originD')[0];
if (!bottomTitleData) {
return;
}
this.bottomTitleData = bottomTitleData;
}
const topLeftLetterData = this.getTopLeftLetterData(data, checkLetter, this.topTitleData, this.bottomTitleData);
if (!topLeftLetterData) {
return;
}
if (isSmall) {
this.topLeftLetterData2 = topLeftLetterData;
} else {
this.topLeftLetterData1 = topLeftLetterData;
}
console.log('topTitleData:', this.topTitleData);
console.log('bottomTitleData:', this.bottomTitleData);
console.log('topLeftLetterData:', topLeftLetterData);
return this.topTitleData && this.bottomTitleData && topLeftLetterData;
// const block = result?.block
// if (!block) {
// return false;
// }
// const letter = this.data.letter || 'a';
// const topLabelData = this.getPhotoLabelData(['tr', 'e', 'wri', 'e'], block);
// if (!topLabelData) {
// console.log(' !topLabelData ')
// return false;
// }
// const bottomLabelData = this.getPhotoLabelData(['or', 'cross', 't', 'out'], block);
// if (!bottomLabelData) {
// console.log(' !bottomLabelData ')
// return false;
// }
// let topLeftLetter = this.getTopLeftLetter(letter, block, topLabelData, bottomLabelData);
// if (!topLeftLetter) {
// console.log(' !topLeftLetter ')
// return false;
// }
// this.topLabelData = topLabelData;
// this.bottomLabelData = bottomLabelData;
// this.topLeftLetter = topLeftLetter;
// // console.log('topLabelData: ', topLabelData);
// // console.log('topLeftLetter: ', topLeftLetter);
// return topLabelData && bottomLabelData && topLeftLetter;
},
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, isSmall) {
let letter = this.data.letter || 'a';
letter = letter.toUpperCase();
let checkLetter;
if (isSmall) {
checkLetter = 'x' + letter + '1'
} else {
checkLetter = letter + '1'
}
const topTitleData = this.topTitleData;
const bottomTitleData = this.bottomTitleData;
let topLeftLetterData;
if (isSmall) {
topLeftLetterData = this.topLeftLetterData2;
} else {
topLeftLetterData = this.topLeftLetterData1;
}
const wordDataArr = this.getPhotoWordArr(checkLetter, data, topTitleData, bottomTitleData);
const dotArr = this.setTestRectDot(topTitleData, bottomTitleData, topLeftLetterData, wordDataArr);
const answerData = {};
console.log('~~wordDataArr:', wordDataArr);
for (let i = 0; i < wordDataArr.length; i++) {
const wordData = wordDataArr[i];
const rect = {
x: wordData.left,
y: -wordData.top,
width: Math.abs(wordData.left - wordData.right),
height: Math.abs(wordData.top - wordData.bottom),
}
const colorRect = this.getColorRect(rect);
this.debugLayer.addChild(colorRect);
this.setOneAnswerData(colorRect, dotArr, answerData);
}
if (this.colorRectTop) {
return answerData;
}
const rectTop = {
x: topTitleData.left,
y: -topTitleData.top,
width: Math.abs( topTitleData.left - topTitleData.right ),
height: Math.abs( topTitleData.top - topTitleData.bottom ),
}
const colorRectTop = this.getColorRect(rectTop, 'green');
this.debugLayer.addChild(colorRectTop);
this.colorRectTop = colorRectTop;
const rectBottom = {
x: bottomTitleData.left,
y: -bottomTitleData.top,
width: Math.abs( bottomTitleData.left - bottomTitleData.right ),
height: Math.abs( bottomTitleData.top - bottomTitleData.bottom ),
}
const colorRectBottom = this.getColorRect(rectBottom, 'green');
this.debugLayer.addChild(colorRectBottom);
return answerData;
// console.log(' in getAnswerData');
// const block = result?.block
// if (!block) {
// return false;
// }
// const letter = this.data.letter || 'a';
// const topLabelData = this.topLabelData;//this.getPhotoLabelData(['tr', 'ce', 'wri', 'e'], block);
// const bottomLabelData = this.bottomLabelData;//this.getPhotoLabelData(['or', 'cross', 'it', 'out'], block);
// let topLeftLetter = this.topLeftLetter; //this.getTopLeftLetter(letter, block, topLabelData, bottomLabelData);
// const wordDataArr = this.getPhotoWordArr(letter, block, topLabelData, bottomLabelData);
// console.log('!!!wordDataArr: ', wordDataArr);
// this.setTestLabel(topLabelData);
// this.setTestLabel(bottomLabelData);
// this.setTestLabel(topLeftLetter);
// // const dotArr = this.setTestRectDot(topLabelData, bottomLabelData, wordDataArr);
// const dotArr = this.setTestRectDot(topLabelData, bottomLabelData, topLeftLetter, wordDataArr);
// // return;
// const answerData = {};
// console.log('~~wordDataArr:', wordDataArr);
// for (let i=0; i<wordDataArr.length; i++) {
// const wordArr = wordDataArr[i].word;
// for (let j=0; j<wordArr.length; j++) {
// const location = wordArr[j].location;
// const rect = {
// x: location.left,
// y: -location.top,
// width: Math.abs( location.left - location.right ),
// height: Math.abs( location.top - location.bottom ),
// }
// const colorRect = this.getColorRect(rect);
// this.debugLayer.addChild(colorRect);
// this.setOneAnswerData(colorRect, dotArr, answerData);
// }
// }
// 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(bbox) {
this.ques_region = [
0, 0.077,
1, 0.077,
1, 0.331,
0, 0.331,
]
console.log('bbox: ', bbox);
const x1 = bbox[0].x1;
const y1 = bbox[0].y1;
const x2 = bbox[1].x2;
const y2 = bbox[1].y2;
const x3 = bbox[2].x3;
const y3 = bbox[2].y3;
const x4 = bbox[3].x4;
const y4 = bbox[3].y4;
const left = this.ques_region[0];
const top = this.ques_region[1];
const right = this.ques_region[2];
const bottom = this.ques_region[7];
const rect = {x: left, y:top, width: right - left, height: bottom - top};
const y1_new = top + y1 * rect.height;
const y2_new = y1_new;
const y3_new = top + y3 * rect.height;
const y4_new = y3_new;
const x1_new = left + x1 * rect.width;
const x2_new = left + x2 * rect.width;
const x3_new = x2_new;
const x4_new = x1_new;
bbox[0].x1 = x1_new;
bbox[0].y1 = y1_new;
bbox[1].x2 = x2_new;
bbox[1].y2 = y2_new;
bbox[2].x3 = x3_new;
bbox[2].y3 = y3_new;
bbox[3].x4 = x4_new;
bbox[3].y4 = y4_new;
console.log('~~rect: ', rect);
},
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;
},
setOneAnswerDataNew(colorRect, dotArr, answerData) {
console.log(' in setOneAnswerDataNew')
const rect = colorRect.ccRect;
const x = rect.x + rect.width / 2;
const y = rect.y +rect.height / 2;
const checkPoint = cc.v2(x, y);
const checkDot = this.getColorDot(x, y, 5);
console.log(' checkPoint:' , checkPoint)
this.sample.addChild(checkDot);
for (let i=0; i<dotArr.length; i++) {
const dotRect = dotArr[i];
const checkRect = dotRect.ccRect;
if (checkRect.contains(checkPoint)) {
answerData[i.toString()] = colorRect;
return;
}
}
},
setOneAnswerData(colorRect, dotArr, answerData) {
// console.log(' in setOneAnswerData')
// console.log('colorRect: ', colorRect)
// console.log('dotArr: ', dotArr)
// console.log('answerData: ', answerData)
const rect = colorRect.ccRect;
for (let i = 0; i < dotArr.length; i++) {
const { dotRect } = dotArr[i];
// const {pos} = dotArr[i];
// if (rect.contains(pos)) {
if (rect.intersects(dotRect)) {
answerData[i.toString()] = colorRect;
return;
}
}
},
getLabel(text) {
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.Label);
label.string = text;
labelNode.color = cc.Color.BLACK;
label.fontSize = 20;
return labelNode;
},
getColorRect(rect, color='red') {
// const node = new cc.Node();
// const colorRect = node.addComponent(cc.Graphics);
// if (!color) {
// color = cc.Color.RED;
// }
// colorRect.fillColor = color
// node.opacity = 0.5;
// colorRect.fillRect(rect.x, rect.y, rect.width, rect.height);
// node.ccRect = new cc.Rect(rect.x, rect.y, rect.width, rect.height);
const node = this.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, r = 10) {
const node = new cc.Node();
if (this.debugLayer.parent && this.debugLayer.active) {
// const colorDot = node.addComponent(cc.Graphics);
// colorDot.fillColor = cc.Color.BLUE;
// colorDot.fillRect( - r/2, - r/ 2, r, r);
const rect = {
x:- r/2,
y: - r/ 2,
width:r,
height:r
}
// const colorDot = this.getColorRect(rect,'blue');
// colorDot.fillColor = cc.Color.BLUE;
// colorDot.fillRect( - r/2, - r/ 2, r, r);
const colorDot = this.getSprNode('blue');
colorDot.anchorX = 0;
colorDot.anchorY = 0;
colorDot.x = rect.x;
colorDot.y = rect.y;
colorDot.scaleX = rect.width / colorDot.width;
colorDot.scaleY = rect.height / colorDot.height;
node.addChild(colorDot);
}
node.x = x;
node.y = y;
// node.pos = new cc.Vec2(x, y);
// node.opacity = 0.5;
const rect = new cc.Rect(node.x - r / 2, node.y - r / 2, r, r);
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.10519801825284958,"right":0.48514851927757263,"top":0.1924528330564499,"bottom":0.04150943458080292,"score":0.531991720199585,"content":"w9ani 2学"},{"left":0.11881188303232193,"right":0.5346534848213196,"top":0.2339622676372528,"bottom":0.5207546949386597,"score":0.8821592926979065,"content":"AAAA"},{"left":0.5061880946159363,"right":0.9863861203193665,"top":0.2037735879421234,"bottom":0.498113214969635,"score":0.9470328688621521,"content":"AAAAA"},{"left":0.13242574036121368,"right":0.9727723002433777,"top":0.7584905624389648,"bottom":0.9094339609146118,"score":0.9460853934288025,"content":"aaaaaaa00"}]}}
// 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);
}
// ------------------------------------------
});
{
"ver": "1.0.8",
"uuid": "88cb9a2d-6891-46a9-8ab6-32b40d3cc977",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// export const defaultData = {"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":"D","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"}
export const defaultData = {"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"}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "c41b0e51-55d7-443c-af3a-b22c3dd9b9e5",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment