@tool class_name AnimalRoutineSite extends Marker3D static var _all: Array[AnimalRoutineSite] = [] @export var site_id: StringName @export var display_name := "Animal site" @export var species_id: StringName = SimulationIds.SPECIES_GOAT @export var resident_animal_id: StringName @export var debug_label_enabled := false func _ready() -> void: _update_debug_label() if Engine.is_editor_hint(): return if site_id.is_empty(): push_error("AnimalRoutineSite at %s has an empty site_id" % get_path()) return var existing := get_by_id(site_id) if existing != null: push_error( ( "Duplicate AnimalRoutineSite site_id '%s' at %s; first registered at %s" % [site_id, get_path(), existing.get_path()] ) ) return _all.append(self) add_to_group("animal_routine_sites") func _exit_tree() -> void: if not Engine.is_editor_hint(): _all.erase(self) func _get_configuration_warnings() -> PackedStringArray: var warnings := PackedStringArray() if site_id.is_empty(): warnings.append("Assign a stable site_id before using this routine site.") if species_id.is_empty(): warnings.append("Assign the species that can use this routine site.") return warnings func supports_species(candidate_species_id: StringName) -> bool: return candidate_species_id == species_id func supports_animal(candidate_animal_id: StringName, candidate_species_id: StringName) -> bool: return ( supports_species(candidate_species_id) and (resident_animal_id.is_empty() or resident_animal_id == candidate_animal_id) ) func get_routine_position() -> Vector3: return global_position func set_debug_label_enabled(is_enabled: bool) -> void: debug_label_enabled = is_enabled _update_debug_label() func _update_debug_label() -> void: var label := get_node_or_null("DebugLabel") as Label3D if label == null: return label.visible = debug_label_enabled label.text = "%s\n%s" % [display_name, site_id] static func get_by_id(search_id: StringName) -> AnimalRoutineSite: for site in _all: if site.site_id == search_id: return site return null static func get_all() -> Array[AnimalRoutineSite]: return _all.duplicate()