mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Updated the State Manager to support extended States
Can now pass in Phaser.State extended classes and it will extract the keys and configure them correctly.
This commit is contained in:
parent
33c2ec79ab
commit
f6663503f4
2 changed files with 20 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'fc3fb9b0-5b9c-11e7-83e9-87986ed5c5cd'
|
||||
build: '905ea200-5ba2-11e7-8485-252c432813f8'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -93,7 +93,11 @@ GlobalStateManager.prototype = {
|
|||
{
|
||||
if (!key) { key = 'default'; }
|
||||
|
||||
if (stateConfig instanceof State)
|
||||
if (typeof stateConfig === 'function')
|
||||
{
|
||||
return key;
|
||||
}
|
||||
else if (stateConfig instanceof State)
|
||||
{
|
||||
key = stateConfig.settings.key;
|
||||
}
|
||||
|
@ -138,7 +142,7 @@ GlobalStateManager.prototype = {
|
|||
autoStart: autoStart
|
||||
});
|
||||
|
||||
console.log('GlobalStateManager not yet booted, adding to list', this._pending.length);
|
||||
// console.log('GlobalStateManager not yet booted, adding to list', this._pending.length);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -152,6 +156,7 @@ GlobalStateManager.prototype = {
|
|||
if (stateConfig instanceof State)
|
||||
{
|
||||
// console.log('GlobalStateManager.add from instance:', key);
|
||||
|
||||
newState = this.createStateFromInstance(key, stateConfig);
|
||||
}
|
||||
else if (typeof stateConfig === 'object')
|
||||
|
@ -169,6 +174,9 @@ GlobalStateManager.prototype = {
|
|||
newState = this.createStateFromFunction(key, stateConfig);
|
||||
}
|
||||
|
||||
// Replace key incase the state changed it
|
||||
key = newState.settings.key;
|
||||
|
||||
this.keys[key] = newState;
|
||||
|
||||
this.states.push(newState);
|
||||
|
@ -216,6 +224,13 @@ GlobalStateManager.prototype = {
|
|||
|
||||
if (newState instanceof State)
|
||||
{
|
||||
key = newState.sys.settings.key;
|
||||
|
||||
if (this.keys.hasOwnProperty(key))
|
||||
{
|
||||
throw new Error('Cannot add a State with duplicate key: ' + key);
|
||||
}
|
||||
|
||||
return this.createStateFromInstance(key, newState);
|
||||
}
|
||||
else
|
||||
|
@ -382,6 +397,8 @@ GlobalStateManager.prototype = {
|
|||
|
||||
var state = this.getState(key);
|
||||
|
||||
// console.log(state);
|
||||
|
||||
if (state)
|
||||
{
|
||||
// Already started? Nothing more to do here ...
|
||||
|
|
Loading…
Reference in a new issue