Updated to use the new BaseTweenData to avoid duplicate props and methods

This commit is contained in:
Richard Davey 2022-09-20 12:40:28 +01:00
parent e2389927ea
commit 009ad199bf
2 changed files with 12 additions and 744 deletions

View file

@ -4,9 +4,9 @@
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var BaseTweenData = require('./BaseTweenData');
var Class = require('../../utils/Class');
var Events = require('../events');
var TWEEN_CONST = require('./const');
/**
* @classdesc
@ -24,6 +24,7 @@ var TWEEN_CONST = require('./const');
*
* @class TweenData
* @memberof Phaser.Tweens
* @extends Phaser.Tweens.BaseTweenData
* @constructor
* @since 3.60.0
*
@ -47,27 +48,13 @@ var TWEEN_CONST = require('./const');
*/
var TweenData = new Class({
Extends: BaseTweenData,
initialize:
function TweenData (tween, targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData)
{
/**
* A reference to the Tween that this TweenData instance belongs to.
*
* @name Phaser.Tweens.TweenData#tween
* @type {Phaser.Tweens.Tween}
* @since 3.60.0
*/
this.tween = tween;
/**
* The index of the target within the Tween `targets` array.
*
* @name Phaser.Tweens.TweenData#targetIndex
* @type {number}
* @since 3.60.0
*/
this.targetIndex = targetIndex;
BaseTweenData.call(this, tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY);
/**
* The property of the target to be tweened.
@ -125,139 +112,6 @@ var TweenData = new Class({
*/
this.ease = ease;
/**
* The duration of the tween in milliseconds, excluding any time required
* for yoyo or repeats.
*
* @name Phaser.Tweens.TweenData#duration
* @type {number}
* @since 3.60.0
*/
this.duration = duration;
/**
* The total calculated duration, in milliseconds, of this TweenData.
* Factoring in the duration, repeats, delays and yoyos.
*
* @name Phaser.Tweens.TweenData#totalDuration
* @type {number}
* @since 3.60.0
*/
this.totalDuration = 0;
/**
* The time, in milliseconds, before this tween will start playing.
*
* This value is generated by the `getDelay` function.
*
* @name Phaser.Tweens.TweenData#delay
* @type {number}
* @since 3.60.0
*/
this.delay = 0;
/**
* This function returns the value to be used for `TweenData.delay`.
*
* @name Phaser.Tweens.TweenData#getDelay
* @type {function}
* @since 3.60.0
*/
this.getDelay = delay;
/**
* Will the Tween ease back to its starting values, after reaching the end
* and any `hold` value that may be set?
*
* @name Phaser.Tweens.TweenData#yoyo
* @type {boolean}
* @since 3.60.0
*/
this.yoyo = yoyo;
/**
* The time, in milliseconds, before this tween will start a yoyo to repeat.
*
* @name Phaser.Tweens.TweenData#hold
* @type {number}
* @since 3.60.0
*/
this.hold = hold;
/**
* The number of times this tween will repeat.
*
* The tween will always run once regardless of this value,
* so a repeat value of '1' will play the tween twice: I.e. the original
* play-through and then it repeats that once (1).
*
* If this value is set to -1 this tween will repeat forever.
*
* @name Phaser.Tweens.TweenData#repeat
* @type {number}
* @since 3.60.0
*/
this.repeat = repeat;
/**
* The time, in milliseconds, before the repeat will start.
*
* @name Phaser.Tweens.TweenData#repeatDelay
* @type {number}
* @since 3.60.0
*/
this.repeatDelay = repeatDelay;
/**
* How many repeats are left to run?
*
* @name Phaser.Tweens.TweenData#repeatCounter
* @type {number}
* @since 3.60.0
*/
this.repeatCounter = 0;
/**
* If `true` this Tween will call `toggleFlipX` on the Tween target
* whenever it yoyo's or repeats. It will only be called if the target
* has a function matching this name, like most Phaser GameObjects do.
*
* @name Phaser.Tweens.TweenData#flipX
* @type {boolean}
* @since 3.60.0
*/
this.flipX = flipX;
/**
* If `true` this Tween will call `toggleFlipY` on the Tween target
* whenever it yoyo's or repeats. It will only be called if the target
* has a function matching this name, like most Phaser GameObjects do.
*
* @name Phaser.Tweens.TweenData#flipY
* @type {boolean}
* @since 3.60.0
*/
this.flipY = flipY;
/**
* A value between 0 and 1 holding the progress of this TweenData.
*
* @name Phaser.Tweens.TweenData#progress
* @type {number}
* @since 3.60.0
*/
this.progress = 0;
/**
* The amount of time, in milliseconds, that has elapsed since this
* TweenData was made active.
*
* @name Phaser.Tweens.TweenData#elapsed
* @type {number}
* @since 3.60.0
*/
this.elapsed = 0;
/**
* The target's starting value, as returned by `getStartValue`.
*
@ -294,15 +148,6 @@ var TweenData = new Class({
*/
this.end = 0;
/**
* The state of this TweenData.
*
* @name Phaser.Tweens.TweenData#state
* @type {Phaser.Types.Tweens.TweenDataState}
* @since 3.60.0
*/
this.state = 0;
/**
* The interpolation function to be used for arrays of data.
*
@ -321,15 +166,6 @@ var TweenData = new Class({
* @since 3.60.0
*/
this.interpolationData = interpolationData;
/**
* Is this Tween Data currently waiting for a countdown to elapse, or not?
*
* @name Phaser.Tweens.TweenData#isCountdown
* @type {boolean}
* @since 3.60.0
*/
this.isCountdown = false;
},
/**
@ -782,206 +618,6 @@ var TweenData = new Class({
}
},
/**
* Sets this TweenData state to CREATED.
*
* @method Phaser.Tweens.TweenData#setCreatedState
* @since 3.60.0
*/
setCreatedState: function ()
{
this.state = TWEEN_CONST.CREATED;
this.isCountdown = false;
},
/**
* Sets this TweenData state to DELAY.
*
* @method Phaser.Tweens.TweenData#setDelayState
* @since 3.60.0
*/
setDelayState: function ()
{
this.state = TWEEN_CONST.DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to PENDING_RENDER.
*
* @method Phaser.Tweens.TweenData#setPendingRenderState
* @since 3.60.0
*/
setPendingRenderState: function ()
{
this.state = TWEEN_CONST.PENDING_RENDER;
this.isCountdown = false;
},
/**
* Sets this TweenData state to PLAYING_FORWARD.
*
* @method Phaser.Tweens.TweenData#setPlayingForwardState
* @since 3.60.0
*/
setPlayingForwardState: function ()
{
this.state = TWEEN_CONST.PLAYING_FORWARD;
this.isCountdown = false;
},
/**
* Sets this TweenData state to PLAYING_BACKWARD.
*
* @method Phaser.Tweens.TweenData#setPlayingBackwardState
* @since 3.60.0
*/
setPlayingBackwardState: function ()
{
this.state = TWEEN_CONST.PLAYING_BACKWARD;
this.isCountdown = false;
},
/**
* Sets this TweenData state to HOLD_DELAY.
*
* @method Phaser.Tweens.TweenData#setHoldState
* @since 3.60.0
*/
setHoldState: function ()
{
this.state = TWEEN_CONST.HOLD_DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to REPEAT_DELAY.
*
* @method Phaser.Tweens.TweenData#setRepeatState
* @since 3.60.0
*/
setRepeatState: function ()
{
this.state = TWEEN_CONST.REPEAT_DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to COMPLETE.
*
* @method Phaser.Tweens.TweenData#setCompleteState
* @since 3.60.0
*/
setCompleteState: function ()
{
this.state = TWEEN_CONST.COMPLETE;
this.isCountdown = false;
},
/**
* Returns `true` if this TweenData has a _current_ state of CREATED, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isCreated
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of CREATED, otherwise `false`.
*/
isCreated: function ()
{
return (this.state === TWEEN_CONST.CREATED);
},
/**
* Returns `true` if this TweenData has a _current_ state of DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isDelayed
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of DELAY, otherwise `false`.
*/
isDelayed: function ()
{
return (this.state === TWEEN_CONST.DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPendingRender
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`.
*/
isPendingRender: function ()
{
return (this.state === TWEEN_CONST.PENDING_RENDER);
},
/**
* Returns `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPlayingForward
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`.
*/
isPlayingForward: function ()
{
return (this.state === TWEEN_CONST.PLAYING_FORWARD);
},
/**
* Returns `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPlayingBackward
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`.
*/
isPlayingBackward: function ()
{
return (this.state === TWEEN_CONST.PLAYING_BACKWARD);
},
/**
* Returns `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isHolding
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`.
*/
isHolding: function ()
{
return (this.state === TWEEN_CONST.HOLD_DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isRepeating
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`.
*/
isRepeating: function ()
{
return (this.state === TWEEN_CONST.REPEAT_DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isComplete
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`.
*/
isComplete: function ()
{
return (this.state === TWEEN_CONST.COMPLETE);
},
/**
* Immediately destroys this TweenData, nulling of all its references.
*
@ -990,13 +626,12 @@ var TweenData = new Class({
*/
destroy: function ()
{
this.tween = null;
BaseTweenData.prototype.destroy.call(this);
this.getActiveValue = null;
this.getEndValue = null;
this.getStartValue = null;
this.ease = null;
this.getDelay = null;
this.setCompleteState();
}
});

View file

@ -4,9 +4,9 @@
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var BaseTweenData = require('./BaseTweenData');
var Class = require('../../utils/Class');
var Events = require('../events');
var TWEEN_CONST = require('./const');
/**
* @classdesc
@ -21,6 +21,7 @@ var TWEEN_CONST = require('./const');
*
* @class TweenFrameData
* @memberof Phaser.Tweens
* @extends Phaser.Tweens.BaseTweenData
* @constructor
* @since 3.60.0
*
@ -38,27 +39,13 @@ var TWEEN_CONST = require('./const');
*/
var TweenFrameData = new Class({
Extends: BaseTweenData,
initialize:
function TweenFrameData (tween, targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY)
{
/**
* A reference to the Tween that this TweenData instance belongs to.
*
* @name Phaser.Tweens.TweenData#tween
* @type {Phaser.Tweens.Tween}
* @since 3.60.0
*/
this.tween = tween;
/**
* The index of the target within the Tween `targets` array.
*
* @name Phaser.Tweens.TweenData#targetIndex
* @type {number}
* @since 3.60.0
*/
this.targetIndex = targetIndex;
BaseTweenData.call(this, tween, targetIndex, delay, duration, false, hold, repeat, repeatDelay, flipX, flipY);
/**
* The texture to be set at the start of the tween.
@ -96,46 +83,6 @@ var TweenFrameData = new Class({
*/
this.endFrame = frame;
/**
* The duration of the tween in milliseconds, excluding any time required
* for yoyo or repeats.
*
* @name Phaser.Tweens.TweenData#duration
* @type {number}
* @since 3.60.0
*/
this.duration = duration;
/**
* The total calculated duration, in milliseconds, of this TweenData.
* Factoring in the duration, repeats, delays and yoyos.
*
* @name Phaser.Tweens.TweenData#totalDuration
* @type {number}
* @since 3.60.0
*/
this.totalDuration = 0;
/**
* The time, in milliseconds, before this tween will start playing.
*
* This value is generated by the `getDelay` function.
*
* @name Phaser.Tweens.TweenData#delay
* @type {number}
* @since 3.60.0
*/
this.delay = 0;
/**
* This function returns the value to be used for `TweenData.delay`.
*
* @name Phaser.Tweens.TweenData#getDelay
* @type {function}
* @since 3.60.0
*/
this.getDelay = delay;
/**
* Will the Tween ease back to its starting values, after reaching the end
* and any `hold` value that may be set?
@ -145,107 +92,6 @@ var TweenFrameData = new Class({
* @since 3.60.0
*/
this.yoyo = (repeat > 0) ? true : false;
/**
* The time, in milliseconds, before this tween will start a yoyo to repeat.
*
* @name Phaser.Tweens.TweenData#hold
* @type {number}
* @since 3.60.0
*/
this.hold = hold;
/**
* The number of times this tween will repeat.
*
* The tween will always run once regardless of this value,
* so a repeat value of '1' will play the tween twice: I.e. the original
* play-through and then it repeats that once (1).
*
* If this value is set to -1 this tween will repeat forever.
*
* @name Phaser.Tweens.TweenData#repeat
* @type {number}
* @since 3.60.0
*/
this.repeat = repeat;
/**
* The time, in milliseconds, before the repeat will start.
*
* @name Phaser.Tweens.TweenData#repeatDelay
* @type {number}
* @since 3.60.0
*/
this.repeatDelay = repeatDelay;
/**
* How many repeats are left to run?
*
* @name Phaser.Tweens.TweenData#repeatCounter
* @type {number}
* @since 3.60.0
*/
this.repeatCounter = 0;
/**
* If `true` this Tween will call `toggleFlipX` on the Tween target
* whenever it yoyo's or repeats. It will only be called if the target
* has a function matching this name, like most Phaser GameObjects do.
*
* @name Phaser.Tweens.TweenData#flipX
* @type {boolean}
* @since 3.60.0
*/
this.flipX = flipX;
/**
* If `true` this Tween will call `toggleFlipY` on the Tween target
* whenever it yoyo's or repeats. It will only be called if the target
* has a function matching this name, like most Phaser GameObjects do.
*
* @name Phaser.Tweens.TweenData#flipY
* @type {boolean}
* @since 3.60.0
*/
this.flipY = flipY;
/**
* A value between 0 and 1 holding the progress of this TweenData.
*
* @name Phaser.Tweens.TweenData#progress
* @type {number}
* @since 3.60.0
*/
this.progress = 0;
/**
* The amount of time, in milliseconds, that has elapsed since this
* TweenData was made active.
*
* @name Phaser.Tweens.TweenData#elapsed
* @type {number}
* @since 3.60.0
*/
this.elapsed = 0;
/**
* The state of this TweenData.
*
* @name Phaser.Tweens.TweenData#state
* @type {Phaser.Types.Tweens.TweenDataState}
* @since 3.60.0
*/
this.state = 0;
/**
* Is this Tween Data currently waiting for a countdown to elapse, or not?
*
* @name Phaser.Tweens.TweenData#isCountdown
* @type {boolean}
* @since 3.60.0
*/
this.isCountdown = false;
},
/**
@ -624,219 +470,6 @@ var TweenFrameData = new Class({
this.dispatchEvent(Events.TWEEN_REPEAT, 'onRepeat');
}
},
/**
* Sets this TweenData state to CREATED.
*
* @method Phaser.Tweens.TweenData#setCreatedState
* @since 3.60.0
*/
setCreatedState: function ()
{
this.state = TWEEN_CONST.CREATED;
this.isCountdown = false;
},
/**
* Sets this TweenData state to DELAY.
*
* @method Phaser.Tweens.TweenData#setDelayState
* @since 3.60.0
*/
setDelayState: function ()
{
this.state = TWEEN_CONST.DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to PENDING_RENDER.
*
* @method Phaser.Tweens.TweenData#setPendingRenderState
* @since 3.60.0
*/
setPendingRenderState: function ()
{
this.state = TWEEN_CONST.PENDING_RENDER;
this.isCountdown = false;
},
/**
* Sets this TweenData state to PLAYING_FORWARD.
*
* @method Phaser.Tweens.TweenData#setPlayingForwardState
* @since 3.60.0
*/
setPlayingForwardState: function ()
{
this.state = TWEEN_CONST.PLAYING_FORWARD;
this.isCountdown = false;
},
/**
* Sets this TweenData state to PLAYING_BACKWARD.
*
* @method Phaser.Tweens.TweenData#setPlayingBackwardState
* @since 3.60.0
*/
setPlayingBackwardState: function ()
{
this.state = TWEEN_CONST.PLAYING_BACKWARD;
this.isCountdown = false;
},
/**
* Sets this TweenData state to HOLD_DELAY.
*
* @method Phaser.Tweens.TweenData#setHoldState
* @since 3.60.0
*/
setHoldState: function ()
{
this.state = TWEEN_CONST.HOLD_DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to REPEAT_DELAY.
*
* @method Phaser.Tweens.TweenData#setRepeatState
* @since 3.60.0
*/
setRepeatState: function ()
{
this.state = TWEEN_CONST.REPEAT_DELAY;
this.isCountdown = true;
},
/**
* Sets this TweenData state to COMPLETE.
*
* @method Phaser.Tweens.TweenData#setCompleteState
* @since 3.60.0
*/
setCompleteState: function ()
{
this.state = TWEEN_CONST.COMPLETE;
this.isCountdown = false;
},
/**
* Returns `true` if this TweenData has a _current_ state of CREATED, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isCreated
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of CREATED, otherwise `false`.
*/
isCreated: function ()
{
return (this.state === TWEEN_CONST.CREATED);
},
/**
* Returns `true` if this TweenData has a _current_ state of DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isDelayed
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of DELAY, otherwise `false`.
*/
isDelayed: function ()
{
return (this.state === TWEEN_CONST.DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPendingRender
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`.
*/
isPendingRender: function ()
{
return (this.state === TWEEN_CONST.PENDING_RENDER);
},
/**
* Returns `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPlayingForward
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`.
*/
isPlayingForward: function ()
{
return (this.state === TWEEN_CONST.PLAYING_FORWARD);
},
/**
* Returns `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isPlayingBackward
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`.
*/
isPlayingBackward: function ()
{
return (this.state === TWEEN_CONST.PLAYING_BACKWARD);
},
/**
* Returns `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isHolding
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`.
*/
isHolding: function ()
{
return (this.state === TWEEN_CONST.HOLD_DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isRepeating
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`.
*/
isRepeating: function ()
{
return (this.state === TWEEN_CONST.REPEAT_DELAY);
},
/**
* Returns `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`.
*
* @method Phaser.Tweens.TweenData#isComplete
* @since 3.60.0
*
* @return {boolean} `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`.
*/
isComplete: function ()
{
return (this.state === TWEEN_CONST.COMPLETE);
},
/**
* Immediately destroys this TweenData, nulling of all its references.
*
* @method Phaser.Tweens.TweenData#destroy
* @since 3.60.0
*/
destroy: function ()
{
this.tween = null;
this.getDelay = null;
this.setCompleteState();
}
});