#@tool
#@icon
#class_name
extends CharacterBody3D
## Documentation comments

enum FaceDirection {LEFT = 0, RIGHT = 1, UP = 2, DOWN = 3}
enum State {IDLE, WALK}

const SPEED: int = 1
## @export variables

## Regular variables
var current_direction: FaceDirection = FaceDirection.DOWN: 
	set = set_direction
var current_direction_string: String = "down"

var current_state: State = State.IDLE:
	set = set_state
var current_state_string: String = "idle"

var input_vector: Vector2

## @onready variables
@onready var player_sprite: AnimatedSprite3D = $PlayerSprite3D

## Overridden built-in virtual methods
#func _init() -> void:
#func _enter_tree() -> void:
#func _ready() -> void:
#func _process(delta: float) -> void:
func _physics_process(_delta: float) -> void:
	input_vector = Vector2.ZERO
	if Input.is_action_pressed("left"):
		input_vector = Vector2.LEFT
		current_direction = FaceDirection.LEFT
		current_state = State.WALK
	elif Input.is_action_pressed("right"):
		input_vector = Vector2.RIGHT
		current_direction = FaceDirection.RIGHT
		current_state = State.WALK
	elif Input.is_action_pressed("up"):
		input_vector = Vector2.UP
		current_direction = FaceDirection.UP
		current_state = State.WALK
	elif Input.is_action_pressed("down"):
		input_vector = Vector2.DOWN
		current_direction = FaceDirection.DOWN
		current_state = State.WALK
	else: current_state = State.IDLE
	velocity = Vector3(input_vector.x, 0, input_vector.y) * SPEED
	move_and_slide()
## Remaining virtual methods
## Overridden custom methods
## Remaining methods
func set_direction(new_direction: FaceDirection) -> void:
	current_direction = new_direction
	current_direction_string = str(FaceDirection.keys()[new_direction]).to_lower()

func set_state(new_state: State) -> void:
	current_state = new_state
	current_state_string = str(State.keys()[new_state]).to_lower()
	var animation_string = current_state_string + "_" + current_direction_string
	player_sprite.play(animation_string)
## Subclasses
