Skip to content

Commit 1bb711e

Browse files
committed
Now using the new GetObjectValue utility.
1 parent 3a96390 commit 1bb711e

1 file changed

Lines changed: 38 additions & 28 deletions

File tree

v3/src/boot/Config.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var CONST = require('../const');
88
var NOOP = require('../utils/NOOP');
9+
var GetObjectValue = require('../utils/GetObjectValue');
910

1011
var defaultBannerColor = [
1112
'#ff0000',
@@ -17,6 +18,7 @@ var defaultBannerColor = [
1718

1819
var defaultBannerTextColor = '#ffffff';
1920

21+
/*
2022
function getValue (obj, key, def)
2123
{
2224
if (obj.hasOwnProperty(key))
@@ -28,63 +30,71 @@ function getValue (obj, key, def)
2830
return def;
2931
}
3032
}
33+
*/
3134

3235
function Config (config)
3336
{
3437
if (config === undefined) { config = {}; }
3538

36-
this.width = getValue(config, 'width', 1024);
37-
this.height = getValue(config, 'height', 768);
39+
this.width = GetObjectValue(config, 'width', 1024);
40+
this.height = GetObjectValue(config, 'height', 768);
3841

39-
this.resolution = getValue(config, 'resolution', 1);
42+
this.resolution = GetObjectValue(config, 'resolution', 1);
4043

41-
this.renderType = getValue(config, 'type', CONST.AUTO);
44+
this.renderType = GetObjectValue(config, 'type', CONST.AUTO);
4245

43-
this.parent = getValue(config, 'parent', null);
44-
this.canvas = getValue(config, 'canvas', null);
45-
this.canvasStyle = getValue(config, 'canvasStyle', null);
46+
this.parent = GetObjectValue(config, 'parent', null);
47+
this.canvas = GetObjectValue(config, 'canvas', null);
48+
this.canvasStyle = GetObjectValue(config, 'canvasStyle', null);
4649

47-
this.stateConfig = getValue(config, 'state', null);
50+
this.stateConfig = GetObjectValue(config, 'state', null);
4851

49-
this.seed = getValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
52+
this.seed = GetObjectValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
5053

51-
this.gameTitle = getValue(config, 'title', '');
52-
this.gameURL = getValue(config, 'url', 'http://phaser.io');
53-
this.gameVersion = getValue(config, 'version', '');
54+
this.gameTitle = GetObjectValue(config, 'title', '');
55+
this.gameURL = GetObjectValue(config, 'url', 'http://phaser.io');
56+
this.gameVersion = GetObjectValue(config, 'version', '');
5457

5558
// If you do: { banner: false } it won't display any banner at all
56-
var banner = getValue(config, 'banner', null);
5759

58-
this.hideBanner = (banner === false);
60+
this.hideBanner = (GetObjectValue(config, 'banner', false) === false);
5961

60-
if (!banner)
61-
{
62-
// Use the default banner set-up
63-
banner = {};
64-
}
62+
this.hidePhaser = GetObjectValue(config, 'banner.hidePhaser', false);
63+
this.bannerTextColor = GetObjectValue(config, 'banner.text', defaultBannerTextColor);
64+
this.bannerBackgroundColor = GetObjectValue(config, 'banner.background', defaultBannerColor);
6565

66-
this.hidePhaser = getValue(banner, 'hidePhaser', false);
67-
this.bannerTextColor = getValue(banner, 'text', defaultBannerTextColor);
68-
this.bannerBackgroundColor = getValue(banner, 'background', defaultBannerColor);
69-
70-
this.forceSetTimeOut = getValue(config, 'forceSetTimeOut', false);
66+
// var banner = getValue(config, 'banner', null);
67+
68+
// this.hideBanner = (banner === false);
7169

72-
this.transparent = getValue(config, 'transparent', false);
70+
// if (!banner)
71+
// {
72+
// Use the default banner set-up
73+
// banner = {};
74+
// }
7375

74-
this.pixelArt = getValue(config, 'pixelArt', false);
76+
// this.hidePhaser = getValue(banner, 'hidePhaser', false);
77+
// this.bannerTextColor = getValue(banner, 'text', defaultBannerTextColor);
78+
// this.bannerBackgroundColor = getValue(banner, 'background', defaultBannerColor);
79+
80+
this.forceSetTimeOut = GetObjectValue(config, 'forceSetTimeOut', false);
81+
this.transparent = GetObjectValue(config, 'transparent', false);
82+
this.pixelArt = GetObjectValue(config, 'pixelArt', false);
7583

7684
// Callbacks
7785

86+
/*
7887
var callbacks = getValue(config, 'callbacks', null);
7988
8089
if (!callbacks)
8190
{
8291
// Use the default banner set-up
8392
callbacks = {};
8493
}
94+
*/
8595

86-
this.preBoot = getValue(callbacks, 'preBoot', NOOP);
87-
this.postBoot = getValue(callbacks, 'postBoot', NOOP);
96+
this.preBoot = GetObjectValue(config, 'callbacks.preBoot', NOOP);
97+
this.postBoot = GetObjectValue(config, 'callbacks.postBoot', NOOP);
8898

8999
}
90100

0 commit comments

Comments
 (0)