Skip to content

Commit

Permalink
format built-in actions
Browse files Browse the repository at this point in the history
  • Loading branch information
reececomo committed Apr 24, 2024
1 parent 4844990 commit 837b934
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 136 deletions.
20 changes: 11 additions & 9 deletions src/actions/chainable/GroupAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
}
Expand Down
28 changes: 15 additions & 13 deletions src/actions/chainable/RepeatAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions src/actions/chainable/RepeatForeverAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
}
Expand Down
16 changes: 8 additions & 8 deletions src/actions/chainable/SequenceAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions src/actions/custom/RunBlockAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions src/actions/display-object/RemoveFromParentAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 7 additions & 5 deletions src/actions/display-object/RunOnChildWithNameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ 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;
}

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);
}
}
10 changes: 6 additions & 4 deletions src/actions/display-object/SetVisibleAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 9 additions & 9 deletions src/actions/follow-path/FollowPathAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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]!;
Expand Down
12 changes: 6 additions & 6 deletions src/actions/move/MoveByAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/actions/move/MoveToAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/actions/rotate/RotateByAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions src/actions/rotate/RotateToAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/actions/scale/ScaleByAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/actions/scale/ScaleToAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
Loading

0 comments on commit 837b934

Please sign in to comment.