/
GetNewValue.js
58 lines (53 loc) · 1.52 KB
/
GetNewValue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Internal function used by the Tween Builder to create a function that will return
* the given value from the source.
*
* @function Phaser.Tweens.Builders.GetNewValue
* @since 3.0.0
*
* @param {any} source - The source object to get the value from.
* @param {string} key - The property to get from the source.
* @param {any} defaultValue - A default value to return should the source not have the property set.
*
* @return {function} A function which when called will return the property value from the source.
*/
var GetNewValue = function (source, key, defaultValue)
{
var valueCallback;
if (source.hasOwnProperty(key))
{
var t = typeof(source[key]);
if (t === 'function')
{
valueCallback = function (target, targetKey, value, targetIndex, totalTargets, tween)
{
return source[key](target, targetKey, value, targetIndex, totalTargets, tween);
};
}
else
{
valueCallback = function ()
{
return source[key];
};
}
}
else if (typeof defaultValue === 'function')
{
valueCallback = defaultValue;
}
else
{
valueCallback = function ()
{
return defaultValue;
};
}
return valueCallback;
};
module.exports = GetNewValue;