Reorganize project into folder structure

This commit is contained in:
JonShard
2026-07-16 15:09:12 +02:00
parent 4b8e017d64
commit e27ddfe3f1
33 changed files with 156 additions and 70 deletions
+24
View File
@@ -0,0 +1,24 @@
class_name CombinableItem
extends Node
## Identity of this item, referenced by other items' recipes.
@export var id: StringName
## Recipes describing what the item holding this component turns into when
## another item is combined into it while snapped. Recipes are directional:
## only the snapped (base) item's recipes are consulted.
@export var recipes: Array[CombineRecipe] = []
func _ready() -> void:
if id.is_empty():
push_error("CombinableItem on ", get_parent().name, " has no 'id' set.")
## Returns the scene this item becomes when combined with [param other_id],
## or null if there is no matching recipe.
func get_result_for(other_id: StringName) -> PackedScene:
for recipe in recipes:
if recipe and recipe.ingredient_id == other_id:
return recipe.result
return null
+1
View File
@@ -0,0 +1 @@
uid://dounic663dn5q
+19
View File
@@ -0,0 +1,19 @@
[gd_scene format=3 uid="uid://3lr2dhy62rhk"]
[ext_resource type="Script" uid="uid://dounic663dn5q" path="res://Prefabs/combinable_item.gd" id="1_q21ti"]
[ext_resource type="Script" uid="uid://coidnv8b2yvxr" path="res://Prefabs/combine_recipe.gd" id="2_anbu7"]
[ext_resource type="Script" uid="uid://e3im02nq5cye" path="res://Prefabs/combine_zone.gd" id="4_0om48"]
[sub_resource type="BoxShape3D" id="BoxShape3D_combine"]
size = Vector3(0.16, 0.16, 0.16)
[node name="CombinableItem" type="Node3D" unique_id=996936271]
script = ExtResource("1_q21ti")
id = &"some_food_item"
recipes = Array[ExtResource("2_anbu7")]([null])
[node name="CombineZone" type="Area3D" parent="." unique_id=1514178016]
script = ExtResource("4_0om48")
[node name="CollisionShape3D" type="CollisionShape3D" parent="CombineZone" unique_id=706892516]
shape = SubResource("BoxShape3D_combine")
+8
View File
@@ -0,0 +1,8 @@
class_name CombineRecipe
extends Resource
## The [CombinableItem.id] of the item that must be combined into the base item.
@export var ingredient_id: StringName
## The scene the base item turns into when [member ingredient_id] is combined in.
@export var result: PackedScene
+1
View File
@@ -0,0 +1 @@
uid://coidnv8b2yvxr
+103
View File
@@ -0,0 +1,103 @@
class_name CombineZone
extends Area3D
## 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 [CombinableItem.id]
## enters, the snapped (base) item transforms into the recipe result and the
## incoming item is consumed.
# The pickable this zone belongs to (its parent).
@onready var _item: XRToolsPickable = get_parent().get_parent() as XRToolsPickable
# The base item's recipe data.
@onready var _combinable: CombinableItem = _find_combinable(_item)
# Guard so a combine only fires once.
var _combining: bool = false
func _ready() -> void:
# Detect items whether held (layer 17 "Held Objects") or loose
# (layer 3 "Pickable Objects"). Don't advertise a layer of our own.
collision_mask = 0b0000_0000_0000_0001_0000_0000_0000_0100
collision_layer = 0
# Deferred: _ready can run during a physics signal flush (when a combine
# spawns the result), where toggling monitoring directly is forbidden.
set_deferred("monitoring", false)
set_deferred("monitorable", false)
if not _item:
push_error("CombineZone must be a grand child of an XRToolsPickable.")
return
if not _combinable:
push_error("CombineZone requires a CombinableItem sibling on ", _item.name, ".")
return
_item.picked_up.connect(_on_item_picked_up)
_item.dropped.connect(_on_item_dropped)
body_entered.connect(_on_body_entered)
# Enable the trigger only while snapped into a snap zone (not hand-held).
func _on_item_picked_up(_pickable: Node3D) -> void:
var by := _item.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(_pickable: Node3D) -> void:
set_deferred("monitoring", false)
func _on_body_entered(body: Node3D) -> void:
if _combining or body == _item:
return
var other := _find_combinable(body)
if not other:
return
var result: PackedScene = _combinable.get_result_for(other.id)
if not result:
return
_combine(body, result)
# Transform the base item into [param result], consuming the incoming item.
func _combine(other_body: Node3D, result: PackedScene) -> void:
_combining = true
var snap_zone := _item.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.")
_combining = false
return
# Spawn the result at the base item's location, in world space.
var base_transform := _item.global_transform
var result_instance: Node3D = result.instantiate()
_item.get_tree().current_scene.add_child(result_instance)
result_instance.global_transform = base_transform
# Free the base item and consume the incoming item.
snap_zone.drop_object()
_item.queue_free()
if other_body.has_method("drop_and_free"):
other_body.drop_and_free()
else:
other_body.queue_free()
# Snap the result into the now-empty zone.
snap_zone.pick_up_object(result_instance)
# Find a CombinableItem among the direct children of [param node].
func _find_combinable(node: Node) -> CombinableItem:
if not node:
return null
for child in node.get_children():
if child is CombinableItem:
return child
return null
+1
View File
@@ -0,0 +1 @@
uid://e3im02nq5cye
-59
View File
@@ -1,59 +0,0 @@
extends Node3D
@export var target_group : String # Items with this tag can be added to the container
@export var meal_positions: Array[Node3D] = []
@export var side_positions: Array[Node3D] = []
@onready var area_3d: Area3D = $Area3D
@onready var xr_pickable: XRToolsPickable = get_parent() as XRToolsPickable
@onready var _meal_container: Node3D = $MealContainer
@onready var _sides_container: Node3D = $SidesContainer
var contained_items: Array[FoodItem]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
area_3d.body_entered.connect(_on_body_entered)
if not area_3d:
push_error("Area3D node not found in container.gd")
if not xr_pickable:
push_error("XRPickable node not found in container.gd")
func _on_body_entered (body) -> void:
if not body.is_in_group(target_group):
return
print("Body is platable: %s" % body.name)
var picked_by = xr_pickable.get_picked_up_by()
if picked_by and picked_by.is_in_group("station"):
print("Container in station")
var food_item = get_node("FoodItem")
if food_item.type == FoodItem.Type.MEAL or food_item.type == FoodItem.Type.SIDE:
# if we're full of that type:
# return
# body disble pickable
# container parent to self
# body set position to apropriate slot
pass
#plate (Pickalbe)
#XRGrapPoints
#container (script) (meal positions[1], side positions[4])
#area
#meals
#meal - burger
#sides
#side - chips
#side - onion rings
#tray (Pickalbe)
#XRGrapPoints
#container (script) (meal positions[4], side positions[0])
#food items
#meals
#meal - cookie
#meal - cookie
#meal - cookie
#meal - cookie
-1
View File
@@ -1 +0,0 @@
uid://6lyhyial1fh5
-21
View File
@@ -1,21 +0,0 @@
[gd_scene format=3 uid="uid://du31pqeytu8as"]
[ext_resource type="Script" uid="uid://6lyhyial1fh5" path="res://Prefabs/container.gd" id="1_r4cle"]
[sub_resource type="SphereShape3D" id="SphereShape3D_vlqg6"]
radius = 0.2
[node name="Container" type="Node3D" unique_id=377793422 node_paths=PackedStringArray("meal_positions")]
script = ExtResource("1_r4cle")
meal_positions = [null]
[node name="Area3D" type="Area3D" parent="." unique_id=126983781]
collision_layer = 2
collision_mask = 65540
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" unique_id=286964882]
shape = SubResource("SphereShape3D_vlqg6")
[node name="MealContainer" type="Node3D" parent="." unique_id=258551044]
[node name="SidesContainer" type="Node3D" parent="." unique_id=1464979199]
+9
View File
@@ -0,0 +1,9 @@
class_name CookableItem
extends Node
@export_range(0.0, 30.0, 0.5, "or_greater", "suffix:s") var cooking_time: float = 4.0
@export var turns_into: PackedScene
func _ready() -> void:
if not turns_into:
push_error("Cooking Error: 'turns_into' PackedScene is missing on ", name, ". Please assign a scene in the Inspector.")
+1
View File
@@ -0,0 +1 @@
uid://bs7cxydoxk1cx
+9
View File
@@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://7earnjgdmwgx"]
[ext_resource type="Script" uid="uid://bs7cxydoxk1cx" path="res://Prefabs/cookable_item.gd" id="1_6hwx6"]
[ext_resource type="PackedScene" uid="uid://cucc3gaqu2nab" path="res://Items/Charcoal.tscn" id="2_rpt7j"]
[node name="CookableItem" type="Node" unique_id=280820828]
script = ExtResource("1_6hwx6")
cooking_time = 2.0
turns_into = ExtResource("2_rpt7j")
+8
View File
@@ -0,0 +1,8 @@
class_name FoodItem
extends Node
# Define the Enum at the top of your script
enum Type { MEAL, SIDE, INGREDIENT, NONE }
@export var id: String
@export var type: Type = Type.NONE
+1
View File
@@ -0,0 +1 @@
uid://5tpoohkopryv
+8
View File
@@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://bfj80jh13t6e5"]
[ext_resource type="Script" uid="uid://5tpoohkopryv" path="res://Prefabs/food_item.gd" id="1_0na5k"]
[node name="FoodItem" type="Node" unique_id=63948206]
script = ExtResource("1_0na5k")
id = "hamburger"
item_type = "Meal"