2017-07-11 15:48:25 +00:00
|
|
|
var Components = require('./components/');
|
2017-07-04 12:58:45 +00:00
|
|
|
var Class = require('../utils/Class');
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
var GlobalSceneManager = 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
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function GlobalSceneManager (game, sceneConfig)
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
|
|
|
this.game = game;
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
// Everything kept in here
|
|
|
|
this.keys = {};
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scenes = [];
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Only active scenes are kept in here. They are moved here when started, and moved out when not.
|
|
|
|
// All scenes are stored in the scenes array, regardless of being active or not.
|
2017-07-04 12:58:45 +00:00
|
|
|
this.active = [];
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// A scene pending to be added to the Scene Manager is stored in here until the manager has time to add it.
|
2017-07-04 12:58:45 +00:00
|
|
|
this._pending = [];
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// An array of scenes waiting to be started once the game has booted
|
2017-07-11 15:48:25 +00:00
|
|
|
this._start = [];
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (sceneConfig)
|
2016-11-29 13:01:16 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
if (Array.isArray(sceneConfig))
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
for (var i = 0; i < sceneConfig.length; i++)
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// The i === 0 part just starts the first Scene given
|
2017-07-04 12:58:45 +00:00
|
|
|
this._pending.push({
|
|
|
|
index: i,
|
|
|
|
key: 'default',
|
2017-07-14 13:30:20 +00:00
|
|
|
scene: sceneConfig[i],
|
2017-07-04 12:58:45 +00:00
|
|
|
autoStart: (i === 0),
|
|
|
|
data: {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-11-29 13:01:16 +00:00
|
|
|
{
|
2016-11-29 15:25:14 +00:00
|
|
|
this._pending.push({
|
2017-07-04 12:58:45 +00:00
|
|
|
index: 0,
|
2016-11-29 15:25:14 +00:00
|
|
|
key: 'default',
|
2017-07-14 13:30:20 +00:00
|
|
|
scene: sceneConfig,
|
2017-07-04 12:58:45 +00:00
|
|
|
autoStart: true,
|
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
|
|
|
}
|
|
|
|
}
|
2017-07-04 12:58:45 +00:00
|
|
|
},
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-11 15:48:25 +00:00
|
|
|
add: Components.Add,
|
2017-07-11 17:18:31 +00:00
|
|
|
boot: Components.Boot,
|
2017-07-14 13:30:20 +00:00
|
|
|
bootScene: Components.BootScene,
|
2017-07-11 17:18:31 +00:00
|
|
|
bringToTop: Components.BringToTop,
|
|
|
|
create: Components.Create,
|
2017-07-14 13:30:20 +00:00
|
|
|
createSceneDisplay: Components.CreateSceneDisplay,
|
|
|
|
createSceneFromFunction: Components.CreateSceneFromFunction,
|
|
|
|
createSceneFromInstance: Components.CreateSceneFromInstance,
|
|
|
|
createSceneFromObject: Components.CreateSceneFromObject,
|
|
|
|
getActiveScene: Components.GetActiveScene,
|
|
|
|
getActiveSceneIndex: Components.GetActiveSceneIndex,
|
|
|
|
getActiveSceneIndexByKey: Components.GetActiveSceneIndexByKey,
|
2017-07-11 17:18:31 +00:00
|
|
|
getKey: Components.GetKey,
|
2017-07-14 13:30:20 +00:00
|
|
|
getScene: Components.GetScene,
|
|
|
|
getSceneAt: Components.GetSceneAt,
|
|
|
|
getSceneIndex: Components.GetSceneIndex,
|
|
|
|
getSceneIndexByKey: Components.GetSceneIndexByKey,
|
2017-07-11 15:48:25 +00:00
|
|
|
isActive: Components.IsActive,
|
2017-07-11 17:18:31 +00:00
|
|
|
isSleeping: Components.IsSleeping,
|
2017-07-11 15:48:25 +00:00
|
|
|
loadComplete: Components.LoadComplete,
|
2017-07-11 17:18:31 +00:00
|
|
|
moveDown: Components.MoveDown,
|
|
|
|
moveUp: Components.MoveUp,
|
2017-07-11 15:48:25 +00:00
|
|
|
pause: Components.Pause,
|
2017-07-11 17:18:31 +00:00
|
|
|
payloadComplete: Components.PayloadComplete,
|
2017-07-11 15:48:25 +00:00
|
|
|
resume: Components.Resume,
|
2017-07-11 17:18:31 +00:00
|
|
|
sendToBack: Components.SendToBack,
|
|
|
|
setupCallbacks: Components.SetupCallbacks,
|
2017-07-11 15:48:25 +00:00
|
|
|
sleep: Components.Sleep,
|
2017-07-11 17:18:31 +00:00
|
|
|
start: Components.Start,
|
2017-07-11 15:48:25 +00:00
|
|
|
stop: Components.Stop,
|
2017-07-11 17:18:31 +00:00
|
|
|
swap: Components.Swap,
|
2017-07-11 15:48:25 +00:00
|
|
|
swapPosition: Components.SwapPosition,
|
2017-07-11 17:18:31 +00:00
|
|
|
wake: Components.Wake
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
});
|
2016-11-29 13:01:16 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
module.exports = GlobalSceneManager;
|