/**
 * @author       Richard Davey <rich@photonstorm.com>
 * @copyright    2022 Photon Storm Ltd.
 * @license      {@link https://opensource.org/licenses/MIT|MIT License}
 */

var Defaults = require('../tween/Defaults');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var GetBoolean = require('./GetBoolean');
var GetEaseFunction = require('./GetEaseFunction');
var GetInterpolationFunction = require('./GetInterpolationFunction');
var GetNewValue = require('./GetNewValue');
var GetProps = require('./GetProps');
var GetTargets = require('./GetTargets');
var GetValue = require('../../utils/object/GetValue');
var GetValueOp = require('./GetValueOp');
var Tween = require('../tween/Tween');

/**
 * Creates a new Tween.
 *
 * @function Phaser.Tweens.Builders.TweenBuilder
 * @since 3.0.0
 *
 * @param {Phaser.Tweens.TweenManager} parent - The owner of the new Tween.
 * @param {Phaser.Types.Tweens.TweenBuilderConfig|object} config - Configuration for the new Tween.
 * @param {Phaser.Types.Tweens.TweenConfigDefaults} defaults - Tween configuration defaults.
 *
 * @return {Phaser.Tweens.Tween} The new tween.
 */
var TweenBuilder = function (parent, config, defaults)
{
    if (defaults === undefined)
    {
        defaults = Defaults;
    }

    //  Create arrays of the Targets and the Properties
    var targets = (defaults.targets) ? defaults.targets : GetTargets(config);

    var props = GetProps(config);

    //  Default Tween values

    var delay = GetValue(config, 'delay', defaults.delay);
    var duration = GetValue(config, 'duration', defaults.duration);
    var easeParams = GetValue(config, 'easeParams', defaults.easeParams);
    var ease = GetValue(config, 'ease', defaults.ease);
    var hold = GetValue(config, 'hold', defaults.hold);
    var repeat = GetValue(config, 'repeat', defaults.repeat);
    var repeatDelay = GetValue(config, 'repeatDelay', defaults.repeatDelay);
    var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo);
    var flipX = GetBoolean(config, 'flipX', defaults.flipX);
    var flipY = GetBoolean(config, 'flipY', defaults.flipY);
    var interpolation = GetValue(config, 'interpolation', defaults.interpolation);

    var addTarget = function (tween, targetIndex, key, value)
    {
        var ops = GetValueOp(key, value);

        tween.add(
            targetIndex,
            key,
            ops.getEnd,
            ops.getStart,
            ops.getActive,
            GetEaseFunction(GetValue(value, 'ease', ease), GetValue(value, 'easeParams', easeParams)),
            GetNewValue(value, 'delay', delay),
            GetNewValue(value, 'duration', duration),
            GetBoolean(value, 'yoyo', yoyo),
            GetNewValue(value, 'hold', hold),
            GetNewValue(value, 'repeat', repeat),
            GetNewValue(value, 'repeatDelay', repeatDelay),
            GetBoolean(value, 'flipX', flipX),
            GetBoolean(value, 'flipY', flipY),
            GetInterpolationFunction(GetValue(value, 'interpolation', interpolation)),
            value
        );
    };

    var tween = new Tween(parent, targets);

    //  Loop through every property defined in the Tween, i.e.: props { x, y, alpha }
    for (var p = 0; p < props.length; p++)
    {
        var key = props[p].key;
        var value = props[p].value;

        //  Create 1 TweenData per target, per property
        for (var targetIndex = 0; targetIndex < targets.length; targetIndex++)
        {
            //  Special-case for scale short-cut:
            if (key === 'scale' && !targets[targetIndex].hasOwnProperty('scale'))
            {
                addTarget(tween, targetIndex, 'scaleX', value);
                addTarget(tween, targetIndex, 'scaleY', value);
            }
            else
            {
                addTarget(tween, targetIndex, key, value);
            }
        }
    }

    tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
    tween.loop = Math.round(GetAdvancedValue(config, 'loop', 0));
    tween.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0));
    tween.paused = GetBoolean(config, 'paused', false);
    tween.persist = GetBoolean(config, 'persist', false);

    //  Set the Callbacks
    var scope = GetValue(config, 'callbackScope', tween);
    var callbacks = Tween.TYPES;

    for (var i = 0; i < callbacks.length; i++)
    {
        var type = callbacks[i];

        var callback = GetValue(config, type, false);

        if (callback)
        {
            var callbackScope = GetValue(config, type + 'Scope', scope);
            var callbackParams = GetValue(config, type + 'Params', []);

            tween.setCallback(type, callback, callbackParams, callbackScope);
        }
    }

    return tween;
};

module.exports = TweenBuilder;

@@ -2587,35 +2587,32 @@
 %0A            Get
-New
 Value(value, 'du
@@ -2631,16 +2631,16 @@
 ation),%0A
+
         
@@ -2683,35 +2683,32 @@
 %0A            Get
-New
 Value(value, 'ho
@@ -2726,35 +2726,32 @@
 %0A            Get
-New
 Value(value, 're
@@ -2773,35 +2773,32 @@
 %0A            Get
-New
 Value(value, 're

Use GetValue for numeric-only properties