@tool
class_name WorldItem extends MeshInstance3D
## A collectable item in the world.

@export var item: Item:
	set = _set_item
@export var interact_radius: float = 0.25:
	set = _set_radius

@onready var interactive: Interactive = %Interactive
@onready var collision_shape_3d: CollisionShape3D = %CollisionShape3D


func _ready() -> void:
	_set_item(item)
	_set_radius(interact_radius)


func _set_item(value: Item) -> void:
	item = value
	if item and interactive:
		interactive.label = item.name


func _set_radius(value: float) -> void:
	interact_radius = value
	if collision_shape_3d:
		(collision_shape_3d.shape as SphereShape3D).radius = interact_radius


func _on_interactive_activated() -> void:
	Player.instance.add_item(item)
	# TODO: animation, sfx on collect?
	queue_free()
