phaser/src/scene/Settings.js

127 lines
4.8 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2018-01-16 19:49:13 +00:00
var CONST = require('./const');
var GetValue = require('../utils/object/GetValue');
var Merge = require('../utils/object/Merge');
var InjectionMap = require('./InjectionMap');
2016-11-29 13:01:16 +00:00
2018-04-16 14:11:51 +00:00
/**
* @namespace Phaser.Scenes.Settings
*/
2018-03-22 12:51:30 +00:00
2018-02-12 15:18:31 +00:00
/**
2018-04-16 14:11:51 +00:00
* @typedef {object} Phaser.Scenes.Settings.Config
2018-02-12 15:18:31 +00:00
*
2018-10-19 14:53:04 +00:00
* @property {string} [key] - The unique key of this Scene. Must be unique within the entire Game instance.
* @property {boolean} [active=false] - Does the Scene start as active or not? An active Scene updates each step.
* @property {boolean} [visible=true] - Does the Scene start as visible or not? A visible Scene renders each step.
* @property {(false|Phaser.Loader.FileTypes.PackFileConfig)} [pack=false] - An optional Loader Packfile to be loaded before the Scene begins.
* @property {?(InputJSONCameraObject|InputJSONCameraObject[])} [cameras=null] - An optional Camera configuration object.
* @property {Object.<string, string>} [map] - Overwrites the default injection map for a scene.
* @property {Object.<string, string>} [mapAdd] - Extends the injection map for a scene.
2018-10-19 14:53:04 +00:00
* @property {object} [physics={}] - The physics configuration object for the Scene.
* @property {object} [loader={}] - The loader configuration object for the Scene.
* @property {(false|*)} [plugins=false] - The plugin configuration object for the Scene.
*/
/**
2018-04-16 14:11:51 +00:00
* @typedef {object} Phaser.Scenes.Settings.Object
2018-02-12 15:18:31 +00:00
*
2018-10-19 14:53:04 +00:00
* @property {number} status - The current status of the Scene. Maps to the Scene constants.
* @property {string} key - The unique key of this Scene. Unique within the entire Game instance.
* @property {boolean} active - The active state of this Scene. An active Scene updates each step.
* @property {boolean} visible - The visible state of this Scene. A visible Scene renders each step.
* @property {boolean} isBooted - Has the Scene finished booting?
* @property {boolean} isTransition - Is the Scene in a state of transition?
* @property {?Phaser.Scene} transitionFrom - The Scene this Scene is transitioning from, if set.
* @property {integer} transitionDuration - The duration of the transition, if set.
* @property {boolean} transitionAllowInput - Is this Scene allowed to receive input during transitions?
* @property {object} data - a data bundle passed to this Scene from the Scene Manager.
* @property {(false|Phaser.Loader.FileTypes.PackFileConfig)} pack - The Loader Packfile to be loaded before the Scene begins.
* @property {?(InputJSONCameraObject|InputJSONCameraObject[])} cameras - The Camera configuration object.
* @property {Object.<string, string>} map - The Scene's Injection Map.
* @property {object} physics - The physics configuration object for the Scene.
* @property {object} loader - The loader configuration object for the Scene.
* @property {(false|*)} plugins - The plugin configuration object for the Scene.
2018-02-12 15:18:31 +00:00
*/
2017-02-06 23:59:15 +00:00
var Settings = {
/**
2018-10-19 14:53:04 +00:00
* Takes a Scene configuration object and returns a fully formed System Settings object.
*
* @function Phaser.Scenes.Settings.create
* @since 3.0.0
*
2018-10-19 14:53:04 +00:00
* @param {(string|Phaser.Scenes.Settings.Config)} config - The Scene configuration object used to create this Scene Settings.
*
2018-10-19 14:53:04 +00:00
* @return {Phaser.Scenes.Settings.Object} The Scene Settings object created as a result of the config and default settings.
*/
2017-02-06 23:59:15 +00:00
create: function (config)
2016-11-29 13:01:16 +00:00
{
2017-02-06 23:59:15 +00:00
if (typeof config === 'string')
{
config = { key: config };
}
else if (config === undefined)
{
// Pass the 'hasOwnProperty' checks
config = {};
}
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
return {
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
status: CONST.PENDING,
2016-11-29 13:01:16 +00:00
key: GetValue(config, 'key', ''),
active: GetValue(config, 'active', false),
visible: GetValue(config, 'visible', true),
isBooted: false,
isTransition: false,
transitionFrom: null,
2018-04-14 03:24:05 +00:00
transitionDuration: 0,
transitionAllowInput: true,
// Loader payload array
2017-02-17 02:07:56 +00:00
data: {},
pack: GetValue(config, 'pack', false),
2016-11-29 13:01:16 +00:00
// Cameras
cameras: GetValue(config, 'cameras', null),
// Scene Property Injection Map
map: GetValue(config, 'map', Merge(InjectionMap, GetValue(config, 'mapAdd', {}))),
// Physics
physics: GetValue(config, 'physics', {}),
// Loader
loader: GetValue(config, 'loader', {}),
// Plugins
2018-06-08 14:16:09 +00:00
plugins: GetValue(config, 'plugins', false),
// Input
input: GetValue(config, 'input', {})
2017-02-06 23:59:15 +00:00
};
}
2017-02-06 23:59:15 +00:00
2016-11-29 13:01:16 +00:00
};
module.exports = Settings;