class_name Player extends CharacterBody2D


const DEADZONE = 0.1

@export var max_speed: float = 300.0

@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var state_machine: StateMachine = $StateMachine


func get_movement_vector() -> Vector2:
	var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
	var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
	return Vector2(x_mov, y_mov)


func match_state(exclude: Array[StringName] = []) -> StringName:
	var movement_vector: Vector2 = get_movement_vector()
	
	if movement_vector.length() > DEADZONE:
		if PlayerState.WALKING in exclude: return ""
		return PlayerState.WALKING
	elif movement_vector.length() < DEADZONE:
		if PlayerState.IDLE in exclude: return ""
		return PlayerState.IDLE
	
	return ""
