extends TextureRect

@onready var base = get_parent().get_parent()
@onready var animationPlayer = $AnimationPlayer
@onready var animList = animationPlayer.get_animation_list()

func _ready():
	if base.isWin():
		queue_free()

	var chosenAnim = animList[randi_range(0, animList.size() - 4)]
	animationPlayer.play(chosenAnim)

func close():
	Audio.buttonClick.play()
	animationPlayer.play("zoom_out")

func _on_gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton and base.isCooldown():
		base.startCooldown()
		base.money += base.earnMultiplier * base.killMoney
		base.updateMoney()
		close()
		
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if anim_name.contains("zoom_out"):
		queue_free()
