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-08-31 14:11:04 +00:00
|
|
|
var EaseMap = require('../../math/easing/EaseMap');
|
2019-06-28 11:21:52 +00:00
|
|
|
var UppercaseFirst = require('../../utils/string/UppercaseFirst');
|
2017-05-10 01:25:46 +00:00
|
|
|
|
2018-02-10 17:11:36 +00:00
|
|
|
/**
|
2019-06-27 10:50:24 +00:00
|
|
|
* This internal function is used to return the correct ease function for a Tween.
|
2022-02-28 14:29:51 +00:00
|
|
|
*
|
2019-06-27 10:50:24 +00:00
|
|
|
* It can take a variety of input, including an EaseMap based string, or a custom function.
|
2018-02-10 17:11:36 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Tweens.Builders.GetEaseFunction
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-06-27 10:50:24 +00:00
|
|
|
* @param {(string|function)} ease - The ease to find. This can be either a string from the EaseMap, or a custom function.
|
|
|
|
* @param {number[]} [easeParams] - An optional array of ease parameters to go with the ease.
|
2018-02-10 17:11:36 +00:00
|
|
|
*
|
2019-06-27 10:50:24 +00:00
|
|
|
* @return {function} The ease function.
|
2018-02-10 17:11:36 +00:00
|
|
|
*/
|
2017-05-24 03:38:17 +00:00
|
|
|
var GetEaseFunction = function (ease, easeParams)
|
2017-05-10 01:25:46 +00:00
|
|
|
{
|
2019-06-27 00:06:25 +00:00
|
|
|
// Default ease function
|
|
|
|
var easeFunction = EaseMap.Power0;
|
|
|
|
|
|
|
|
// Prepare ease function
|
2019-06-28 11:21:52 +00:00
|
|
|
if (typeof ease === 'string')
|
2017-05-10 01:25:46 +00:00
|
|
|
{
|
2019-06-27 00:06:25 +00:00
|
|
|
// String based look-up
|
2019-06-28 11:21:52 +00:00
|
|
|
|
|
|
|
// 1) They specified it correctly
|
|
|
|
if (EaseMap.hasOwnProperty(ease))
|
|
|
|
{
|
|
|
|
easeFunction = EaseMap[ease];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do some string manipulation to try and find it
|
|
|
|
var direction = '';
|
|
|
|
|
|
|
|
if (ease.indexOf('.'))
|
|
|
|
{
|
|
|
|
// quad.in = Quad.easeIn
|
|
|
|
// quad.out = Quad.easeOut
|
2020-01-20 23:34:40 +00:00
|
|
|
// quad.inout = Quad.easeInOut
|
2019-06-28 11:21:52 +00:00
|
|
|
|
|
|
|
direction = ease.substr(ease.indexOf('.') + 1);
|
|
|
|
|
|
|
|
if (direction.toLowerCase() === 'in')
|
|
|
|
{
|
|
|
|
direction = 'easeIn';
|
|
|
|
}
|
|
|
|
else if (direction.toLowerCase() === 'out')
|
|
|
|
{
|
|
|
|
direction = 'easeOut';
|
|
|
|
}
|
|
|
|
else if (direction.toLowerCase() === 'inout')
|
|
|
|
{
|
|
|
|
direction = 'easeInOut';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ease = UppercaseFirst(ease.substr(0, ease.indexOf('.') + 1) + direction);
|
|
|
|
|
|
|
|
if (EaseMap.hasOwnProperty(ease))
|
|
|
|
{
|
|
|
|
easeFunction = EaseMap[ease];
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 01:25:46 +00:00
|
|
|
}
|
|
|
|
else if (typeof ease === 'function')
|
|
|
|
{
|
|
|
|
// Custom function
|
2019-06-27 00:06:25 +00:00
|
|
|
easeFunction = ease;
|
2017-05-10 01:25:46 +00:00
|
|
|
}
|
|
|
|
else if (Array.isArray(ease) && ease.length === 4)
|
|
|
|
{
|
|
|
|
// Bezier function (TODO)
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:06:25 +00:00
|
|
|
// No custom ease parameters?
|
|
|
|
if (!easeParams)
|
|
|
|
{
|
|
|
|
// Return ease function
|
|
|
|
return easeFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cloneParams = easeParams.slice(0);
|
|
|
|
|
|
|
|
cloneParams.unshift(0);
|
|
|
|
|
|
|
|
// Return ease function with custom ease parameters
|
|
|
|
return function (v)
|
|
|
|
{
|
|
|
|
cloneParams[0] = v;
|
|
|
|
|
|
|
|
return easeFunction.apply(this, cloneParams);
|
|
|
|
};
|
2017-05-10 01:25:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetEaseFunction;
|