- MVCBricks_WEB.zip
- MVCBricks_WEB
- bin
- Content
- images
- Blue.png
- Board.png
- Bob.png
- Cyan.png
- Green.png
- None.png
- Orange.png
- Purple.png
- Red.png
- Thumbs.db
- Title.png
- Yellow.png
- Site.css
- themes
- base
- images
- ui-bg_flat_0_aaaaaa_40x100.png
- ui-bg_flat_75_ffffff_40x100.png
- ui-bg_glass_55_fbf9ee_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_glass_75_dadada_1x400.png
- ui-bg_glass_75_e6e6e6_1x400.png
- ui-bg_glass_95_fef1ec_1x400.png
- ui-bg_highlight-soft_75_cccccc_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_2e83ff_256x240.png
- ui-icons_454545_256x240.png
- ui-icons_888888_256x240.png
- ui-icons_cd0a0a_256x240.png
- jquery-ui.css
- Controllers
- Global.asax
- Global.asax.cs
- Properties
- Scripts
- Views
- Web.config
- Web.Debug.config
- Web.Release.config
- MVCBricks_SRC.zip
- MVCBricks.Core
- MVCBricks.sln
- MVCBricks
- Content
- images
- Blue.png
- Board.png
- Bob.png
- Cyan.png
- Green.png
- None.png
- Orange.png
- Purple.png
- Red.png
- Thumbs.db
- Title.png
- Yellow.png
- Site.css
- themes
- base
- images
- ui-bg_flat_0_aaaaaa_40x100.png
- ui-bg_flat_75_ffffff_40x100.png
- ui-bg_glass_55_fbf9ee_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_glass_75_dadada_1x400.png
- ui-bg_glass_75_e6e6e6_1x400.png
- ui-bg_glass_95_fef1ec_1x400.png
- ui-bg_highlight-soft_75_cccccc_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_2e83ff_256x240.png
- ui-icons_454545_256x240.png
- ui-icons_888888_256x240.png
- ui-icons_cd0a0a_256x240.png
- jquery-ui.css
- Controllers
- Global.asax
- Global.asax.cs
- MVCBricks.csproj
- MVCBricks.csproj.user
- MVCBricks.sln
- MVCBricks.suo
- Properties
- Scripts
- Views
- Web.config
- Web.Debug.config
- Web.Release.config
|
/*
Finite state machine (FSM) library.
A simple finite state machine library for code flow and transition control.
Anthony Blackshaw <ant@getme.co.uk> (www.getme.co.uk)
Copyright (c)2008
Taken from a Python FSM implementation by Noah Spurrier
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146262).
*/
function FSM( initial_state, data ) {
/* Finite State Machine (FSM) class.*/
this.state_transitions = {};
this.state_transitions_any = {};
this.default_transition = null;
this.transition = null;
this.initial_state = initial_state;
this.current_state = this.initial_state;
this.callback = null;
this.data = data;
}
FSM.prototype.reset = function () {
/* Reset the FSM to the initial state. */
this.current_state = this.initial_state;
this.transition = null;
}
FSM.prototype.add_transition = function ( action, state, callback, next_state ) {
/* Add a transition for the input symbol. */
if ( !next_state ) {
next_state = state;
}
this.state_transitions[ [ action, state ] ] = [ callback, next_state ];
}
FSM.prototype.add_transition_list = function ( action_list, state, callback, next_state ) {
/* Add a transition to a list of input symbols. */
if ( !next_state ) {
next_state = state;
}
for ( i = 0; i < action_list; i++ ) {
this.add_transition( action_list[ i ], state, callback, next_state );
}
}
FSM.prototype.add_transition_any = function ( state, callback, next_state ) {
/* Add a transition that is supported by any state. */
if ( !next_state ) {
next_state = state;
}
this.state_transitions_any[ state ] = [ callback, next_state ];
}
FSM.prototype.set_default_transition = function ( callback, next_state ) {
/* Set the default transition for if no transition can be found. */
this.default_transition = ( callback, next_state );
}
FSM.prototype.get_transition = function ( action, state ) {
/* Get the transition for the specified action and state. */
if ( this.state_transitions[ [ action, state ] ] ) {
return this.state_transitions[ [ action, state ] ];
} else if ( this.state_transitions_any[ [ action, state ] ] ) {
return this.state_transitions_any[ [ action, state ] ];
} else if ( this.default_transition ) {
return this.default_transition;
} else {
throw Error( "Transition is undefined: (" + action + ", " + state + ")" );
}
}
FSM.prototype.process = function ( action ) {
/* Process an action. */
this.action = action;
result = this.get_transition( this.action, this.current_state );
this.action = result[0];
if ( this.action ) {
this.action.call( this );
}
this.current_state = result[1];
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.