feat: index loaded resource discovery
This commit is contained in:
@@ -45,11 +45,14 @@ func _ready() -> void:
|
||||
return
|
||||
_all.append(self)
|
||||
add_to_group("resource_nodes")
|
||||
set_notify_transform(true)
|
||||
_try_register_with_simulation()
|
||||
_notify_world_adapters()
|
||||
_update_presentation()
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
_unregister_from_world_adapters()
|
||||
_all.erase(self)
|
||||
if state != null and state.changed.is_connected(_on_state_changed):
|
||||
state.changed.disconnect(_on_state_changed)
|
||||
@@ -71,6 +74,7 @@ func bind_state(resource_state: ResourceStateRecord) -> bool:
|
||||
if not state.depleted.is_connected(_on_state_depleted):
|
||||
state.depleted.connect(_on_state_depleted)
|
||||
_update_presentation()
|
||||
_notify_world_adapters()
|
||||
return true
|
||||
|
||||
|
||||
@@ -83,6 +87,27 @@ func _try_register_with_simulation() -> void:
|
||||
manager.register_resource_node(self)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_TRANSFORM_CHANGED and is_node_ready():
|
||||
_notify_world_adapters()
|
||||
|
||||
|
||||
func _notify_world_adapters() -> void:
|
||||
if not is_inside_tree():
|
||||
return
|
||||
for adapter in get_tree().get_nodes_in_group("active_world_adapter"):
|
||||
if adapter.has_method("register_resource_node"):
|
||||
adapter.register_resource_node(self, state)
|
||||
|
||||
|
||||
func _unregister_from_world_adapters() -> void:
|
||||
if not is_inside_tree():
|
||||
return
|
||||
for adapter in get_tree().get_nodes_in_group("active_world_adapter"):
|
||||
if adapter.has_method("unregister_resource_node"):
|
||||
adapter.unregister_resource_node(node_id)
|
||||
|
||||
|
||||
func get_amount_remaining() -> float:
|
||||
return state.get_amount_remaining() if state != null else initial_amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user