Add BuildModeController that deletes loose items on enter BuildMode

This commit is contained in:
JonShard
2026-08-02 13:43:30 +02:00
parent 71c338da3c
commit b24a3f99ee
6 changed files with 46 additions and 4 deletions
+38
View File
@@ -0,0 +1,38 @@
extends Node
class_name BuildModeController
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Signals.game_state_changed.connect(_on_game_state_changed)
func _on_game_state_changed(new_state: GameManager.GameState) -> void:
print("BuildModeController: game_state_changed to %s" % new_state)
if new_state == GameManager.GameState.BUILDING:
despawn_unheld_pickables()
# Despawn all food_items unless it's in a "persistent_inventory" snap_zone
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):
continue
var held_by: Node = pickable.get_picked_up_by()
if not held_by:
NetworkManager.despawn_item(pickable)
continue
if not held_by.is_in_group("persistent_inventory"):
held_by.get_parent().print_tree_pretty()
print("BuildModeController despawn_unheld_pickables held_by: %s, pickable: %s " % [held_by, pickable])
NetworkManager.despawn_item(pickable)
func _collect_pickables(node: Node, out_array: Array) -> void:
if node is XRToolsPickable:
out_array.append(node)
for child in node.get_children():
if child is Node:
_collect_pickables(child, out_array)
+1
View File
@@ -0,0 +1 @@
uid://bsdpd18i1i17s
+4
View File
@@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="7_jnxsa"] [ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="7_jnxsa"]
[ext_resource type="PackedScene" uid="uid://drwuhqb3pjtiy" path="res://items/potato.tscn" id="8_1qeqw"] [ext_resource type="PackedScene" uid="uid://drwuhqb3pjtiy" path="res://items/potato.tscn" id="8_1qeqw"]
[ext_resource type="PackedScene" uid="uid://dlw5geheupgpt" path="res://stations/hatch.tscn" id="8_atgwk"] [ext_resource type="PackedScene" uid="uid://dlw5geheupgpt" path="res://stations/hatch.tscn" id="8_atgwk"]
[ext_resource type="Script" uid="uid://bsdpd18i1i17s" path="res://prefabs/build_mode_controller.gd" id="9_atgwk"]
[sub_resource type="Environment" id="Environment_bvwq1"] [sub_resource type="Environment" id="Environment_bvwq1"]
background_mode = 2 background_mode = 2
@@ -99,3 +100,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.2, 0, 0)
[node name="Hatch2" parent="." unique_id=1755144529 instance=ExtResource("8_atgwk")] [node name="Hatch2" parent="." unique_id=1755144529 instance=ExtResource("8_atgwk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6, 0, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6, 0, 0)
[node name="BuildModeController" type="Node" parent="." unique_id=1876729190]
script = ExtResource("9_atgwk")
+1 -1
View File
@@ -18,7 +18,7 @@ albedo_color = Color(0.38, 0.35162666, 0.3268, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"] [sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"]
size = Vector3(0.6, 0.34027833, 0.6) size = Vector3(0.6, 0.34027833, 0.6)
[node name="Hatch" type="StaticBody3D" unique_id=1341321603] [node name="Hatch" type="StaticBody3D" unique_id=1341321603 groups=["persistent_inventory"]]
[node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=2093161322 groups=["station"]] [node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=2093161322 groups=["station"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2495586, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2495586, 0)
+1 -3
View File
@@ -17,6 +17,7 @@ static func _set_game_state(value: GameState):
game_state = value game_state = value
Signals.game_state_changed.emit(value) Signals.game_state_changed.emit(value)
static func _restart(): static func _restart():
print("restart Game") print("restart Game")
game_state = GameState.RUNNING game_state = GameState.RUNNING
@@ -45,6 +46,3 @@ static func game_over():
print("Game Over") print("Game Over")
game_state = GameState.GAME_OVER game_state = GameState.GAME_OVER
Signals.game_over.emit() Signals.game_over.emit()
+1
View File
@@ -48,6 +48,7 @@ platalbe_item="Meals, sides, augments for meals"
station="Hobs, Counters ..." station="Hobs, Counters ..."
table="all nodes with table script" table="all nodes with table script"
chopping_tool="A pickable body that chops" chopping_tool="A pickable body that chops"
persistent_inventory="A station that keeps it's held items in build mode"
[input] [input]