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
+45 -1
View File
@@ -15,6 +15,7 @@ const PRESENTATION_UPDATE_INTERVAL_SECONDS := 0.25
var state: StorageStateRecord
var _last_label_text := ""
var _presentation_elapsed := 0.0
var _active_world_adapter: ActiveWorldAdapter
func _ready() -> void:
@@ -24,7 +25,8 @@ func _ready() -> void:
push_error("StorageNode at %s has empty storage_id" % get_path())
_update_presentation()
return
var existing: StorageNode = get_by_id(storage_id) as StorageNode
_active_world_adapter = ActiveWorldAdapter.find_for_node(self)
var existing: StorageNode = get_by_id_in_context(storage_id, _active_world_adapter)
if existing != null:
push_error(
(
@@ -36,7 +38,9 @@ func _ready() -> void:
return
_all.append(self)
add_to_group("storage_nodes")
set_notify_transform(true)
_try_register_with_simulation()
_notify_world_adapter()
_update_presentation()
set_process(debug_label_enabled)
@@ -50,6 +54,7 @@ func _process(delta: float) -> void:
func _exit_tree() -> void:
_unregister_from_world_adapter()
_all.erase(self)
state = null
@@ -59,6 +64,7 @@ func bind_state(storage_state: StorageStateRecord) -> bool:
return false
state = storage_state
_update_presentation()
_notify_world_adapter()
return true
@@ -79,6 +85,37 @@ func _try_register_with_simulation() -> void:
manager.register_storage_node(self)
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED and is_node_ready():
if is_instance_valid(_active_world_adapter):
_active_world_adapter.refresh_world_target_position(self)
func _notify_world_adapter() -> void:
if not is_inside_tree():
return
if (
not is_instance_valid(_active_world_adapter)
or not _active_world_adapter.owns_target_node(self)
):
_active_world_adapter = ActiveWorldAdapter.find_for_node(self)
if _active_world_adapter != null:
_active_world_adapter.register_world_target(self)
func _bind_active_world_adapter(adapter: ActiveWorldAdapter) -> void:
if adapter != null and adapter.owns_target_node(self):
_active_world_adapter = adapter
func _unregister_from_world_adapter() -> void:
if not is_instance_valid(_active_world_adapter):
_active_world_adapter = ActiveWorldAdapter.find_for_node(self)
if is_instance_valid(_active_world_adapter):
_active_world_adapter.unregister_world_target(self)
_active_world_adapter = null
func _update_presentation() -> void:
if not has_node("DebugLabel"):
return
@@ -112,5 +149,12 @@ static func get_by_id(search_id: StringName):
return null
static func get_by_id_in_context(search_id: StringName, adapter: ActiveWorldAdapter) -> StorageNode:
for node in _all:
if node.storage_id == search_id and ActiveWorldAdapter.find_for_node(node) == adapter:
return node as StorageNode
return null
static func get_all() -> Array:
return _all.duplicate()