Skip to content

Commit f666350

Browse files
committed
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.
1 parent 33c2ec7 commit f666350

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'fc3fb9b0-5b9c-11e7-83e9-87986ed5c5cd'
2+
build: '905ea200-5ba2-11e7-8485-252c432813f8'
33
};
44
module.exports = CHECKSUM;

v3/src/state/GlobalStateManager.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ GlobalStateManager.prototype = {
9393
{
9494
if (!key) { key = 'default'; }
9595

96-
if (stateConfig instanceof State)
96+
if (typeof stateConfig === 'function')
97+
{
98+
return key;
99+
}
100+
else if (stateConfig instanceof State)
97101
{
98102
key = stateConfig.settings.key;
99103
}
@@ -138,7 +142,7 @@ GlobalStateManager.prototype = {
138142
autoStart: autoStart
139143
});
140144

141-
console.log('GlobalStateManager not yet booted, adding to list', this._pending.length);
145+
// console.log('GlobalStateManager not yet booted, adding to list', this._pending.length);
142146

143147
return;
144148
}
@@ -152,6 +156,7 @@ GlobalStateManager.prototype = {
152156
if (stateConfig instanceof State)
153157
{
154158
// console.log('GlobalStateManager.add from instance:', key);
159+
155160
newState = this.createStateFromInstance(key, stateConfig);
156161
}
157162
else if (typeof stateConfig === 'object')
@@ -169,6 +174,9 @@ GlobalStateManager.prototype = {
169174
newState = this.createStateFromFunction(key, stateConfig);
170175
}
171176

177+
// Replace key incase the state changed it
178+
key = newState.settings.key;
179+
172180
this.keys[key] = newState;
173181

174182
this.states.push(newState);
@@ -216,6 +224,13 @@ GlobalStateManager.prototype = {
216224

217225
if (newState instanceof State)
218226
{
227+
key = newState.sys.settings.key;
228+
229+
if (this.keys.hasOwnProperty(key))
230+
{
231+
throw new Error('Cannot add a State with duplicate key: ' + key);
232+
}
233+
219234
return this.createStateFromInstance(key, newState);
220235
}
221236
else
@@ -382,6 +397,8 @@ GlobalStateManager.prototype = {
382397

383398
var state = this.getState(key);
384399

400+
// console.log(state);
401+
385402
if (state)
386403
{
387404
// Already started? Nothing more to do here ...

0 commit comments

Comments
 (0)