phaser/src/scene/ScenePlugin.js

517 lines
11 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 Class = require('../utils/Class');
var CONST = require('./const');
var PluginManager = require('../boot/PluginManager');
2018-02-12 16:18:34 +00:00
/**
* @classdesc
* A proxy class to the Global Scene Manager.
*
* @class ScenePlugin
* @memberOf Phaser.Scenes
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var ScenePlugin = new Class({
initialize:
function ScenePlugin (scene)
{
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
2018-01-16 02:08:22 +00:00
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
2018-01-16 02:08:22 +00:00
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#settings
* @type {object}
* @since 3.0.0
*/
this.settings = scene.sys.settings;
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#key
* @type {string}
* @since 3.0.0
*/
this.key = scene.sys.settings.key;
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#manager
* @type {Phaser.Scenes.SceneManager}
* @since 3.0.0
*/
this.manager = scene.sys.game.scene;
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#boot
* @since 3.0.0
*/
2018-01-16 02:08:22 +00:00
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
2018-01-16 02:08:22 +00:00
},
2018-02-12 16:18:34 +00:00
/**
* Shutdown this Scene and run the given one.
*
* @method Phaser.Scenes.ScenePlugin#start
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} [data] - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
2018-02-22 11:34:19 +00:00
start: function (key, data)
{
if (key === undefined) { key = this.key; }
if (key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('stop', this.key);
this.manager.queueOp('start', key);
}
else
{
this.manager.stop(this.key);
2018-02-22 11:34:19 +00:00
this.manager.start(key, data);
}
}
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set.
*
* @method Phaser.Scenes.ScenePlugin#add
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} sceneConfig - [description]
* @param {boolean} autoStart - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
add: function (key, sceneConfig, autoStart)
{
this.manager.add(key, sceneConfig, autoStart);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Launch the given Scene and run it in parallel with this one.
*
* @method Phaser.Scenes.ScenePlugin#launch
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} [data] - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
2018-02-22 11:34:19 +00:00
launch: function (key, data)
{
if (key && key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('start', key, data);
}
else
{
2018-02-22 11:34:19 +00:00
this.manager.start(key, data);
}
}
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Pause the Scene - this stops the update step from happening but it still renders.
*
* @method Phaser.Scenes.ScenePlugin#pause
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
pause: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.pause(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Resume the Scene - starts the update loop again.
*
* @method Phaser.Scenes.ScenePlugin#resume
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
resume: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.resume(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Makes the Scene sleep (no update, no render) but doesn't shutdown.
*
* @method Phaser.Scenes.ScenePlugin#sleep
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sleep: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sleep(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Makes the Scene wake-up (starts update and render)
*
* @method Phaser.Scenes.ScenePlugin#wake
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
wake: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.wake(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Makes this Scene sleep then starts the Scene given.
*
* @method Phaser.Scenes.ScenePlugin#switch
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
switch: function (key)
{
if (key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('switch', this.key, key);
}
else
{
this.manager.switch(this.key, key);
}
}
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Shutdown the Scene, clearing display list, timers, etc.
*
* @method Phaser.Scenes.ScenePlugin#stop
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
stop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.stop(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Sets the active state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setActive
* @since 3.0.0
*
* @param {boolean} value - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setActive: function (value)
{
this.settings.active = value;
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Sets the visible state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setVisible
* @since 3.0.0
*
* @param {boolean} value - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
2018-02-12 16:18:34 +00:00
/**
* Checks if the given Scene is sleeping or not?
*
* @method Phaser.Scenes.ScenePlugin#isSleeping
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isSleeping: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isSleeping(key);
},
2018-02-12 16:18:34 +00:00
/**
* Checks if the given Scene is active or not?
*
* @method Phaser.Scenes.ScenePlugin#isActive
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
},
2018-02-12 16:18:34 +00:00
/**
* Checks if the given Scene is visible or not?
*
* @method Phaser.Scenes.ScenePlugin#isVisible
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isVisible: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isVisible(key);
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#swapPosition
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
swapPosition: function (key)
{
if (key && key !== this.key)
{
this.manager.swapPosition(this.key, key);
}
return this;
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#moveUp
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveUp: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveUp(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#moveDown
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveDown: function (key)
2017-07-05 02:47:32 +00:00
{
if (key === undefined) { key = this.key; }
this.manager.moveDown(key);
return this;
2017-07-05 02:47:32 +00:00
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#bringToTop
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
bringToTop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.bringToTop(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#sendToBack
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sendToBack: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sendToBack(key);
return this;
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#get
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scene} [description]
*/
get: function (key)
{
return this.manager.getScene(key);
2018-01-16 02:08:22 +00:00
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#shutdown
* @since 3.0.0
*/
2018-01-16 02:08:22 +00:00
shutdown: function ()
{
// TODO
2018-01-16 02:08:22 +00:00
},
2018-02-12 16:18:34 +00:00
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#destroy
* @since 3.0.0
*/
2018-01-16 02:08:22 +00:00
destroy: function ()
{
// TODO
}
});
PluginManager.register('ScenePlugin', ScenePlugin, 'scenePlugin');
2018-01-16 02:08:22 +00:00
module.exports = ScenePlugin;