refactor: scope active world targets

This commit is contained in:
Rijad Zuzo
2026-08-12 21:58:52 +02:00
parent d12e9515fb
commit acffe6aa0f
8 changed files with 950 additions and 57 deletions
+38 -1
View File
@@ -4,6 +4,8 @@ extends RefCounted
var last_error := ""
var _context_id: StringName
var _world_id: StringName
var _location_id: StringName
var _entries_by_id: Dictionary = {}
var _generation_by_id: Dictionary = {}
var _sorted_target_ids: Array[StringName] = []
@@ -11,8 +13,14 @@ var _target_ids_by_kind: Dictionary = {}
var _target_ids_by_capability: Dictionary = {}
func _init(owned_context_id: StringName = &"") -> void:
func _init(
owned_context_id: StringName = &"",
owned_world_id: StringName = &"",
owned_location_id: StringName = &""
) -> void:
_context_id = owned_context_id
_world_id = owned_world_id
_location_id = owned_location_id
func register_target(
@@ -75,6 +83,19 @@ func update_target(handle: WorldTargetHandle, descriptor: WorldTargetDescriptor)
return true
func update_target_position(handle: WorldTargetHandle, local_position: Vector3) -> bool:
last_error = ""
var entry := _get_handle_entry(handle)
if entry.is_empty():
return _fail_bool("Target handle is stale or belongs to another registry")
if not local_position.is_finite():
return _fail_bool("Target position must be finite")
var previous := entry["descriptor"] as WorldTargetDescriptor
entry["descriptor"] = previous.with_local_position(local_position)
_entries_by_id[previous.get_target_id()] = entry
return true
func unregister_target(handle: WorldTargetHandle) -> bool:
last_error = ""
var entry := _get_handle_entry(handle)
@@ -112,6 +133,22 @@ func get_context_id() -> StringName:
return _context_id
func get_world_id() -> StringName:
return _world_id
func get_location_id() -> StringName:
return _location_id
func get_identity() -> Dictionary:
return {
"context_id": _context_id,
"world_id": _world_id,
"location_id": _location_id,
}
func size() -> int:
return _entries_by_id.size()