2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-16 16:33:23 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-01-20 16:22:40 +00:00
|
|
|
var CONST = require('./const');
|
2019-01-18 12:19:41 +00:00
|
|
|
var Events = require('./events');
|
2019-01-18 13:41:43 +00:00
|
|
|
var GameEvents = require('../core/events');
|
2018-01-16 16:33:23 +00:00
|
|
|
var GetValue = require('../utils/object/GetValue');
|
2019-01-18 13:41:43 +00:00
|
|
|
var LoaderEvents = require('../loader/events');
|
2018-01-16 16:33:23 +00:00
|
|
|
var NOOP = require('../utils/NOOP');
|
2018-01-16 22:28:29 +00:00
|
|
|
var Scene = require('./Scene');
|
|
|
|
var Systems = require('./Systems');
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-02-13 01:39:22 +00:00
|
|
|
* The Scene Manager.
|
|
|
|
*
|
|
|
|
* The Scene Manager is a Game level system, responsible for creating, processing and updating all of the
|
|
|
|
* Scenes in a Game instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @class SceneManager
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Scenes
|
2018-02-12 16:18:34 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Game} game - The Phaser.Game instance this Scene Manager belongs to.
|
|
|
|
* @param {object} sceneConfig - Scene specific configuration settings.
|
|
|
|
*/
|
2018-01-16 16:33:23 +00:00
|
|
|
var SceneManager = new Class({
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
initialize:
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-01-16 16:33:23 +00:00
|
|
|
function SceneManager (game, sceneConfig)
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* The Game that this SceneManager belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#game
|
|
|
|
* @type {Phaser.Game}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:58:45 +00:00
|
|
|
this.game = game;
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* An object that maps the keys to the scene so we can quickly get a scene from a key without iteration.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#keys
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:58:45 +00:00
|
|
|
this.keys = {};
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* The array in which all of the scenes are kept.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#scenes
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
this.scenes = [];
|
2017-07-04 12:58:45 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Scenes pending to be added are stored in here until the manager has time to add it.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#_pending
|
|
|
|
* @type {array}
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:58:45 +00:00
|
|
|
this._pending = [];
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* An array of scenes waiting to be started once the game has booted.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#_start
|
|
|
|
* @type {array}
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-11 15:48:25 +00:00
|
|
|
this._start = [];
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* An operations queue, because we don't manipulate the scenes array during processing.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#_queue
|
|
|
|
* @type {array}
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
this._queue = [];
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-09 11:57:47 +00:00
|
|
|
* Boot time data to merge.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-09 11:57:47 +00:00
|
|
|
* @name Phaser.Scenes.SceneManager#_data
|
|
|
|
* @type {object}
|
2018-02-12 16:18:34 +00:00
|
|
|
* @private
|
2018-04-09 11:57:47 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
this._data = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the Scene Manager actively processing the Scenes list?
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#isProcessing
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-04-09 11:57:47 +00:00
|
|
|
this.isProcessing = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the Scene Manager properly started?
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#isBooted
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-04-09 11:57:47 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
this.isBooted = false;
|
2018-01-20 04:47:03 +00:00
|
|
|
|
2018-07-26 22:05:08 +00:00
|
|
|
/**
|
|
|
|
* Do any of the Cameras in any of the Scenes require a custom viewport?
|
|
|
|
* If not we can skip scissor tests.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.SceneManager#customViewports
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.12.0
|
|
|
|
*/
|
|
|
|
this.customViewports = 0;
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (sceneConfig)
|
2016-11-29 13:01:16 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (!Array.isArray(sceneConfig))
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
sceneConfig = [ sceneConfig ];
|
2017-07-04 12:58:45 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < sceneConfig.length; i++)
|
2016-11-29 13:01:16 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
// The i === 0 part just autostarts the first Scene given (unless it says otherwise in its config)
|
2016-11-29 15:25:14 +00:00
|
|
|
this._pending.push({
|
|
|
|
key: 'default',
|
2018-01-20 04:47:03 +00:00
|
|
|
scene: sceneConfig[i],
|
|
|
|
autoStart: (i === 0),
|
2017-02-16 17:18:50 +00:00
|
|
|
data: {}
|
2016-11-29 15:25:14 +00:00
|
|
|
});
|
2016-11-29 13:01:16 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-06-13 22:35:25 +00:00
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
game.events.once(GameEvents.READY, this.bootQueue, this);
|
2018-01-18 14:00:31 +00:00
|
|
|
},
|
|
|
|
|
2018-03-05 14:11:42 +00:00
|
|
|
/**
|
|
|
|
* Internal first-time Scene boot handler.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#bootQueue
|
2018-03-05 14:48:30 +00:00
|
|
|
* @private
|
2018-03-05 14:11:42 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
bootQueue: function ()
|
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isBooted)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-05 14:11:42 +00:00
|
|
|
var i;
|
|
|
|
var entry;
|
|
|
|
var key;
|
|
|
|
var sceneConfig;
|
|
|
|
|
|
|
|
for (i = 0; i < this._pending.length; i++)
|
|
|
|
{
|
|
|
|
entry = this._pending[i];
|
|
|
|
|
|
|
|
key = entry.key;
|
|
|
|
sceneConfig = entry.scene;
|
|
|
|
|
|
|
|
var newScene;
|
|
|
|
|
|
|
|
if (sceneConfig instanceof Scene)
|
|
|
|
{
|
|
|
|
newScene = this.createSceneFromInstance(key, sceneConfig);
|
|
|
|
}
|
|
|
|
else if (typeof sceneConfig === 'object')
|
|
|
|
{
|
|
|
|
newScene = this.createSceneFromObject(key, sceneConfig);
|
|
|
|
}
|
|
|
|
else if (typeof sceneConfig === 'function')
|
|
|
|
{
|
|
|
|
newScene = this.createSceneFromFunction(key, sceneConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace key in case the scene changed it
|
|
|
|
key = newScene.sys.settings.key;
|
2018-03-17 12:42:42 +00:00
|
|
|
|
2018-03-05 14:11:42 +00:00
|
|
|
this.keys[key] = newScene;
|
|
|
|
|
|
|
|
this.scenes.push(newScene);
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
// Any data to inject?
|
|
|
|
if (this._data[key])
|
|
|
|
{
|
|
|
|
newScene.sys.settings.data = this._data[key].data;
|
|
|
|
|
|
|
|
if (this._data[key].autoStart)
|
|
|
|
{
|
|
|
|
entry.autoStart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 14:11:42 +00:00
|
|
|
if (entry.autoStart || newScene.sys.settings.active)
|
|
|
|
{
|
|
|
|
this._start.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the pending lists
|
|
|
|
this._pending.length = 0;
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this._data = {};
|
|
|
|
|
|
|
|
this.isBooted = true;
|
|
|
|
|
2018-03-05 14:11:42 +00:00
|
|
|
// _start might have been populated by the above
|
|
|
|
for (i = 0; i < this._start.length; i++)
|
|
|
|
{
|
|
|
|
entry = this._start[i];
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this.start(entry);
|
2018-03-05 14:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._start.length = 0;
|
|
|
|
},
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Process the Scene operations queue.
|
2018-01-18 14:00:31 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#processQueue
|
2018-01-18 14:00:31 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
processQueue: function ()
|
2018-01-18 14:00:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var pendingLength = this._pending.length;
|
|
|
|
var queueLength = this._queue.length;
|
2018-01-18 14:00:31 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (pendingLength === 0 && queueLength === 0)
|
2018-01-18 14:00:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
return;
|
2018-01-18 14:00:31 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
var i;
|
|
|
|
var entry;
|
2018-01-18 14:00:31 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (pendingLength)
|
2018-01-18 14:00:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
for (i = 0; i < pendingLength; i++)
|
|
|
|
{
|
|
|
|
entry = this._pending[i];
|
2018-01-19 16:29:25 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this.add(entry.key, entry.scene, entry.autoStart, entry.data);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-01-19 16:29:25 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
// _start might have been populated by this.add
|
|
|
|
for (i = 0; i < this._start.length; i++)
|
|
|
|
{
|
|
|
|
entry = this._start[i];
|
2018-01-18 14:00:31 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this.start(entry);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-01-23 02:12:33 +00:00
|
|
|
|
|
|
|
// Clear the pending lists
|
|
|
|
this._start.length = 0;
|
|
|
|
this._pending.length = 0;
|
|
|
|
|
|
|
|
return;
|
2018-01-18 14:00:31 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 20:25:43 +00:00
|
|
|
for (i = 0; i < this._queue.length; i++)
|
2018-01-18 14:00:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
entry = this._queue[i];
|
2018-01-18 14:00:31 +00:00
|
|
|
|
2018-01-23 02:12:33 +00:00
|
|
|
this[entry.op](entry.keyA, entry.keyB);
|
2018-01-18 14:00:31 +00:00
|
|
|
}
|
2018-02-28 20:25:43 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this._queue.length = 0;
|
2017-07-04 12:58:45 +00:00
|
|
|
},
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
/**
|
|
|
|
* Adds a new Scene into the SceneManager.
|
|
|
|
* You must give each Scene a unique key by which you'll identify it.
|
|
|
|
*
|
|
|
|
* The `sceneConfig` can be:
|
|
|
|
*
|
|
|
|
* * A `Phaser.Scene` object, or an object that extends it.
|
|
|
|
* * A plain JavaScript object
|
|
|
|
* * A JavaScript ES6 Class that extends `Phaser.Scene`
|
|
|
|
* * A JavaScript ES5 prototype based Class
|
|
|
|
* * A JavaScript function
|
|
|
|
*
|
|
|
|
* If a function is given then a new Scene will be created by calling it.
|
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#add
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`.
|
2018-04-18 11:13:49 +00:00
|
|
|
* @param {(Phaser.Scene|Phaser.Scenes.Settings.Config|function)} sceneConfig - The config for the Scene
|
2018-01-16 16:29:58 +00:00
|
|
|
* @param {boolean} [autoStart=false] - If `true` the Scene will be started immediately after being added.
|
2018-04-09 11:57:47 +00:00
|
|
|
* @param {object} [data] - Optional data object. This will be set as Scene.settings.data and passed to `Scene.init`.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-09 11:57:47 +00:00
|
|
|
* @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-04-09 11:57:47 +00:00
|
|
|
add: function (key, sceneConfig, autoStart, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
|
|
|
if (autoStart === undefined) { autoStart = false; }
|
2018-04-09 11:57:47 +00:00
|
|
|
if (data === undefined) { data = {}; }
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
// If processing or not booted then put scene into a holding pattern
|
|
|
|
if (this.isProcessing || !this.isBooted)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
|
|
|
this._pending.push({
|
|
|
|
key: key,
|
|
|
|
scene: sceneConfig,
|
2018-01-20 04:47:03 +00:00
|
|
|
autoStart: autoStart,
|
2018-04-09 11:57:47 +00:00
|
|
|
data: data
|
2018-01-16 16:29:58 +00:00
|
|
|
});
|
|
|
|
|
2018-04-25 16:14:10 +00:00
|
|
|
if (!this.isBooted)
|
|
|
|
{
|
|
|
|
this._data[key] = { data: data };
|
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return null;
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
key = this.getKey(key, sceneConfig);
|
|
|
|
|
|
|
|
var newScene;
|
|
|
|
|
|
|
|
if (sceneConfig instanceof Scene)
|
|
|
|
{
|
|
|
|
newScene = this.createSceneFromInstance(key, sceneConfig);
|
|
|
|
}
|
|
|
|
else if (typeof sceneConfig === 'object')
|
|
|
|
{
|
|
|
|
sceneConfig.key = key;
|
|
|
|
|
|
|
|
newScene = this.createSceneFromObject(key, sceneConfig);
|
|
|
|
}
|
|
|
|
else if (typeof sceneConfig === 'function')
|
|
|
|
{
|
|
|
|
newScene = this.createSceneFromFunction(key, sceneConfig);
|
|
|
|
}
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
// Any data to inject?
|
|
|
|
newScene.sys.settings.data = data;
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
// Replace key in case the scene changed it
|
|
|
|
key = newScene.sys.settings.key;
|
|
|
|
|
|
|
|
this.keys[key] = newScene;
|
|
|
|
|
|
|
|
this.scenes.push(newScene);
|
|
|
|
|
|
|
|
if (autoStart || newScene.sys.settings.active)
|
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this._pending.length)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
this._start.push(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
this.start(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newScene;
|
|
|
|
},
|
|
|
|
|
2018-03-02 03:50:55 +00:00
|
|
|
/**
|
|
|
|
* Removes a Scene from the SceneManager.
|
|
|
|
*
|
|
|
|
* The Scene is removed from the local scenes array, it's key is cleared from the keys
|
|
|
|
* cache and Scene.Systems.destroy is then called on it.
|
|
|
|
*
|
2018-07-26 22:41:52 +00:00
|
|
|
* If the SceneManager is processing the Scenes when this method is called it will
|
2018-03-02 03:50:55 +00:00
|
|
|
* queue the operation for the next update sequence.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#remove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2018-03-20 15:12:42 +00:00
|
|
|
* @param {(string|Phaser.Scene)} scene - The Scene to be removed.
|
2018-03-02 03:50:55 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
|
|
|
*/
|
|
|
|
remove: function (key)
|
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-03-02 03:50:55 +00:00
|
|
|
{
|
|
|
|
this._queue.push({ op: 'remove', keyA: key, keyB: null });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var sceneToRemove = this.getScene(key);
|
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
if (!sceneToRemove || sceneToRemove.sys.isTransitioning())
|
2018-03-02 03:50:55 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var index = this.scenes.indexOf(sceneToRemove);
|
|
|
|
var sceneKey = sceneToRemove.sys.settings.key;
|
|
|
|
|
|
|
|
if (index > -1)
|
|
|
|
{
|
2018-03-17 12:42:42 +00:00
|
|
|
delete this.keys[sceneKey];
|
2018-03-02 03:50:55 +00:00
|
|
|
this.scenes.splice(index, 1);
|
|
|
|
|
|
|
|
if (this._start.indexOf(sceneKey) > -1)
|
|
|
|
{
|
|
|
|
index = this._start.indexOf(sceneKey);
|
|
|
|
this._start.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sceneToRemove.sys.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Boot the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#bootScene
|
|
|
|
* @private
|
2019-01-18 12:19:41 +00:00
|
|
|
* @fires Phaser.Scenes.Events#TRANSITION_INIT
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:43:41 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene to boot.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
bootScene: function (scene)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-13 19:12:29 +00:00
|
|
|
var sys = scene.sys;
|
|
|
|
var settings = sys.settings;
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene.init)
|
|
|
|
{
|
2018-04-13 19:12:29 +00:00
|
|
|
scene.init.call(scene, settings.data);
|
|
|
|
|
2018-06-26 15:35:45 +00:00
|
|
|
settings.status = CONST.INIT;
|
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
if (settings.isTransition)
|
2018-04-13 19:12:29 +00:00
|
|
|
{
|
2019-01-18 12:19:41 +00:00
|
|
|
sys.events.emit(Events.TRANSITION_INIT, settings.transitionFrom, settings.transitionDuration);
|
2018-04-13 19:12:29 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var loader;
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-04-13 19:12:29 +00:00
|
|
|
if (sys.load)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-04-13 19:12:29 +00:00
|
|
|
loader = sys.load;
|
2018-02-28 20:25:43 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
loader.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loader && scene.preload)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
scene.preload.call(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
// Is the loader empty?
|
|
|
|
if (loader.list.size === 0)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
this.create(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
else
|
|
|
|
{
|
2018-04-13 19:12:29 +00:00
|
|
|
settings.status = CONST.LOADING;
|
2018-01-20 16:22:40 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
// Start the loader going as we have something in the queue
|
2019-01-18 13:41:43 +00:00
|
|
|
loader.once(LoaderEvents.COMPLETE, this.loadComplete, this);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
loader.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No preload? Then there was nothing to load either
|
|
|
|
this.create(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Handles load completion for a Scene's Loader.
|
|
|
|
*
|
|
|
|
* Starts the Scene that the Loader belongs to.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#loadComplete
|
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
loadComplete: function (loader)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = loader.scene;
|
|
|
|
|
2018-04-14 15:47:29 +00:00
|
|
|
// Try to unlock HTML5 sounds every time any loader completes
|
|
|
|
if (this.game.sound.onBlurPausedSounds)
|
|
|
|
{
|
|
|
|
this.game.sound.unlock();
|
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.create(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Handle payload completion for a Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#payloadComplete
|
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading its Scene's payload.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
payloadComplete: function (loader)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
this.bootScene(loader.scene);
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Updates the Scenes.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#update
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {number} time - Time elapsed.
|
|
|
|
* @param {number} delta - Delta time from the last update.
|
2018-01-20 04:47:03 +00:00
|
|
|
*/
|
|
|
|
update: function (time, delta)
|
|
|
|
{
|
|
|
|
this.processQueue();
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this.isProcessing = true;
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
// Loop through the active scenes in reverse order
|
|
|
|
for (var i = this.scenes.length - 1; i >= 0; i--)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var sys = this.scenes[i].sys;
|
|
|
|
|
2018-06-12 15:21:17 +00:00
|
|
|
if (sys.settings.status > CONST.START && sys.settings.status <= CONST.RUNNING)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
sys.step(time, delta);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Renders the Scenes.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#render
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer to use.
|
2018-01-20 04:47:03 +00:00
|
|
|
*/
|
|
|
|
render: function (renderer)
|
|
|
|
{
|
|
|
|
// Loop through the scenes in forward order
|
|
|
|
for (var i = 0; i < this.scenes.length; i++)
|
|
|
|
{
|
|
|
|
var sys = this.scenes[i].sys;
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-03-09 15:33:07 +00:00
|
|
|
if (sys.settings.visible && sys.settings.status >= CONST.LOADING && sys.settings.status < CONST.SLEEPING)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
sys.render(renderer);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
this.isProcessing = false;
|
2018-01-20 04:47:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Calls the given Scene's {@link Phaser.Scene#create} method and updates its status.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#create
|
|
|
|
* @private
|
2019-01-18 12:19:41 +00:00
|
|
|
* @fires Phaser.Scenes.Events#TRANSITION_INIT
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene to create.
|
2018-01-20 04:47:03 +00:00
|
|
|
*/
|
|
|
|
create: function (scene)
|
|
|
|
{
|
2018-04-13 19:12:29 +00:00
|
|
|
var sys = scene.sys;
|
|
|
|
var settings = sys.settings;
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene.create)
|
|
|
|
{
|
2018-06-13 16:27:30 +00:00
|
|
|
settings.status = CONST.CREATING;
|
2018-01-23 02:12:33 +00:00
|
|
|
|
2018-06-13 16:27:30 +00:00
|
|
|
scene.create.call(scene, settings.data);
|
2019-01-18 12:06:43 +00:00
|
|
|
}
|
2018-04-13 19:12:29 +00:00
|
|
|
|
2019-01-18 12:06:43 +00:00
|
|
|
if (settings.isTransition)
|
|
|
|
{
|
2019-01-18 12:19:41 +00:00
|
|
|
sys.events.emit(Events.TRANSITION_START, settings.transitionFrom, settings.transitionDuration);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-01-23 02:12:33 +00:00
|
|
|
|
2018-06-12 15:21:17 +00:00
|
|
|
// If the Scene has an update function we'll set it now, otherwise it'll remain as NOOP
|
|
|
|
if (scene.update)
|
|
|
|
{
|
|
|
|
sys.sceneUpdate = scene.update;
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:35:45 +00:00
|
|
|
settings.status = CONST.RUNNING;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Creates and initializes a Scene from a function.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#createSceneFromFunction
|
2018-01-20 04:47:03 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The key of the Scene.
|
|
|
|
* @param {function} scene - The function to create the Scene from.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scene} The created Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
|
|
|
createSceneFromFunction: function (key, scene)
|
|
|
|
{
|
|
|
|
var newScene = new scene();
|
|
|
|
|
|
|
|
if (newScene instanceof Scene)
|
|
|
|
{
|
|
|
|
var configKey = newScene.sys.settings.key;
|
|
|
|
|
|
|
|
if (configKey !== '')
|
|
|
|
{
|
|
|
|
key = configKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.keys.hasOwnProperty(key))
|
|
|
|
{
|
|
|
|
throw new Error('Cannot add a Scene with duplicate key: ' + key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.createSceneFromInstance(key, newScene);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newScene.sys = new Systems(newScene);
|
|
|
|
|
|
|
|
newScene.sys.settings.key = key;
|
|
|
|
|
|
|
|
newScene.sys.init(this.game);
|
|
|
|
|
|
|
|
return newScene;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Creates and initializes a Scene instance.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#createSceneFromInstance
|
2018-01-20 04:47:03 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The key of the Scene.
|
|
|
|
* @param {Phaser.Scene} newScene - The Scene instance.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scene} The created Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
|
|
|
createSceneFromInstance: function (key, newScene)
|
|
|
|
{
|
|
|
|
var configKey = newScene.sys.settings.key;
|
|
|
|
|
|
|
|
if (configKey !== '')
|
|
|
|
{
|
|
|
|
key = configKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newScene.sys.settings.key = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
newScene.sys.init(this.game);
|
|
|
|
|
|
|
|
return newScene;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Creates and initializes a Scene from an Object definition.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#createSceneFromObject
|
2018-01-20 04:47:03 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The key of the Scene.
|
2018-04-18 11:13:49 +00:00
|
|
|
* @param {(string|Phaser.Scenes.Settings.Config)} sceneConfig - The Scene config.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scene} The created Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
|
|
|
createSceneFromObject: function (key, sceneConfig)
|
|
|
|
{
|
|
|
|
var newScene = new Scene(sceneConfig);
|
|
|
|
|
|
|
|
var configKey = newScene.sys.settings.key;
|
|
|
|
|
|
|
|
if (configKey !== '')
|
|
|
|
{
|
|
|
|
key = configKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newScene.sys.settings.key = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
newScene.sys.init(this.game);
|
|
|
|
|
2018-01-19 16:29:25 +00:00
|
|
|
// Extract callbacks
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-03-14 20:28:04 +00:00
|
|
|
var defaults = [ 'init', 'preload', 'create', 'update', 'render' ];
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < defaults.length; i++)
|
|
|
|
{
|
2018-01-18 05:16:52 +00:00
|
|
|
var sceneCallback = GetValue(sceneConfig, defaults[i], null);
|
|
|
|
|
|
|
|
if (sceneCallback)
|
|
|
|
{
|
|
|
|
newScene[defaults[i]] = sceneCallback;
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 16:29:25 +00:00
|
|
|
// Now let's move across any other functions or properties that may exist in the extend object:
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
scene: {
|
|
|
|
preload: preload,
|
|
|
|
create: create,
|
|
|
|
extend: {
|
|
|
|
hello: 1,
|
|
|
|
test: 'atari',
|
|
|
|
addImage: addImage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sceneConfig.hasOwnProperty('extend'))
|
|
|
|
{
|
|
|
|
for (var propertyKey in sceneConfig.extend)
|
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
var value = sceneConfig.extend[propertyKey];
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
if (propertyKey === 'data' && newScene.hasOwnProperty('data') && typeof value === 'object')
|
|
|
|
{
|
|
|
|
// Populate the DataManager
|
|
|
|
newScene.data.merge(value);
|
|
|
|
}
|
|
|
|
else if (propertyKey !== 'sys')
|
|
|
|
{
|
|
|
|
newScene[propertyKey] = value;
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 19:40:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
return newScene;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Retrieves the key of a Scene from a Scene config.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#getKey
|
2018-01-20 04:47:03 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The key to check in the Scene config.
|
2018-04-18 11:13:49 +00:00
|
|
|
* @param {(Phaser.Scene|Phaser.Scenes.Settings.Config|function)} sceneConfig - The Scene config.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {string} The Scene key.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
|
|
|
getKey: function (key, sceneConfig)
|
|
|
|
{
|
|
|
|
if (!key) { key = 'default'; }
|
|
|
|
|
|
|
|
if (typeof sceneConfig === 'function')
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
else if (sceneConfig instanceof Scene)
|
|
|
|
{
|
|
|
|
key = sceneConfig.sys.settings.key;
|
|
|
|
}
|
|
|
|
else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key'))
|
|
|
|
{
|
|
|
|
key = sceneConfig.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By this point it's either 'default' or extracted from the Scene
|
|
|
|
|
|
|
|
if (this.keys.hasOwnProperty(key))
|
|
|
|
{
|
|
|
|
throw new Error('Cannot add a Scene with duplicate key: ' + key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Retrieves a Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#getScene
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-17 14:07:54 +00:00
|
|
|
* @param {string|Phaser.Scene} key - The Scene to retrieve.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {?Phaser.Scene} The Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
|
|
|
getScene: function (key)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (typeof key === 'string')
|
|
|
|
{
|
|
|
|
if (this.keys[key])
|
|
|
|
{
|
|
|
|
return this.keys[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this.scenes.length; i++)
|
|
|
|
{
|
|
|
|
if (key === this.scenes[i])
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return null;
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Determines whether a Scene is active.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#isActive
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {boolean} Whether the Scene is active.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isActive: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
return scene.sys.isActive();
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return null;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Determines whether a Scene is visible.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#isVisible
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {boolean} Whether the Scene is visible.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isVisible: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
return scene.sys.isVisible();
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return null;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Determines whether a Scene is sleeping.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#isSleeping
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {boolean} Whether the Scene is sleeping.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isSleeping: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
return scene.sys.isSleeping();
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return null;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Pauses the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#pause
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to pause.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted by its pause event.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
pause: function (key, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-06-26 15:08:14 +00:00
|
|
|
scene.sys.pause(data);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Resumes the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#resume
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to resume.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted by its resume event.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
resume: function (key, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene)
|
|
|
|
{
|
2018-06-26 15:08:14 +00:00
|
|
|
scene.sys.resume(data);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Puts the given Scene to sleep.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#sleep
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to put to sleep.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted by its sleep event.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
sleep: function (key, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
if (scene && !scene.sys.isTransitioning())
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-06-26 15:08:14 +00:00
|
|
|
scene.sys.sleep(data);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Awakens the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#wake
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to wake up.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted by its wake event.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
wake: function (key, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (scene)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-06-26 15:08:14 +00:00
|
|
|
scene.sys.wake(data);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
2018-06-08 14:07:00 +00:00
|
|
|
/**
|
|
|
|
* Runs the given Scene, but does not change the state of this Scene.
|
2018-06-13 22:35:25 +00:00
|
|
|
*
|
2018-06-08 14:07:00 +00:00
|
|
|
* If the given Scene is paused, it will resume it. If sleeping, it will wake it.
|
|
|
|
* If not running at all, it will be started.
|
|
|
|
*
|
|
|
|
* Use this if you wish to open a modal Scene by calling `pause` on the current
|
|
|
|
* Scene, then `run` on the modal Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#run
|
|
|
|
* @since 3.10.0
|
|
|
|
*
|
|
|
|
* @param {string} key - The Scene to run.
|
2018-06-14 01:34:27 +00:00
|
|
|
* @param {object} [data] - A data object that will be passed to the Scene on start, wake, or resume.
|
2018-06-08 14:07:00 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.SceneManager} This Scene Manager.
|
|
|
|
*/
|
|
|
|
run: function (key, data)
|
|
|
|
{
|
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
|
|
|
if (!scene)
|
|
|
|
{
|
2018-06-13 22:35:25 +00:00
|
|
|
for (var i = 0; i < this._pending.length; i++)
|
|
|
|
{
|
|
|
|
if (this._pending[i].key === key)
|
|
|
|
{
|
2018-06-22 10:55:21 +00:00
|
|
|
this.queueOp('start', key, data);
|
2018-06-13 22:35:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 14:07:00 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scene.sys.isSleeping())
|
|
|
|
{
|
|
|
|
// Sleeping?
|
2018-06-14 01:34:27 +00:00
|
|
|
scene.sys.wake(data);
|
2018-06-08 14:07:00 +00:00
|
|
|
}
|
|
|
|
else if (scene.sys.isBooted && !scene.sys.isActive())
|
|
|
|
{
|
|
|
|
// Paused?
|
2018-06-14 01:34:27 +00:00
|
|
|
scene.sys.resume(data);
|
2018-06-08 14:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not actually running?
|
|
|
|
this.start(key, data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Starts the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#start
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to start.
|
2018-04-09 11:57:47 +00:00
|
|
|
* @param {object} [data] - Optional data object to pass to Scene.Settings and Scene.init.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
start: function (key, data)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
// If the Scene Manager is not running, then put the Scene into a holding pattern
|
|
|
|
if (!this.isBooted)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
this._data[key] = {
|
|
|
|
autoStart: true,
|
|
|
|
data: data
|
|
|
|
};
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
2018-09-13 15:32:02 +00:00
|
|
|
// If the Scene is already running (perhaps they called start from a launched sub-Scene?)
|
|
|
|
// then we close it down before starting it again.
|
2018-09-14 17:05:14 +00:00
|
|
|
if (scene.sys.isActive() || scene.sys.isPaused())
|
2018-09-13 15:32:02 +00:00
|
|
|
{
|
|
|
|
scene.sys.shutdown();
|
2018-01-20 04:47:03 +00:00
|
|
|
|
2018-09-14 17:05:14 +00:00
|
|
|
scene.sys.start(data);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2018-09-14 17:05:14 +00:00
|
|
|
else
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-09-14 17:05:14 +00:00
|
|
|
scene.sys.start(data);
|
2018-01-20 04:47:03 +00:00
|
|
|
|
2018-09-14 17:05:14 +00:00
|
|
|
var loader;
|
|
|
|
|
|
|
|
if (scene.sys.load)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-09-14 17:05:14 +00:00
|
|
|
loader = scene.sys.load;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Files payload?
|
|
|
|
if (loader && scene.sys.settings.hasOwnProperty('pack'))
|
|
|
|
{
|
|
|
|
loader.reset();
|
|
|
|
|
|
|
|
if (loader.addPack({ payload: scene.sys.settings.pack }))
|
|
|
|
{
|
|
|
|
scene.sys.settings.status = CONST.LOADING;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
loader.once(LoaderEvents.COMPLETE, this.payloadComplete, this);
|
2018-09-14 17:05:14 +00:00
|
|
|
|
|
|
|
loader.start();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-28 20:25:43 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.bootScene(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Stops the given Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#stop
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} key - The Scene to stop.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
stop: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
if (scene && !scene.sys.isTransitioning())
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
|
|
|
scene.sys.shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Sleeps one one Scene and starts the other.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#switch
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {string} from - The Scene to sleep.
|
|
|
|
* @param {string} to - The Scene to start.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
switch: function (from, to)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var sceneA = this.getScene(from);
|
|
|
|
var sceneB = this.getScene(to);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (sceneA && sceneB && sceneA !== sceneB)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
this.sleep(from);
|
|
|
|
|
|
|
|
if (this.isSleeping(to))
|
|
|
|
{
|
|
|
|
this.wake(to);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.start(to);
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Retrieves a Scene by numeric index.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#getAt
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {integer} index - The index of the Scene to retrieve.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {(Phaser.Scene|undefined)} The Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
getAt: function (index)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
return this.scenes[index];
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Retrieves the numeric index of a Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#getIndex
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The key of the Scene.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {integer} The index of the Scene.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
getIndex: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this.scenes.indexOf(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Brings a Scene to the top of the Scenes list.
|
|
|
|
*
|
|
|
|
* This means it will render above all other Scenes.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#bringToTop
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to move.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
bringToTop: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: 'bringToTop', keyA: key, keyB: null });
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var index = this.getIndex(key);
|
|
|
|
|
|
|
|
if (index !== -1 && index < this.scenes.length)
|
|
|
|
{
|
|
|
|
var scene = this.getScene(key);
|
|
|
|
|
|
|
|
this.scenes.splice(index, 1);
|
|
|
|
this.scenes.push(scene);
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Sends a Scene to the back of the Scenes list.
|
|
|
|
*
|
|
|
|
* This means it will render below all other Scenes.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#sendToBack
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to move.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
sendToBack: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: 'sendToBack', keyA: key, keyB: null });
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
else
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var index = this.getIndex(key);
|
2018-01-18 05:16:52 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (index !== -1 && index > 0)
|
2018-01-18 05:16:52 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var scene = this.getScene(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.scenes.splice(index, 1);
|
|
|
|
this.scenes.unshift(scene);
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Moves a Scene down one position in the Scenes list.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#moveDown
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to move.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
moveDown: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: 'moveDown', keyA: key, keyB: null });
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var indexA = this.getIndex(key);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (indexA > 0)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var indexB = indexA - 1;
|
|
|
|
var sceneA = this.getScene(key);
|
|
|
|
var sceneB = this.getAt(indexB);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.scenes[indexA] = sceneB;
|
|
|
|
this.scenes[indexB] = sceneA;
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Moves a Scene up one position in the Scenes list.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#moveUp
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to move.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
moveUp: function (key)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: 'moveUp', keyA: key, keyB: null });
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var indexA = this.getIndex(key);
|
|
|
|
|
|
|
|
if (indexA < this.scenes.length - 1)
|
|
|
|
{
|
|
|
|
var indexB = indexA + 1;
|
|
|
|
var sceneA = this.getScene(key);
|
|
|
|
var sceneB = this.getAt(indexB);
|
|
|
|
|
|
|
|
this.scenes[indexA] = sceneB;
|
|
|
|
this.scenes[indexB] = sceneA;
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
|
|
|
},
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-03-02 18:25:44 +00:00
|
|
|
/**
|
|
|
|
* Moves a Scene so it is immediately above another Scene in the Scenes list.
|
2018-04-02 17:01:17 +00:00
|
|
|
*
|
2018-03-02 18:25:44 +00:00
|
|
|
* This means it will render over the top of the other Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#moveAbove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2018-03-20 15:12:42 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved above.
|
|
|
|
* @param {(string|Phaser.Scene)} keyB - The Scene to be moved.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-03-02 18:25:44 +00:00
|
|
|
*/
|
|
|
|
moveAbove: function (keyA, keyB)
|
|
|
|
{
|
|
|
|
if (keyA === keyB)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-03-02 18:25:44 +00:00
|
|
|
{
|
|
|
|
this._queue.push({ op: 'moveAbove', keyA: keyA, keyB: keyB });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var indexA = this.getIndex(keyA);
|
|
|
|
var indexB = this.getIndex(keyB);
|
|
|
|
|
2018-05-01 00:23:34 +00:00
|
|
|
if (indexA !== -1 && indexB !== -1)
|
2018-03-02 18:25:44 +00:00
|
|
|
{
|
|
|
|
var tempScene = this.getAt(indexB);
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
this.scenes.splice(indexB, 1);
|
|
|
|
|
|
|
|
// Add in new location
|
2018-05-01 00:23:34 +00:00
|
|
|
this.scenes.splice(indexA + 1, 0, tempScene);
|
2018-03-02 18:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a Scene so it is immediately below another Scene in the Scenes list.
|
2018-04-02 17:01:17 +00:00
|
|
|
*
|
2018-03-02 18:25:44 +00:00
|
|
|
* This means it will render behind the other Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#moveBelow
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2018-03-20 15:12:42 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved above.
|
|
|
|
* @param {(string|Phaser.Scene)} keyB - The Scene to be moved.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-03-02 18:25:44 +00:00
|
|
|
*/
|
|
|
|
moveBelow: function (keyA, keyB)
|
|
|
|
{
|
|
|
|
if (keyA === keyB)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-03-02 18:25:44 +00:00
|
|
|
{
|
|
|
|
this._queue.push({ op: 'moveBelow', keyA: keyA, keyB: keyB });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var indexA = this.getIndex(keyA);
|
|
|
|
var indexB = this.getIndex(keyB);
|
|
|
|
|
2018-05-01 00:23:34 +00:00
|
|
|
if (indexA !== -1 && indexB !== -1)
|
2018-03-02 18:25:44 +00:00
|
|
|
{
|
|
|
|
var tempScene = this.getAt(indexB);
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
this.scenes.splice(indexB, 1);
|
|
|
|
|
2018-05-01 00:23:34 +00:00
|
|
|
if (indexA === 0)
|
|
|
|
{
|
|
|
|
this.scenes.unshift(tempScene);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add in new location
|
|
|
|
this.scenes.splice(indexA, 0, tempScene);
|
|
|
|
}
|
2018-03-02 18:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
/**
|
|
|
|
* Queue a Scene operation for the next update.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#queueOp
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {string} op - The operation to perform.
|
|
|
|
* @param {(string|Phaser.Scene)} keyA - Scene A.
|
|
|
|
* @param {(string|Phaser.Scene)} [keyB] - Scene B.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
|
|
|
*/
|
2018-01-23 02:12:33 +00:00
|
|
|
queueOp: function (op, keyA, keyB)
|
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: op, keyA: keyA, keyB: keyB });
|
2018-01-23 02:12:33 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Swaps the positions of two Scenes in the Scenes list.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-16 16:33:23 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#swapPosition
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The first Scene to swap.
|
|
|
|
* @param {(string|Phaser.Scene)} keyB - The second Scene to swap.
|
2018-01-20 04:47:03 +00:00
|
|
|
*
|
2018-04-02 17:01:17 +00:00
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
2018-01-16 16:29:58 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
swapPosition: function (keyA, keyB)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (keyA === keyB)
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 11:57:47 +00:00
|
|
|
if (this.isProcessing)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
this._queue.push({ op: 'swapPosition', keyA: keyA, keyB: keyB });
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
else
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
var indexA = this.getIndex(keyA);
|
|
|
|
var indexB = this.getIndex(keyB);
|
2018-01-16 16:29:58 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (indexA !== indexB && indexA !== -1 && indexB !== -1)
|
|
|
|
{
|
|
|
|
var tempScene = this.getAt(indexA);
|
|
|
|
|
|
|
|
this.scenes[indexA] = this.scenes[indexB];
|
|
|
|
this.scenes[indexB] = tempScene;
|
|
|
|
}
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
return this;
|
2018-01-16 16:29:58 +00:00
|
|
|
},
|
2018-01-20 04:47:03 +00:00
|
|
|
|
2018-04-02 17:01:17 +00:00
|
|
|
/**
|
|
|
|
* Dumps debug information about each Scene to the developer console.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.SceneManager#dump
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2018-03-02 17:48:45 +00:00
|
|
|
dump: function ()
|
|
|
|
{
|
2018-03-05 01:40:11 +00:00
|
|
|
var out = [];
|
2018-03-02 17:48:45 +00:00
|
|
|
var map = [ 'pending', 'init', 'start', 'loading', 'creating', 'running', 'paused', 'sleeping', 'shutdown', 'destroyed' ];
|
|
|
|
|
|
|
|
for (var i = 0; i < this.scenes.length; i++)
|
|
|
|
{
|
|
|
|
var sys = this.scenes[i].sys;
|
|
|
|
|
|
|
|
var key = (sys.settings.visible && (sys.settings.status === CONST.RUNNING || sys.settings.status === CONST.PAUSED)) ? '[*] ' : '[-] ';
|
|
|
|
key += sys.settings.key + ' (' + map[sys.settings.status] + ')';
|
|
|
|
|
|
|
|
out.push(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(out.join('\n'));
|
|
|
|
},
|
|
|
|
|
2018-01-16 16:29:58 +00:00
|
|
|
/**
|
2018-04-02 17:01:17 +00:00
|
|
|
* Destroy the SceneManager and all of its Scene's systems.
|
2018-01-16 16:29:58 +00:00
|
|
|
*
|
2018-01-20 04:47:03 +00:00
|
|
|
* @method Phaser.Scenes.SceneManager#destroy
|
2018-01-16 16:29:58 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
destroy: function ()
|
2018-01-16 16:29:58 +00:00
|
|
|
{
|
2018-07-31 10:33:38 +00:00
|
|
|
for (var i = 0; i < this.scenes.length; i++)
|
2018-01-31 03:38:10 +00:00
|
|
|
{
|
|
|
|
var sys = this.scenes[i].sys;
|
|
|
|
|
|
|
|
sys.destroy();
|
|
|
|
}
|
|
|
|
|
2018-04-16 16:02:32 +00:00
|
|
|
this.update = NOOP;
|
|
|
|
|
2018-01-31 03:38:10 +00:00
|
|
|
this.scenes = [];
|
|
|
|
|
|
|
|
this._pending = [];
|
|
|
|
this._start = [];
|
|
|
|
this._queue = [];
|
|
|
|
|
|
|
|
this.game = null;
|
2018-01-16 16:29:58 +00:00
|
|
|
}
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
});
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2018-01-16 16:33:23 +00:00
|
|
|
module.exports = SceneManager;
|