Drag[en]gine Script Module DragonScript
1.23
|
State machine context. More...
Public Member Functions | |
void | forEachAction (Block ablock) |
Visit actions using block with parameters String (name and SMAction (action). More... | |
void | forEachCondition (Block ablock) |
Visit conditions using block with parameters String (name and SMCondition (condition). More... | |
SMAction | getAction (String name) |
Action for name or null if absent. More... | |
int | getActionCount () |
Count of actions. More... | |
SMCondition | getCondition (String name) |
Condition for name or null if absent. More... | |
int | getConditionCount () |
Count of conditions. More... | |
Console | getConsole () |
Console or null if not wishing to log anything. More... | |
SMState | getCurrentState () |
Current state or null if in transition. More... | |
String | getLoggingName () |
Logging name to tell apart logs. More... | |
bool | getLogStateChanges () |
Log state machine state changes. More... | |
bool | getLogTransitions () |
Log state machine steps. More... | |
StateMachine | getStateMachine () |
State machine. More... | |
bool | hasAction (String name) |
Action is present. More... | |
bool | hasCondition (String name) |
Condition is present. More... | |
SMContext | new (SMContext context) |
Create copy of state machine context. More... | |
SMContext | new (SMContext context, StateMachine stateMachine) |
Create copy of state machine context but using a different state machine. More... | |
SMContext | new (StateMachine stateMachine) |
Create state machine context. More... | |
void | readFromFile (PersistencyEnvironment env, FileReader reader) |
Read state from file. More... | |
void | removeAction (String name) |
Remove action. More... | |
void | removeAllActions () |
Remove all actions. More... | |
void | removeAllConditions () |
Remove all conditions. More... | |
void | removeCondition (String name) |
Remove condition. More... | |
void | reset () |
Reset to initial state. More... | |
void | runEvent (String event) |
Run event on state machine. More... | |
void | setAction (String name, Block action) |
Set action for name using block. More... | |
void | setCondition (String name, Block condition) |
Set condition for name using block. More... | |
void | setConsole (Console console) |
Set console or null if not wishing to log anything. More... | |
void | setCurrentState (SMState state) |
Set current state or null if in transition. More... | |
void | setCurrentStateByID (String id) |
Set current state by identifier or null if in transition. More... | |
void | setLoggingName (String name) |
Set logging name to tell apart logs. More... | |
void | setLogStateChanges (bool logStateChanges) |
Set log state machine state changes. More... | |
void | setLogTransitions (bool logSteps) |
Set log state machine steps. More... | |
void | writeToFile (PersistencyEnvironment env, FileWriter writer) |
Write state to file. More... | |
Protected Member Functions | |
void | onCurrentStateChanged () |
Hook method called if setCurrentState() is called. More... | |
State machine context.
Used to run a state machine instance. The state machine itself is shared across contexts while the individual state is stored in the context. Context has to provide the SMAction instances for the state machine states to call. Subclass the context to provide the required data for your SMAction subclasses to work properly.
After creating the context the initial state is the current state. No enter actions are run on the initial state since during that time no actions and conditions are present yet.
The context can be written to and restored from file readers. This class saves only the current state identifier. Subclass has to save its own states by overwriting readFromFile() and writeToFile().
void Dragengine.StateMachineSystem.SMContext.forEachAction | ( | Block | ablock | ) |
Visit actions using block with parameters String (name and SMAction (action).
void Dragengine.StateMachineSystem.SMContext.forEachCondition | ( | Block | ablock | ) |
Visit conditions using block with parameters String (name and SMCondition (condition).
SMAction Dragengine.StateMachineSystem.SMContext.getAction | ( | String | name | ) |
Action for name or null if absent.
int Dragengine.StateMachineSystem.SMContext.getActionCount | ( | ) |
Count of actions.
SMCondition Dragengine.StateMachineSystem.SMContext.getCondition | ( | String | name | ) |
Condition for name or null if absent.
int Dragengine.StateMachineSystem.SMContext.getConditionCount | ( | ) |
Count of conditions.
Console Dragengine.StateMachineSystem.SMContext.getConsole | ( | ) |
Console or null if not wishing to log anything.
SMState Dragengine.StateMachineSystem.SMContext.getCurrentState | ( | ) |
Current state or null if in transition.
String Dragengine.StateMachineSystem.SMContext.getLoggingName | ( | ) |
Logging name to tell apart logs.
bool Dragengine.StateMachineSystem.SMContext.getLogStateChanges | ( | ) |
Log state machine state changes.
bool Dragengine.StateMachineSystem.SMContext.getLogTransitions | ( | ) |
Log state machine steps.
StateMachine Dragengine.StateMachineSystem.SMContext.getStateMachine | ( | ) |
State machine.
bool Dragengine.StateMachineSystem.SMContext.hasAction | ( | String | name | ) |
Action is present.
bool Dragengine.StateMachineSystem.SMContext.hasCondition | ( | String | name | ) |
Condition is present.
Create copy of state machine context.
Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.
SMContext Dragengine.StateMachineSystem.SMContext.new | ( | SMContext | context, |
StateMachine | stateMachine | ||
) |
Create copy of state machine context but using a different state machine.
Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.
This method is useful to use an initialized base context with a fallback state machine. Whenever a new context is required the base context is copied. This avoids the need to assign actions and conditions since they are copied from the base context.
SMContext Dragengine.StateMachineSystem.SMContext.new | ( | StateMachine | stateMachine | ) |
Create state machine context.
|
protected |
Hook method called if setCurrentState() is called.
Allows subclasses to react to current state changes. This might be required for certain SMAction to reset states if states change.
void Dragengine.StateMachineSystem.SMContext.readFromFile | ( | PersistencyEnvironment | env, |
FileReader | reader | ||
) |
Read state from file.
void Dragengine.StateMachineSystem.SMContext.removeAction | ( | String | name | ) |
Remove action.
void Dragengine.StateMachineSystem.SMContext.removeAllActions | ( | ) |
Remove all actions.
void Dragengine.StateMachineSystem.SMContext.removeAllConditions | ( | ) |
Remove all conditions.
void Dragengine.StateMachineSystem.SMContext.removeCondition | ( | String | name | ) |
Remove condition.
void Dragengine.StateMachineSystem.SMContext.reset | ( | ) |
Reset to initial state.
Sets the state machine root state as current state.
void Dragengine.StateMachineSystem.SMContext.runEvent | ( | String | event | ) |
Run event on state machine.
void Dragengine.StateMachineSystem.SMContext.setAction | ( | String | name, |
Block | action | ||
) |
Set action for name using block.
void Dragengine.StateMachineSystem.SMContext.setCondition | ( | String | name, |
Block | condition | ||
) |
Set condition for name using block.
void Dragengine.StateMachineSystem.SMContext.setConsole | ( | Console | console | ) |
Set console or null if not wishing to log anything.
void Dragengine.StateMachineSystem.SMContext.setCurrentState | ( | SMState | state | ) |
Set current state or null if in transition.
If a state is already present the exit actions are run before switching. If state is not null entering actions are run after switching.
Calls onCurrentStateChanged() after all changes are done.
void Dragengine.StateMachineSystem.SMContext.setCurrentStateByID | ( | String | id | ) |
Set current state by identifier or null if in transition.
If a state is already present the exit actions are run before switching. If state is not null entering actions are run after switching.
Calls onCurrentStateChanged() after all changes are done.
void Dragengine.StateMachineSystem.SMContext.setLoggingName | ( | String | name | ) |
Set logging name to tell apart logs.
void Dragengine.StateMachineSystem.SMContext.setLogStateChanges | ( | bool | logStateChanges | ) |
Set log state machine state changes.
void Dragengine.StateMachineSystem.SMContext.setLogTransitions | ( | bool | logSteps | ) |
Set log state machine steps.
void Dragengine.StateMachineSystem.SMContext.writeToFile | ( | PersistencyEnvironment | env, |
FileWriter | writer | ||
) |
Write state to file.