@tool
extends Node3D

const GOAL_KEY := "UI_GOAL"
const LABEL_FMT := "{0}\n{1} m"

@export var show_distance: bool:
	set(value):
		if distance_label:
			distance_label.visible = value
	get:
		return distance_label.visible
@onready var distance_label: Label3D = %DistanceLabel


func _process(_delta: float) -> void:
	if show_distance:
		var viewport := get_viewport()
		if viewport:
			var camera := viewport.get_camera_3d()
			if camera:
				var distance := int(global_position.distance_to(camera.global_position))
				distance_label.text = LABEL_FMT.format([tr(GOAL_KEY), str(distance)])
