From f6663503f4df1d68b224d9395f6b95844c262d20 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 28 Jun 2017 02:49:38 +0100 Subject: [PATCH] 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. --- v3/src/checksum.js | 2 +- v3/src/state/GlobalStateManager.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 280f379c8..eef250397 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: 'fc3fb9b0-5b9c-11e7-83e9-87986ed5c5cd' +build: '905ea200-5ba2-11e7-8485-252c432813f8' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/state/GlobalStateManager.js b/v3/src/state/GlobalStateManager.js index 02704d1ac..17ad37213 100644 --- a/v3/src/state/GlobalStateManager.js +++ b/v3/src/state/GlobalStateManager.js @@ -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 ...