From b5dcad5614fe9fee35889a6a705144f3cadc1c05 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 9 Apr 2025 18:14:05 +0200 Subject: [PATCH 1/6] Vesna walking and idle animations work for all movement directions. --- .idea/.idea.Babushka/.idea/.name | 1 - .../3d/best_house_blender.blend.import | 3 +- prefabs/UI/Inventory/Inventory.tscn | 3 +- project.godot | 6 ++- scenes/Babushka_scene_farm_vesna.tscn | 6 ++- .../Common/CharacterControls/Player3D.cs | 54 ++++++++++++------- 6 files changed, 49 insertions(+), 24 deletions(-) delete mode 100644 .idea/.idea.Babushka/.idea/.name diff --git a/.idea/.idea.Babushka/.idea/.name b/.idea/.idea.Babushka/.idea/.name deleted file mode 100644 index 4ba9019..0000000 --- a/.idea/.idea.Babushka/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Babushka \ 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 7f3f516..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"] @@ -42,6 +42,7 @@ columns = 10 [node name="SlotSelectContainer" type="Control" parent="SlotsContainer"] custom_minimum_size = Vector2(1000, 100) layout_mode = 1 +anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 anchor_right = 0.5 diff --git a/project.godot b/project.godot index 2ed10d7..d61222a 100644 --- a/project.godot +++ b/project.godot @@ -66,6 +66,10 @@ translation/id_counter=22 translation/locales=["de", "en"] text/autopauses={} +[display] + +window/size/always_on_top=true + [dotnet] project/assembly_name="Babushka" @@ -129,7 +133,7 @@ interact={ } ui_inventory_open_close={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) ] } ui_inventory_advance={ diff --git a/scenes/Babushka_scene_farm_vesna.tscn b/scenes/Babushka_scene_farm_vesna.tscn index 4a3b2e3..6d807cf 100644 --- a/scenes/Babushka_scene_farm_vesna.tscn +++ b/scenes/Babushka_scene_farm_vesna.tscn @@ -40,7 +40,7 @@ _fieldParent = NodePath("../FieldParent") transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262) [node name="BaseField" parent="." instance=ExtResource("2_72r8y")] -transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.001, 0) +transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0) [node name="HoePickup" parent="." instance=ExtResource("4_r4sre")] transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -4.327, 1.5, -3.447) @@ -53,5 +53,9 @@ shape = SubResource("SphereShape3D_0ptl4") [node name="FieldParent" type="Node3D" parent="."] [node name="Inventory" parent="." instance=ExtResource("5_obfp0")] +visible = false + +[connection signal="Interacted" from="HoePickup" to="HoePickup/SpriteSwitcher Hoe" method="SwitchState"] +[connection signal="Switch" from="HoePickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateHoe"] [editable path="HoePickup"] diff --git a/scripts/CSharp/Common/CharacterControls/Player3D.cs b/scripts/CSharp/Common/CharacterControls/Player3D.cs index a8d4030..665d208 100644 --- a/scripts/CSharp/Common/CharacterControls/Player3D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player3D.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Godot; namespace Babushka.scripts.CSharp.Common.CharacterControls; @@ -17,21 +18,25 @@ public partial class Player3D : CharacterBody3D [Export] private AnimatedSprite3D[] _backSpritesAnimated; private bool _sideFlipped; + private Vector2 _lastDirection; public override void _PhysicsProcess(double delta) { - var inputDir = Input.GetVector("move_left", "move_right", "move_up", "move_down"); + var inputDir = Input.GetVector("move_left", "move_right", "move_down", "move_up"); if (inputDir == Vector2.Zero) + { + if(_lastDirection != Vector2.Zero) + SwitchIdleSprites(); return; - + } + MoveOnInput(inputDir, delta); - SwitchSprites(inputDir); + SwitchMovementSprites(inputDir); } private void MoveOnInput(Vector2 inputDir, double delta) { - inputDir = inputDir.Rotated(-_camera.GlobalRotation.Y); - var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized(); + var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y * (-1))).Normalized(); if (direction != Vector3.Zero) Velocity = new Vector3(direction.X * _speed * (float) delta * Scale.X, Velocity.Y, direction.Z * _speed * (float) delta * Scale.Z); else @@ -40,20 +45,34 @@ public partial class Player3D : CharacterBody3D MoveAndSlide(); } - private void SwitchSprites(Vector2 inputDir) + private void SwitchIdleSprites() { - float X = inputDir.X; - float Y = inputDir.Y; - - if (X == 0.0 && Y == 0.0) + if (_lastDirection.X != 0) { - ActivateFrontSpriteIdle(0, true, false, false); + ActivateSprite(0, false, true, false); return; } + if(_lastDirection.Y <= 0.0f) + ActivateSprite(0, true, false, false); + + if(_lastDirection.Y > 0.0f) + ActivateSprite(0, false, false, true); + + _lastDirection = Vector2.Zero; + } + + private void SwitchMovementSprites(Vector2 inputDir) + { + float X = inputDir.X; + float Y = inputDir.Y; + + _lastDirection = new Vector2(X, Y); + Debug.Print(_lastDirection.ToString()); + if (X != 0) { - ActivateFrontSpriteIdle(1, false, true, false); + ActivateSprite(1, false, true, false); if (X > 0.0f) { @@ -74,20 +93,19 @@ public partial class Player3D : CharacterBody3D if (Y != 0) { - if (Y < 0.0f) + if (Y > 0.0f) { - ActivateFrontSpriteIdle(1, false, false, true); + ActivateSprite(1, false, false, true); } - if (Y > 0.0f) + if (Y < 0.0f) { - ActivateFrontSpriteIdle(0, true, false, false); + ActivateSprite(1, true, false, false); } } - } - private void ActivateFrontSpriteIdle(int index, bool frontActive, bool sideActive, bool backActive) + private void ActivateSprite(int index, bool frontActive, bool sideActive, bool backActive) { DeactivateAll(); _frontSpritesAnimated[index].Visible = frontActive; From 6016f1cf38e1de7bb3136df0e7a2f8b0653080ab Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 9 Apr 2025 18:18:19 +0200 Subject: [PATCH 2/6] Removed Debug.Log --- scripts/CSharp/Common/CharacterControls/Player3D.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/CSharp/Common/CharacterControls/Player3D.cs b/scripts/CSharp/Common/CharacterControls/Player3D.cs index 665d208..03e2d3a 100644 --- a/scripts/CSharp/Common/CharacterControls/Player3D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player3D.cs @@ -68,7 +68,6 @@ public partial class Player3D : CharacterBody3D float Y = inputDir.Y; _lastDirection = new Vector2(X, Y); - Debug.Print(_lastDirection.ToString()); if (X != 0) { From ce5d2b65d34bb50937935e84dffd416f7f063719 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sun, 13 Apr 2025 14:35:14 +0200 Subject: [PATCH 3/6] Separated farming controls from vesna behvaiour and adjusted the setup --- prefabs/Player3D.tscn | 18 ++++++++----- .../CharacterControls/VesnaBehaviour.cs | 25 +++++++++++++++++++ .../CSharp/Common/Farming/FarmingControls.cs | 8 +++--- 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 22822e0..8a6d342 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=302 format=3 uid="uid://dbd1niu3tp8y5"] +[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"] [ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"] +[ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] [ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_3trg2"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"] [ext_resource type="Script" uid="uid://r5tahuqvbucy" path="res://scripts/CSharp/Common/Camera/CameraPivot.cs" id="3_3trg2"] @@ -1210,11 +1211,9 @@ animations = [{ "speed": 25.0 }] -[node name="Player3d" type="Node3D" node_paths=PackedStringArray("_hoeSprite", "_movingPlayer")] -script = ExtResource("4_q5t2e") -_hoeSprite = NodePath("CharacterBody3D/Farming/Hoe") -_fieldPrefab = ExtResource("2_oq5hi") -_movingPlayer = NodePath("CharacterBody3D") +[node name="Player3d" type="Node3D" node_paths=PackedStringArray("_farmingControls")] +script = ExtResource("1_pkl5l") +_farmingControls = NodePath("FarmingControls") [node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera", "_frontSpritesAnimated", "_sideSpritesAnimated", "_backSpritesAnimated")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000654221, 0.102765, -0.00300497) @@ -1330,3 +1329,10 @@ render_priority = 50 sprite_frames = SubResource("SpriteFrames_4q8ml") autoplay = "default" frame_progress = 0.481133 + +[node name="FarmingControls" type="Node3D" parent="." node_paths=PackedStringArray("_hoeSprite", "_movingPlayer")] +script = ExtResource("4_q5t2e") +_hoeSprite = NodePath("../CharacterBody3D/Farming/Hoe") +_fieldPrefab = ExtResource("2_oq5hi") +_movingPlayer = NodePath("../CharacterBody3D") +metadata/_custom_type_script = "uid://b1sscdr4ptec8" diff --git a/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs new file mode 100644 index 0000000..7a8e700 --- /dev/null +++ b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs @@ -0,0 +1,25 @@ +using Babushka.scripts.CSharp.Common.Farming; +using Godot; + +namespace Babushka.scripts.CSharp.Common.CharacterControls; + +public partial class VesnaBehaviour : Node +{ + [ExportGroup("Farming")] + [Export] private Node _fieldParent; + [Export] private FarmingControls _farmingControls; + + public override void _Ready() + { + _farmingControls.FieldParent = _fieldParent; + } + + #region Farming + + public void ActivateHoe(bool activate) + { + _farmingControls.ActivateHoe(activate); + } + + #endregion +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FarmingControls.cs b/scripts/CSharp/Common/Farming/FarmingControls.cs index d70d56a..2973a51 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls.cs @@ -2,13 +2,15 @@ using Godot; namespace Babushka.scripts.CSharp.Common.Farming; +[GlobalClass] public partial class FarmingControls : Node3D { [Export] private Sprite3D _hoeSprite; [Export] private PackedScene _fieldPrefab; - [Export] private Node _fieldParent; [Export] private Node3D _movingPlayer; + public Node FieldParent; + private bool _hoeInHand = false; public void ActivateHoe(bool activate) { @@ -26,7 +28,7 @@ public partial class FarmingControls : Node3D private void MakeField() { - if(_fieldParent == null || _fieldPrefab == null) + if(FieldParent == null || _fieldPrefab == null) return; Node fieldInstance = _fieldPrefab.Instantiate(); @@ -36,7 +38,7 @@ public partial class FarmingControls : Node3D field3d.Position = _movingPlayer.GlobalPosition; } - _fieldParent.AddChild(fieldInstance); + FieldParent.AddChild(fieldInstance); } From 5db71adf0350ad96b04dafc344b55aafdb3a800f Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sun, 13 Apr 2025 14:56:25 +0200 Subject: [PATCH 4/6] Fields spawn on a grid --- prefabs/farming/base_field.tscn | 2 +- scripts/CSharp/Common/Farming/FarmingControls.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/prefabs/farming/base_field.tscn b/prefabs/farming/base_field.tscn index f1ce041..4da26ea 100644 --- a/prefabs/farming/base_field.tscn +++ b/prefabs/farming/base_field.tscn @@ -19,7 +19,7 @@ _showLabel = false shape = SubResource("SphereShape3D_u7egi") [node name="Sprite3D" type="Sprite3D" parent="."] -transform = Transform3D(0.5, 0, 0, 0, -2.18557e-08, -0.5, 0, 0.5, -2.18557e-08, 0, 0, 0) +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") diff --git a/scripts/CSharp/Common/Farming/FarmingControls.cs b/scripts/CSharp/Common/Farming/FarmingControls.cs index 2973a51..4463a22 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; @@ -12,6 +13,7 @@ public partial class FarmingControls : Node3D public Node FieldParent; private bool _hoeInHand = false; + private Dictionary, bool> _spawnedFields = new Dictionary, bool>(); public void ActivateHoe(bool activate) { _hoeSprite.Visible = !activate; @@ -35,11 +37,16 @@ public partial class FarmingControls : Node3D if (fieldInstance is Node3D field3d) { - field3d.Position = _movingPlayer.GlobalPosition; + Vector3 playerPos = _movingPlayer.GlobalPosition; + field3d.Position = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z)); } FieldParent.AddChild(fieldInstance); - + } + private float AdjustValue(float value) + { + return Mathf.Floor(value); } + } \ No newline at end of file From 0e775309fb92f1111f1ec8260812d87c8d1cb094 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sun, 13 Apr 2025 15:01:49 +0200 Subject: [PATCH 5/6] Scene changes --- prefabs/Player3D.tscn | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 8a6d342..582711b 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"] +[gd_scene load_steps=302 format=3 uid="uid://dbd1niu3tp8y5"] [ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"] [ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] [ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_3trg2"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"] -[ext_resource type="Script" uid="uid://r5tahuqvbucy" path="res://scripts/CSharp/Common/Camera/CameraPivot.cs" id="3_3trg2"] [ext_resource type="Texture2D" uid="uid://c4ggew55w0icj" path="res://art/farm/farming/farmobjekte/harke.png" id="4_kngqo"] [ext_resource type="Script" uid="uid://b1sscdr4ptec8" path="res://scripts/CSharp/Common/Farming/FarmingControls.cs" id="4_q5t2e"] [ext_resource type="Texture2D" uid="uid://dygkh117flcou" path="res://art/animation/vesna/Front/F01-Idle/0001.png" id="7_okmao"] @@ -1240,10 +1239,8 @@ region_rect = Rect2(52, 20, 648, 1175) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.119886, 0) shape = SubResource("CapsuleShape3D_1vdrh") -[node name="CameraPivot2" type="Node3D" parent="CharacterBody3D" node_paths=PackedStringArray("_subPivot")] +[node name="CameraPivot2" type="Node3D" parent="CharacterBody3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.159723, 0) -script = ExtResource("3_3trg2") -_subPivot = NodePath("SubPivot") [node name="SubPivot" type="Node3D" parent="CharacterBody3D/CameraPivot2"] From c200098f0caeedc4f383f8638a5e20876d0ce4e9 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Mon, 14 Apr 2025 00:08:19 +0200 Subject: [PATCH 6/6] WIP reworking the field behaviour to implement watering. Broken state. --- prefabs/Player3D.tscn | 17 ++++++- prefabs/interactions/sprite_switcher.tscn | 8 ++-- scenes/Babushka_scene_farm_vesna.tscn | 33 +++++++++++-- .../CharacterControls/VesnaBehaviour.cs | 25 +++++++++- .../CSharp/Common/Farming/FarmingControls.cs | 46 +++++++++++++++--- .../CSharp/Common/Farming/FieldBehaviour.cs | 10 +++- scripts/CSharp/Common/Farming/FieldService.cs | 47 +++++++++++++++++++ 7 files changed, 168 insertions(+), 18 deletions(-) create mode 100644 scripts/CSharp/Common/Farming/FieldService.cs diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 582711b..73507af 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=302 format=3 uid="uid://dbd1niu3tp8y5"] +[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"] [ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"] [ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"] [ext_resource type="Texture2D" uid="uid://c4ggew55w0icj" path="res://art/farm/farming/farmobjekte/harke.png" id="4_kngqo"] [ext_resource type="Script" uid="uid://b1sscdr4ptec8" path="res://scripts/CSharp/Common/Farming/FarmingControls.cs" id="4_q5t2e"] +[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="5_pkl5l"] [ext_resource type="Texture2D" uid="uid://dygkh117flcou" path="res://art/animation/vesna/Front/F01-Idle/0001.png" id="7_okmao"] [ext_resource type="Texture2D" uid="uid://rwqptk0hk53" path="res://art/animation/vesna/Front/F01-Idle/0002.png" id="8_ctpgn"] [ext_resource type="Texture2D" uid="uid://c5om11bu7mtvh" path="res://art/animation/vesna/Front/F01-Idle/0003.png" id="9_8n7il"] @@ -1257,6 +1258,15 @@ billboard = 1 render_priority = 51 texture = ExtResource("4_kngqo") +[node name="Watering can" type="Sprite3D" parent="CharacterBody3D/Farming"] +visible = false +pixel_size = 0.002 +billboard = 1 +render_priority = 51 +texture = ExtResource("5_pkl5l") +region_enabled = true +region_rect = Rect2(-2, 1135, 425, 291) + [node name="Front" type="Node3D" parent="CharacterBody3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.001, 0.1, 0.003) @@ -1327,9 +1337,12 @@ sprite_frames = SubResource("SpriteFrames_4q8ml") autoplay = "default" frame_progress = 0.481133 -[node name="FarmingControls" type="Node3D" parent="." node_paths=PackedStringArray("_hoeSprite", "_movingPlayer")] +[node name="FarmingControls" type="Node3D" parent="." node_paths=PackedStringArray("_hoeSprite", "_wateringCanSprite", "_movingPlayer")] script = ExtResource("4_q5t2e") _hoeSprite = NodePath("../CharacterBody3D/Farming/Hoe") +_wateringCanSprite = NodePath("../CharacterBody3D/Farming/Watering can") _fieldPrefab = ExtResource("2_oq5hi") _movingPlayer = NodePath("../CharacterBody3D") metadata/_custom_type_script = "uid://b1sscdr4ptec8" + +[connection signal="WaterField" from="FarmingControls" to="." method="UseWateringCan"] diff --git a/prefabs/interactions/sprite_switcher.tscn b/prefabs/interactions/sprite_switcher.tscn index f69e2cb..196aab6 100644 --- a/prefabs/interactions/sprite_switcher.tscn +++ b/prefabs/interactions/sprite_switcher.tscn @@ -13,17 +13,17 @@ emission = Color(1, 1, 1, 1) [node name="SpriteSwitcher" type="Node3D" node_paths=PackedStringArray("_trueSprite", "_falseSprite")] script = ExtResource("1_scmhv") -_trueSprite = NodePath("Hoe on") -_falseSprite = NodePath("Hoe off") +_trueSprite = NodePath("On Sprite") +_falseSprite = NodePath("Off Sprite") -[node name="Hoe on" type="Sprite3D" parent="."] +[node name="On Sprite" type="Sprite3D" parent="."] modulate = Color(0, 0.996078, 0, 1) pixel_size = 0.001 billboard = 1 texture = ExtResource("2_jv400") region_rect = Rect2(484, 143, 365, 1317) -[node name="Hoe off" type="Sprite3D" parent="."] +[node name="Off Sprite" type="Sprite3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, -8.47033e-22, 0, 8.47033e-22, 1, 0.106585, 0, 0.0173626) visible = false modulate = Color(1, 0, 0, 1) diff --git a/scenes/Babushka_scene_farm_vesna.tscn b/scenes/Babushka_scene_farm_vesna.tscn index 6d807cf..9e1516f 100644 --- a/scenes/Babushka_scene_farm_vesna.tscn +++ b/scenes/Babushka_scene_farm_vesna.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=10 format=3 uid="uid://br7yq757cawts"] +[gd_scene load_steps=12 format=3 uid="uid://br7yq757cawts"] [ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="1_b1ibi"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_72r8y"] [ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="4_r4sre"] [ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="5_obfp0"] +[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="5_r4sre"] [ext_resource type="PackedScene" uid="uid://cf0jpuio8tgim" path="res://prefabs/interactions/sprite_switcher.tscn" id="6_r4sre"] +[ext_resource type="Script" uid="uid://c6hh7m8wikv04" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_0ptl4"] [sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"] @@ -34,13 +36,14 @@ shape = SubResource("BoxShape3D_t58di") [node name="Player3d" parent="." node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_b1ibi")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249) -_fieldParent = NodePath("../FieldParent") +_fieldParent = NodePath("../FieldService") [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262) [node name="BaseField" parent="." instance=ExtResource("2_72r8y")] transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0) +visible = false [node name="HoePickup" parent="." instance=ExtResource("4_r4sre")] transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -4.327, 1.5, -3.447) @@ -50,12 +53,36 @@ shape = SubResource("SphereShape3D_0ptl4") [node name="SpriteSwitcher Hoe" parent="HoePickup" instance=ExtResource("6_r4sre")] -[node name="FieldParent" type="Node3D" parent="."] +[node name="Watering Can Pickup" parent="." instance=ExtResource("4_r4sre")] +transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -2.3908, 1.5, -3.447) + +[node name="CollisionShape3D" parent="Watering Can Pickup/Area3D" index="0"] +shape = SubResource("SphereShape3D_0ptl4") + +[node name="SpriteSwitcher Hoe" parent="Watering Can Pickup" instance=ExtResource("6_r4sre")] + +[node name="On Sprite" parent="Watering Can Pickup/SpriteSwitcher Hoe" index="0"] +texture = ExtResource("5_r4sre") +region_enabled = true +region_rect = Rect2(-3, 1141, 423, 280) + +[node name="Off Sprite" parent="Watering Can Pickup/SpriteSwitcher Hoe" index="1"] +texture = ExtResource("5_r4sre") +region_enabled = true +region_rect = Rect2(-3, 1137, 424, 285) [node name="Inventory" parent="." instance=ExtResource("5_obfp0")] visible = false +[node name="FieldService" type="Node3D" parent="."] +script = ExtResource("7_0ptl4") +metadata/_custom_type_script = "uid://c6hh7m8wikv04" + [connection signal="Interacted" from="HoePickup" to="HoePickup/SpriteSwitcher Hoe" method="SwitchState"] [connection signal="Switch" from="HoePickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateHoe"] +[connection signal="Interacted" from="Watering Can Pickup" to="Watering Can Pickup/SpriteSwitcher Hoe" method="SwitchState"] +[connection signal="Switch" from="Watering Can Pickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateWateringCan"] [editable path="HoePickup"] +[editable path="Watering Can Pickup"] +[editable path="Watering Can Pickup/SpriteSwitcher Hoe"] diff --git a/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs index 7a8e700..b8ba6a8 100644 --- a/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs +++ b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs @@ -6,8 +6,10 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls; public partial class VesnaBehaviour : Node { [ExportGroup("Farming")] - [Export] private Node _fieldParent; + [Export] private FieldService _fieldParent; [Export] private FarmingControls _farmingControls; + + [Signal] public delegate void ToolPickupEventHandler(bool success); public override void _Ready() { @@ -18,7 +20,26 @@ public partial class VesnaBehaviour : Node public void ActivateHoe(bool activate) { - _farmingControls.ActivateHoe(activate); + ActivateTool(activate, 0); + } + + public void ActivateWateringCan(bool activate) + { + ActivateTool(activate, 1); + } + + private void ActivateTool(bool activate , int toolId) + { + bool success = false; + if (toolId == 0) + { + success = _farmingControls.ActivateHoe(activate); + } + else if (toolId == 1) + { + success = _farmingControls.ActivateWateringCan(activate); + } + EmitSignal(SignalName.ToolPickup, success); } #endregion diff --git a/scripts/CSharp/Common/Farming/FarmingControls.cs b/scripts/CSharp/Common/Farming/FarmingControls.cs index 4463a22..737e124 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls.cs @@ -7,18 +7,38 @@ namespace Babushka.scripts.CSharp.Common.Farming; public partial class FarmingControls : Node3D { [Export] private Sprite3D _hoeSprite; + [Export] private Sprite3D _wateringCanSprite; [Export] private PackedScene _fieldPrefab; [Export] private Node3D _movingPlayer; - public Node FieldParent; + public FieldService FieldParent; private bool _hoeInHand = false; - private Dictionary, bool> _spawnedFields = new Dictionary, bool>(); - public void ActivateHoe(bool activate) + private bool _waterCanInHand = false; + + #region Tools + + public bool ActivateHoe(bool activate) + { + bool success = ActivateTool(activate, _hoeSprite); + _hoeInHand = success; + return success; + } + + public bool ActivateWateringCan(bool activate) { - _hoeSprite.Visible = !activate; - _hoeInHand = !activate; + bool success = ActivateTool(activate, _wateringCanSprite); + _waterCanInHand = success; + return success; } + + private bool ActivateTool(bool activate, Sprite3D tool) + { + tool.Visible = !activate; + return !activate; + } + + #endregion public override void _Input(InputEvent @event) { @@ -26,6 +46,16 @@ public partial class FarmingControls : Node3D { MakeField(); } + + if (@event.IsActionPressed("click") && _waterCanInHand) + { + WaterTheField(); + } + } + + private void WaterTheField() + { + } private void MakeField() @@ -38,9 +68,13 @@ public partial class FarmingControls : Node3D if (fieldInstance is Node3D field3d) { Vector3 playerPos = _movingPlayer.GlobalPosition; - field3d.Position = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z)); + playerPos = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z)); + field3d.Position = playerPos; + Vector2I intPosition = new Vector2I((int) playerPos.X, (int) playerPos.Z); + FieldParent.AddEntry(intPosition, FieldState.Tilled); } + FieldParent.AddChild(fieldInstance); } diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour.cs b/scripts/CSharp/Common/Farming/FieldBehaviour.cs index dd7ba4d..23bcde9 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour.cs @@ -13,14 +13,22 @@ public enum FieldState public partial class FieldBehaviour : Sprite3D { [Export] private Texture2D Tilled; - [Export] private Texture3D Watered; + [Export] private Texture2D Watered; [Export] private FieldState FieldState = FieldState.Empty; + public Vector2 FieldPosition; + public override void _Ready() { Texture = Tilled; base._Ready(); } + + public void Water() + { + FieldState = FieldState.Watered; + Texture = Watered; + } /// /// Called when the player enters the field'S interaction area and presses . diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs new file mode 100644 index 0000000..79834b1 --- /dev/null +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -0,0 +1,47 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Common.Farming; + +[GlobalClass] +public partial class FieldService : Node3D +{ + [Export] private Dictionary fields = new Dictionary(); + + //Create + + public void AddEntry(Vector2I key, FieldState state) + { + fields.Add(key, state); + } + + // Read + + public FieldState Get(Vector2I key) + { + return fields[key]; + } + + //Update + public void UpdateEntry(Vector2I fieldPosition, FieldState state) + { + if (fields.ContainsKey(fieldPosition)) + { + fields[fieldPosition] = state; + } + else + { + AddEntry(fieldPosition, state); + } + } + + //Delete + + public void RemoveEntry(Vector2I fieldPosition) + { + if (fields.ContainsKey(fieldPosition)) + { + fields.Remove(fieldPosition); + } + } +} \ No newline at end of file