From d1a8ff0cbfe3b2d4f89e28884672d6f6817b1bf2 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 9 Sep 2025 23:57:55 +0200 Subject: [PATCH] WIP reworking the item repository --- Babushka.sln.DotSettings.user | 1 + prefabs/farm/base_field.tscn | 4 +- prefabs/farm/tomato_plant.tscn | 6 +- project.godot | 1 + scenes/Babushka_scene_indoor_common_room.tscn | 7 +- scenes/Babushka_scene_outside_beets.tscn | 83 ++++++++++--------- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 30 +++---- .../CSharp/Common/Inventory/ItemRepository.cs | 28 +++++++ .../CSharp/Common/Inventory/ItemResource.cs | 4 - 9 files changed, 93 insertions(+), 71 deletions(-) create mode 100644 scripts/CSharp/Common/Inventory/ItemRepository.cs diff --git a/Babushka.sln.DotSettings.user b/Babushka.sln.DotSettings.user index 036b687..a3c8dc9 100644 --- a/Babushka.sln.DotSettings.user +++ b/Babushka.sln.DotSettings.user @@ -10,4 +10,5 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded \ No newline at end of file diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 2e64a2e..ab21577 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=9 format=3 uid="uid://b1d2e7ely6hyw"] [ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"] [ext_resource type="Texture2D" uid="uid://cgmu3qlovdr22" path="res://art/masks/field_outline_1.png" id="2_w8caw"] @@ -7,6 +7,7 @@ [ext_resource type="Texture2D" uid="uid://c2pirgay3jfnn" path="res://art/farm/tilable grounds/böden/trockene farming erde.png" id="5_wx561"] [ext_resource type="Texture2D" uid="uid://ctvdxwgmfaj5c" path="res://art/farm/tilable grounds/böden/nasse farming erde.png" id="6_7m4xq"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="7_2eegd"] +[ext_resource type="Resource" uid="uid://d284vxftxhym0" path="res://resources/itemRepository.tres" id="7_w8caw"] [node name="BaseField" type="Node2D"] @@ -21,6 +22,7 @@ Tilled = ExtResource("5_wx561") Watered = ExtResource("6_7m4xq") PlantingInteraction = NodePath("../InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") +ItemRepository = ExtResource("7_w8caw") [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 diff --git a/prefabs/farm/tomato_plant.tscn b/prefabs/farm/tomato_plant.tscn index 438467c..0934f89 100644 --- a/prefabs/farm/tomato_plant.tscn +++ b/prefabs/farm/tomato_plant.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://gishbn0a8eke"] +[gd_scene load_steps=12 format=3 uid="uid://gishbn0a8eke"] [ext_resource type="Script" uid="uid://cms357f23fmfy" path="res://scripts/CSharp/Common/Farming/PlantBehaviour2D.cs" id="1_66p1c"] [ext_resource type="Texture2D" uid="uid://dtr4uga5uspg" path="res://art/farm/farming/farmobjekte/tomaten/tomaten baby.png" id="2_vjw4j"] @@ -6,7 +6,6 @@ [ext_resource type="Texture2D" uid="uid://b2gu6ur2xc7s4" path="res://art/farm/farming/farmobjekte/tomaten/tomaten blume.png" id="4_hmj2d"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="5_3j24b"] [ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="6_gdrin"] -[ext_resource type="Resource" uid="uid://blr8tine5m0ma" path="res://resources/items/tomato.tres" id="7_di4m0"] [ext_resource type="Texture2D" uid="uid://cnwd3mb3jnuxm" path="res://art/farm/farming/farmobjekte/tomaten/teen adulte tomaten.png" id="8_evgr8"] [ext_resource type="Texture2D" uid="uid://bleimj6jr1jka" path="res://art/general/rectangle.png" id="9_vjw4j"] @@ -151,9 +150,6 @@ shape = SubResource("CircleShape2D_vjw4j") position = Vector2(0, 2.3) IsActive = false -[node name="SpawnWithItem" parent="ReadyPlantInventoryItem" index="0"] -_blueprint = ExtResource("7_di4m0") - [node name="ItemLabel" parent="ReadyPlantInventoryItem" index="1"] visible = false z_index = 100 diff --git a/project.godot b/project.godot index 2996b44..9731e15 100644 --- a/project.godot +++ b/project.godot @@ -146,6 +146,7 @@ directories/tres_directory={ "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", "inventory_interactable_outline": "res://art/materials/inventory_interactable_outline.tres", +"itemRepository": "res://resources/itemRepository.tres", "preview_character": "res://addons/dialogic/Modules/Character/preview_character.tres", "rake": "res://resources/items/rake.tres", "scythe": "res://resources/items/scythe.tres", diff --git a/scenes/Babushka_scene_indoor_common_room.tscn b/scenes/Babushka_scene_indoor_common_room.tscn index 959037f..4c596d6 100644 --- a/scenes/Babushka_scene_indoor_common_room.tscn +++ b/scenes/Babushka_scene_indoor_common_room.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=41 format=3 uid="uid://bm21nqepnwaik"] +[gd_scene load_steps=40 format=3 uid="uid://bm21nqepnwaik"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_3vr4f"] [ext_resource type="Texture2D" uid="uid://cnhsxxps2cw5" path="res://art/indoor/room export/Room_01_table.png" id="2_ubg3a"] @@ -7,7 +7,6 @@ [ext_resource type="Texture2D" uid="uid://waqmjrxduxfq" path="res://art/indoor/room export/Room_01_walls.png" id="5_sndxu"] [ext_resource type="Texture2D" uid="uid://bqwhptcgg5ons" path="res://art/indoor/room export/Room_01_dorr_R.png" id="6_blyw3"] [ext_resource type="Texture2D" uid="uid://vyk63d0pgqm5" path="res://art/indoor/room export/Room_01_dioor L.png" id="7_yd2gv"] -[ext_resource type="Material" uid="uid://blch5kdhkbj75" path="res://art/materials/simple_interactable_outline.tres" id="8_7a68a"] [ext_resource type="Texture2D" uid="uid://b2rj7wkyu6ehy" path="res://art/indoor/room export/Room_01_pechka.png" id="8_ofqcg"] [ext_resource type="Texture2D" uid="uid://dhvi5404cqioa" path="res://art/indoor/room export/Room_01_window.png" id="9_aoesu"] [ext_resource type="Texture2D" uid="uid://bpi35nxbhput8" path="res://art/indoor/room export/Room_01_pechkaDoor.png" id="10_xcryd"] @@ -312,7 +311,6 @@ region_rect = Rect2(3161, 313, 679, 1050) [node name="OutsideDoor" parent="BackWall/Room01DorrR" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-7, 248) -_outlineMaterial = ExtResource("8_7a68a") _spriteToOutline = NodePath("..") _id = 1 @@ -325,7 +323,6 @@ region_rect = Rect2(0, 0, 3840, 2160) [node name="VesnasRoomDoor" parent="BackWall/Room01DoorL" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-1559, -16) -_outlineMaterial = ExtResource("8_7a68a") _spriteToOutline = NodePath("..") _id = 0 @@ -362,7 +359,6 @@ region_rect = Rect2(2360, 864, 356, 251) [node name="InteractionArea" parent="BackWall/Room01PechkaDoor" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] scale = Vector2(1.8, 1.96) -_outlineMaterial = ExtResource("8_7a68a") _spriteToOutline = NodePath("..") [node name="CollisionShape3D" parent="BackWall/Room01PechkaDoor/InteractionArea/Area2D" index="0"] @@ -413,7 +409,6 @@ script = ExtResource("22_tggq2") [node name="InteractionArea" parent="BackWall/Katze" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-6.5, -44) scale = Vector2(0.5, 0.5) -_outlineMaterial = ExtResource("8_7a68a") _spriteToOutline = NodePath("..") [node name="Room assets" type="Node" parent="BackWall"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 8a36080..cea1adf 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=91 format=3 uid="uid://b3ibx4resa1f3"] +[gd_scene load_steps=92 format=3 uid="uid://b3ibx4resa1f3"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_6krrk"] [ext_resource type="Script" uid="uid://bqomwxclsbhd3" path="res://scripts/CSharp/Common/Camera/CameraController.cs" id="2_4ktoi"] @@ -137,11 +137,15 @@ size = Vector2(1041, 368) resource_local_to_scene = true radius = 371.058 -[sub_resource type="CircleShape2D" id="CircleShape2D_2nee2"] +[sub_resource type="CircleShape2D" id="CircleShape2D_dr6bm"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_ipqaa"] +[sub_resource type="CircleShape2D" id="CircleShape2D_34r5t"] +resource_local_to_scene = true +radius = 300.0 + +[sub_resource type="CircleShape2D" id="CircleShape2D_hpgl7"] resource_local_to_scene = true radius = 300.0 @@ -173,27 +177,27 @@ shader_parameter/offset = 0.0 shader = ExtResource("24_anpd4") shader_parameter/tiling_scale = Vector2(1, 20) -[sub_resource type="CircleShape2D" id="CircleShape2D_hpgl7"] +[sub_resource type="CircleShape2D" id="CircleShape2D_qavgq"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_qavgq"] +[sub_resource type="CircleShape2D" id="CircleShape2D_njxly"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_dr6bm"] +[sub_resource type="CircleShape2D" id="CircleShape2D_54ty3"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_njxly"] +[sub_resource type="CircleShape2D" id="CircleShape2D_gbxtf"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_34r5t"] +[sub_resource type="CircleShape2D" id="CircleShape2D_6krrk"] resource_local_to_scene = true radius = 300.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_54ty3"] +[sub_resource type="CircleShape2D" id="CircleShape2D_4ktoi"] resource_local_to_scene = true radius = 300.0 @@ -947,7 +951,6 @@ z_index = 1 position = Vector2(2693, 1876) _fieldParent = NodePath("../Farm visuals/FieldParent") _hoe = ExtResource("28_le48k") -_wateringCan = ExtResource("29_6laxt") [node name="Animated Sprites" parent="YSorted/Vesna/CharacterBody2D/visuals" index="0"] position = Vector2(-33, 554) @@ -987,8 +990,8 @@ position = Vector2(6095, 2087) [node name="SpawnWithItem" parent="YSorted/HoeGenericPickup" index="0"] _blueprint = ExtResource("33_v0fwx") -[node name="CollisionShape3D" parent="YSorted/HoeGenericPickup/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_2nee2") +[node name="CollisionShape3D" parent="YSorted/HoeGenericPickup/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_dr6bm") [node name="CanGenericPickup" parent="YSorted" instance=ExtResource("32_752hh")] visible = false @@ -997,11 +1000,8 @@ position = Vector2(8192, 3507) [node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"] _blueprint = ExtResource("29_6laxt") -[node name="InteractionArea2" parent="YSorted/CanGenericPickup" index="3"] -position = Vector2(0, -159) - -[node name="CollisionShape3D" parent="YSorted/CanGenericPickup/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_ipqaa") +[node name="CollisionShape3D" parent="YSorted/CanGenericPickup/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_34r5t") [node name="RakeGenericPickup" parent="YSorted" instance=ExtResource("32_752hh")] visible = false @@ -1010,8 +1010,8 @@ position = Vector2(8391, 2060) [node name="SpawnWithItem" parent="YSorted/RakeGenericPickup" index="0"] _blueprint = ExtResource("28_le48k") -[node name="CollisionShape3D" parent="YSorted/RakeGenericPickup/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_ipqaa") +[node name="CollisionShape3D" parent="YSorted/RakeGenericPickup/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_hpgl7") [node name="Farm visuals" type="Node2D" parent="YSorted"] position = Vector2(-60, 122) @@ -1751,10 +1751,11 @@ rotation = 1.5708 scale = Vector2(0.1, 8.7) texture = ExtResource("26_bwvai") -[node name="FieldParent" type="Node2D" parent="YSorted/Farm visuals"] +[node name="FieldParent" type="Node2D" parent="YSorted/Farm visuals" node_paths=PackedStringArray("fields")] position = Vector2(53, 20) scale = Vector2(1, 0.993819) script = ExtResource("46_xkmgh") +fields = {} metadata/_custom_type_script = "uid://dhxtdhfqx3bte" [node name="BaseField" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] @@ -1769,8 +1770,8 @@ visible = true [node name="01" parent="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/BigPlant" index="0"] visible = false -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_hpgl7") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_qavgq") [node name="BaseField2" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] position = Vector2(1230, 2590) @@ -1784,8 +1785,8 @@ visible = false [node name="03" parent="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/BigPlant" index="2"] visible = true -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_qavgq") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_njxly") [node name="BaseField3" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] position = Vector2(1994, 2603) @@ -1799,8 +1800,8 @@ visible = true [node name="01" parent="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/BigPlant" index="0"] visible = false -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_dr6bm") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_54ty3") [node name="BaseField4" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] position = Vector2(478, 3098) @@ -1814,8 +1815,8 @@ visible = true [node name="01" parent="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/BigPlant" index="0"] visible = false -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_njxly") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_gbxtf") [node name="BaseField5" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] position = Vector2(1279, 3123) @@ -1832,8 +1833,8 @@ visible = false [node name="02" parent="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/BigPlant" index="1"] visible = true -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_34r5t") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_6krrk") [node name="BaseField6" parent="YSorted/Farm visuals" instance=ExtResource("43_dr6bm")] position = Vector2(2037, 3135) @@ -1847,8 +1848,8 @@ visible = true [node name="01" parent="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/BigPlant" index="0"] visible = false -[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] -shape = SubResource("CircleShape2D_54ty3") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_4ktoi") [node name="Blocker" type="Node2D" parent="YSorted"] @@ -1958,33 +1959,33 @@ script = ExtResource("58_m3hs4") [editable path="YSorted/Vesna"] [editable path="YSorted/Brünnen/InteractionArea"] [editable path="YSorted/HoeGenericPickup"] -[editable path="YSorted/HoeGenericPickup/InteractionArea2"] +[editable path="YSorted/HoeGenericPickup/PickupInteractionArea"] [editable path="YSorted/CanGenericPickup"] -[editable path="YSorted/CanGenericPickup/InteractionArea2"] +[editable path="YSorted/CanGenericPickup/PickupInteractionArea"] [editable path="YSorted/RakeGenericPickup"] -[editable path="YSorted/RakeGenericPickup/InteractionArea2"] +[editable path="YSorted/RakeGenericPickup/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField"] [editable path="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField2"] [editable path="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField2/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField3"] [editable path="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField3/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField4"] [editable path="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField4/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField5"] [editable path="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField5/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="YSorted/Farm visuals/BaseField6"] [editable path="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot"] [editable path="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem"] -[editable path="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/InteractionArea2"] +[editable path="YSorted/Farm visuals/BaseField6/FieldBehaviour/BeetRoot/ReadyPlantInventoryItem/PickupInteractionArea"] [editable path="CanvasLayer"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 5bb384a..eea9ce8 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -16,6 +16,7 @@ public partial class FieldBehaviour2D : Sprite2D [Export] public FieldState FieldState = FieldState.Tilled; [Export] public InteractionArea2D PlantingInteraction; [Export] public Node2D PlantingPlaceholder; + [Export] public ItemRepository ItemRepository; public Vector2 FieldPosition; @@ -83,24 +84,25 @@ public partial class FieldBehaviour2D : Sprite2D if (item == null || PlantingPlaceholder.GetChildCount() > 0) return success; - PackedScene? plantPrefab = item.blueprint.itemPrefab; + string prefabPath = ItemRepository.TryGetPrefabPath(item.blueprint); - if (plantPrefab != null) + if (prefabPath != null) { - Node plantInstance = plantPrefab.Instantiate(); - if (plantInstance is Node2D plant2d) - { - PlantingPlaceholder.AddChild(plant2d); - plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition; - PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D; - if (plantBehaviour != null) - { - plantBehaviour.Field = this; - } - - success = true; + // todo: Error: cannot convert value at key from string to object + PackedScene prefab = ResourceLoader.Load(prefabPath, nameof(PackedScene)); + Node2D plant2d = prefab.Instantiate(); + PlantingPlaceholder.AddChild(plant2d); + plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition; + PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D; + + if (plantBehaviour != null) + { + plantBehaviour.Field = this; } + + success = true; + } return success; diff --git a/scripts/CSharp/Common/Inventory/ItemRepository.cs b/scripts/CSharp/Common/Inventory/ItemRepository.cs new file mode 100644 index 0000000..ed71183 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/ItemRepository.cs @@ -0,0 +1,28 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Common.Inventory; + +/// +/// A dictionary wrapper resource that holds references to ItemResources and maps them to their respective prefabs. +/// +[GlobalClass] +public partial class ItemRepository : Resource +{ + [Export] public Dictionary itemInventoryRepository; + + /// + /// Returns the path to the itemPrefab for the inventory item. + /// + /// + /// + public string TryGetPrefabPath(ItemResource resource) + { + if (itemInventoryRepository.Keys.Contains(resource)) + { + return itemInventoryRepository[resource]; + } + + return null; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Inventory/ItemResource.cs b/scripts/CSharp/Common/Inventory/ItemResource.cs index 33d29af..fd1b427 100644 --- a/scripts/CSharp/Common/Inventory/ItemResource.cs +++ b/scripts/CSharp/Common/Inventory/ItemResource.cs @@ -17,15 +17,11 @@ public partial class ItemResource : Resource [Export] public int maxStack; - [Export] - public PackedScene? itemPrefab; - public ItemResource() { name = ""; color = Colors.Red; maxStack = 1; - itemPrefab = null; } }