Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tween.sequence #16168

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions cocos/tween/actions/action-interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class ActionInterval extends FiniteTimeAction {
protected MAX_VALUE = 2;
protected _elapsed = 0;
protected _firstTick = false;
// eslint-disable-next-line @typescript-eslint/ban-types
protected _easeList: Function[] = [];
protected _speed = 1;
protected _repeatForever = false;
Expand All @@ -59,7 +60,7 @@ export class ActionInterval extends FiniteTimeAction {

constructor (d?: number) {
super();
if (d !== undefined && !isNaN(d)) {
if (d !== undefined && !Number.isNaN(d)) {
this.initWithDuration(d);
}
}
Expand Down Expand Up @@ -128,6 +129,7 @@ export class ActionInterval extends FiniteTimeAction {
easing (easeObj: any): ActionInterval {
if (this._easeList) this._easeList.length = 0;
else this._easeList = [];
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
for (let i = 0; i < arguments.length; i++) this._easeList.push(arguments[i]);
return this;
}
Expand Down Expand Up @@ -256,7 +258,7 @@ export class ActionInterval extends FiniteTimeAction {
*/
repeat (times: number): ActionInterval {
times = Math.round(times);
if (isNaN(times) || times < 1) {
if (Number.isNaN(times) || times < 1) {
logID(1014);
return this;
}
Expand Down Expand Up @@ -289,7 +291,7 @@ export class Sequence extends ActionInterval {
const sequence = new Sequence();
sequence.initWithTwoActions(actionOne, actionTwo);
return sequence;
}
};

private _actions: ActionInterval[] = [];
private _split = 0;
Expand Down Expand Up @@ -323,7 +325,7 @@ export class Sequence extends ActionInterval {
for (let i = 1; i < last; i++) {
if (paramArray[i]) {
action1 = prev;
prev = Sequence._actionOneTwo(action1, paramArray[i]);
prev = Sequence._actionOneTwo(action1 as ActionInterval, paramArray[i] as ActionInterval);
}
}
this.initWithTwoActions(prev, paramArray[last]);
Expand All @@ -346,7 +348,7 @@ export class Sequence extends ActionInterval {
durationOne *= actionOne._repeatMethod ? actionOne._timesForRepeat : 1;
durationTwo *= actionTwo._repeatMethod ? actionTwo._timesForRepeat : 1;
const d = durationOne + durationTwo;
this.initWithDuration(d);
this.initWithDuration(d as number);

this._actions[0] = actionOne;
this._actions[1] = actionTwo;
Expand All @@ -355,7 +357,7 @@ export class Sequence extends ActionInterval {

clone (): any {
const action = new Sequence();
this._cloneDecoration(action as any);
this._cloneDecoration(action as ActionInterval);
action.initWithTwoActions(this._actions[0].clone(), this._actions[1].clone());
return action as any;
}
Expand Down Expand Up @@ -411,6 +413,7 @@ export class Sequence extends ActionInterval {
}
}

// eslint-disable-next-line prefer-const
actionFound = locActions[found];
// Last action found and it is done.
if (locLast === found && actionFound.isDone()) return;
Expand Down Expand Up @@ -454,8 +457,9 @@ export class Sequence extends ActionInterval {
export function sequence (/* Multiple Arguments */tempArray: any): ActionInterval {
const paramArray = (tempArray instanceof Array) ? tempArray : arguments;
if (paramArray.length === 1) {
errorID(1019);
return null as any;
// errorID(1019);
// return null as any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments?

return paramArray[0] as ActionInterval;
}
const last = paramArray.length - 1;
if ((last >= 0) && (paramArray[last] == null)) logID(1015);
Expand All @@ -465,12 +469,12 @@ export function sequence (/* Multiple Arguments */tempArray: any): ActionInterva
result = paramArray[0];
for (let i = 1; i <= last; i++) {
if (paramArray[i]) {
result = Sequence._actionOneTwo(result, paramArray[i]);
result = Sequence._actionOneTwo(result as ActionInterval, paramArray[i] as ActionInterval);
}
}
}

return result;
return result as ActionInterval;
}

/*
Expand All @@ -493,7 +497,7 @@ export class Repeat extends ActionInterval {

constructor (action?: any, times?: any) {
super();
times !== undefined && this.initWithAction(action, times);
times !== undefined && this.initWithAction(action as FiniteTimeAction, times as number);
}

/*
Expand Down Expand Up @@ -666,7 +670,7 @@ export class RepeatForever extends ActionInterval {

step (dt: any): void {
const locInnerAction = this._innerAction!;
locInnerAction.step(dt);
locInnerAction.step(dt as number);
if (locInnerAction.isDone()) {
// var diff = locInnerAction.getElapsed() - locInnerAction._duration;
locInnerAction.startWithTarget(this.target);
Expand Down Expand Up @@ -731,7 +735,7 @@ export class Spawn extends ActionInterval {
const pSpawn = new Spawn();
pSpawn.initWithTwoActions(action1, action2);
return pSpawn;
}
};

private _one: ActionInterval | null = null;
private _two: ActionInterval | null = null;
Expand Down Expand Up @@ -775,14 +779,14 @@ export class Spawn extends ActionInterval {
const d1 = action1._duration;
const d2 = action2._duration;

if (this.initWithDuration(Math.max(d1, d2))) {
if (this.initWithDuration(Math.max(d1 as number, d2 as number))) {
this._one = action1;
this._two = action2;

if (d1 > d2) {
this._two = Sequence._actionOneTwo(action2, delayTime(d1 - d2));
this._two = Sequence._actionOneTwo(action2 as ActionInterval, delayTime(d1 - d2));
} else if (d1 < d2) {
this._one = Sequence._actionOneTwo(action1, delayTime(d2 - d1));
this._one = Sequence._actionOneTwo(action1 as ActionInterval, delayTime(d2 - d1));
}

ret = true;
Expand Down Expand Up @@ -811,8 +815,8 @@ export class Spawn extends ActionInterval {

update (dt: any): void {
dt = this._computeEaseTime(dt);
if (this._one) this._one.update(dt);
if (this._two) this._two.update(dt);
if (this._one) this._one.update(dt as number);
if (this._two) this._two.update(dt as number);
}

reverse (): any {
Expand All @@ -839,6 +843,7 @@ export function spawn (/* Multiple Arguments */tempArray: any): FiniteTimeAction
const paramArray = (tempArray instanceof Array) ? tempArray : arguments;
if (paramArray.length === 1) {
errorID(1020);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return null as any;
}
if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null)) logID(1015);
Expand All @@ -847,14 +852,15 @@ export function spawn (/* Multiple Arguments */tempArray: any): FiniteTimeAction
for (let i = 1; i < paramArray.length; i++) {
if (paramArray[i] != null) prev = Spawn._actionOneTwo(prev, paramArray[i]);
}
return prev;
return prev as FiniteTimeAction;
}

/* Delays the action a certain amount of seconds
* @class DelayTime
* @extends ActionInterval
*/
class DelayTime extends ActionInterval {
// eslint-disable-next-line @typescript-eslint/no-empty-function
update (dt: any): void { }

reverse (): any {
Expand Down Expand Up @@ -905,7 +911,7 @@ export class ReverseTime extends ActionInterval {

constructor (action?: any) {
super();
action && this.initWithAction(action);
action && this.initWithAction(action as ActionInterval);
}

/*
Expand Down
25 changes: 25 additions & 0 deletions tests/tween/tween.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,30 @@ test('destroySelf', function () {
tween(node).destroySelf().start();
game.step();
expect(onDestroy).toBeCalledTimes(1);
director.unregisterSystem(sys);
});

test('sequence', function () {
const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);

const node = new Node();
const target = new Vec3(10, 20, 30);
const tweenact = tween(node).to(1, {position: target}, { easing: "bounceOut" });
tween(node).sequence(tweenact).start();

for (let i = 0; i < 100; ++i) {
game.step();
}
// @ts-expect-error access private property
const action = tweenact._actions[0] as TweenAction;
// @ts-expect-error access private property
const props = action._props;
for (const property in props) {
const prop = props[property];
expect(Vec3.equals(prop.current, target)).toBeTruthy();
}

director.unregisterSystem(sys);
});
Loading