extends Node
class_name InputManager

var Strategies : Dictionary = {
	InputStrategy.State.IDLE : InputStrategy_Idle.new(),
	InputStrategy.State.STUCK : InputStrategy_Stuck.new(),
	InputStrategy.State.INPUT_INTRO : InputStrategy_InputIntro.new(),
	InputStrategy.State.LETTER_CLICKED : InputStrategy_LetterClicked.new(),
	InputStrategy.State.DRAGGING : InputStrategy_Dragging.new(),
	InputStrategy.State.DRAG_OUTRO : InputStrategy_DragOutro.new(),
	InputStrategy.State.ANIMATING : InputStrategy_Animating.new(),
	InputStrategy.State.HALT : InputStrategy_Halt.new()
}

@onready var wordLibrary = $"../WordLibrary"

# set up an event to let other modules know when we are idle
signal waiting_for_input()

var currentState : InputStrategy.State = InputStrategy.State.IDLE

func get_letter_manager() -> LetterManager:
	return get_node("../LetterManager")

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	for state in Strategies:
		var strategy = Strategies[state]
		strategy.parentManager = self
		add_child(strategy)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	Strategies[currentState].update()


func transition_to_state(state : InputStrategy.State) -> void:
	print("Transitioning from ", currentState, " to ", state)
	Strategies[currentState].exit()
	currentState = state
	Strategies[currentState].enter()
	
	if (currentState == InputStrategy.State.IDLE):
		waiting_for_input.emit()
