Clean up what the AI did

This commit is contained in:
JonShard
2026-07-17 19:02:41 +02:00
parent 4d06e72bc1
commit 847af48394
3 changed files with 28 additions and 115 deletions
+13 -24
View File
@@ -17,6 +17,13 @@ func _ready() -> void:
if not _food_item:
push_error("CombinableItem is missing FoodItem reference. must be a sibling of a FoodItem on ", get_parent().name, ".")
if not _pickable:
push_error("CombineZone must be a grand child of an XRToolsPickable.")
return
if not _food_item:
push_error("CombineZone requires a FoodItem sibling on ", _pickable.name, ".")
return
# Detect items whether held (layer 17 "Held Objects") or loose
# (layer 3 "Pickable Objects"). Don't advertise a layer of our own.
combine_area_3d.collision_mask = 0b0000_0000_0000_0001_0000_0000_0000_0100
@@ -26,40 +33,22 @@ func _ready() -> void:
set_deferred("monitoring", false)
set_deferred("monitorable", false)
if not _pickable:
push_error("CombineZone must be a grand child of an XRToolsPickable.")
return
if not _food_item:
push_error("CombineZone requires a FoodItem sibling on ", _pickable.name, ".")
return
# Signals
_pickable.picked_up.connect(_on_item_picked_up)
_pickable.dropped.connect(_on_item_dropped)
combine_area_3d.body_entered.connect(_on_body_entered)
func get_result_for(other_id: StringName) -> PackedScene:
return RECIPE_MANAGER.get_combination(_food_item.id, other_id)
## Trigger area that lets a snapped item combine with another item pushed into
## it. The zone only monitors while its owning item is held by an
## [XRToolsSnapZone]; when an item carrying a matching [FoodItem.id]
## enters, the snapped (base) item transforms into the recipe result and the
## incoming item is consumed.
# Enable the trigger only while snapped into a snap zone (not hand-held).
func _on_item_picked_up(_item: Node3D) -> void:
var by := _pickable.get_picked_up_by()
var snapped: bool = by != null and by.has_method("is_xr_class") and by.is_xr_class("XRToolsSnapZone")
set_deferred("monitoring", snapped)
func _on_item_dropped(_item: Node3D) -> void:
set_deferred("monitoring", false)
# If the other body is a FoodItem, check for a recipe and combine if one exists.
func _on_body_entered(body: Node3D) -> void:
print("CombinableItem _on_body_entered")
if _combining or body == _pickable:
@@ -78,12 +67,12 @@ func _on_body_entered(body: Node3D) -> void:
_combine(body, result)
# Transform the base item into [param result], consuming the incoming item.
# Instantiate the result of combination and free the two ingredient items
func _combine(other_body: Node3D, result: PackedScene) -> void:
print("CombinableItem _combine: combining %s + %s into %s" % [_food_item.id, _find_food_item(other_body).id, result.resource_path])
_combining = true
# Get Snapzone
var snap_zone := _pickable.get_picked_up_by()
if not snap_zone or not snap_zone.has_method("pick_up_object"):
push_warning("CombineZone: base item is not held by a snap zone; cannot combine.")
@@ -96,10 +85,10 @@ func _combine(other_body: Node3D, result: PackedScene) -> void:
_pickable.get_tree().current_scene.add_child(result_instance)
result_instance.global_transform = base_transform
# Free the base item and consume the incoming item.
# Free the pickable / root of this item and consume the incoming item.
snap_zone.drop_object()
_pickable.queue_free()
if other_body.has_method("drop_and_free"):
if other_body.has_method("drop_and_free"): # XRToolsPickable has this method
other_body.drop_and_free()
else:
other_body.queue_free()