diff --git a/src/actions/chainable/GroupAction.ts b/src/actions/chainable/GroupAction.ts index 82d30f2..4272509 100644 --- a/src/actions/chainable/GroupAction.ts +++ b/src/actions/chainable/GroupAction.ts @@ -15,7 +15,17 @@ export class GroupAction extends Action { } public reversed(): Action { - return new GroupAction(this.actions.map(action => action.reversed())); + return new GroupAction(this.actions.map(action => action.reversed())) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + ticker.autoComplete = false; + + return { + childTickers: this.actions.map(action => new ActionTicker(undefined, target, action)) + }; } protected onTick( @@ -39,14 +49,6 @@ export class GroupAction extends Action { } } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { - ticker.autoComplete = false; - - return { - childTickers: this.actions.map(action => new ActionTicker(undefined, target, action)) - }; - } - protected onTickerDidReset(ticker: IActionTicker): any { ticker.data.childTickers.forEach((ticker: IActionTicker) => ticker.reset()); } diff --git a/src/actions/chainable/RepeatAction.ts b/src/actions/chainable/RepeatAction.ts index 45ed9a6..04456c5 100644 --- a/src/actions/chainable/RepeatAction.ts +++ b/src/actions/chainable/RepeatAction.ts @@ -19,7 +19,21 @@ export class RepeatAction extends Action { } public reversed(): Action { - return new RepeatAction(this.action.reversed(), this.repeats); + return new RepeatAction(this.action.reversed(), this.repeats) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + ticker.autoComplete = false; + + const childTicker = new ActionTicker(undefined, target, this.action); + childTicker.timingMode = (x: number) => ticker.timingMode(childTicker.timingMode(x)); + + return { + childTicker, + n: 0, + }; } protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker, deltaTime: number): void { @@ -39,18 +53,6 @@ export class RepeatAction extends Action { } } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { - ticker.autoComplete = false; - - const childTicker = new ActionTicker(undefined, target, this.action); - childTicker.timingMode = (x: number) => ticker.timingMode(childTicker.timingMode(x)); - - return { - childTicker, - n: 0, - }; - } - protected onTickerDidReset(ticker: IActionTicker): any { ticker.data.childTicker.reset(); ticker.data.n = 0; diff --git a/src/actions/chainable/RepeatForeverAction.ts b/src/actions/chainable/RepeatForeverAction.ts index 7bb52ec..6d7762c 100644 --- a/src/actions/chainable/RepeatForeverAction.ts +++ b/src/actions/chainable/RepeatForeverAction.ts @@ -15,7 +15,18 @@ export class RepeatForeverAction extends Action { } public reversed(): Action { - return new RepeatForeverAction(this.action.reversed()); + return new RepeatForeverAction(this.action.reversed()) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + const childTicker = new ActionTicker(undefined, target, this.action); + childTicker.timingMode = (x: number) => ticker.timingMode(childTicker.timingMode(x)); + + return { + childTicker + }; } protected onTick( @@ -36,15 +47,6 @@ export class RepeatForeverAction extends Action { } } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { - const childTicker = new ActionTicker(undefined, target, this.action); - childTicker.timingMode = (x: number) => ticker.timingMode(childTicker.timingMode(x)); - - return { - childTicker - }; - } - protected onTickerDidReset(ticker: IActionTicker): any { ticker.data.childTicker.reset(); } diff --git a/src/actions/chainable/SequenceAction.ts b/src/actions/chainable/SequenceAction.ts index 9507a11..b9272a4 100644 --- a/src/actions/chainable/SequenceAction.ts +++ b/src/actions/chainable/SequenceAction.ts @@ -19,6 +19,14 @@ export class SequenceAction extends Action { .setSpeed(this.speed); } + protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + ticker.autoComplete = false; + + return { + childTickers: this.actions.map(action => new ActionTicker(undefined, target, action)) + }; + } + protected onTick( target: TargetNode, t: number, @@ -51,14 +59,6 @@ export class SequenceAction extends Action { } } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { - ticker.autoComplete = false; - - return { - childTickers: this.actions.map(action => new ActionTicker(undefined, target, action)) - }; - } - protected onTickerDidReset(ticker: IActionTicker): any { ticker.data.childTickers.forEach((ticker: IActionTicker) => ticker.reset()); } diff --git a/src/actions/custom/RunBlockAction.ts b/src/actions/custom/RunBlockAction.ts index f0fd5ad..ab7c9c8 100644 --- a/src/actions/custom/RunBlockAction.ts +++ b/src/actions/custom/RunBlockAction.ts @@ -8,11 +8,11 @@ export class RunBlockAction extends Action { super(0); } - protected onTick(): void { - this.block(); - } - public reversed(): Action { return this; } + + protected onTick(): void { + this.block(); + } } diff --git a/src/actions/display-object/RemoveFromParentAction.ts b/src/actions/display-object/RemoveFromParentAction.ts index f337a72..a81a571 100644 --- a/src/actions/display-object/RemoveFromParentAction.ts +++ b/src/actions/display-object/RemoveFromParentAction.ts @@ -5,11 +5,11 @@ export class RemoveFromParentAction extends Action { super(0); } - protected onTick(target: TargetNode): void { - target.parent?.removeChild(target); - } - public reversed(): Action { return this; } + + protected onTick(target: TargetNode): void { + target.parent?.removeChild(target); + } } diff --git a/src/actions/display-object/RunOnChildWithNameAction.ts b/src/actions/display-object/RunOnChildWithNameAction.ts index c6667b0..25d6e7e 100644 --- a/src/actions/display-object/RunOnChildWithNameAction.ts +++ b/src/actions/display-object/RunOnChildWithNameAction.ts @@ -8,7 +8,13 @@ export class RunOnChildWithNameAction extends Action { super(0); } - protected onTick(target: TargetNode, t: number, dt: number): void { + public reversed(): Action { + return new RunOnChildWithNameAction(this.action.reversed(), this.name) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onTick(target: TargetNode): void { if (!('children' in target) || !Array.isArray(target.children)) { return; } @@ -16,8 +22,4 @@ export class RunOnChildWithNameAction extends Action { const child: TargetNode | undefined = target.children.find((c: any) => c.name === this.name); child?.run(this.action); } - - public reversed(): Action { - return new RunOnChildWithNameAction(this.action.reversed(), this.name); - } } diff --git a/src/actions/display-object/SetVisibleAction.ts b/src/actions/display-object/SetVisibleAction.ts index f7a0cbb..612dc56 100644 --- a/src/actions/display-object/SetVisibleAction.ts +++ b/src/actions/display-object/SetVisibleAction.ts @@ -7,11 +7,13 @@ export class SetVisibleAction extends Action { super(0); } - protected onTick(target: TargetNode): void { - target.visible = this.visible; + public reversed(): Action { + return new SetVisibleAction(!this.visible) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); } - public reversed(): Action { - return new SetVisibleAction(!this.visible); + protected onTick(target: TargetNode): void { + target.visible = this.visible; } } diff --git a/src/actions/follow-path/FollowPathAction.ts b/src/actions/follow-path/FollowPathAction.ts index 1327de8..c13f91f 100644 --- a/src/actions/follow-path/FollowPathAction.ts +++ b/src/actions/follow-path/FollowPathAction.ts @@ -57,7 +57,7 @@ export class FollowPathAction extends Action { public reversed(): Action { return new FollowPathAction( - this._reversePath(), + this._getReversedPath(), this.duration, this.asOffset, this.orientToPath, @@ -67,6 +67,13 @@ export class FollowPathAction extends Action { .setSpeed(this.speed); } + protected onSetupTicker(target: any): any { + return { + x: this.asOffset ? target.x : 0, + y: this.asOffset ? target.y : 0, + }; + } + protected onTick(target: any, t: number, dt: number, ticker: IActionTicker): void { if (this.lastIndex < 0) { return; // Empty path. @@ -94,16 +101,9 @@ export class FollowPathAction extends Action { } } - protected onSetupTicker(target: any): any { - return { - x: this.asOffset ? target.x : 0, - y: this.asOffset ? target.y : 0, - }; - } - // ----- Internal: ----- - protected _reversePath(): VectorLike[] { + protected _getReversedPath(): VectorLike[] { if (this.asOffset && this.path.length > 0) { // Calculate the relative delta offset when first and last are flipped. const first = this.path[0]!, last = this.path[this.path.length - 1]!; diff --git a/src/actions/move/MoveByAction.ts b/src/actions/move/MoveByAction.ts index 9c34b6e..e3228f3 100644 --- a/src/actions/move/MoveByAction.ts +++ b/src/actions/move/MoveByAction.ts @@ -10,14 +10,14 @@ export class MoveByAction extends Action { super(duration); } + public reversed(): Action { + return new MoveByAction(-this.x, -this.y, this.duration) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + protected onTick(target: TargetNode, t: number, dt: number): void { target.position.x += this.x * dt; target.position.y += this.y * dt; } - - public reversed(): Action { - return new MoveByAction(-this.x, -this.y, this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); - } } diff --git a/src/actions/move/MoveToAction.ts b/src/actions/move/MoveToAction.ts index 02e9ca3..78a8c7a 100644 --- a/src/actions/move/MoveToAction.ts +++ b/src/actions/move/MoveToAction.ts @@ -11,7 +11,11 @@ export class MoveToAction extends Action { super(duration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + + protected onSetupTicker(target: TargetNode): any { return { startX: target.x, startY: target.y @@ -24,8 +28,4 @@ export class MoveToAction extends Action { this.y === undefined ? target.position.y : ticker.data.startY + (this.y - ticker.data.startY) * t ); } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } } diff --git a/src/actions/rotate/RotateByAction.ts b/src/actions/rotate/RotateByAction.ts index 243d9a2..55ddb91 100644 --- a/src/actions/rotate/RotateByAction.ts +++ b/src/actions/rotate/RotateByAction.ts @@ -8,13 +8,13 @@ export class RotateByAction extends Action { super(duration); } - protected onTick(target: TargetNode, t: number, dt: number): void { - target.rotation += this.rotation * dt; - } - public reversed(): Action { return new RotateByAction(-this.rotation, this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onTick(target: TargetNode, t: number, dt: number): void { + target.rotation += this.rotation * dt; } } diff --git a/src/actions/rotate/RotateToAction.ts b/src/actions/rotate/RotateToAction.ts index 48870c5..cdfa044 100644 --- a/src/actions/rotate/RotateToAction.ts +++ b/src/actions/rotate/RotateToAction.ts @@ -10,7 +10,11 @@ export class RotateToAction extends Action { super(duration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + + protected onSetupTicker(target: TargetNode): any { return { startRotation: target.rotation }; @@ -19,8 +23,4 @@ export class RotateToAction extends Action { protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { target.rotation = ticker.data.startRotation + (this.rotation - ticker.data.startRotation) * t; } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } } diff --git a/src/actions/scale/ScaleByAction.ts b/src/actions/scale/ScaleByAction.ts index ea4277e..533d219 100644 --- a/src/actions/scale/ScaleByAction.ts +++ b/src/actions/scale/ScaleByAction.ts @@ -10,7 +10,13 @@ export class ScaleByAction extends Action { super(duration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new ScaleByAction(-this.x, -this.y, this.duration) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode): any { return { dx: target.scale.x * this.x - target.scale.x, dy: target.scale.y * this.y - target.scale.y @@ -23,10 +29,4 @@ export class ScaleByAction extends Action { target.scale.y + ticker.data.dy * dt, ); } - - public reversed(): Action { - return new ScaleByAction(-this.x, -this.y, this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); - } } diff --git a/src/actions/scale/ScaleToAction.ts b/src/actions/scale/ScaleToAction.ts index 7b92286..ff8fa10 100644 --- a/src/actions/scale/ScaleToAction.ts +++ b/src/actions/scale/ScaleToAction.ts @@ -12,6 +12,10 @@ export class ScaleToAction extends Action { super(duration); } + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + protected onSetupTicker(target: TargetNode): any { return { startX: target.scale.x, @@ -25,8 +29,4 @@ export class ScaleToAction extends Action { this.y === undefined ? target.scale.y : ticker.data.startY + (this.y - ticker.data.startY) * t ); } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } } diff --git a/src/actions/scale/ScaleToSizeAction.ts b/src/actions/scale/ScaleToSizeAction.ts index 2d31be2..a65e289 100644 --- a/src/actions/scale/ScaleToSizeAction.ts +++ b/src/actions/scale/ScaleToSizeAction.ts @@ -11,6 +11,10 @@ export class ScaleToSizeAction extends Action { super(duration); } + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + protected onSetupTicker(target: SizedTargetNode): any { if (target.width === undefined) { throw new Error('Action can only be run against a target with a width & height.'); @@ -26,8 +30,4 @@ export class ScaleToSizeAction extends Action { target.width = ticker.data.sW + (this.width - ticker.data.sW) * t; target.height = ticker.data.sH + (this.height - ticker.data.sH) * t; } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } } diff --git a/src/actions/speed/SpeedByAction.ts b/src/actions/speed/SpeedByAction.ts index 5fda9ec..596381d 100644 --- a/src/actions/speed/SpeedByAction.ts +++ b/src/actions/speed/SpeedByAction.ts @@ -1,5 +1,4 @@ import { Action } from '../../lib/Action'; -import { IActionTicker } from '../../lib/IActionTicker'; export class SpeedByAction extends Action { public constructor( @@ -9,11 +8,13 @@ export class SpeedByAction extends Action { super(duration); } - protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { + protected onTick(target: TargetNode, t: number, dt: number): void { target.rotation += this._speed * dt; } public reversed(): Action { - return new SpeedByAction(-this._speed, this.duration); + return new SpeedByAction(-this._speed, this.duration) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); } } diff --git a/src/actions/speed/SpeedToAction.ts b/src/actions/speed/SpeedToAction.ts index b9ca8d1..5142558 100644 --- a/src/actions/speed/SpeedToAction.ts +++ b/src/actions/speed/SpeedToAction.ts @@ -11,7 +11,11 @@ export class SpeedToAction extends Action { super(duration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + + protected onSetupTicker(target: TargetNode): any { return { startSpeed: target.speed }; @@ -20,8 +24,4 @@ export class SpeedToAction extends Action { protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { target.rotation = ticker.data.startRotation + (this._speed - ticker.data.startSpeed) * t; } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } } diff --git a/src/actions/transparency/FadeByAction.ts b/src/actions/transparency/FadeByAction.ts index 4f3cf74..4250d00 100644 --- a/src/actions/transparency/FadeByAction.ts +++ b/src/actions/transparency/FadeByAction.ts @@ -9,13 +9,13 @@ export class FadeByAction extends Action { super(duration); } - protected onTick(target: TargetNode, t: number, dt: number): void { - target.alpha += this.alpha * dt; - } - public reversed(): Action { return new FadeByAction(-this.alpha, this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onTick(target: TargetNode, t: number, dt: number): void { + target.alpha += this.alpha * dt; } } diff --git a/src/actions/transparency/FadeInAction.ts b/src/actions/transparency/FadeInAction.ts index 8df7e64..6b53083 100644 --- a/src/actions/transparency/FadeInAction.ts +++ b/src/actions/transparency/FadeInAction.ts @@ -3,7 +3,13 @@ import { IActionTicker } from '../../lib/IActionTicker'; import { FadeOutAction } from './FadeOutAction'; export class FadeInAction extends Action { - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new FadeOutAction(this.duration) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode): any { return { startAlpha: target.alpha }; @@ -12,10 +18,4 @@ export class FadeInAction extends Action { protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { target.alpha = ticker.data.startAlpha + (1.0 - ticker.data.startAlpha) * t; } - - public reversed(): Action { - return new FadeOutAction(this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); - } } diff --git a/src/actions/transparency/FadeOutAction.ts b/src/actions/transparency/FadeOutAction.ts index 08f578a..0667987 100644 --- a/src/actions/transparency/FadeOutAction.ts +++ b/src/actions/transparency/FadeOutAction.ts @@ -4,7 +4,13 @@ import { IActionTicker } from '../../lib/IActionTicker'; import { FadeInAction } from './FadeInAction'; export class FadeOutAction extends Action { - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new FadeInAction(this.duration) + .setTimingMode(this.timingMode) + .setSpeed(this.speed); + } + + protected onSetupTicker(target: TargetNode): any { return { startAlpha: target.alpha }; @@ -13,10 +19,4 @@ export class FadeOutAction extends Action { protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { target.alpha = ticker.data.startAlpha + (0.0 - ticker.data.startAlpha) * t; } - - public reversed(): Action { - return new FadeInAction(this.duration) - .setSpeed(this.speed) - .setTimingMode(this.timingMode); - } } diff --git a/src/actions/transparency/FadeToAction.ts b/src/actions/transparency/FadeToAction.ts index a793539..11936b2 100644 --- a/src/actions/transparency/FadeToAction.ts +++ b/src/actions/transparency/FadeToAction.ts @@ -11,7 +11,11 @@ export class FadeToAction extends Action { super(duration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + public reversed(): Action { + return new DelayAction(this.scaledDuration); + } + + protected onSetupTicker(target: TargetNode): any { return { startAlpha: target.alpha }; @@ -20,8 +24,4 @@ export class FadeToAction extends Action { protected onTick(target: TargetNode, t: number, dt: number, ticker: IActionTicker): void { target.alpha = ticker.data.startAlpha + (this.alpha - ticker.data.startAlpha) * t; } - - public reversed(): Action { - return new DelayAction(this.scaledDuration); - } }