Refactor food items to use shared inherited scene.

This commit is contained in:
JonShard
2026-08-16 10:31:39 +02:00
parent f0bb044d12
commit 1a7f641974
14 changed files with 259 additions and 519 deletions
+5 -2
View File
@@ -25,13 +25,16 @@ func _set_stations_enabled(value: bool) -> void:
station.enabled = value
# Despawn all food_items unless it's in a "persistent_inventory" snap_zone
# Despawn all despawnable pickables unless it's in a "persistent_inventory"
# snap_zone. Permanent fixtures (e.g. a station's knife) opt out entirely by
# having no DespawningItem child, or a disabled one.
func despawn_unheld_pickables():
var root = get_tree().get_root()
var pickables: Array[Node] = []
_collect_pickables(root, pickables)
for pickable in pickables:
if not Helper.find_food_item(pickable):
var despawning_item := pickable.get_node_or_null("DespawningItem") as DespawningItem
if not despawning_item or not despawning_item.enabled:
continue
var held_by: Node = pickable.get_picked_up_by()
if not held_by:
+4
View File
@@ -1,6 +1,8 @@
class_name CombinableItem
extends Node
@export var enabled: bool = true
@onready var combine_area_3d: Area3D = $Area3d
@onready var _pickable: XRToolsPickable = get_parent() as XRToolsPickable
@@ -21,6 +23,8 @@ func _ready() -> void:
if not _food_item:
SweetLogger.warning("{0} requires a FoodItem sibling", [_pickable.name])
return
if not enabled:
return
# Detect items whether held (layer 17 "Held Objects") or loose
# (layer 3 "Pickable Objects"). Don't advertise a layer of our own.
+6 -1
View File
@@ -1,6 +1,8 @@
extends Node
class_name DespawningItem
@export var enabled: bool = true
@export var time_to_despawn: float = 8
# The minimum speed required to reset despawn timer.
@@ -20,9 +22,12 @@ func _ready() -> void:
if not _rigid:
SweetLogger.error("{0} must be a grandchild of a RigidBody3D", [name])
return
func _process(delta: float) -> void:
if not enabled:
return
# Despawning is a world decision, so only the owner of world logic runs the
# clock. Every peer used to run its own copy: the countdown drifted between
# them and the blink below toggled `visible` locally, so the same item was