Skip to content

Commit a27d42b

Browse files
committed
Added State Injection Map
State level properties can now be set and modified via the State config. State.settings removed and all accesses to it moved to sys.settings.
1 parent 58ed6e5 commit a27d42b

7 files changed

Lines changed: 61 additions & 39 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: '0a9c3370-5ce3-11e7-886b-43134c9cdc6e'
2+
build: '0d93fb90-5d23-11e7-a642-d974c901baec'
33
};
44
module.exports = CHECKSUM;

v3/src/loader/BaseLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ BaseLoader.prototype = {
6767

6868
start: function ()
6969
{
70-
console.log(this.state.settings.key, '- BaseLoader start. Files to load:', this.list.size);
70+
console.log(this.state.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size);
7171

7272
if (!this.isReady())
7373
{
@@ -247,7 +247,7 @@ BaseLoader.prototype = {
247247

248248
processComplete: function ()
249249
{
250-
console.log(this.state.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
250+
console.log(this.state.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
251251

252252
this.list.clear();
253253
this.inflight.clear();

v3/src/state/GlobalStateManager.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ GlobalStateManager.prototype = {
9999
}
100100
else if (stateConfig instanceof State)
101101
{
102-
key = stateConfig.settings.key;
102+
key = stateConfig.sys.settings.key;
103103
}
104104
else if (typeof stateConfig === 'object' && stateConfig.hasOwnProperty('key'))
105105
{
@@ -175,13 +175,13 @@ GlobalStateManager.prototype = {
175175
}
176176

177177
// Replace key incase the state changed it
178-
key = newState.settings.key;
178+
key = newState.sys.settings.key;
179179

180180
this.keys[key] = newState;
181181

182182
this.states.push(newState);
183183

184-
if (autoStart || newState.settings.active)
184+
if (autoStart || newState.sys.settings.active)
185185
{
186186
if (this.game.isBooted)
187187
{
@@ -198,7 +198,7 @@ GlobalStateManager.prototype = {
198198

199199
createStateFromInstance: function (key, newState)
200200
{
201-
newState.settings.key = key;
201+
newState.sys.settings.key = key;
202202

203203
newState.sys.init(this.game);
204204

@@ -298,7 +298,7 @@ GlobalStateManager.prototype = {
298298

299299
createStateDisplay: function (state)
300300
{
301-
// console.log('createStateDisplay', state.settings.key);
301+
// console.log('createStateDisplay', state.sys.settings.key);
302302

303303
var settings = state.sys.settings;
304304

@@ -366,7 +366,7 @@ GlobalStateManager.prototype = {
366366
{
367367
var state = this.getState(key);
368368

369-
return (state && state.settings.active && this.active.indexOf(state) !== -1);
369+
return (state && state.sys.settings.active && this.active.indexOf(state) !== -1);
370370
},
371371

372372
start: function (key, data)
@@ -407,9 +407,9 @@ GlobalStateManager.prototype = {
407407
return;
408408
}
409409

410-
state.settings.active = true;
410+
state.sys.settings.active = true;
411411

412-
state.settings.data = data;
412+
state.sys.settings.data = data;
413413

414414
var loader = state.sys.load;
415415

@@ -524,7 +524,7 @@ GlobalStateManager.prototype = {
524524
{
525525
var state = this.getState(key);
526526

527-
state.settings.active = false;
527+
state.sys.settings.active = false;
528528

529529
this.active.splice(index, 1);
530530

v3/src/state/InjectionMap.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// These properties get injected into the State and map to local systems
2+
// The key is the local system reference, the value is the property that is added to the State
3+
// These can be modified via the config object
4+
5+
var InjectionMap = {
6+
7+
game: 'game',
8+
9+
anims: 'anims',
10+
cache: 'cache',
11+
input: 'input',
12+
registry: 'registry',
13+
textures: 'textures',
14+
15+
add: 'add',
16+
cameras: 'cameras',
17+
events: 'events',
18+
load: 'load',
19+
make: 'make',
20+
stateManager: 'state',
21+
time: 'time',
22+
tweens: 'tweens',
23+
24+
children: 'children',
25+
color: 'color',
26+
data: 'data'
27+
28+
};
29+
30+
module.exports = InjectionMap;

v3/src/state/Settings.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var CONST = require('./const');
22
var ScaleModes = require('../renderer/ScaleModes');
33
var GetValue = require('../utils/object/GetValue');
4+
var InjectionMap = require('./InjectionMap');
45

56
var Settings = {
67

@@ -22,7 +23,7 @@ var Settings = {
2223

2324
op: CONST.BOOT,
2425

25-
key: GetValue(config, 'key', ''),
26+
key: GetValue(config, 'key', 'default'),
2627
active: GetValue(config, 'active', false),
2728
visible: GetValue(config, 'visible', true),
2829

@@ -36,6 +37,10 @@ var Settings = {
3637

3738
cameras: GetValue(config, 'cameras', null),
3839

40+
// State Property Injection Map
41+
42+
map: GetValue(config, 'map', InjectionMap),
43+
3944
// State Render Settings (applies only to this State)
4045

4146
scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT),

v3/src/state/State.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ var State = function (config)
1616
{
1717
// The State Systems. You must never overwrite this property, or all hell will break lose.
1818
this.sys = new Systems(this, config);
19-
20-
this.settings = this.sys.settings;
2119
};
2220

23-
State.prototype.constructor = State;
24-
2521
State.prototype = {
2622

2723
// Should be overridden by your own States
@@ -36,4 +32,6 @@ State.prototype = {
3632

3733
};
3834

35+
State.prototype.constructor = State;
36+
3937
module.exports = State;

v3/src/state/Systems.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,17 @@ Systems.prototype = {
9292

9393
inject: function ()
9494
{
95-
// Defaults properties injected into the State
96-
97-
this.state.game = this.game;
98-
99-
this.state.anims = this.anims;
100-
this.state.cache = this.cache;
101-
this.state.input = this.input;
102-
this.state.registry = this.registry;
103-
this.state.textures = this.textures;
104-
105-
this.state.add = this.add;
106-
this.state.cameras = this.cameras;
107-
this.state.events = this.events;
108-
this.state.load = this.load;
109-
this.state.make = this.make;
110-
this.state.state = this.stateManager;
111-
this.state.time = this.time;
112-
this.state.tweens = this.tweens;
113-
114-
this.state.children = this.children;
115-
this.state.color = this.color;
116-
this.state.data = this.data;
95+
var map = this.settings.map;
96+
97+
for (var key in map)
98+
{
99+
if (key === 'sys')
100+
{
101+
continue;
102+
}
103+
104+
this.state[map[key]] = this[key];
105+
}
117106
},
118107

119108
step: function (time, delta)

0 commit comments

Comments
 (0)