phaser/src/scene/ScenePlugin.js

264 lines
5.4 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');
2018-01-16 19:49:13 +00:00
var PluginManager = require('../plugins/PluginManager');
// A proxy class to the Global Scene Manager
var ScenePlugin = new Class({
initialize:
function ScenePlugin (scene)
{
// The Scene that owns this plugin
this.scene = scene;
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
this.settings = scene.sys.settings;
this.key = scene.sys.settings.key;
// SceneManager
this.manager = scene.sys.game.scene;
// Private
this._queue = [];
},
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
},
// Shutdown this Scene and run the given one
2017-02-17 02:07:56 +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);
this.manager.start(key);
}
}
return this;
},
// Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set
add: function (key, sceneConfig, autoStart)
{
this.manager.add(key, sceneConfig, autoStart);
return this;
},
// Launch the given Scene and run it in parallel with this one
launch: function (key, data)
{
if (key && key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('start', key);
}
else
{
this.manager.start(key);
}
}
return this;
},
// Pause the Scene - this stops the update step from happening but it still renders
pause: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.pause(key);
return this;
},
// Resume the Scene - starts the update loop again
resume: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.resume(key);
return this;
},
// Makes the Scene sleep (no update, no render) but doesn't shutdown
sleep: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sleep(key);
return this;
},
// Makes the Scene wake-up (starts update and render)
wake: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.wake(key);
return this;
},
// Makes this Scene sleep then starts the Scene given
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;
},
// Shutdown the Scene, clearing display list, timers, etc
stop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.stop(key);
return this;
},
setActive: function (value)
{
this.settings.active = value;
return this;
},
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
isSleeping: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isSleeping(key);
},
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
},
isVisible: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isVisible(key);
},
swapPosition: function (key)
{
if (key && key !== this.key)
{
this.manager.swapPosition(this.key, key);
}
return this;
},
moveUp: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveUp(key);
return this;
},
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
},
bringToTop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.bringToTop(key);
return this;
},
sendToBack: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sendToBack(key);
return this;
},
get: function (key)
{
return this.manager.getScene(key);
2018-01-16 02:08:22 +00:00
},
shutdown: function ()
{
// TODO
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;