Commit 03da6730 authored by 范雪寒's avatar 范雪寒

feat: 精简

parent 8029fd2d
import { asyncDelay, callMiddleLayerFunction, onHomeworkFinish, playAudio } from "../script/util";
import { asyncDelay, asyncLoadDragonBoneAnime, callMiddleLayerFunction, onHomeworkFinish, playAudio } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
......@@ -13,7 +13,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: (this.data.lrcData && this.data.lrcData.audio_url) || ''});
this._audioResList.push({ url: (this.data.lrcData && this.data.lrcData.audio_url) || '' });
}
addPreloadAnima() {
......@@ -21,14 +21,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log('this.data: ' + JSON.stringify(this.data));
if (this.data?.skeJsonData?.url) {
this.data.skeJsonData.url += '?time=' + new Date().getTime()
this.data.texJsonData.url += '?time=' + new Date().getTime()
this.data.texPngData.url += '?time=' + new Date().getTime()
this.data.skeJsonData.url += '?time=' + new Date().getTime()
this.data.texJsonData.url += '?time=' + new Date().getTime()
this.data.texPngData.url += '?time=' + new Date().getTime()
}
this._animaResList.push({ url: this.data.skeJsonData.url || '' });
this._animaResList.push({ url: this.data.texJsonData.url || ''});
this._animaResList.push({ url: this.data.texPngData.url || ''});
this._animaResList.push({ url: this.data.texJsonData.url || '' });
this._animaResList.push({ url: this.data.texPngData.url || '' });
}
onLoadEnd() {
......@@ -43,17 +43,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
let isDataLoaded = false;
let isAnimLoaded = false;
const checkStart = () => {
console.log( ' in checkStart: ', isDataLoaded)
console.log( ' in isAnimLoaded: ', isAnimLoaded)
console.log(' in checkStart: ', isDataLoaded)
console.log(' in isAnimLoaded: ', isAnimLoaded)
if (isDataLoaded && isAnimLoaded) {
window["air"].hideAirClassLoading();
this.initView();
}
}
}
this.getState(() => {
isDataLoaded = true;
checkStart();
......@@ -87,7 +87,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
callMiddleLayerFunction('PSQS_get_course_info', {}, (data) => {
console.log(' in getState 2');
console.log(' in getState 2');
this.isFirst = data.first; //this.checkIsFirst();
......@@ -144,7 +144,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
return;
}
for (let i=0; i<lyrics.length; i++) {
for (let i = 0; i < lyrics.length; i++) {
const data = lyrics[i].data;
if (!data) {
......@@ -155,10 +155,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
let duration = 0;
if (i != lyrics.length - 1) {
duration = lyrics[i+1].time - lyrics[i].time;
duration = lyrics[i + 1].time - lyrics[i].time;
}
this.textArr.push({data, time, duration});
this.textArr.push({ data, time, duration });
}
}
......@@ -179,7 +179,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
initView() {
console.log( ' in initView')
console.log(' in initView')
if (this.jumpData) {
this.junpAnim();
......@@ -196,7 +196,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
return;
}
......@@ -216,9 +216,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
let disFrame = maxDisFrame;
for (let i=1; i<arr.length; i++) {
for (let i = 1; i < arr.length; i++) {
const curDis = (arr[i].text - arr[i-1].text) / 2;
const curDis = (arr[i].text - arr[i - 1].text) / 2;
if (disFrame > curDis) {
disFrame = curDis;
}
......@@ -236,7 +236,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.showStartTitleReady();
}
}
lightBg;
lightLeft;
......@@ -248,7 +248,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
lightBg.scaleY = this.canvas.height / lightBg.height;
lightBg.opacity = 180;
this.canvas.addChild(lightBg, 10);
const lightLeft = this.getSprNode('light');
lightLeft.anchorY = 0.9;
......@@ -260,12 +260,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
lightLeft.rotation = 45;
lightLeft.opacity = 0;
cc.tween(lightLeft)
.to(1, {rotation: -45}, {easing: "cubicOut"})
.to(1, { rotation: -45 }, { easing: "cubicOut" })
.start();
cc.tween(lightLeft)
.to(0.5, {opacity: 255})
.to(0.5, { opacity: 255 })
.start();
const lightRight = this.getSprNode('light');
lightRight.anchorY = 0.9;
lightRight.x = this.canvas.width / 2;
......@@ -276,10 +276,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
lightRight.rotation = -45;
lightRight.opacity = 0;
cc.tween(lightRight)
.to(1, {rotation: 45}, {easing: "cubicOut"})
.to(1, { rotation: 45 }, { easing: "cubicOut" })
.start();
cc.tween(lightRight)
.to(0.5, {opacity: 255})
.to(0.5, { opacity: 255 })
.start();
......@@ -306,7 +306,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.startAudioEnd();
}));
})
.to(1.5, {y: 0}, {easing: "elasticOut"})
.to(1.5, { y: 0 }, { easing: "elasticOut" })
.start();
this.title = title
......@@ -334,13 +334,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
sprNode.opacity = 0;
cc.tween(sprNode)
.to(time/10, {opacity: 255})
.to(time / 10, { opacity: 255 })
.start();
cc.tween(sprNode)
.to(0.8 * time, {scale: this._mapScaleMin}, {easing: 'elasticOut'})
.to(0.8 * time, { scale: this._mapScaleMin }, { easing: 'elasticOut' })
.delay(0 * time)
.to(0.2 * time, {opacity: 0})
.to(0.2 * time, { opacity: 0 })
.start();
}
......@@ -373,9 +373,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
async hideStartView() {
const hideSpr = (sprNode, cb=null) => {
const hideSpr = (sprNode, cb = null) => {
cc.tween(sprNode)
.to(0.3, {opacity: 0})
.to(0.3, { opacity: 0 })
.call(() => {
sprNode.active = false;
cb && cb();
......@@ -425,8 +425,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// this.delayDeleteAnim();
callMiddleLayerFunction('PSQS_jump_to_question', {step: id}, null)
callMiddleLayerFunction('PSQS_jump_to_question', { step: id }, null)
return;
}
......@@ -463,16 +463,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log('PSQS_show_rabbit 1');
// callMiddleLayerFunction('PSQS_show_rabbit', null, () => {
this.changeToMiddleLayer();
console.log('in changeToMiddleLayer1 ');
this.changeToMiddleLayer();
console.log('in changeToMiddleLayer1 ');
// this.delayDeleteAnim();
// this.delayDeleteAnim();
console.log('PSQS_show_rabbit 2')
callMiddleLayerFunction('PSQS_jump_to_question', {step: id}, null)
console.log('PSQS_show_rabbit 2')
callMiddleLayerFunction('PSQS_jump_to_question', { step: id }, null)
// })
})
}
......@@ -486,17 +486,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
middleLayer.myAnimNode = null;
let dragonDisplay = this.animaNode.getComponent(dragonBones.ArmatureDisplay);
const oldAtlas = dragonDisplay.dragonAtlasAsset;
const oldAsset = dragonDisplay.dragonAsset;
this.delayRelease(oldAtlas, oldAsset, this.animaNode);
console.log(' setOneAnima 101')
this.animaNode.removeComponent(dragonBones.ArmatureDisplay)
dragonDisplay = this.animaNode.addComponent(dragonBones.ArmatureDisplay);
......@@ -539,7 +539,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
jumpAudio(id) {
console.log('in jumpAudio id: ', id);
const stepData = this.data.stepArr[id-1];
const stepData = this.data.stepArr[id - 1];
console.log('stepData: ', stepData);
const time = stepData.text / this.data.frame;
......@@ -549,13 +549,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.audioId = audioId;
this.audioClip = audioClip;
});
}
continueAnim(id) {
console.log(' in continueAnim')
// this.dragonDisplay.timeScale = 1;
callMiddleLayerFunction('PSQS_hide_rabbit', null, () => {
......@@ -580,7 +580,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.continueAnim(id);
this.jumpData = null;
}
return
return
}
console.log('id: ', id);
......@@ -620,13 +620,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
back.scale = 0.3;
back.opacity = 0
cc.tween(back)
.to(0.9, {scale: this._mapScaleMin, opacity:255}, {easing: 'elasticOut'})
.to(0.9, { scale: this._mapScaleMin, opacity: 255 }, { easing: 'elasticOut' })
.start();
back.addComponent(cc.Button);
back.on('click', () => {
console.log('click back')
callMiddleLayerFunction('PSQS_exit_book', null, () => {});
callMiddleLayerFunction('PSQS_exit_book', null, () => { });
})
}
......@@ -636,16 +636,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
// callMiddleLayerFunction('PSQS_show_rabbit', null, () => {
this.changeToMiddleLayer();
console.log(' in animPlayEnd 2')
this.changeToMiddleLayer();
// setTimeout(() => {
callMiddleLayerFunction('PSQS_play_animate_over', null, () => {})
// }, 100);
// callMiddleLayerFunction('PSQS_play_animate_over', this.animaNode, () => {})
console.log(' in animPlayEnd 2')
// setTimeout(() => {
callMiddleLayerFunction('PSQS_play_animate_over', null, () => { })
// }, 100);
// callMiddleLayerFunction('PSQS_play_animate_over', this.animaNode, () => {})
// })
}
changeToMiddleLayer() {
......@@ -667,28 +667,86 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.animaNode.scale = cScale / mScale * this._mapScaleMax;
if (this.data.scale) {
this.animaNode.scale *= this.data.scale;
}
}
this.dragonDisplay.dragonAtlasAsset.addRef();
this.dragonDisplay.dragonAsset.addRef();
// setTimeout(() => {
console.log('in changeToMiddleLayer 2 ');
this.animaNode.parent = middleLayer;
console.log('in changeToMiddleLayer 2 ');
this.animaNode.parent = middleLayer;
// }, 50);
}
}
async setOneAnima1(data, cb) {
if (!data.texPngData) {
return
}
asyncLoadDragonBoneAnime(this.canvas, data);
const animaNode = this.canvas.animaNode;
animaNode.scale = this._mapScaleMax;
if (this.data.scale) {
animaNode.scale *= this.data.scale;
}
const dragonDisplay = animaNode.getComponent(dragonBones.ArmatureDisplay);
dragonDisplay.armatureName = dragonDisplay.getArmatureNames()[0];
const animationName = dragonDisplay.getAnimationNames()[0];
dragonDisplay.playAnimation(animationName, 1);
dragonDisplay.timeScale = 0;
dragonDisplay.off(dragonBones.EventObject.FRAME_EVENT)
dragonDisplay.on(dragonBones.EventObject.FRAME_EVENT, (event) => {
console.log(' in frameEventFunc ')
if (this.playTimes > 0) {
this.animChangeStep(event.name);
}
})
dragonDisplay.off(dragonBones.EventObject.COMPLETE)
dragonDisplay.on(dragonBones.EventObject.COMPLETE, () => {
console.log(' in compFunc ')
if (this.isLast && this.playTimes > 0) {
this.showGoodjob();
} else {
this.animPlayEnd();
}
})
animaNode.off('touchstart')
animaNode.on('touchstart', (e) => {
const pos = e.getLocation();
const x = pos.x// - e.currentTarget.width / 2;
const y = pos.y// - e.currentTarget.height / 2;
const newPos = animaNode.convertToNodeSpaceAR(cc.v2(x, y));
console.log('X: ', Math.round(newPos.x));
console.log('Y: ', Math.round(newPos.y));
});
this.dragonDisplay = dragonDisplay;
this.animaNode = animaNode;
cb && cb();
}
dragonDisplay;
animaNode;
maxTexture;
setOneAnima(data, cb) {
setOneAnima(data, cb) {
this.setOneAnima1(data, cb);
return;
console.log(' setOneAnima 1')
......@@ -724,7 +782,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// animaNode.scale *= data.scale;
// console.log('in updateScale 2');
// }
// }
// if (middleLayer) {
......@@ -741,18 +799,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!data.texPngData) {
return
}
if (!data.texPngData) {
return
}
console.log(' setOneAnima 5')
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";
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";
// let oldAtlas;
// let oldAsset;
// if (myAnimNode) {
......@@ -760,22 +818,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
// oldAtlas = oldDragonDisplay.dragonAtlasAsset;
// oldAsset = oldDragonDisplay.dragonAsset;
// }
cc.assetManager.loadRemote(image, (error, texture) => {
console.log(' setOneAnima 6')
// cc.loader.load({url: atlas, type: 'txt'}, (error, atlasJson) => {
// cc.loader.load({url: atlas, type: 'txt'}, (error, atlasJson) => {
cc.assetManager.loadAny({ url: atlas, reload: true }, (error, atlasJson) => {
console.log(' setOneAnima 7')
// cc.loader.load({url: ske, type: 'txt'}, (error, dragonBonesJson) => {
// cc.loader.load({url: ske, type: 'txt'}, (error, dragonBonesJson) => {
cc.assetManager.loadAny({ url: ske, reload: true }, (error, dragonBonesJson) => {
console.log(' setOneAnima 8')
......@@ -805,9 +863,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// this.maxTexture = texture;
// const atlas = new dragonBones.DragonBonesAtlasAsset();
// atlas.atlasJson = atlasJson;
// atlas.texture = texture;
// const atlas = new dragonBones.DragonBonesAtlasAsset();
// atlas.atlasJson = atlasJson;
// atlas.texture = texture;
const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = JSON.stringify(atlasJson);
......@@ -818,54 +876,54 @@ export default class SceneComponent extends MyCocosSceneComponent {
const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
// console.log(' setOneAnima 10')
// animaNode.removeComponent(dragonBones.ArmatureDisplay)
// dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
console.log('dragonDisplay = ' + typeof(dragonDisplay));
dragonDisplay.dragonAtlasAsset = atlas;
console.log('dragonDisplay = ' + typeof (dragonDisplay));
dragonDisplay.dragonAtlasAsset = atlas;
console.log('汪汪汪 1')
dragonDisplay.dragonAsset = asset;
dragonDisplay.dragonAsset = asset;
console.log('汪汪汪 2')
console.log('type: ' + typeof(asset.dragonBonesJson));
console.log('type: ' + typeof (asset.dragonBonesJson));
let json = JSON.parse(asset.dragonBonesJson);
console.log('json: ', json);
let json = JSON.parse(asset.dragonBonesJson);
console.log('json: ', json);
let armatures = json["armature"];
console.log('armatures: ', armatures);
let armatureNames = [];
for (let i = 0; i < armatures.length; i++) {
armatureNames.push(armatures[i].name);
}
console.log('armatureNames: ', armatureNames);
let armatures = json["armature"];
console.log('armatures: ', armatures);
let armatureNames = [];
for (let i = 0; i < armatures.length; i++) {
armatureNames.push(armatures[i].name);
}
console.log('armatureNames: ', armatureNames);
console.log(' setOneAnima 11')
if (armatureNames.length > 0) {
let defaultArmatureName = armatureNames[0];
dragonDisplay.armatureName = defaultArmatureName;
// let animationNames = dragonDisplay.getAnimationNames(defaultArmatureName);
let defaultArmature = armatures[0];
let animations = defaultArmature.animation;
let animationNames = [];
for (let i = 0; i < animations.length; i++) {
animationNames.push(animations[i].name);
}
if (armatureNames.length > 0) {
let defaultArmatureName = armatureNames[0];
dragonDisplay.armatureName = defaultArmatureName;
// let animationNames = dragonDisplay.getAnimationNames(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;
}
}
console.log(' setOneAnima 12')
animaNode.scale = this._mapScaleMax;
if (this.data.scale) {
animaNode.scale *= this.data.scale;
}
}
// dragonDisplay.timeScale = 50;
......@@ -875,7 +933,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// animaNode.parent = middleLayer;
// // dragonDisplay.dragonAtlasAsset.decRef();
// // dragonDisplay.destroy();
......@@ -885,10 +943,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
// setTimeout(() => {
// callMiddleLayerFunction('PSQS_play_animate_over', null, () => {})
// }, 1000);
// }, 10000);
// return ;
......@@ -921,7 +979,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
dragonDisplay.off(dragonBones.EventObject.COMPLETE)
dragonDisplay.on(dragonBones.EventObject.COMPLETE, compFunc)
console.log(' setOneAnima 15')
const touchFunc = (e) => {
......@@ -933,8 +991,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
const y = pos.y// - e.currentTarget.height / 2;
const newPos = animaNode.convertToNodeSpaceAR(cc.v2(x, y));
console.log('X: ', Math.round( newPos.x ));
console.log('Y: ', Math.round( newPos.y ));
console.log('X: ', Math.round(newPos.x));
console.log('Y: ', Math.round(newPos.y));
}
animaNode.off('touchstart')
animaNode.on('touchstart', touchFunc)
......@@ -947,19 +1005,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
cb && cb();
// console.log("animaNode: ", animaNode);
});
});
});
});
});
});
}
}
delayRelease(oldAtlas, oldAsset, delteItem=null) {
delayRelease(oldAtlas, oldAsset, delteItem = null) {
setTimeout(() => {
if (oldAtlas) {
console.log(' in aaaa 1')
if (oldAtlas.texture) {
......@@ -1008,7 +1066,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
getCurTextObj() {
const data = this.textArr[this.textArrIndex];
if (data) {
this.textArrIndex ++;
this.textArrIndex++;
}
return data;
}
......@@ -1036,30 +1094,30 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.textLabel.curTween.stop();
}
this.textLabel.node.opacity = 0;
this.textLabel.string = `<outline color=white width=4>${textObj.data}</outline>`
if (textObj.duration ) {
if (textObj.duration) {
this.textLabel.curTween = cc.tween(this.textLabel.node)
.to(0.2, {opacity: 255}, {easing: 'sineOut'})
.delay(textObj.duration )
.call(() => {
this.curTextObj = null;
})
.to(0.1, {opacity: 0})
.start();
.to(0.2, { opacity: 255 }, { easing: 'sineOut' })
.delay(textObj.duration)
.call(() => {
this.curTextObj = null;
})
.to(0.1, { opacity: 0 })
.start();
} else {
this.textLabel.curTween = cc.tween(this.textLabel.node)
.to(0.2, {opacity: 255}, {easing: 'sineOut'})
.start();
.to(0.2, { opacity: 255 }, { easing: 'sineOut' })
.start();
}
}
getTextLabel() {
const richTextNode = new cc.Node();
richTextNode.y = -this.canvas.height / 2 + 20 * this._mapScaleMin ;
richTextNode.y = -this.canvas.height / 2 + 20 * this._mapScaleMin;
richTextNode.opacity = 0;
richTextNode.anchorY = 0;
richTextNode.scale = this._mapScaleMin;
......@@ -1091,7 +1149,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
update (dt) {
update(dt) {
this.checkShowText();
}
......@@ -1111,7 +1169,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// cc.assetManager.cacheManager.clearCache()
// }
}
onDestroy() {
console.log(' in onDestroy');
this.releaseAssets();
......
......@@ -238,7 +238,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => {
const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = JSON.stringify(atlasJson);
atlas.texture = texture;
atlas.texture = <any>texture;
const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
......@@ -246,7 +246,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset;
let armatureNames = dragonBonesJson.armature.map(data => data.name);
let armatureNames = (<any>dragonBonesJson).armature.map(data => data.name);
if (armatureNames.length > 0) {
dragonDisplay.armatureName = armatureNames[0];
......
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