extends State
class_name StateMachine

var current_state : Node = null 
var previous_state : Node = null 


signal state_changed(state)
signal state_changed_recursive(state)

#### ACCESSORS ####



func set_state(state) -> void:
	if state is String:
		state = get_node_or_null(state)

	if state != current_state:
		emit_signal("state_changed", current_state)

	if current_state != null:
		current_state.exit_state(current_state == state)

	previous_state = current_state
	current_state = state

	if current_state != null:
		current_state.enter_state()


func get_state() -> Node : return current_state


func get_state_name() -> String:
	if current_state != null:
		return current_state.name
	
	return ""


func get_state_by_name(state_name : String) -> Node:
	return get_node_or_null(state_name)


func get_previous_state() -> Node:
	return previous_state


#### BUILT-IN ####

func _ready() -> void:
	pass


#### VIRTUALS ####

func update(_delta : float) -> void:
	if current_state != null:
		current_state.update(_delta)


#### LOGIC ####



#### INPUTS ####




#### SIGNAL RESPONSES ####
