diff --git a/packages/melonjs/src/tweens/tween.ts b/packages/melonjs/src/tweens/tween.ts index e7ee0398e..99ee78271 100644 --- a/packages/melonjs/src/tweens/tween.ts +++ b/packages/melonjs/src/tweens/tween.ts @@ -30,8 +30,8 @@ type OnCompleteCallback = (this: T) => void; * author lechecacharro
* author Josh Faul / http://jocafa.com/ */ -export default class Tween> { - _object: T; +export default class Tween { + _object: Object; _valuesStart: Record; _valuesEnd: Record; _valuesStartRepeat: Record; @@ -43,11 +43,11 @@ export default class Tween> { _startTime: number | null; _easingFunction: EasingFunction; _interpolationFunction: InterpolationFunction; - _chainedTweens: Tween>[]; - _onStartCallback: OnStartCallback | null; + _chainedTweens: Array; + _onStartCallback: OnStartCallback | null; _onStartCallbackFired: boolean; - _onUpdateCallback: OnUpdateCallback | null; - _onCompleteCallback: OnCompleteCallback | null; + _onUpdateCallback: OnUpdateCallback | null; + _onCompleteCallback: OnCompleteCallback | null; _tweenTimeTracker: number; isPersistent: boolean; updateWhenPaused: boolean; @@ -68,7 +68,7 @@ export default class Tween> { * autoStart : true * }).onComplete(myFunc); */ - constructor(object: T) { + constructor(object: Object) { this.setProperties(object); this.#boundResumeCallback = this._resumeCallback.bind(this); @@ -77,14 +77,14 @@ export default class Tween> { /** * @ignore */ - onResetEvent(object: T) { + onResetEvent(object: Object) { this.setProperties(object); } /** * @ignore */ - setProperties(object: T) { + setProperties(object: Object) { this._object = object; this._valuesStart = {}; this._valuesEnd = {}; @@ -223,10 +223,14 @@ export default class Tween> { } // create a local copy of the Array with the start value at the front - this._valuesEnd[property] = [this._object[property]].concat(endValue); + this._valuesEnd[property] = [ + (this._object as Record)[property], + ].concat(endValue); } - this._valuesStart[property] = this._object[property]; + this._valuesStart[property] = (this._object as Record)[ + property + ]; if (!Array.isArray(this._valuesStart[property])) { (this._valuesStart[property] as number) *= 1.0; // Ensures we're using numbers, not strings @@ -237,7 +241,6 @@ export default class Tween> { return this; } - /** * stop the tween * @returns this instance for object chaining @@ -304,7 +307,7 @@ export default class Tween> { * @param tweens - Tween(s) to be chained * @returns this instance for object chaining */ - chain(...tweens: Tween[]) { + chain(...tweens: Tween[]) { this._chainedTweens = tweens; return this; } @@ -314,7 +317,7 @@ export default class Tween> { * @param onStartCallback - callback * @returns this instance for object chaining */ - onStart(onStartCallback: OnStartCallback) { + onStart(onStartCallback: OnStartCallback) { this._onStartCallback = onStartCallback; return this; } @@ -324,7 +327,7 @@ export default class Tween> { * @param onUpdateCallback - callback * @returns this instance for object chaining */ - onUpdate(onUpdateCallback: OnUpdateCallback) { + onUpdate(onUpdateCallback: OnUpdateCallback) { this._onUpdateCallback = onUpdateCallback; return this; } @@ -334,7 +337,7 @@ export default class Tween> { * @param onCompleteCallback - callback * @returns this instance for object chaining */ - onComplete(onCompleteCallback: OnCompleteCallback) { + onComplete(onCompleteCallback: OnCompleteCallback) { this._onCompleteCallback = onCompleteCallback; return this; } @@ -457,15 +460,13 @@ export default class Tween> { } } -export const tweenPool = createPool( - >(object: T) => { - const tween = new Tween(object); - - return { - instance: tween, - reset(object: T) { - tween.setProperties(object); - }, - }; - }, -); +export const tweenPool = createPool((object: globalThis.Object) => { + const tween = new Tween(object); + + return { + instance: tween, + reset(object: globalThis.Object) { + tween.setProperties(object); + }, + }; +});