2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
var GetValue = require('./GetValue');
|
2017-04-11 01:48:11 +00:00
|
|
|
var Clamp = require('../../math/Clamp');
|
|
|
|
|
2018-01-26 14:23:00 +00:00
|
|
|
/**
|
2018-10-01 10:35:01 +00:00
|
|
|
* Retrieves and clamps a numerical value from an object.
|
2018-01-26 14:23:00 +00:00
|
|
|
*
|
2018-07-28 20:37:51 +00:00
|
|
|
* @function Phaser.Utils.Objects.GetMinMaxValue
|
2018-01-26 14:23:00 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-01 10:35:01 +00:00
|
|
|
* @param {object} source - The object to retrieve the value from.
|
|
|
|
* @param {string} key - The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (`.`).
|
|
|
|
* @param {number} min - The minimum value which can be returned.
|
|
|
|
* @param {number} max - The maximum value which can be returned.
|
|
|
|
* @param {number} defaultValue - The value to return if the property doesn't exist. It's also constrained to the given bounds.
|
2018-01-26 14:23:00 +00:00
|
|
|
*
|
2018-10-01 10:35:01 +00:00
|
|
|
* @return {number} The clamped value from the `source` object.
|
2018-01-26 14:23:00 +00:00
|
|
|
*/
|
2017-04-11 01:48:11 +00:00
|
|
|
var GetMinMaxValue = function (source, key, min, max, defaultValue)
|
|
|
|
{
|
|
|
|
if (defaultValue === undefined) { defaultValue = min; }
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
var value = GetValue(source, key, defaultValue);
|
2017-04-11 01:48:11 +00:00
|
|
|
|
|
|
|
return Clamp(value, min, max);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetMinMaxValue;
|