var State = require('../State'); var Add = function (key, stateConfig, autoStart){ if (autoStart === undefined) { autoStart = false ; } if (!this.game.isBooted) { this._pending.push({ index: _AN_Read_length('length', this._pending), key: key, state: stateConfig, autoStart: autoStart} ); return ; } key = this.getKey(key, stateConfig); var newState; if (stateConfig instanceof State) { newState = this.createStateFromInstance(key, stateConfig); } else if (typeof stateConfig === 'object') { stateConfig.key = key; newState = this.createStateFromObject(key, stateConfig); } else if (typeof stateConfig === 'function') { newState = this.createStateFromFunction(key, stateConfig); } key = newState.sys.settings.key; this.keys[key] = newState; this.states.push(newState); if (autoStart || newState.sys.settings.active) { if (this.game.isBooted) { this.start(key); } else { this._start.push(key); } } return newState; } ; module.exports = Add;