StateMachine class

Finite state machine (FSM) for implementing State-driven agent design.

@author {@link https://github.com/Mugen87|Mugen87}

Constructors

StateMachine([GameEntity? owner])
Constructs a new state machine with the given values.

Properties

currentState ↔ State?
getter/setter pair
globalState ↔ State?
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
owner ↔ GameEntity?
getter/setter pair
previousState ↔ State?
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
states → Map<String, State>
final

Methods

add(String id, State? state) → StateMachine
Adds a new state with the given ID to the state machine.
changeTo(String id) → StateMachine
Performs a state change to the state defined by its ID.
fromJSON(Map<String, dynamic> json) → StateMachine
Restores this instance from the given JSON object.
get(String id) → State?
Returns the state for the given ID.
handleMessage(dynamic telegram) → bool
Tries to dispatch the massage to the current or global state and returns true if the message was processed successfully.
insert(dynamic id) → bool
Returns true if this FSM is in the given state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerType(String type, Function constructor) → StateMachine
Registers a custom type for deserialization. When calling {@link StateMachine#fromJSON} the state machine is able to pick the correct constructor in order to create custom states.
remove(String id) → StateMachine
Removes a state via its ID from the state machine.
resolveReferences(Map<String, GameEntity> entities) → StateMachine
Restores UUIDs with references to GameEntity objects.
revert() → StateMachine
Returns to the previous state.
toJSON() → Map<String, dynamic>
Transforms this instance into a JSON object.
toString() → String
A string representation of this object.
inherited
update() → StateMachine
Updates the internal state of the FSM. Usually called by {@link GameEntity#update}.

Operators

operator ==(Object other) → bool
The equality operator.
inherited