2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-01 16:51:51 +00:00
|
|
|
var Clone = require('../../utils/object/Clone');
|
|
|
|
var Defaults = require('../tween/Defaults');
|
2018-02-10 17:11:36 +00:00
|
|
|
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
2017-09-01 16:51:51 +00:00
|
|
|
var GetBoolean = require('./GetBoolean');
|
|
|
|
var GetEaseFunction = require('./GetEaseFunction');
|
|
|
|
var GetNewValue = require('./GetNewValue');
|
|
|
|
var GetTargets = require('./GetTargets');
|
|
|
|
var GetTweens = require('./GetTweens');
|
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
2018-01-16 22:28:29 +00:00
|
|
|
var Timeline = require('../Timeline');
|
2017-09-01 16:51:51 +00:00
|
|
|
var TweenBuilder = require('./TweenBuilder');
|
|
|
|
|
2018-02-10 17:11:36 +00:00
|
|
|
/**
|
2018-12-03 15:16:23 +00:00
|
|
|
* Builds a Timeline of Tweens based on a configuration object.
|
|
|
|
*
|
2018-02-10 17:11:36 +00:00
|
|
|
* @function Phaser.Tweens.Builders.TimelineBuilder
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {Phaser.Tweens.TweenManager} manager - The Tween Manager to which the Timeline will belong.
|
2019-06-03 19:12:01 +00:00
|
|
|
* @param {Phaser.Types.Tweens.TimelineBuilderConfig} config - The configuration object for the Timeline.
|
2018-02-10 17:11:36 +00:00
|
|
|
*
|
2018-12-03 15:16:23 +00:00
|
|
|
* @return {Phaser.Tweens.Timeline} The created Timeline.
|
2018-02-10 17:11:36 +00:00
|
|
|
*/
|
2017-09-01 16:51:51 +00:00
|
|
|
var TimelineBuilder = function (manager, config)
|
|
|
|
{
|
2017-09-07 14:40:38 +00:00
|
|
|
var timeline = new Timeline(manager);
|
2017-09-01 16:51:51 +00:00
|
|
|
|
2017-09-02 02:16:59 +00:00
|
|
|
timeline.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
|
|
|
|
timeline.loop = Math.round(GetAdvancedValue(config, 'loop', 0));
|
|
|
|
timeline.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0));
|
|
|
|
timeline.paused = GetBoolean(config, 'paused', false);
|
|
|
|
timeline.useFrames = GetBoolean(config, 'useFrames', false);
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
|
|
|
|
var scope = GetValue(config, 'callbackScope', timeline);
|
|
|
|
var onStart = GetValue(config, 'onStart', false);
|
|
|
|
|
|
|
|
// The Start of the Timeline
|
|
|
|
if (onStart)
|
|
|
|
{
|
|
|
|
var onStartScope = GetValue(config, 'onStartScope', scope);
|
|
|
|
var onStartParams = GetValue(config, 'onStartParams', []);
|
|
|
|
|
2021-06-27 00:30:24 +00:00
|
|
|
timeline.setCallback('onStart', onStart, onStartParams, onStartScope);
|
2017-09-02 02:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onUpdate = GetValue(config, 'onUpdate', false);
|
|
|
|
|
|
|
|
// Every time the Timeline updates (regardless which Tweens are running)
|
|
|
|
if (onUpdate)
|
|
|
|
{
|
|
|
|
var onUpdateScope = GetValue(config, 'onUpdateScope', scope);
|
|
|
|
var onUpdateParams = GetValue(config, 'onUpdateParams', []);
|
|
|
|
|
2021-06-27 00:30:24 +00:00
|
|
|
timeline.setCallback('onUpdate', onUpdate, onUpdateParams, onUpdateScope);
|
2017-09-02 02:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onLoop = GetValue(config, 'onLoop', false);
|
|
|
|
|
|
|
|
// Called when the whole Timeline loops
|
|
|
|
if (onLoop)
|
|
|
|
{
|
|
|
|
var onLoopScope = GetValue(config, 'onLoopScope', scope);
|
|
|
|
var onLoopParams = GetValue(config, 'onLoopParams', []);
|
|
|
|
|
2021-06-27 00:30:24 +00:00
|
|
|
timeline.setCallback('onLoop', onLoop, onLoopParams, onLoopScope);
|
2017-09-02 02:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onYoyo = GetValue(config, 'onYoyo', false);
|
|
|
|
|
|
|
|
// Called when a Timeline yoyos
|
|
|
|
if (onYoyo)
|
|
|
|
{
|
|
|
|
var onYoyoScope = GetValue(config, 'onYoyoScope', scope);
|
|
|
|
var onYoyoParams = GetValue(config, 'onYoyoParams', []);
|
|
|
|
|
2021-06-27 00:30:24 +00:00
|
|
|
timeline.setCallback('onYoyo', onYoyo, onYoyoParams, onYoyoScope);
|
2017-09-02 02:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onComplete = GetValue(config, 'onComplete', false);
|
|
|
|
|
|
|
|
// Called when the Timeline completes, after the completeDelay, etc.
|
|
|
|
if (onComplete)
|
|
|
|
{
|
|
|
|
var onCompleteScope = GetValue(config, 'onCompleteScope', scope);
|
|
|
|
var onCompleteParams = GetValue(config, 'onCompleteParams', []);
|
|
|
|
|
2021-06-27 00:30:24 +00:00
|
|
|
timeline.setCallback('onComplete', onComplete, onCompleteParams, onCompleteScope);
|
2017-09-02 02:16:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 18:44:40 +00:00
|
|
|
// Tweens
|
|
|
|
|
|
|
|
var tweens = GetTweens(config);
|
|
|
|
|
|
|
|
if (tweens.length === 0)
|
|
|
|
{
|
|
|
|
timeline.paused = true;
|
|
|
|
|
|
|
|
return timeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaults = Clone(Defaults);
|
|
|
|
|
|
|
|
defaults.targets = GetTargets(config);
|
|
|
|
|
|
|
|
// totalDuration: If specified each tween in the Timeline is given an equal portion of the totalDuration
|
|
|
|
|
|
|
|
var totalDuration = GetAdvancedValue(config, 'totalDuration', 0);
|
|
|
|
|
|
|
|
if (totalDuration > 0)
|
|
|
|
{
|
|
|
|
defaults.duration = Math.floor(totalDuration / tweens.length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defaults.duration = GetNewValue(config, 'duration', defaults.duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
defaults.delay = GetNewValue(config, 'delay', defaults.delay);
|
|
|
|
defaults.easeParams = GetValue(config, 'easeParams', defaults.easeParams);
|
|
|
|
defaults.ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), defaults.easeParams);
|
|
|
|
defaults.hold = GetNewValue(config, 'hold', defaults.hold);
|
|
|
|
defaults.repeat = GetNewValue(config, 'repeat', defaults.repeat);
|
|
|
|
defaults.repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay);
|
|
|
|
defaults.yoyo = GetBoolean(config, 'yoyo', defaults.yoyo);
|
|
|
|
defaults.flipX = GetBoolean(config, 'flipX', defaults.flipX);
|
|
|
|
defaults.flipY = GetBoolean(config, 'flipY', defaults.flipY);
|
|
|
|
|
|
|
|
// Create the Tweens
|
|
|
|
for (var i = 0; i < tweens.length; i++)
|
|
|
|
{
|
|
|
|
timeline.queue(TweenBuilder(timeline, tweens[i], defaults));
|
|
|
|
}
|
|
|
|
|
2017-09-01 16:51:51 +00:00
|
|
|
return timeline;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TimelineBuilder;
|