All of the class are located in res://addons/imjp94.yafsm/src
but you can just preload res://addons/imjp94.yafsm/YAFSM.gd
to import all class available:
const YAFSM = preload("res://addons/imjp94.yafsm/YAFSM.gd")
const StackPlayer = YAFSM.StackPlayer
const StateMachinePlayer = YAFSM.StateMachinePlayer
const StateMachine = YAFSM.StateMachine
const State = YAFSM.State
- StackPlayer
Manage stack of item, use push/pop function to set current item on top of stack
current # Current item on top of stack
stack
- signals:
pushed(to) # When item pushed to stack
popped(from) # When item popped from stack
- StateMachinePlayer(extends StackPlayer)
Manage state based on
StateMachine
and parameters inputtedstate_machine # StateMachine being played
active # Activeness of player
autostart # Automatically enter Entry state on ready if true
process_mode # ProcessMode of player
- signals:
transited(from, to) # Transition of state
entered(to) # Entry of state machine(including nested), empty string equals to root
exited(from) # Exit of state machine(including nested, empty string equals to root
updated(state, delta) # Time to update(based on process_mode), up to user to handle any logic, for example, update movement of KinematicBody
- StackPlayerDebugger
Visualize stack of parent StackPlayer on screen
- StateDirectory
Convert state path to directory object for traversal, mainly used for nested state
Relationship between all Resource
s can be best represented as below:
var state_machine = state_machine_player.state_machine
var state = state_machine.states[state_name] # keyed by state name
var transition = state_machine.transitions[from][to] # keyed by state name transition from/to
var condition = transition.conditions[condition_name] # keyed by condition name
For normal usage, you really don't have to access any
Resource
during runtime as they only store static data that describe the state machine, accessingStackPlayer
/StateMachinePlayer
alone should be sufficient.
- State
Resource that represent a state
name
- StateMachine(
extends State
)StateMachine
is also aState
, but mainly used as container ofState
s andTransitions
sstates
transitions
- Transition
Describing connection from one state to another, all conditions must be fulfilled to transit to next state
from
to
conditions
- Condition
Empty condition with just a name, treated as trigger
name
- ValueCondition(
extends Condition
)Condition with value, fulfilled by comparing values based on comparation
comparation
value
- BooleanCondition(
extends ValueCondition
) - IntegerCondition(
extends ValueCondition
) - FloatCondition(
extends ValueCondition
) - StringCondition(
extends ValueCondition
)