phaser/v3/src/boot/Config.js

104 lines
2.9 KiB
JavaScript
Raw Normal View History

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2016-11-24 15:40:05 +00:00
var CONST = require('../const');
var NOOP = require('../utils/NOOP');
var GetObjectValue = require('../utils/GetObjectValue');
2016-11-24 15:40:05 +00:00
var defaultBannerColor = [
'#ff0000',
'#ffff00',
'#00ff00',
'#00ffff',
'#000000'
];
var defaultBannerTextColor = '#ffffff';
/*
2016-11-24 15:40:05 +00:00
function getValue (obj, key, def)
{
if (obj.hasOwnProperty(key))
{
return obj[key];
}
else
{
return def;
}
}
*/
function Config (config)
{
if (config === undefined) { config = {}; }
this.width = GetObjectValue(config, 'width', 1024);
this.height = GetObjectValue(config, 'height', 768);
2016-11-24 15:40:05 +00:00
this.resolution = GetObjectValue(config, 'resolution', 1);
2016-11-24 15:40:05 +00:00
this.renderType = GetObjectValue(config, 'type', CONST.AUTO);
2016-11-24 15:40:05 +00:00
this.parent = GetObjectValue(config, 'parent', null);
this.canvas = GetObjectValue(config, 'canvas', null);
this.canvasStyle = GetObjectValue(config, 'canvasStyle', null);
2016-11-24 15:40:05 +00:00
this.stateConfig = GetObjectValue(config, 'state', null);
2016-11-24 15:40:05 +00:00
this.seed = GetObjectValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
2016-11-24 15:40:05 +00:00
this.gameTitle = GetObjectValue(config, 'title', '');
this.gameURL = GetObjectValue(config, 'url', 'http://phaser.io');
this.gameVersion = GetObjectValue(config, 'version', '');
2016-11-24 15:40:05 +00:00
// If you do: { banner: false } it won't display any banner at all
this.hideBanner = (GetObjectValue(config, 'banner', false) === false);
2016-11-24 15:40:05 +00:00
this.hidePhaser = GetObjectValue(config, 'banner.hidePhaser', false);
this.bannerTextColor = GetObjectValue(config, 'banner.text', defaultBannerTextColor);
this.bannerBackgroundColor = GetObjectValue(config, 'banner.background', defaultBannerColor);
2016-11-24 15:40:05 +00:00
// var banner = getValue(config, 'banner', null);
// this.hideBanner = (banner === false);
2016-11-25 00:34:37 +00:00
// if (!banner)
// {
// Use the default banner set-up
// banner = {};
// }
// this.hidePhaser = getValue(banner, 'hidePhaser', false);
// this.bannerTextColor = getValue(banner, 'text', defaultBannerTextColor);
// this.bannerBackgroundColor = getValue(banner, 'background', defaultBannerColor);
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)
{
// Use the default banner set-up
callbacks = {};
}
*/
this.preBoot = GetObjectValue(config, 'callbacks.preBoot', NOOP);
this.postBoot = GetObjectValue(config, 'callbacks.postBoot', NOOP);
}
Config.prototype.constructor = Config;
module.exports = Config;