extends BaseState
class_name FiringArrowState

signal PlayerBeganFiringArrow
signal ArrowFired(spawn_position: Vector2, direction: Vector2)

@export var direction_component: FacingDirectionComponent
@export var arrow_spawn_marker: Marker2D

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


func Enter(_extra_parameters: Dictionary) -> void:
	PlayerBeganFiringArrow.emit()
	
	var position := arrow_spawn_marker.global_position
	var direction := Vector2.ZERO
	if direction_component.current_direction == Enums.Directions.LEFT:
		direction = Vector2.LEFT
	elif direction_component.current_direction == Enums.Directions.RIGHT:
		direction = Vector2.RIGHT
	elif direction_component.current_direction == Enums.Directions.UP:
		direction = Vector2.UP
	elif direction_component.current_direction == Enums.Directions.DOWN:
		direction = Vector2.DOWN
	ArrowFired.emit(position, direction)


func OnFiringArrowAnimationFinished() -> void:	
	state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
