2017-06-30 14:47:51 +00:00
|
|
|
var Class = require('../utils/Class');
|
2016-11-24 15:40:05 +00:00
|
|
|
var CONST = require('../const');
|
2018-01-26 05:21:45 +00:00
|
|
|
var DefaultScenePlugins = require('../plugins/DefaultScenePlugins');
|
2017-04-26 15:03:14 +00:00
|
|
|
var GetValue = require('../utils/object/GetValue');
|
2017-09-13 16:09:16 +00:00
|
|
|
var MATH = require('../math/const');
|
2017-06-30 14:47:51 +00:00
|
|
|
var NOOP = require('../utils/NOOP');
|
2017-10-11 16:05:59 +00:00
|
|
|
var ValueToColor = require('../display/color/ValueToColor');
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-10-04 18:59:08 +00:00
|
|
|
/**
|
|
|
|
* This callback type is completely empty, a no-operation.
|
|
|
|
*
|
|
|
|
* @callback NOOP
|
|
|
|
*/
|
|
|
|
|
2017-10-04 22:48:16 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} FPSConfig
|
2018-01-08 16:39:46 +00:00
|
|
|
*
|
2017-10-04 22:48:16 +00:00
|
|
|
* @property {integer} [min=10] - [description]
|
|
|
|
* @property {integer} [target=60] - [description]
|
|
|
|
* @property {boolean} [forceSetTimeOut=false] - [description]
|
|
|
|
* @property {integer} [deltaHistory=10] - [description]
|
|
|
|
* @property {integer} [panicMax=120] - [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-01-25 00:48:48 +00:00
|
|
|
* @typedef {object} LoaderConfig
|
2017-10-04 22:48:16 +00:00
|
|
|
*
|
2018-01-25 00:48:48 +00:00
|
|
|
* @property {string} [baseURL] - [description]
|
|
|
|
* @property {string} [path] - [description]
|
|
|
|
* @property {boolean} [enableParallel=true] - [description]
|
|
|
|
* @property {integer} [maxParallelDownloads=4] - [description]
|
|
|
|
* @property {string|undefined} [crossOrigin=undefined] - [description]
|
|
|
|
* @property {string} [responseType] - [description]
|
|
|
|
* @property {boolean} [async=true] - [description]
|
|
|
|
* @property {string} [user] - [description]
|
|
|
|
* @property {string} [password] - [description]
|
|
|
|
* @property {integer} [timeout=0] - [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} GameConfig
|
2018-01-08 16:39:46 +00:00
|
|
|
*
|
2017-10-04 22:48:16 +00:00
|
|
|
* @property {integer|string} [width=1024] - [description]
|
|
|
|
* @property {integer|string} [height=768] - [description]
|
|
|
|
* @property {number} [zoom=1] - [description]
|
|
|
|
* @property {number} [resolution=1] - [description]
|
|
|
|
* @property {number} [type=CONST.AUTO] - [description]
|
|
|
|
* @property {object} [?parent=null] - [description]
|
|
|
|
* @property {HTMLCanvasElement} [?canvas=null] - [description]
|
|
|
|
* @property {string} [?canvasStyle=null] - [description]
|
|
|
|
* @property {object} [?scene=null] - [description]
|
|
|
|
* @property {array} [seed] - [description]
|
|
|
|
* @property {string} [title=''] - [description]
|
|
|
|
* @property {string} [url='http://phaser.io'] - [description]
|
|
|
|
* @property {string} [version=''] - [description]
|
|
|
|
* @property {object} [input] - [description]
|
|
|
|
* @property {boolean} [input.keyboard=true] - [description]
|
|
|
|
* @property {object} [input.keyboard.target=window] - [description]
|
|
|
|
* @property {boolean} [input.mouse=true] - [description]
|
|
|
|
* @property {object} [?input.mouse.target=null] - [description]
|
|
|
|
* @property {boolean} [input.touch=true] - [description]
|
|
|
|
* @property {object} [?input.touch.target=null] - [description]
|
2017-12-27 23:52:46 +00:00
|
|
|
* @property {object} [?input.touch.capture=true] - [description]
|
2017-10-04 22:48:16 +00:00
|
|
|
* @property {boolean} [input.gamepad=false] - [description]
|
|
|
|
* @property {boolean} [disableContextMenu=false] - [description]
|
|
|
|
* @property {boolean} [banner=false] - [description]
|
|
|
|
* @property {boolean} [banner.hidePhaser=false] - [description]
|
|
|
|
* @property {string} [banner.text='#ffffff'] - [description]
|
|
|
|
* @property {array} [banner.background] - [description]
|
|
|
|
* @property {FPSConfig} [?fps] - [description]
|
|
|
|
* @property {boolean} [pixelArt=false] - [description]
|
|
|
|
* @property {boolean} [transparent=false] - [description]
|
|
|
|
* @property {boolean} [clearBeforeRender=true] - [description]
|
|
|
|
* @property {string|number} [backgroundColor=0x000000] - [description]
|
|
|
|
* @property {object} [?callbacks] - [description]
|
|
|
|
* @property {function} [callbacks.preBoot=NOOP] - [description]
|
|
|
|
* @property {function} [callbacks.postBoot=NOOP] - [description]
|
2018-01-25 00:48:48 +00:00
|
|
|
* @property {LoaderConfig} [?loader] - [description]
|
2017-10-04 22:48:16 +00:00
|
|
|
* @property {object} [?images] - [description]
|
|
|
|
* @property {string} [images.default] - [description]
|
|
|
|
* @property {string} [images.missing] - [description]
|
|
|
|
*/
|
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Config
|
|
|
|
* @memberOf Phaser.Boot
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {object} [GameConfig] - The configuration object for your Phaser Game instance.
|
|
|
|
*
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
var Config = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Config (config)
|
|
|
|
{
|
|
|
|
if (config === undefined) { config = {}; }
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
var defaultBannerColor = [
|
|
|
|
'#ff0000',
|
|
|
|
'#ffff00',
|
|
|
|
'#00ff00',
|
|
|
|
'#00ffff',
|
|
|
|
'#000000'
|
|
|
|
];
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
var defaultBannerTextColor = '#ffffff';
|
2016-11-24 01:35:02 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.width = GetValue(config, 'width', 1024);
|
|
|
|
this.height = GetValue(config, 'height', 768);
|
|
|
|
this.zoom = GetValue(config, 'zoom', 1);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.resolution = GetValue(config, 'resolution', 1);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.renderType = GetValue(config, 'type', CONST.AUTO);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.parent = GetValue(config, 'parent', null);
|
|
|
|
this.canvas = GetValue(config, 'canvas', null);
|
|
|
|
this.canvasStyle = GetValue(config, 'canvasStyle', null);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.sceneConfig = GetValue(config, 'scene', null);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
MATH.RND.init(this.seed);
|
2017-01-25 12:01:52 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.gameTitle = GetValue(config, 'title', '');
|
2018-01-28 04:10:44 +00:00
|
|
|
this.gameURL = GetValue(config, 'url', 'https://phaser.io');
|
2017-06-30 14:47:51 +00:00
|
|
|
this.gameVersion = GetValue(config, 'version', '');
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Input
|
|
|
|
this.inputKeyboard = GetValue(config, 'input.keyboard', true);
|
|
|
|
this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window);
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.inputMouse = GetValue(config, 'input.mouse', true);
|
|
|
|
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
|
2017-12-27 23:52:46 +00:00
|
|
|
this.inputMouseCapture = GetValue(config, 'input.mouse.capture', true);
|
2017-06-12 23:38:48 +00:00
|
|
|
|
2017-07-28 02:28:10 +00:00
|
|
|
this.inputTouch = GetValue(config, 'input.touch', true);
|
|
|
|
this.inputTouchEventTarget = GetValue(config, 'input.touch.target', null);
|
2017-12-27 23:52:46 +00:00
|
|
|
this.inputTouchCapture = GetValue(config, 'input.touch.capture', true);
|
2017-07-28 02:28:10 +00:00
|
|
|
|
2017-09-13 13:18:34 +00:00
|
|
|
this.inputGamepad = GetValue(config, 'input.gamepad', false);
|
2017-09-09 02:17:13 +00:00
|
|
|
|
2017-07-25 11:33:37 +00:00
|
|
|
this.disableContextMenu = GetValue(config, 'disableContextMenu', false);
|
|
|
|
|
2018-01-08 16:39:46 +00:00
|
|
|
this.audio = GetValue(config, 'audio');
|
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// If you do: { banner: false } it won't display any banner at all
|
|
|
|
this.hideBanner = (GetValue(config, 'banner', null) === false);
|
2016-11-24 15:40:05 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.hidePhaser = GetValue(config, 'banner.hidePhaser', false);
|
|
|
|
this.bannerTextColor = GetValue(config, 'banner.text', defaultBannerTextColor);
|
|
|
|
this.bannerBackgroundColor = GetValue(config, 'banner.background', defaultBannerColor);
|
2017-10-04 22:48:16 +00:00
|
|
|
|
|
|
|
if (this.gameTitle === '' && this.hidePhaser)
|
|
|
|
{
|
|
|
|
this.hideBanner = true;
|
|
|
|
}
|
2018-01-08 16:39:46 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Frame Rate config
|
|
|
|
// fps: {
|
|
|
|
// min: 10,
|
|
|
|
// target: 60,
|
|
|
|
// forceSetTimeOut: false,
|
|
|
|
// deltaHistory: 10
|
|
|
|
// }
|
2017-05-03 16:07:15 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.fps = GetValue(config, 'fps', null);
|
2017-02-07 18:41:53 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.pixelArt = GetValue(config, 'pixelArt', false);
|
|
|
|
this.transparent = GetValue(config, 'transparent', false);
|
|
|
|
this.clearBeforeRender = GetValue(config, 'clearBeforeRender', true);
|
|
|
|
this.backgroundColor = ValueToColor(GetValue(config, 'backgroundColor', 0));
|
2016-11-25 02:08:33 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Callbacks
|
|
|
|
this.preBoot = GetValue(config, 'callbacks.preBoot', NOOP);
|
|
|
|
this.postBoot = GetValue(config, 'callbacks.postBoot', NOOP);
|
2017-02-07 12:43:20 +00:00
|
|
|
|
2017-08-15 22:34:39 +00:00
|
|
|
// Physics
|
|
|
|
// physics: {
|
|
|
|
// system: 'impact',
|
2017-08-18 00:42:14 +00:00
|
|
|
// setBounds: true,
|
2017-08-15 22:34:39 +00:00
|
|
|
// gravity: 0,
|
2017-08-18 00:42:14 +00:00
|
|
|
// cellSize: 64
|
2017-08-15 22:34:39 +00:00
|
|
|
// }
|
2017-08-18 00:42:14 +00:00
|
|
|
this.physics = GetValue(config, 'physics', {});
|
|
|
|
this.defaultPhysicsSystem = GetValue(this.physics, 'default', false);
|
2017-08-15 22:34:39 +00:00
|
|
|
|
2018-01-19 16:56:41 +00:00
|
|
|
// Loader Defaults
|
|
|
|
this.loaderBaseURL = GetValue(config, 'loader.baseURL', '');
|
|
|
|
this.loaderPath = GetValue(config, 'loader.path', '');
|
|
|
|
this.loaderEnableParallel = GetValue(config, 'loader.enableParallel', true);
|
|
|
|
this.loaderMaxParallelDownloads = GetValue(config, 'loader.maxParallelDownloads', 4);
|
|
|
|
this.loaderCrossOrigin = GetValue(config, 'loader.crossOrigin', undefined);
|
|
|
|
this.loaderResponseType = GetValue(config, 'loader.responseType', '');
|
|
|
|
this.loaderAsync = GetValue(config, 'loader.async', true);
|
|
|
|
this.loaderUser = GetValue(config, 'loader.user', '');
|
|
|
|
this.loaderPassword = GetValue(config, 'loader.password', '');
|
|
|
|
this.loaderTimeout = GetValue(config, 'loader.timeout', 0);
|
|
|
|
|
2018-01-18 05:16:02 +00:00
|
|
|
// Scene Plugins
|
|
|
|
this.defaultPlugins = GetValue(config, 'plugins', DefaultScenePlugins);
|
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Default / Missing Images
|
|
|
|
var pngPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAg';
|
2017-03-28 22:56:00 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.defaultImage = GetValue(config, 'images.default', pngPrefix + 'AQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==');
|
|
|
|
this.missingImage = GetValue(config, 'images.missing', pngPrefix + 'CAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==');
|
|
|
|
}
|
2016-11-24 01:35:02 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
});
|
2016-11-24 01:35:02 +00:00
|
|
|
|
|
|
|
module.exports = Config;
|