Skip to content

Instantly share code, notes, and snippets.

@neilmanuell
Created June 12, 2012 11:35
Show Gist options
  • Save neilmanuell/2917012 to your computer and use it in GitHub Desktop.
Save neilmanuell/2917012 to your computer and use it in GitHub Desktop.
FSM for a latchable door
private function configProcesses():void
{
// LOCK Process
fsmConfig.configureProcess( LOCK )
.ifCurrentState( CLOSED )
.transitionTo( LOCK );
fsmConfig.configureProcess( LOCK )
.ifCurrentState( OPENED )
.transitionTo( CLOSED, LOCK );
fsmConfig.configureProcess( LOCK )
.ifCurrentState( LATCHED )
.transitionTo( OPENED, CLOSED, LOCK );
// CLOSE Process
fsmConfig.configureProcess( CLOSE )
.ifCurrentState( OPENED )
.transitionTo( CLOSED );
fsmConfig.configureProcess( CLOSE )
.ifCurrentState( LATCHED )
.transitionTo( OPENED, CLOSED );
// OPEN Process
fsmConfig.configureProcess( OPEN )
.ifCurrentState( LOCKED )
.transitionTo( CLOSED, OPENED );
fsmConfig.configureProcess( OPEN )
.ifCurrentState( CLOSED )
.transitionTo( OPENED );
// LATCH Process
fsmConfig.configureProcess( LATCH )
.ifCurrentState( OPENED )
.transitionTo( LATCHED );
fsmConfig.configureProcess( LATCH )
.ifCurrentState( CLOSED )
.transitionTo( OPENED, LATCHED );
fsmConfig.configureProcess( LATCH )
.ifCurrentState( LOCKED )
.transitionTo( CLOSED, OPENED, LATCHED );
}
private function configStates():void
{
fsmConfig.configureState( LOCKED )
.withEnteringGuards( OnlyIfKeyFits )
.withExitingGuards( OnlyIfKeyFits )
.withTransitionTargets( CLOSED );
fsmConfig.configureState( CLOSED )
.withTransitionTargets( LOCKED, OPENED );
fsmConfig.configureState( OPENED )
.withTransitionTargets( CLOSED, LATCHED );
fsmConfig.configureState( LATCHED )
.withTransitionTargets( OPENED );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment