extends Node
class_name FacingDirectionComponent

signal DirectionChanged

@export var current_direction: Enums.Directions = Enums.Directions.DOWN

# Public Methods
func GetCurrentDirection() -> Enums.Directions:
	return current_direction


func ChangeDirectionUsingMovementVector(movement_vector: Vector2) -> void:
	var new_direction := _get_direction_from_mov_vec(movement_vector)
	if current_direction != new_direction:
		current_direction = new_direction
		DirectionChanged.emit()


func SetDirectionManually(direction: Enums.Directions) -> void:
	if current_direction != direction:
		current_direction = direction
		DirectionChanged.emit()


# Private Methods
func _get_direction_from_mov_vec(mov_vec: Vector2) -> Enums.Directions:
	if mov_vec.x < 0: return Enums.Directions.LEFT
	if mov_vec.x > 0: return Enums.Directions.RIGHT
	if mov_vec.y < 0: return Enums.Directions.UP
	if mov_vec.y > 0: return Enums.Directions.DOWN
	return Enums.Directions.DOWN
