Refactor container to work in muliplayer

This commit is contained in:
JonShard
2026-08-19 13:13:04 +02:00
parent cd466c73b5
commit 62ea4a1540
21 changed files with 311 additions and 312 deletions
+4 -25
View File
@@ -6,12 +6,10 @@ extends Node
@export var is_dirty: bool = false
## Synced plate contents (item ids), replacing reparented child nodes so
## contents survive replication (a MultiplayerSpawner-tracked item would
## despawn on every client the instant it was reparented out of WorldContent).
## Server writes it via ItemContainer; every peer (server included) renders
## the cosmetic result via the setter below.
@export var contained_ids: Array[String] = []: set = _set_contained_ids
## Synced summary of the plate's contents (item ids). The contents themselves
## are the real item nodes ItemContainer reparents under the plate; this is only
## what other systems read to ask "what is on this plate" without walking them.
@export var contained_ids: Array[String] = []
func get_food_items() -> Array[FoodItem]:
return container.contained_items
@@ -29,22 +27,3 @@ func _process(_delta: float) -> void:
else:
container.enabled = true
dirty_node.visible = false
func _set_contained_ids(value: Array[String]) -> void:
# Only rebuild when the contents actually changed. This property is
# replicated in ALWAYS mode, so the synchronizer assigns it every network
# tick on every peer that doesn't own the plate — and refresh_visuals()
# frees and re-instantiates a scene per item each time. That was thousands
# of throwaway nodes per run (and a log line from each one's NetPickable).
if contained_ids == value:
return
contained_ids = value
# Deferred: this can be written by the replicated spawn payload before
# this node's own @onready vars (container) have resolved.
_refresh_visuals.call_deferred()
func _refresh_visuals() -> void:
if container:
container.refresh_visuals(contained_ids)