tween array fixes

This commit is contained in:
lavrton 2015-09-21 15:43:03 +07:00
parent 77f9af4e06
commit 8006bed344
2 changed files with 68 additions and 2 deletions

View File

@ -216,7 +216,7 @@
_addAttr: function(key, end) {
var node = this.node,
nodeId = node._id,
start, diff, tweenId, n, len, trueEnd;
start, diff, tweenId, n, len, trueEnd, trueStart;
// remove conflict from tween map if it exists
tweenId = Konva.Tween.tweens[nodeId][key];
@ -238,6 +238,7 @@
if (end.length > start.length) {
// so in this case we will increase number of starting points
trueStart = start;
start = Konva.Util._prepareArrayForTween(start, end, node.closed());
} else {
// in this case we will increase number of eding points
@ -267,7 +268,8 @@
start: start,
diff: diff,
end: end,
trueEnd: trueEnd
trueEnd: trueEnd,
trueStart: trueStart
};
Konva.Tween.tweens[nodeId][key] = this._id;
},
@ -330,6 +332,13 @@
}
};
this.tween.onReset = function() {
var node = that.node;
// after tweening points of line we need to set original start
var attrs = Konva.Tween.attrs[node._id][that._id];
if (attrs.points && attrs.points.trueStart) {
node.points(attrs.points.trueStart);
}
if (that.onReset) {
that.onReset();
}

View File

@ -277,6 +277,63 @@ suite('Tween', function() {
}
});
});
test('tween array to lower size and go back', function(done) {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var line = new Konva.Line({
stroke: 'black',
points: [100, 100, 200, 100, 200, 200, 100, 200],
closed: true
});
layer.add(line);
var tween = new Konva.Tween({
node: line,
points: [100, 100, 200, 100, 200, 200],
duration: 0.01,
onFinish: function() {
tween.reverse();
},
onReset: function() {
assert.deepEqual(line.points(), [100, 100, 200, 100, 200, 200, 100, 200]);
done();
}
});
tween.play();
});
test('tween array to bigger size and go back', function(done) {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var line = new Konva.Line({
stroke: 'black',
points: [100, 100, 200, 100, 200, 200],
closed: true
});
layer.add(line);
var tween = new Konva.Tween({
node: line,
points: [100, 100, 200, 100, 200, 200, 100, 200],
duration: 0.01,
onFinish: function() {
tween.reverse();
},
onReset: function() {
assert.deepEqual(line.points(), [100, 100, 200, 100, 200, 200]);
done();
}
});
tween.play();
});
});
});