Now using the new GetObjectValue utility.

This commit is contained in:
photonstorm 2016-11-29 13:01:05 +00:00
parent 3a963905b2
commit 1bb711ea2c

View file

@ -6,6 +6,7 @@
var CONST = require('../const');
var NOOP = require('../utils/NOOP');
var GetObjectValue = require('../utils/GetObjectValue');
var defaultBannerColor = [
'#ff0000',
@ -17,6 +18,7 @@ var defaultBannerColor = [
var defaultBannerTextColor = '#ffffff';
/*
function getValue (obj, key, def)
{
if (obj.hasOwnProperty(key))
@ -28,53 +30,60 @@ function getValue (obj, key, def)
return def;
}
}
*/
function Config (config)
{
if (config === undefined) { config = {}; }
this.width = getValue(config, 'width', 1024);
this.height = getValue(config, 'height', 768);
this.width = GetObjectValue(config, 'width', 1024);
this.height = GetObjectValue(config, 'height', 768);
this.resolution = getValue(config, 'resolution', 1);
this.resolution = GetObjectValue(config, 'resolution', 1);
this.renderType = getValue(config, 'type', CONST.AUTO);
this.renderType = GetObjectValue(config, 'type', CONST.AUTO);
this.parent = getValue(config, 'parent', null);
this.canvas = getValue(config, 'canvas', null);
this.canvasStyle = getValue(config, 'canvasStyle', null);
this.parent = GetObjectValue(config, 'parent', null);
this.canvas = GetObjectValue(config, 'canvas', null);
this.canvasStyle = GetObjectValue(config, 'canvasStyle', null);
this.stateConfig = getValue(config, 'state', null);
this.stateConfig = GetObjectValue(config, 'state', null);
this.seed = getValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
this.seed = GetObjectValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
this.gameTitle = getValue(config, 'title', '');
this.gameURL = getValue(config, 'url', 'http://phaser.io');
this.gameVersion = getValue(config, 'version', '');
this.gameTitle = GetObjectValue(config, 'title', '');
this.gameURL = GetObjectValue(config, 'url', 'http://phaser.io');
this.gameVersion = GetObjectValue(config, 'version', '');
// If you do: { banner: false } it won't display any banner at all
var banner = getValue(config, 'banner', null);
this.hideBanner = (banner === false);
this.hideBanner = (GetObjectValue(config, 'banner', false) === false);
if (!banner)
{
this.hidePhaser = GetObjectValue(config, 'banner.hidePhaser', false);
this.bannerTextColor = GetObjectValue(config, 'banner.text', defaultBannerTextColor);
this.bannerBackgroundColor = GetObjectValue(config, 'banner.background', defaultBannerColor);
// var banner = getValue(config, 'banner', null);
// this.hideBanner = (banner === false);
// if (!banner)
// {
// Use the default banner set-up
banner = {};
}
// banner = {};
// }
this.hidePhaser = getValue(banner, 'hidePhaser', false);
this.bannerTextColor = getValue(banner, 'text', defaultBannerTextColor);
this.bannerBackgroundColor = getValue(banner, 'background', defaultBannerColor);
// this.hidePhaser = getValue(banner, 'hidePhaser', false);
// this.bannerTextColor = getValue(banner, 'text', defaultBannerTextColor);
// this.bannerBackgroundColor = getValue(banner, 'background', defaultBannerColor);
this.forceSetTimeOut = getValue(config, 'forceSetTimeOut', false);
this.transparent = getValue(config, 'transparent', false);
this.pixelArt = getValue(config, 'pixelArt', false);
this.forceSetTimeOut = GetObjectValue(config, 'forceSetTimeOut', false);
this.transparent = GetObjectValue(config, 'transparent', false);
this.pixelArt = GetObjectValue(config, 'pixelArt', false);
// Callbacks
/*
var callbacks = getValue(config, 'callbacks', null);
if (!callbacks)
@ -82,9 +91,10 @@ function Config (config)
// Use the default banner set-up
callbacks = {};
}
*/
this.preBoot = getValue(callbacks, 'preBoot', NOOP);
this.postBoot = getValue(callbacks, 'postBoot', NOOP);
this.preBoot = GetObjectValue(config, 'callbacks.preBoot', NOOP);
this.postBoot = GetObjectValue(config, 'callbacks.postBoot', NOOP);
}