2017-08-18 00:42:14 +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-09-13 13:17:38 +00:00
|
|
|
add: require('./inc/Add'),
|
|
|
|
boot: require('./inc/Boot'),
|
|
|
|
bootScene: require('./inc/BootScene'),
|
|
|
|
bringToTop: require('./inc/BringToTop'),
|
|
|
|
create: require('./inc/Create'),
|
|
|
|
createSceneDisplay: require('./inc/CreateSceneDisplay'),
|
|
|
|
createSceneFromFunction: require('./inc/CreateSceneFromFunction'),
|
|
|
|
createSceneFromInstance: require('./inc/CreateSceneFromInstance'),
|
|
|
|
createSceneFromObject: require('./inc/CreateSceneFromObject'),
|
|
|
|
getActiveScene: require('./inc/GetActiveScene'),
|
|
|
|
getActiveSceneIndex: require('./inc/GetActiveSceneIndex'),
|
|
|
|
getActiveSceneIndexByKey: require('./inc/GetActiveSceneIndexByKey'),
|
|
|
|
getKey: require('./inc/GetKey'),
|
|
|
|
getScene: require('./inc/GetScene'),
|
|
|
|
getSceneAt: require('./inc/GetSceneAt'),
|
|
|
|
getSceneIndex: require('./inc/GetSceneIndex'),
|
|
|
|
getSceneIndexByKey: require('./inc/GetSceneIndexByKey'),
|
|
|
|
isActive: require('./inc/IsActive'),
|
|
|
|
isSleeping: require('./inc/IsSleeping'),
|
|
|
|
loadComplete: require('./inc/LoadComplete'),
|
|
|
|
moveDown: require('./inc/MoveDown'),
|
|
|
|
moveUp: require('./inc/MoveUp'),
|
|
|
|
pause: require('./inc/Pause'),
|
|
|
|
payloadComplete: require('./inc/PayloadComplete'),
|
|
|
|
resume: require('./inc/Resume'),
|
|
|
|
sendToBack: require('./inc/SendToBack'),
|
|
|
|
sleep: require('./inc/Sleep'),
|
|
|
|
start: require('./inc/Start'),
|
|
|
|
stop: require('./inc/Stop'),
|
|
|
|
swap: require('./inc/Swap'),
|
|
|
|
swapPosition: require('./inc/SwapPosition'),
|
|
|
|
wake: require('./inc/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;
|