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');
|
2018-01-23 02:12:33 +00:00
|
|
|
var CONST = require('./const');
|
2018-01-16 19:49:13 +00:00
|
|
|
var PluginManager = require('../plugins/PluginManager');
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// A proxy class to the Global Scene Manager
|
2018-01-18 05:20:00 +00:00
|
|
|
var ScenePlugin = new Class({
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
initialize:
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
function ScenePlugin (scene)
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// The Scene that owns this plugin
|
|
|
|
this.scene = scene;
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
if (!scene.sys.settings.isBooted)
|
|
|
|
{
|
|
|
|
scene.sys.events.once('boot', this.boot, this);
|
|
|
|
}
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.settings = scene.sys.settings;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.key = scene.sys.settings.key;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
// SceneManager
|
2017-08-15 22:37:38 +00:00
|
|
|
this.manager = scene.sys.game.scene;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
// Private
|
|
|
|
this._queue = [];
|
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
boot: function ()
|
|
|
|
{
|
2018-01-18 14:00:31 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Shutdown this Scene and run the given one
|
2017-02-17 02:07:56 +00:00
|
|
|
start: function (key, data)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key !== this.key)
|
|
|
|
{
|
2018-01-23 02:12:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// 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)
|
2017-07-11 17:54:30 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.add(key, sceneConfig, autoStart);
|
2017-07-11 17:54:30 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Launch the given Scene and run it in parallel with this one
|
2017-06-30 02:31:31 +00:00
|
|
|
launch: function (key, data)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key && key !== this.key)
|
|
|
|
{
|
2018-01-23 02:12:33 +00:00
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
|
|
|
{
|
|
|
|
this.manager.queueOp('start', key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.manager.start(key);
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Pause the Scene - this stops the update step from happening but it still renders
|
2017-02-08 01:07:01 +00:00
|
|
|
pause: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.pause(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Resume the Scene - starts the update loop again
|
2017-06-30 02:31:31 +00:00
|
|
|
resume: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.resume(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Makes the Scene sleep (no update, no render) but doesn't shutdown
|
2017-06-30 02:31:31 +00:00
|
|
|
sleep: function (key)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.sleep(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Makes the Scene wake-up (starts update and render)
|
2017-06-30 02:31:31 +00:00
|
|
|
wake: function (key)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.wake(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Makes this Scene sleep then starts the Scene given
|
2018-01-20 04:47:03 +00:00
|
|
|
switch: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key !== this.key)
|
|
|
|
{
|
2018-01-23 02:12:33 +00:00
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
|
|
|
{
|
|
|
|
this.manager.queueOp('switch', this.key, key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.manager.switch(this.key, key);
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Shutdown the Scene, clearing display list, timers, etc
|
2017-06-30 02:31:31 +00:00
|
|
|
stop: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.stop(key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setActive: function (value)
|
|
|
|
{
|
|
|
|
this.settings.active = value;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
setVisible: function (value)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
this.settings.visible = value;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
isSleeping: function (key)
|
2017-07-11 15:48:25 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isSleeping(key);
|
2017-07-11 15:48:25 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
isActive: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isActive(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
isVisible: function (key)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isVisible(key);
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
swapPosition: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key && key !== this.key)
|
|
|
|
{
|
|
|
|
this.manager.swapPosition(this.key, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
moveUp: function (key)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.moveUp(key);
|
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
moveDown: function (key)
|
2017-07-05 02:47:32 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.moveDown(key);
|
|
|
|
|
|
|
|
return this;
|
2017-07-05 02:47:32 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
bringToTop: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.bringToTop(key);
|
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
sendToBack: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.sendToBack(key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function (key)
|
|
|
|
{
|
|
|
|
return this.manager.getScene(key);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
2018-01-18 05:20:00 +00:00
|
|
|
// TODO
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-01-18 05:20:00 +00:00
|
|
|
// TODO
|
2017-02-08 01:07:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
});
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
PluginManager.register('ScenePlugin', ScenePlugin, 'scenePlugin');
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
module.exports = ScenePlugin;
|