class_name StateMachine
extends Node

@export var current_state : State

var states : Array[Node]

@onready var entity: Entity = get_owner()


func _ready() -> void:
	states = get_children()
	await entity.ready
	current_state._notification(GameConstants.NOTIFICATION_ENTER_STATE)


func switch_state(next_state : State):
	if next_state as State and ( next_state in states ):
		current_state._notification(GameConstants.NOTIFICATION_EXIT_STATE)
		current_state = next_state
		current_state._notification(GameConstants.NOTIFICATION_ENTER_STATE)
