Skip to content

Commit 7999f72

Browse files
committed
Moved GetObjectValue into utils/object
1 parent 7c06670 commit 7999f72

7 files changed

Lines changed: 43 additions & 6 deletions

File tree

v3/src/boot/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
var MATH = require('../math');
88
var CONST = require('../const');
99
var NOOP = require('../utils/NOOP');
10-
var GetObjectValue = require('../utils/GetObjectValue');
10+
var GetObjectValue = require('../utils/object/GetObjectValue');
1111

1212
var defaultBannerColor = [
1313
'#ff0000',

v3/src/input/keyboard/combo/KeyCombo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var GetObjectValue = require('../../../utils/GetObjectValue');
1+
var GetObjectValue = require('../../../utils/object/GetObjectValue');
22

33
// Keys can be either:
44
//

v3/src/sound/dynamic/FX.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
var Between = require('../../math/Between');
3-
var GetObjectValue = require('../../utils/GetObjectValue');
3+
var GetObjectValue = require('../../utils/object/GetObjectValue');
44

55
// Phaser.Sound.Dynamic.FX
66

v3/src/state/Settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var CONST = require('./const');
22
var ScaleModes = require('../renderer/ScaleModes');
3-
var GetObjectValue = require('../utils/GetObjectValue');
3+
var GetObjectValue = require('../utils/object/GetObjectValue');
44

55
var Settings = function (config, gameConfig)
66
{

v3/src/state/StateManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var NOOP = require('../utils/NOOP');
99
var State = require('./State');
1010
var Settings = require('./Settings');
1111
var Systems = require('./Systems');
12-
var GetObjectValue = require('../utils/GetObjectValue');
12+
var GetObjectValue = require('../utils/object/GetObjectValue');
1313
var EventDispatcher = require('../events/EventDispatcher');
1414

1515
/**

v3/src/textures/parsers/SpriteSheetTextureParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7-
var GetObjectValue = require('../../utils/GetObjectValue');
7+
var GetObjectValue = require('../../utils/object/GetObjectValue');
88

99
/**
1010
* Parse a Sprite Sheet and extracts the frame data from it.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Source object
2+
// The key as a string, or an array of keys, i.e. 'banner', or 'banner.hideBanner'
3+
// The default value to use if the key doesn't exist
4+
5+
var GetObjectValue = function (source, key, defaultValue)
6+
{
7+
if (key.indexOf('.'))
8+
{
9+
var keys = key.split('.');
10+
var parent = source;
11+
var value = defaultValue;
12+
13+
// Use for loop here so we can break early
14+
for (var i = 0; i < keys.length; i++)
15+
{
16+
if (parent.hasOwnProperty(keys[i]))
17+
{
18+
// Yes it has a key property, let's carry on down
19+
value = parent[keys[i]];
20+
21+
parent = parent[keys[i]];
22+
}
23+
else
24+
{
25+
break;
26+
}
27+
}
28+
29+
return value;
30+
}
31+
else
32+
{
33+
return (source.hasOwnProperty(key)) ? source[key] : defaultValue;
34+
}
35+
};
36+
37+
module.exports = GetObjectValue;

0 commit comments

Comments
 (0)