Manages character state transitions and state-dependent behavior
The CharacterStateManager centralizes all state-related logic including:
- State transition validation and execution
- State-dependent behavior coordination
- State change notifications and callbacks
- State consistency enforcement
Instance methods
add_transition_rule(from : CharacterState, to : CharacterState)
Adds custom transition rule
Sourceavailable?
Checks if character is available for interaction
Sourcebusy?
Checks if character is busy (cannot be interrupted)
Sourcecan_interact?
Checks if character can interact
Sourcecan_move?
Checks if character is in a movement-capable state
Sourcecan_talk?
Checks if character can talk
Sourcecan_transition_to?(target_state : CharacterState) : Bool
Checks if character can transition to a specific state
Sourcecreate_snapshot
Creates a state snapshot for saving/loading
Sourcedirection=(direction : Direction)
Sourcedirection_description
Gets direction description
Sourceforce_idle
Forces character to idle state
Sourceforce_talking
Forces character to talking state
Sourceforce_walking
Forces character to walking state
Sourcemood=(mood : CharacterMood)
Sourcemoving?
Checks if character is currently moving
Sourceon_direction_changed=(on_direction_changed : Proc(Direction, Direction, Nil) | Nil)
Sourceon_mood_changed=(on_mood_changed : Proc(CharacterMood, CharacterMood, Nil) | Nil)
Sourceon_state_changed
Callbacks for state changes
Sourceon_state_changed=(on_state_changed : Proc(CharacterState, CharacterState, Nil) | Nil)
Callbacks for state changes
Sourceremove_transition_rule(from : CharacterState, to : CharacterState)
Removes custom transition rule
Sourcereset_transition_rules
Resets to default transition rules
Sourcerestore_from_snapshot(snapshot : Hash(String, String))
Restores state from snapshot
Sourceset_direction(new_direction : Direction)
Changes character direction
Sourceset_mood(new_mood : CharacterMood)
Sourceset_state(new_state : CharacterState, force : Bool = false) : Bool
Changes character state with validation
Sourcestate=(state : CharacterState)
Sourcestate_description
Gets state description for debugging
Sourcetalking?
Checks if character is currently talking
Sourcetry_return_to_idle
Attempts to return to idle state from any state
Sourcevalid_transitions_from_current
Gets all valid transitions from current state
Sourcevalidate_state
Validates current state consistency
Source