src/FSM.js
/**
 * A Finite State Machine.
 *
 * @param {Object} host
 * @param {Array} states a list where even positions are identifiers with a
 *			value that is position / 2 and odd positions are state classes.
 * @param {Function} [onStateChange] a callback function that will be called when
 *			the state changes.
 */
A Finite State Machine.
@param {Object} host
@param {Array} states a list where even positions are identifiers with a
value that is position / 2 and odd positions are state classes.
@param {Function} [onStateChange] a callback function that will be called when
the state changes.
A Finite State Machine . @param { Object } host @param { Array } states a list where even positions are identifiers with a value that is position / 2 and odd positions are state classes . @param { Function } [ onStateChange ] a callback function that will be called when the state changes .
function FSM(host, states, onStateChange) {
	if (host === undefined) return;
	this.host = host;
	this.onStateChange = onStateChange;
	this.stateArray = [];
	for (var i = 0; i < states.length; i += 2) {
		if(states[i+1] instanceof SimpleState)
			this.stateArray[states[i]] = states[i+1];
		else
			this.stateArray[states[i]] = new states[i + 1](host, this, states[i]);
	}
	this.currentState = fsmStates.kNoState;
	this.numSuspended = 0;
	this.suspendedArray = [];
	this.numPreloaded = 0;
	this.preloadedArray = [];
	this.numStates = this.stateArray.length;
}
function FSM ( host , states , onStateChange ) { if ( host === undefined ) return ; this . host = host ; this . onStateChange = onStateChange ; this . stateArray = [ ] ; for ( var i = 0 ; i < states . length ; i += 2 ) { if ( states [ i + 1 ] instanceof SimpleState ) this . stateArray [ states [ i ] ] = states [ i + 1 ] ; else this . stateArray [ states [ i ] ] = new states [ i + 1 ] ( host , this , states [ i ] ) ; } this . currentState = fsmStates . kNoState ; this . numSuspended = 0 ; this . suspendedArray = [ ] ; this . numPreloaded = 0 ; this . preloadedArray = [ ] ; this . numStates = this . stateArray . length ; }
A Finite State Machine.
A Finite State Machine .
//assert(states[i] == i / 2 && typeof (states[i + 1]) == "function", "State " + i / 2 //		+ " did not initialize correctly.");