2017-09-01 16:51:51 +00:00
|
|
|
var Defaults = require('../tween/Defaults');
|
2017-08-31 14:11:04 +00:00
|
|
|
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
2017-09-01 16:51:51 +00:00
|
|
|
var GetBoolean = require('./GetBoolean');
|
2017-05-17 01:44:04 +00:00
|
|
|
var GetEaseFunction = require('./GetEaseFunction');
|
2017-09-01 16:51:51 +00:00
|
|
|
var GetNewValue = require('./GetNewValue');
|
|
|
|
var GetProps = require('./GetProps');
|
|
|
|
var GetTargets = require('./GetTargets');
|
2017-08-31 14:11:04 +00:00
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
2017-09-01 16:51:51 +00:00
|
|
|
var GetValueOp = require('./GetValueOp');
|
2017-08-31 14:11:04 +00:00
|
|
|
var Tween = require('../tween/Tween');
|
|
|
|
var TweenData = require('../tween/TweenData');
|
2017-05-17 01:44:04 +00:00
|
|
|
|
2017-09-01 16:51:51 +00:00
|
|
|
var TweenBuilder = function (manager, config, defaults)
|
2017-05-17 01:44:04 +00:00
|
|
|
{
|
2017-09-01 16:51:51 +00:00
|
|
|
if (defaults === undefined)
|
2017-05-17 01:44:04 +00:00
|
|
|
{
|
2017-09-01 16:51:51 +00:00
|
|
|
defaults = Defaults;
|
2017-05-17 01:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create arrays of the Targets and the Properties
|
2017-09-01 16:51:51 +00:00
|
|
|
var targets = (defaults.targets) ? defaults.targets : GetTargets(config);
|
|
|
|
|
|
|
|
// var props = (defaults.props) ? defaults.props : GetProps(config);
|
2017-05-17 01:44:04 +00:00
|
|
|
var props = GetProps(config);
|
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// Default Tween values
|
2017-09-01 16:51:51 +00:00
|
|
|
var delay = GetNewValue(config, 'delay', defaults.delay);
|
|
|
|
var duration = GetNewValue(config, 'duration', defaults.duration);
|
|
|
|
var easeParams = GetValue(config, 'easeParams', defaults.easeParams);
|
|
|
|
var ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), easeParams);
|
|
|
|
var hold = GetNewValue(config, 'hold', defaults.hold);
|
|
|
|
var repeat = GetNewValue(config, 'repeat', defaults.repeat);
|
|
|
|
var repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay);
|
|
|
|
var startAt = GetNewValue(config, 'startAt', defaults.startAt);
|
|
|
|
var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo);
|
|
|
|
var flipX = GetBoolean(config, 'flipX', defaults.flipX);
|
|
|
|
var flipY = GetBoolean(config, 'flipY', defaults.flipY);
|
2017-05-18 05:39:47 +00:00
|
|
|
|
2017-05-24 00:27:04 +00:00
|
|
|
var data = [];
|
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// Loop through every property defined in the Tween, i.e.: props { x, y, alpha }
|
2017-05-17 01:44:04 +00:00
|
|
|
for (var p = 0; p < props.length; p++)
|
|
|
|
{
|
|
|
|
var key = props[p].key;
|
2017-05-23 18:04:15 +00:00
|
|
|
var value = props[p].value;
|
|
|
|
|
2017-08-11 16:12:18 +00:00
|
|
|
// Create 1 TweenData per target, per property
|
2017-05-24 02:29:31 +00:00
|
|
|
for (var t = 0; t < targets.length; t++)
|
|
|
|
{
|
|
|
|
var tweenData = TweenData(
|
|
|
|
targets[t],
|
|
|
|
key,
|
|
|
|
GetValueOp(key, value),
|
2017-05-24 03:38:17 +00:00
|
|
|
GetEaseFunction(GetValue(value, 'ease', ease), easeParams),
|
2017-05-24 02:29:31 +00:00
|
|
|
GetNewValue(value, 'delay', delay),
|
|
|
|
GetNewValue(value, 'duration', duration),
|
|
|
|
GetBoolean(value, 'yoyo', yoyo),
|
2017-05-24 04:24:20 +00:00
|
|
|
GetNewValue(value, 'hold', hold),
|
2017-05-24 02:29:31 +00:00
|
|
|
GetNewValue(value, 'repeat', repeat),
|
|
|
|
GetNewValue(value, 'repeatDelay', repeatDelay),
|
2017-08-11 12:14:34 +00:00
|
|
|
GetNewValue(value, 'startAt', startAt),
|
|
|
|
GetBoolean(value, 'flipX', flipX),
|
|
|
|
GetBoolean(value, 'flipY', flipY)
|
2017-05-24 02:29:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
data.push(tweenData);
|
|
|
|
}
|
2017-05-17 01:44:04 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 02:29:31 +00:00
|
|
|
var tween = new Tween(manager, data);
|
2017-05-24 00:27:04 +00:00
|
|
|
|
2017-05-24 02:29:31 +00:00
|
|
|
tween.totalTargets = targets.length;
|
2017-08-11 03:08:21 +00:00
|
|
|
|
2017-09-01 16:51:51 +00:00
|
|
|
tween.offset = GetAdvancedValue(config, 'offset', null);
|
2017-08-11 03:08:21 +00:00
|
|
|
tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
|
2017-08-09 16:23:39 +00:00
|
|
|
tween.loop = GetAdvancedValue(config, 'loop', 0);
|
2017-05-24 00:27:04 +00:00
|
|
|
tween.loopDelay = GetAdvancedValue(config, 'loopDelay', 0);
|
2017-05-24 02:29:31 +00:00
|
|
|
tween.paused = GetBoolean(config, 'paused', false);
|
2017-08-11 03:08:21 +00:00
|
|
|
tween.useFrames = GetBoolean(config, 'useFrames', false);
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
|
|
|
|
var scope = GetValue(config, 'callbackScope', tween);
|
|
|
|
|
2017-08-11 12:14:34 +00:00
|
|
|
var tweenArray = [ tween ];
|
|
|
|
|
2017-08-11 03:08:21 +00:00
|
|
|
var onStart = GetValue(config, 'onStart', false);
|
|
|
|
|
|
|
|
// The Start of the Tween
|
|
|
|
if (onStart)
|
|
|
|
{
|
|
|
|
var onStartScope = GetValue(config, 'onStartScope', scope);
|
|
|
|
var onStartParams = GetValue(config, 'onStartParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onStart', onStart, tweenArray.concat(onStartParams), onStartScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onUpdate = GetValue(config, 'onUpdate', false);
|
|
|
|
|
|
|
|
// Every time the tween updates (regardless which TweenDatas are running)
|
|
|
|
if (onUpdate)
|
|
|
|
{
|
|
|
|
var onUpdateScope = GetValue(config, 'onUpdateScope', scope);
|
|
|
|
var onUpdateParams = GetValue(config, 'onUpdateParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onUpdate', onUpdate, tweenArray.concat(onUpdateParams), onUpdateScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onRepeat = GetValue(config, 'onRepeat', false);
|
|
|
|
|
|
|
|
// When a TweenData repeats
|
|
|
|
if (onRepeat)
|
|
|
|
{
|
|
|
|
var onRepeatScope = GetValue(config, 'onRepeatScope', scope);
|
|
|
|
var onRepeatParams = GetValue(config, 'onRepeatParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onRepeat', onRepeat, tweenArray.concat(null, onRepeatParams), onRepeatScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onLoop = GetValue(config, 'onLoop', false);
|
|
|
|
|
|
|
|
// Called when the whole Tween loops
|
|
|
|
if (onLoop)
|
|
|
|
{
|
|
|
|
var onLoopScope = GetValue(config, 'onLoopScope', scope);
|
|
|
|
var onLoopParams = GetValue(config, 'onLoopParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onLoop', onLoop, tweenArray.concat(onLoopParams), onLoopScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onYoyo = GetValue(config, 'onYoyo', false);
|
|
|
|
|
|
|
|
// Called when a TweenData yoyos
|
|
|
|
if (onYoyo)
|
|
|
|
{
|
|
|
|
var onYoyoScope = GetValue(config, 'onYoyoScope', scope);
|
|
|
|
var onYoyoParams = GetValue(config, 'onYoyoParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onYoyo', onYoyo, tweenArray.concat(null, onYoyoParams), onYoyoScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var onComplete = GetValue(config, 'onComplete', false);
|
|
|
|
|
|
|
|
// Called when the Tween completes, after the completeDelay, etc.
|
|
|
|
if (onComplete)
|
|
|
|
{
|
|
|
|
var onCompleteScope = GetValue(config, 'onCompleteScope', scope);
|
|
|
|
var onCompleteParams = GetValue(config, 'onCompleteParams', []);
|
|
|
|
|
2017-08-14 14:57:15 +00:00
|
|
|
tween.setCallback('onComplete', onComplete, tweenArray.concat(onCompleteParams), onCompleteScope);
|
2017-08-11 03:08:21 +00:00
|
|
|
}
|
2017-05-24 00:27:04 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
return tween;
|
2017-05-17 01:44:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TweenBuilder;
|