extends Node3D

@onready var tooltip: Label3D = $Tooltip

func _ready() -> void:
	add_to_group("interactable")
	tooltip.visible = false
	var tw := create_tween().set_loops()
	tw.tween_property(self, "position:y", 0.45, 0.65)
	tw.tween_property(self, "position:y", 0.2, 0.65)

func _process(delta: float) -> void:
	rotation.y += delta * 1.1
	var players := get_tree().get_nodes_in_group("player")
	if players.is_empty():
		tooltip.visible = false
		return
	var p := players[0] as Node3D
	tooltip.visible = p != null and global_position.distance_to(p.global_position) < 2.5

func interact(player: Node) -> void:
	if player.call("apply_leather_armor"):
		queue_free()
		var mains := get_tree().get_nodes_in_group("main")
		if not mains.is_empty():
			mains[0].call("show_tutorial", "Tutorial_LeatherArmor")
