phaser/v3/src/state/GlobalStateManager.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

var Components = require('./components/');
var Class = require('../utils/Class');
2016-11-29 13:01:16 +00:00
var GlobalStateManager = new Class({
2016-11-29 13:01:16 +00:00
initialize:
2016-11-29 13:01:16 +00:00
function GlobalStateManager (game, stateConfig)
{
this.game = game;
2016-11-29 13:01:16 +00:00
// Everything kept in here
this.keys = {};
this.states = [];
2016-11-29 13:01:16 +00:00
// Only active states are kept in here. They are moved here when started, and moved out when not.
// All states are stored in the states array, regardless of being active or not.
this.active = [];
// A state pending to be added to the State Manager is stored in here until the manager has time to add it.
this._pending = [];
// An array of states waiting to be started once the game has booted
this._start = [];
if (stateConfig)
2016-11-29 13:01:16 +00:00
{
if (Array.isArray(stateConfig))
{
for (var i = 0; i < stateConfig.length; i++)
{
// The i === 0 part just starts the first State given
this._pending.push({
index: i,
key: 'default',
state: stateConfig[i],
autoStart: (i === 0),
data: {}
});
}
}
else
2016-11-29 13:01:16 +00:00
{
this._pending.push({
index: 0,
key: 'default',
state: stateConfig,
autoStart: true,
2017-02-16 17:18:50 +00:00
data: {}
});
2016-11-29 13:01:16 +00:00
}
}
},
2016-11-29 13:01:16 +00:00
add: Components.Add,
boot: Components.Boot,
bootState: Components.BootState,
bringToTop: Components.BringToTop,
create: Components.Create,
createStateDisplay: Components.CreateStateDisplay,
createStateFromFunction: Components.CreateStateFromFunction,
createStateFromInstance: Components.CreateStateFromInstance,
createStateFromObject: Components.CreateStateFromObject,
getActiveState: Components.GetActiveState,
getActiveStateIndex: Components.GetActiveStateIndex,
getActiveStateIndexByKey: Components.GetActiveStateIndexByKey,
getKey: Components.GetKey,
getState: Components.GetState,
getStateAt: Components.GetStateAt,
getStateIndex: Components.GetStateIndex,
getStateIndexByKey: Components.GetStateIndexByKey,
isActive: Components.IsActive,
isSleeping: Components.IsSleeping,
loadComplete: Components.LoadComplete,
moveDown: Components.MoveDown,
moveUp: Components.MoveUp,
pause: Components.Pause,
payloadComplete: Components.PayloadComplete,
resume: Components.Resume,
sendToBack: Components.SendToBack,
setupCallbacks: Components.SetupCallbacks,
sleep: Components.Sleep,
start: Components.Start,
stop: Components.Stop,
swap: Components.Swap,
swapPosition: Components.SwapPosition,
wake: Components.Wake
2016-11-29 13:01:16 +00:00
});
2016-11-29 13:01:16 +00:00
module.exports = GlobalStateManager;