From 339428c31268a4ea4dc7c3e019b0325b30a6e80f Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Thu, 24 Apr 2025 23:36:23 +0200 Subject: [PATCH] Basic watering functionality implemented --- Babushka.sln.DotSettings.user | 3 +- .../3d/best_house_blender.blend.import | 3 +- prefabs/UI/Inventory/Inventory.tscn | 2 +- prefabs/farming/base_field.tscn | 16 ++-- project.godot | 2 +- resources/items/pickaxe.tres | 1 - .../Babushka_scene_item_pickup_testing.tscn | 2 +- .../CSharp/Common/Farming/FarmingControls.cs | 17 +++- .../CSharp/Common/Farming/FieldBehaviour.cs | 93 ++++++++++--------- scripts/CSharp/Common/Farming/FieldService.cs | 8 +- .../Common/Inventory/InventoryUI.cs.uid | 1 - 11 files changed, 85 insertions(+), 63 deletions(-) delete mode 100644 scripts/CSharp/Common/Inventory/InventoryUI.cs.uid diff --git a/Babushka.sln.DotSettings.user b/Babushka.sln.DotSettings.user index d4f4df7..79d2b6c 100644 --- a/Babushka.sln.DotSettings.user +++ b/Babushka.sln.DotSettings.user @@ -1,2 +1,3 @@  - ForceIncluded \ No newline at end of file + ForceIncluded + ForceIncluded \ No newline at end of file diff --git a/art/mockups/3d/best_house_blender.blend.import b/art/mockups/3d/best_house_blender.blend.import index 7031f50..2f414a6 100644 --- a/art/mockups/3d/best_house_blender.blend.import +++ b/art/mockups/3d/best_house_blender.blend.import @@ -4,12 +4,11 @@ importer="scene" importer_version=1 type="PackedScene" uid="uid://b3kyrsoobmkhp" -path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn" +valid=false [deps] source_file="res://art/mockups/3d/best_house_blender.blend" -dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"] [params] diff --git a/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index 5d59d26..5435acc 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://cgjc4wurbgimy"] -[ext_resource type="Script" uid="uid://b7vlkecrn0t5c" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"] +[ext_resource type="Script" uid="uid://hg7jay2kt441" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"] [ext_resource type="Script" uid="uid://b2jhdxcrhtm2d" path="res://scripts/CSharp/Common/Inventory/InventoryTestScript.cs" id="3_exrk4"] [ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/pickaxe.tres" id="4_5fdxq"] [ext_resource type="Texture2D" uid="uid://c7wqla0mbu3np" path="res://graphics/ui/babushka_ui_tmp_inventory_select.png" id="4_tiss4"] diff --git a/prefabs/farming/base_field.tscn b/prefabs/farming/base_field.tscn index 4da26ea..2ad2990 100644 --- a/prefabs/farming/base_field.tscn +++ b/prefabs/farming/base_field.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=6 format=3 uid="uid://biwd3jj65qrlh"] +[gd_scene load_steps=7 format=3 uid="uid://biwd3jj65qrlh"] [ext_resource type="Texture2D" uid="uid://c2pirgay3jfnn" path="res://art/farm/tilable grounds/böden/trockene farming erde.png" id="1_2cisk"] [ext_resource type="Script" uid="uid://histmmyi1wr" path="res://scripts/CSharp/Common/Farming/FieldBehaviour.cs" id="2_u7egi"] +[ext_resource type="Texture2D" uid="uid://ctvdxwgmfaj5c" path="res://art/farm/tilable grounds/böden/nasse farming erde.png" id="4_lsseu"] [ext_resource type="PackedScene" uid="uid://bjhj1wa5olwcu" path="res://prefabs/farming/base_plant.tscn" id="4_u7egi"] [ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="4_xc4m0"] @@ -18,17 +19,20 @@ _showLabel = false [node name="CollisionShape3D" parent="InteractionArea/Area3D" index="0"] shape = SubResource("SphereShape3D_u7egi") -[node name="Sprite3D" type="Sprite3D" parent="."] +[node name="FieldBehaviour" type="Sprite3D" parent="."] transform = Transform3D(0.4, 0, 0, 0, -1.74846e-08, -0.4, 0, 0.4, -1.74846e-08, 0, 0, 0) pixel_size = 0.004 -texture = ExtResource("1_2cisk") script = ExtResource("2_u7egi") Tilled = ExtResource("1_2cisk") +Watered = ExtResource("4_lsseu") FieldState = 1 +metadata/_custom_type_script = "uid://histmmyi1wr" -[node name="BasePlant" parent="Sprite3D" instance=ExtResource("4_u7egi")] +[node name="BasePlant" parent="FieldBehaviour" node_paths=PackedStringArray("_seeds", "_smallPlants", "_bigPlants", "_readyPlants") instance=ExtResource("4_u7egi")] transform = Transform3D(0.5, 0, 0, 0, -2.18557e-08, 0.5, 0, -0.5, -2.18557e-08, 0, 0, 0) - -[connection signal="Interacted" from="InteractionArea" to="Sprite3D/BasePlant" method="Grow"] +_seeds = [null, null, null] +_smallPlants = [null, null, null, null] +_bigPlants = [null, null, null, null] +_readyPlants = [null, null, null, null] [editable path="InteractionArea"] diff --git a/project.godot b/project.godot index 0cc2d20..d61222a 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Babushka" -run/main_scene="uid://dbxy2y85r1d8x" +run/main_scene="uid://br7yq757cawts" config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="res://icon.svg" diff --git a/resources/items/pickaxe.tres b/resources/items/pickaxe.tres index 31870c8..afc788d 100644 --- a/resources/items/pickaxe.tres +++ b/resources/items/pickaxe.tres @@ -6,5 +6,4 @@ script = ExtResource("1_07aya") name = "Pick Axe" color = Color(0.589014, 0.823353, 0.998475, 1) -maxStack = 1 metadata/_custom_type_script = "uid://cbskymrxs6ksu" diff --git a/scenes/testing/Babushka_scene_item_pickup_testing.tscn b/scenes/testing/Babushka_scene_item_pickup_testing.tscn index 39b37c4..122af0d 100644 --- a/scenes/testing/Babushka_scene_item_pickup_testing.tscn +++ b/scenes/testing/Babushka_scene_item_pickup_testing.tscn @@ -5,7 +5,7 @@ [ext_resource type="PackedScene" uid="uid://5hltxpdxmqcq" path="res://prefabs/interactions/generic_item_on_ground.tscn" id="5_sjt6k"] [ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="6_876p1"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"] -[ext_resource type="Script" uid="uid://d17si23dtlg72" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"] +[ext_resource type="Script" uid="uid://c6hh7m8wikv04" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"] [ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_hv2km"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls.cs b/scripts/CSharp/Common/Farming/FarmingControls.cs index c78f02c..a8f702a 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls.cs @@ -1,5 +1,8 @@ using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using Godot; +using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Farming; @@ -55,7 +58,13 @@ public partial class FarmingControls : Node3D private void WaterTheField() { + Vector2I currentPos = new Vector2I(AdjustValue(_movingPlayer.GlobalPosition.X), AdjustValue(_movingPlayer.GlobalPosition.Z)); + FieldBehaviour field = FieldParent.Get(currentPos); + if (field == null) + return; + field.Water(); + Debug.Print("Watered the field."); } private void MakeField() @@ -75,7 +84,9 @@ public partial class FarmingControls : Node3D if (fieldInstance is Node3D field3d) { // add dictionary entry for the field - FieldParent.TryAddEntry(intPosition, field3d as FieldBehaviour); + Array fields = field3d.FindChildren("*", nameof(FieldBehaviour)); + if (fields.Count > 0) + FieldParent.TryAddEntry(intPosition, fields[0] as FieldBehaviour); // reposition and reparent the instance field3d.Position = playerPos; @@ -84,9 +95,9 @@ public partial class FarmingControls : Node3D } } - private float AdjustValue(float value) + private int AdjustValue(float value) { - return Mathf.Floor(value); + return (int) Mathf.Floor(value); } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour.cs b/scripts/CSharp/Common/Farming/FieldBehaviour.cs index 0885caf..b9f45f1 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour.cs @@ -1,55 +1,60 @@ +using System.Diagnostics; using Godot; -namespace Babushka.scripts.CSharp.Common.Farming; - -public enum FieldState +namespace Babushka.scripts.CSharp.Common.Farming { - Empty = 0, - Tilled = 1, - Planted = 2, - Watered = 3, - NotFound = 99 -} - -public partial class FieldBehaviour : Sprite3D -{ - [Export] private Texture2D Tilled; - [Export] private Texture2D Watered; - [Export] public FieldState FieldState = FieldState.Empty; - - public Vector2 FieldPosition; - - public override void _Ready() + public enum FieldState { - Texture = Tilled; - base._Ready(); + Empty = 0, + Tilled = 1, + Planted = 2, + Watered = 3, + NotFound = 99 } - public void Water() + [GlobalClass] + public partial class FieldBehaviour : Sprite3D { - FieldState = FieldState.Watered; - Texture = Watered; - } - - /// - /// Called when the player enters the field'S interaction area and presses . - /// - public void Farm() - { - switch (FieldState) + [Export] private Texture2D Tilled; + [Export] private Texture2D Watered; + [Export] public FieldState FieldState = FieldState.Empty; + + public Vector2 FieldPosition; + + public override void _Ready() { - case FieldState.Empty: - Texture = Tilled; - FieldState = FieldState.Tilled; - break; - case FieldState.Tilled: - FieldState = FieldState.Planted; - break; - case FieldState.Planted: - break; - default: - break; + Texture = Tilled; + base._Ready(); } + + public void Water() + { + FieldState = FieldState.Watered; + Texture = Watered; + Debug.Print($"Current Texture: {Texture.ResourceName}"); + } + + /// + /// Called when the player enters the field'S interaction area and presses . + /// + public void Farm() + { + switch (FieldState) + { + case FieldState.Empty: + Texture = Tilled; + FieldState = FieldState.Tilled; + break; + case FieldState.Tilled: + FieldState = FieldState.Planted; + break; + case FieldState.Planted: + break; + default: + break; + } + } } -} \ No newline at end of file +} + diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index c4469dd..1929081 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -15,9 +15,9 @@ public partial class FieldService : Node3D if (!fields.ContainsKey(key)) { fields.Add(key, field); + Debug.Print("Added entry: " + key); return true; } - Debug.Print("Added entry: " + key); return false; } @@ -25,8 +25,12 @@ public partial class FieldService : Node3D public FieldBehaviour Get(Vector2I key) { Debug.Print($"Getting field at {key}. Found: {fields.ContainsKey(key)}."); - if(fields.TryGetValue(key, out FieldBehaviour field)) + if (fields.TryGetValue(key, out FieldBehaviour field)) + { + Debug.Print($"Getting field at {key}, field: {field.Name}."); return field; + } + return null; } diff --git a/scripts/CSharp/Common/Inventory/InventoryUI.cs.uid b/scripts/CSharp/Common/Inventory/InventoryUI.cs.uid deleted file mode 100644 index 8b727e9..0000000 --- a/scripts/CSharp/Common/Inventory/InventoryUI.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b7vlkecrn0t5c