This commit is contained in:
2026-03-13 22:00:02 -05:00
parent 90241d6830
commit 6738e8d217
676 changed files with 15819 additions and 78 deletions

View File

@@ -2,18 +2,54 @@ extends Node
class_name PlayerStateMachine
enum States {
IDLE, WALKING
UNSET, IDLE, WALKING, USING_ITEM_A, DRAWING_BOW, FIRING_ARROW,
SITTING, CUTSCENE
}
@export var states_container: Node
@export var current_state: BaseState
var state_dict := {}
var queued_state: PlayerStateMachine.States = PlayerStateMachine.States.UNSET
var queued_parameters: Dictionary = {}
# Public Methods
func GetCurrentState() -> States:
return States.IDLE
func GetCurrentStateEnum() -> States:
return current_state.GetStateEnum()
func QueueStateChange(to_state_enum: PlayerStateMachine.States, extra_parameters: Dictionary = {}) -> void:
queued_state = to_state_enum
queued_parameters = extra_parameters
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
var children := states_container.get_children()
for child in children:
if child is not BaseState:
continue
var state := child as BaseState
state_dict[state.GetStateEnum()] = state
if current_state:
current_state.Enter({})
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func _process(delta: float) -> void:
if current_state:
current_state.Update(delta)
if queued_state != PlayerStateMachine.States.UNSET:
_swap_state()
func _swap_state() -> void:
if current_state:
current_state.Exit()
current_state = state_dict[queued_state] as BaseState
current_state.Enter(queued_parameters)
queued_state = PlayerStateMachine.States.UNSET
queued_parameters = {}