修改代码

This commit is contained in:
ival 2021-04-04 21:00:42 +08:00
parent e3900b6f9e
commit b8ef4c33da
3 changed files with 34 additions and 23 deletions

View File

@ -13,39 +13,43 @@ function traverse(group, map) {
class Animate {
constructor(state) {
this.state = {...state}
this.shapeFactory = this.shape? this.shape.shapeFactory: null;
this.sum = 0;
this.count = 0;
this.first = true;
this._state = {...state}
this._sum = 0;
this._count = 0;
this._first = true;
this._dispose = false;
}
run(interval) {
this.sum = this.sum + interval;
const total = this.state.time + (this.first? this.state.delay: 0)
if (this.sum > total) {
this._sum = this._sum + interval;
const total = this._state.time + (this._first? this._state.delay: 0)
if (this._sum > total) {
this.animate(this)
this.count = this.count + 1;
this.sum = 0;
this.first = false;
this._count = this._count + 1;
this._sum = 0;
this._first = false;
}
}
isLoop() {
return this.state.loop;
return this._state.loop;
}
isNeedDefault() {
return this.state.isNeedDefault;
return this._state.isNeedDefault;
}
isDispose() {
return this._dispose;
}
animate() {
const shape = this.state.shape;
const frameList = this.state.frameList;
const shape = this._state.shape;
const frameList = this._state.frameList;
const mapView = traverse(shape, {});
if(shape && frameList) {
const size = frameList.length;
const index = this.count%size;
const index = this._count%size;
const frame = frameList[index];
Object.keys(frame).forEach(name => {
const view = mapView[name];
@ -57,25 +61,33 @@ class Animate {
})
}
}
dispose() {
this._dispose = true;
}
}
class AnimateHandle {
constructor(painter) {
this.animates = [];
this._animates = [];
}
onframe (delay) {
const animate = this.animates.shift();
const animate = this._animates.shift();
if (animate) {
animate.run(delay);
if (animate.isLoop()) {
this.animates.push(animate);
if (animate.isLoop() && !animate.isDispose()) {
this._animates.push(animate);
}
}
}
animate(state) {
this.animates.push(new Animate(state));
const animate = this._animates.find(el => el.code == state.code);
if (animate) {
animate.dispose();
}
this._animates.push(new Animate(state));
}
}

View File

@ -162,7 +162,7 @@ export default class Controller extends Eventful {
const dy2 = Math.pow(e.dy, 2);
const scale = this.option.getScaleRate();
const diff = Math.ceil(Math.sqrt(dx2+dy2));
return scale > 1 && (diff > 2/scale);
return (scale > 1) || (diff > 2/scale);
}
mousedown(e) {

View File

@ -3,7 +3,6 @@ export default class KeyBoardHandle {
constructor(map, controller) {
this.$map = map;
this.$controller = controller;
this.keyStr = '';
}
execFunc(moduleName, funcName, args) {