Skip to content

Commit

Permalink
Cancel grandchild tweens (#2354)
Browse files Browse the repository at this point in the history
Allow cancelTweensOf to cancel grandchild tweens. fixes #2316
  • Loading branch information
Geokureli authored Jul 22, 2021
1 parent 6ffd64d commit 3cb8c75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions flixel/tweens/misc/VarTween.hx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class VarTween extends FlxTween

override function isTweenOf(object:Dynamic, ?field:String):Bool
{
if (object == _object && field == null)
return true;

for (property in _propertyInfos)
{
if (object == property.object && (field == property.field || field == null))
Expand Down
18 changes: 16 additions & 2 deletions tests/unit/src/flixel/tweens/FlxTweenTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,29 @@ class FlxTweenTest extends FlxTest
Assert.isTrue(tween2a.finished);
Assert.isFalse(tween2b.finished);

var foo3 = {a: {f:0}, b: {f:0}, c: {f:0}};
var foo3 = {a: {f:0}, b: {f:0}, c: {f:0}, d: {f:0}};
var tween3a = FlxTween.tween(foo3, {"a.f": 1}, 0.1);
var tween3b = FlxTween.tween(foo3, {"b.f": 1}, 0.1);
var tween3c = FlxTween.tween(foo3, {"c.f": 1}, 0.1);
var tween3d = FlxTween.tween(foo3.d, {"f": 1}, 0.1);
// cancel call matches tween call
FlxTween.cancelTweensOf(foo3, ["a.f"]);
FlxTween.cancelTweensOf(foo3.b, ["f"]);
Assert.isTrue(tween3a.finished);
Assert.isFalse(tween3b.finished);
Assert.isFalse(tween3c.finished);
Assert.isFalse(tween3d.finished);
// cancel called on child property, with grandchild field
FlxTween.cancelTweensOf(foo3.b, ["f"]);
Assert.isTrue(tween3b.finished);
Assert.isFalse(tween3c.finished);
Assert.isFalse(tween3d.finished);
// cancel grandchild tweens when cancel target matches tween target
FlxTween.cancelTweensOf(foo3);
Assert.isTrue(tween3c.finished);
Assert.isFalse(tween3d.finished);// doesn't cancel all grandchildren
// cancel called on parent property, with dotted grandchild field
FlxTween.cancelTweensOf(foo3, ["d.f"]);
Assert.isTrue(tween3d.finished);
}

@Test // #2273
Expand Down

0 comments on commit 3cb8c75

Please sign in to comment.