2017-07-04 00:59:31 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// A proxy class to the Global Scene Manager
|
|
|
|
var SceneManager = 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
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function SceneManager (scene, game)
|
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
|
|
|
|
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
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// GlobalSceneManager
|
|
|
|
this.manager = 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
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
update: function ()
|
|
|
|
{
|
|
|
|
var len = this._queue.length;
|
|
|
|
|
|
|
|
if (len === 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var manager = this.manager;
|
|
|
|
|
|
|
|
// Process the queue
|
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
var action = this._queue[i];
|
|
|
|
|
|
|
|
switch (action.type)
|
|
|
|
{
|
2017-07-11 17:54:30 +00:00
|
|
|
case 'add':
|
|
|
|
manager.add(action.key, action.data, action.autoStart);
|
|
|
|
break;
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
case 'start':
|
|
|
|
manager.stop(this.key);
|
|
|
|
manager.start(action.key, action.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'launch':
|
|
|
|
manager.start(action.key, action.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'pause':
|
|
|
|
manager.pause(action.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'resume':
|
|
|
|
manager.resume(action.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'stop':
|
|
|
|
manager.stop(action.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'swap':
|
|
|
|
manager.swap(this.key, action.key);
|
|
|
|
break;
|
|
|
|
|
2017-07-11 15:48:25 +00:00
|
|
|
case 'moveUp':
|
|
|
|
manager.moveUp(this.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'moveDown':
|
|
|
|
manager.moveDown(this.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bringToTop':
|
|
|
|
manager.bringToTop(this.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'sendToBack':
|
|
|
|
manager.sendToBack(this.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'swapPosition':
|
|
|
|
manager.swapPosition(this.key, action.key);
|
|
|
|
break;
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
case 'sleep':
|
|
|
|
manager.sleep(action.key);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'wake':
|
|
|
|
manager.wake(action.key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._queue.length = 0;
|
|
|
|
},
|
|
|
|
|
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; }
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
this._queue.push({ type: 'start', key: key, data: data });
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this._queue.push({ type: 'add', key: key, data: sceneConfig, autoStart: 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)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this._queue.push({ type: 'launch', key: key, data: data });
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
this._queue.push({ type: 'pause', key: key });
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
this._queue.push({ type: 'resume', key: key });
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this._queue.push({ type: 'sleep', key: key });
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this._queue.push({ type: 'wake', key: key });
|
|
|
|
|
|
|
|
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
|
2017-02-08 01:07:01 +00:00
|
|
|
swap: function (key)
|
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
this._queue.push({ type: 'swap', key: key });
|
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; }
|
|
|
|
|
|
|
|
this._queue.push({ type: 'stop', key: key });
|
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
|
|
|
},
|
|
|
|
|
2017-07-11 15:48:25 +00:00
|
|
|
swapPosition: function (key)
|
|
|
|
{
|
|
|
|
this._queue.push({ type: 'swapPosition', key: key });
|
|
|
|
},
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
moveUp: function ()
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
this._queue.push({ type: 'moveUp' });
|
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
moveDown: function ()
|
|
|
|
{
|
|
|
|
this._queue.push({ type: 'moveDown' });
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
bringToTop: function ()
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
this._queue.push({ type: 'bringToTop' });
|
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
sendToBack: function ()
|
|
|
|
{
|
|
|
|
this._queue.push({ type: 'sendToBack' });
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2017-07-05 02:47:32 +00:00
|
|
|
get: function (key)
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
return this.manager.getScene(key);
|
2017-07-05 02:47:32 +00:00
|
|
|
},
|
|
|
|
|
2017-02-08 01:07:01 +00:00
|
|
|
transitionTo: function (key, duration)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
isActive: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isActive(key);
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
});
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
module.exports = SceneManager;
|