extends BaseState

# walking_state.gd

signal StartedWalking

@export var walking_speed := 100
@export var body: CharacterBody2D

var _queued_dv: Vector2

func _ready() -> void:
	SubscribeToEvent("MovementQueued", OnMovementQueued)
	SubscribeToEvent("NoMovementQueued", OnNoMovementQueued)


func Enter(_extra_parameters: Dictionary) -> void:
	print("Walking State Entered")
	_queued_dv = _extra_parameters["dv"]
	StartedWalking.emit()


func Update(_delta: float) -> void:
	if _queued_dv == Vector2.ZERO:
		state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
		return
	
	body.velocity = _queued_dv * walking_speed
	body.move_and_slide()


func OnMovementQueued(dv: Vector2) -> void:
	_queued_dv = dv


func OnNoMovementQueued() -> void:
	_queued_dv = Vector2.ZERO


func GetStateEnum() -> PlayerStateMachine.States:
	return PlayerStateMachine.States.WALKING
