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.
This commit is contained in:
Richard Davey 2017-06-30 00:32:18 +01:00
parent 58ed6e51ce
commit a27d42bc13
7 changed files with 59 additions and 37 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '0a9c3370-5ce3-11e7-886b-43134c9cdc6e'
build: '0d93fb90-5d23-11e7-a642-d974c901baec'
};
module.exports = CHECKSUM;

View file

@ -67,7 +67,7 @@ BaseLoader.prototype = {
start: function ()
{
console.log(this.state.settings.key, '- BaseLoader start. Files to load:', this.list.size);
console.log(this.state.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size);
if (!this.isReady())
{
@ -247,7 +247,7 @@ BaseLoader.prototype = {
processComplete: function ()
{
console.log(this.state.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
console.log(this.state.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
this.list.clear();
this.inflight.clear();

View file

@ -99,7 +99,7 @@ GlobalStateManager.prototype = {
}
else if (stateConfig instanceof State)
{
key = stateConfig.settings.key;
key = stateConfig.sys.settings.key;
}
else if (typeof stateConfig === 'object' && stateConfig.hasOwnProperty('key'))
{
@ -175,13 +175,13 @@ GlobalStateManager.prototype = {
}
// Replace key incase the state changed it
key = newState.settings.key;
key = newState.sys.settings.key;
this.keys[key] = newState;
this.states.push(newState);
if (autoStart || newState.settings.active)
if (autoStart || newState.sys.settings.active)
{
if (this.game.isBooted)
{
@ -198,7 +198,7 @@ GlobalStateManager.prototype = {
createStateFromInstance: function (key, newState)
{
newState.settings.key = key;
newState.sys.settings.key = key;
newState.sys.init(this.game);
@ -298,7 +298,7 @@ GlobalStateManager.prototype = {
createStateDisplay: function (state)
{
// console.log('createStateDisplay', state.settings.key);
// console.log('createStateDisplay', state.sys.settings.key);
var settings = state.sys.settings;
@ -366,7 +366,7 @@ GlobalStateManager.prototype = {
{
var state = this.getState(key);
return (state && state.settings.active && this.active.indexOf(state) !== -1);
return (state && state.sys.settings.active && this.active.indexOf(state) !== -1);
},
start: function (key, data)
@ -407,9 +407,9 @@ GlobalStateManager.prototype = {
return;
}
state.settings.active = true;
state.sys.settings.active = true;
state.settings.data = data;
state.sys.settings.data = data;
var loader = state.sys.load;
@ -524,7 +524,7 @@ GlobalStateManager.prototype = {
{
var state = this.getState(key);
state.settings.active = false;
state.sys.settings.active = false;
this.active.splice(index, 1);

View file

@ -0,0 +1,30 @@
// These properties get injected into the State and map to local systems
// The key is the local system reference, the value is the property that is added to the State
// These can be modified via the config object
var InjectionMap = {
game: 'game',
anims: 'anims',
cache: 'cache',
input: 'input',
registry: 'registry',
textures: 'textures',
add: 'add',
cameras: 'cameras',
events: 'events',
load: 'load',
make: 'make',
stateManager: 'state',
time: 'time',
tweens: 'tweens',
children: 'children',
color: 'color',
data: 'data'
};
module.exports = InjectionMap;

View file

@ -1,6 +1,7 @@
var CONST = require('./const');
var ScaleModes = require('../renderer/ScaleModes');
var GetValue = require('../utils/object/GetValue');
var InjectionMap = require('./InjectionMap');
var Settings = {
@ -22,7 +23,7 @@ var Settings = {
op: CONST.BOOT,
key: GetValue(config, 'key', ''),
key: GetValue(config, 'key', 'default'),
active: GetValue(config, 'active', false),
visible: GetValue(config, 'visible', true),
@ -36,6 +37,10 @@ var Settings = {
cameras: GetValue(config, 'cameras', null),
// State Property Injection Map
map: GetValue(config, 'map', InjectionMap),
// State Render Settings (applies only to this State)
scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT),

View file

@ -16,12 +16,8 @@ var State = function (config)
{
// The State Systems. You must never overwrite this property, or all hell will break lose.
this.sys = new Systems(this, config);
this.settings = this.sys.settings;
};
State.prototype.constructor = State;
State.prototype = {
// Should be overridden by your own States
@ -36,4 +32,6 @@ State.prototype = {
};
State.prototype.constructor = State;
module.exports = State;

View file

@ -92,28 +92,17 @@ Systems.prototype = {
inject: function ()
{
// Defaults properties injected into the State
var map = this.settings.map;
this.state.game = this.game;
for (var key in map)
{
if (key === 'sys')
{
continue;
}
this.state.anims = this.anims;
this.state.cache = this.cache;
this.state.input = this.input;
this.state.registry = this.registry;
this.state.textures = this.textures;
this.state.add = this.add;
this.state.cameras = this.cameras;
this.state.events = this.events;
this.state.load = this.load;
this.state.make = this.make;
this.state.state = this.stateManager;
this.state.time = this.time;
this.state.tweens = this.tweens;
this.state.children = this.children;
this.state.color = this.color;
this.state.data = this.data;
this.state[map[key]] = this[key];
}
},
step: function (time, delta)