extends AnimatedSprite2D
class_name PlayerSprite

# Signals
signal DrawingBowAnimationFinished
signal FiringArrowAnimationFinished
signal AnimationFinished(animation_name: String)

# Private Variables
var _current_animation := "idle-down"
var _is_flipped := false

# Public Methods
func OnAnimationFinished() -> void:
	if _current_animation.begins_with("drawing-bow-"):
		DrawingBowAnimationFinished.emit()
	elif _current_animation.begins_with("firing-arrow-"):
		FiringArrowAnimationFinished.emit()
	AnimationFinished.emit(_current_animation)


func PlaySpecifiedAnimation(animation_name: String) -> void:
	_current_animation = animation_name
	animation = animation_name
	play()


func _build_animation_name(state: BaseState, direction: Enums.Directions) -> String:
	# e.g. "idle-down", "walking-up"
	var state_str := state.GetAnimationBaseName().replace("_", "-")
	var direction_str := _direction_to_animation_state(direction)
	return "%s-%s" % [state_str, direction_str]


func _direction_to_animation_state(direction: Enums.Directions) -> String:
	if direction == Enums.Directions.LEFT or direction == Enums.Directions.RIGHT:
		return "side"
	return Enums.Directions.keys()[direction].to_lower()
