From 6194988bf002a93ec8640572ea45afb2d606694e Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 31 Oct 2025 12:07:05 +0100 Subject: [PATCH 01/29] :art: removed plant growing call group and replaced it with an event call. Made FarmingAnimation play on event. --- prefabs/characters/Player2D.tscn | 11 +++++++++-- prefabs/farm/base_field.tscn | 9 ++++++++- project.godot | 2 +- resources/low code/farming/event_newPlantCreated.tres | 7 +++++++ scripts/CSharp/Common/Farming/FieldBehaviour2D.cs | 9 ++++++--- scripts/CSharp/Common/Farming/PlantBehaviour2D.cs | 2 -- 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 resources/low code/farming/event_newPlantCreated.tres diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index 4e36931..5ce1757 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=482 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=484 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -272,8 +272,10 @@ [ext_resource type="Texture2D" uid="uid://vahac0df0dhj" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0008.png" id="464_pbc3r"] [ext_resource type="PackedScene" uid="uid://pflu0uaig7vv" path="res://prefabs/interactions/detection_cross.tscn" id="466_e04c3"] [ext_resource type="Texture2D" uid="uid://b37lpqrsjjuc0" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0010.png" id="466_pw1ip"] +[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="467_8hbu5"] [ext_resource type="Script" uid="uid://er03dkj8axlr" path="res://scripts/CSharp/Common/UI/WateringCanUi.cs" id="467_j4m0f"] [ext_resource type="Texture2D" uid="uid://oi11ax6tml6j" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0012.png" id="468_08021"] +[ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="468_t1d6r"] [ext_resource type="Texture2D" uid="uid://dsjj23763pej5" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0014.png" id="470_bmmei"] [ext_resource type="AudioStream" uid="uid://ce5mxs2yrwgrh" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_01_R.wav" id="470_dnm27"] [ext_resource type="Script" uid="uid://dx25g14a7xi4w" path="res://scripts/CSharp/Common/Audio/AudioPlayer.cs" id="471_2f15g"] @@ -2103,7 +2105,7 @@ position = Vector2(-24, -13) shape = SubResource("CircleShape2D_ssqtd") debug_color = Color(0.923708, 0.202722, 0.475262, 0.42) -[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles") groups=["Pickup", "PlantGrowing"]] +[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles") groups=["Pickup"]] position = Vector2(0, -374) script = ExtResource("3_f6xmn") _sprite = NodePath("Animated Sprites") @@ -2142,6 +2144,10 @@ scrollable = false [node name="DetectionCross" parent="CharacterBody2D" instance=ExtResource("466_e04c3")] position = Vector2(0, -200) +[node name="PlantCreatedEventListener" type="Node" parent="CharacterBody2D"] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("468_t1d6r")]) + [node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_wateringParticles")] script = ExtResource("817_6nrw3") _fieldPrefab = ExtResource("818_16w6h") @@ -2192,6 +2198,7 @@ wait_time = 0.5 [connection signal="PickedUpTool" from="." to="CharacterBody2D/visuals" method="ActivateTool"] [connection signal="PickedUpTool" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] [connection signal="LookDirection" from="CharacterBody2D/visuals" to="CharacterBody2D/DetectionCross" method="SetDirection"] +[connection signal="EventRaised" from="CharacterBody2D/PlantCreatedEventListener" to="CharacterBody2D/visuals" method="PlayFarmingAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/WateringCanUI" method="Water"] [connection signal="timelineEnded" from="dialogic toggle" to="." method="EnableMovement"] diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index ab21577..43b27a3 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=11 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"] @@ -8,6 +8,8 @@ [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"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="9_teirr"] +[ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"] [node name="BaseField" type="Node2D"] @@ -39,4 +41,9 @@ position = Vector2(-16, -54) _active = false _spriteToOutline = NodePath("../FieldBehaviour/MaskedField/FieldTexture") +[node name="PlantCreationEventRaiser" type="Node" parent="."] +script = ExtResource("9_teirr") +_eventResources = Array[Object]([ExtResource("10_wx561")]) + +[connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] diff --git a/project.godot b/project.godot index 177a1b4..30e30a1 100644 --- a/project.godot +++ b/project.godot @@ -145,6 +145,7 @@ directories/tres_directory={ "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", "event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", +"event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres", "event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", @@ -215,7 +216,6 @@ folder_colors={ [global_group] -PlantGrowing="" Pickup="" [input] diff --git a/resources/low code/farming/event_newPlantCreated.tres b/resources/low code/farming/event_newPlantCreated.tres new file mode 100644 index 0000000..754f2e2 --- /dev/null +++ b/resources/low code/farming/event_newPlantCreated.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://b4hawvsc7cmkn"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_o6pnj"] + +[resource] +script = ExtResource("1_o6pnj") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 19ad9d0..30d8f4d 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -21,6 +21,8 @@ public partial class FieldBehaviour2D : Sprite2D public Vector2 FieldPosition; + [Signal] public delegate void PlantedEventHandler(); + public override void _Ready() { UpdateFieldState(FieldState); @@ -65,13 +67,14 @@ public partial class FieldBehaviour2D : Sprite2D } /// - /// Called when the player enters the field's interaction area and presses . + /// Called when the player enters the field's interaction area and presses or clicks. /// public void Farm() { if (TryPlant()) - { - UpdateFieldState(FieldState.Planted); + { + EmitSignal(SignalName.Planted); + UpdateFieldState(FieldState.Planted); } } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 6a3439a..ca8bc30 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -39,7 +39,6 @@ public partial class PlantBehaviour2D : Node2D { if (_state == PlantState.None) { - GetTree().CallGroup("PlantGrowing", VesnaAnimations.MethodName.PlayFarmingAnimation); _state = PlantState.Planted; _currentPlantSprite = GetRandomSprite(_seeds); _currentPlantSprite.Visible = true; @@ -52,7 +51,6 @@ public partial class PlantBehaviour2D : Node2D public void Grow() { - GetTree().CallGroup("PlantGrowing", VesnaAnimations.MethodName.PlayFarmingAnimation); GrowPlant(); } -- 2.36.3 From b54f784d51e4b67cd8de2912c7fe53510cc009af Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 31 Oct 2025 12:36:08 +0100 Subject: [PATCH 02/29] :art: Replaced pickup animation group call with event --- prefabs/Interactables/trash_object.tscn | 12 ++++++++---- prefabs/characters/Player2D.tscn | 8 +++++++- prefabs/interactions/generic_item_on_ground_2d.tscn | 8 +++++++- project.godot | 5 +---- .../interactables/event_PickedUpInteractable.tres | 7 +++++++ scripts/CSharp/Common/Items/NonInventoryPickup.cs | 13 ------------- .../CSharp/Common/Items/NonInventoryPickup.cs.uid | 1 - 7 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 resources/low code/interactables/event_PickedUpInteractable.tres delete mode 100644 scripts/CSharp/Common/Items/NonInventoryPickup.cs delete mode 100644 scripts/CSharp/Common/Items/NonInventoryPickup.cs.uid diff --git a/prefabs/Interactables/trash_object.tscn b/prefabs/Interactables/trash_object.tscn index 190183e..fc5f532 100644 --- a/prefabs/Interactables/trash_object.tscn +++ b/prefabs/Interactables/trash_object.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=16 format=3 uid="uid://sbf12hin4kes"] +[gd_scene load_steps=17 format=3 uid="uid://sbf12hin4kes"] [ext_resource type="Texture2D" uid="uid://bylgmr0skwtrs" path="res://art/farm/farming/farmobjekte/broken tools atlas.png" id="1_k4ca3"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="2_gcgfd"] -[ext_resource type="Script" uid="uid://dkk1vjijvgrd7" path="res://scripts/CSharp/Common/Items/NonInventoryPickup.cs" id="2_ic616"] [ext_resource type="AudioStream" uid="uid://be6g8b3v3u1ai" path="res://audio/sfx/Kitchen/SFX_Cooking_Knife_PickUp_01.wav" id="3_ktmp7"] [ext_resource type="AudioStream" uid="uid://cgjsajsdrrn0j" path="res://audio/sfx/Kitchen/SFX_Cooking_Knife_PutDown_01.wav" id="4_ic616"] [ext_resource type="AudioStream" uid="uid://br4drgupled6c" path="res://audio/sfx/Kitchen/SFX_Cooking_Pot_01.wav" id="5_dx175"] @@ -14,6 +13,8 @@ [ext_resource type="AudioStream" uid="uid://bc216pfieuc8h" path="res://audio/sfx/Kitchen/SFX_Cutlery_04.wav" id="11_kb03l"] [ext_resource type="AudioStream" uid="uid://dp6qen84ptlvx" path="res://audio/sfx/Kitchen/SFX_Cutlery_05.wav" id="12_kka6u"] [ext_resource type="Script" uid="uid://cfnrd5k1k0gxw" path="res://scripts/CSharp/Common/AudioPlayer2D.cs" id="13_wswkg"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="14_dx175"] +[ext_resource type="Resource" uid="uid://78t0o27g6aq6" path="res://resources/low code/interactables/event_PickedUpInteractable.tres" id="15_u7jgg"] [sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_dich4"] streams_count = 10 @@ -35,7 +36,6 @@ texture = ExtResource("1_k4ca3") offset = Vector2(1, -215) region_enabled = true region_rect = Rect2(44, 479, 356, 503) -script = ExtResource("2_ic616") [node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("2_gcgfd")] position = Vector2(0, -172) @@ -47,6 +47,10 @@ bus = &"SFX" playback_type = 2 script = ExtResource("13_wswkg") +[node name="PickupAnimationEventRaiser" type="Node" parent="."] +script = ExtResource("14_dx175") +_eventResources = Array[Object]([ExtResource("15_u7jgg")]) + [connection signal="Interacted" from="InteractionArea" to="." method="queue_free"] -[connection signal="Interacted" from="InteractionArea" to="." method="PlayPickupAnimation"] [connection signal="Interacted" from="InteractionArea" to="AudioStreamPlayer2D" method="PlayOneShot"] +[connection signal="Interacted" from="InteractionArea" to="PickupAnimationEventRaiser" method="RaiseEvents"] diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index 5ce1757..fc8ae04 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=484 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=485 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -276,6 +276,7 @@ [ext_resource type="Script" uid="uid://er03dkj8axlr" path="res://scripts/CSharp/Common/UI/WateringCanUi.cs" id="467_j4m0f"] [ext_resource type="Texture2D" uid="uid://oi11ax6tml6j" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0012.png" id="468_08021"] [ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="468_t1d6r"] +[ext_resource type="Resource" uid="uid://78t0o27g6aq6" path="res://resources/low code/interactables/event_PickedUpInteractable.tres" id="469_t1d6r"] [ext_resource type="Texture2D" uid="uid://dsjj23763pej5" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0014.png" id="470_bmmei"] [ext_resource type="AudioStream" uid="uid://ce5mxs2yrwgrh" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_01_R.wav" id="470_dnm27"] [ext_resource type="Script" uid="uid://dx25g14a7xi4w" path="res://scripts/CSharp/Common/Audio/AudioPlayer.cs" id="471_2f15g"] @@ -2148,6 +2149,10 @@ position = Vector2(0, -200) script = ExtResource("467_8hbu5") _eventResources = Array[Object]([ExtResource("468_t1d6r")]) +[node name="PickedUpInteractableListener" type="Node" parent="CharacterBody2D"] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("469_t1d6r")]) + [node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_wateringParticles")] script = ExtResource("817_6nrw3") _fieldPrefab = ExtResource("818_16w6h") @@ -2199,6 +2204,7 @@ wait_time = 0.5 [connection signal="PickedUpTool" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] [connection signal="LookDirection" from="CharacterBody2D/visuals" to="CharacterBody2D/DetectionCross" method="SetDirection"] [connection signal="EventRaised" from="CharacterBody2D/PlantCreatedEventListener" to="CharacterBody2D/visuals" method="PlayFarmingAnimation"] +[connection signal="EventRaised" from="CharacterBody2D/PickedUpInteractableListener" to="CharacterBody2D/visuals" method="PlayPickUpAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/WateringCanUI" method="Water"] [connection signal="timelineEnded" from="dialogic toggle" to="." method="EnableMovement"] diff --git a/prefabs/interactions/generic_item_on_ground_2d.tscn b/prefabs/interactions/generic_item_on_ground_2d.tscn index 574dac0..5282bd1 100644 --- a/prefabs/interactions/generic_item_on_ground_2d.tscn +++ b/prefabs/interactions/generic_item_on_ground_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://dpbbroif2tnil"] +[gd_scene load_steps=17 format=3 uid="uid://dpbbroif2tnil"] [ext_resource type="Script" uid="uid://btusf04xnywhm" path="res://scripts/CSharp/Common/Inventory/ItemOnGround2D.cs" id="1_tlhp6"] [ext_resource type="Script" uid="uid://c8suoi3i6kqai" path="res://scripts/CSharp/Common/Inventory/ItemOnGroundSpawnWith.cs" id="3_xu8me"] @@ -10,6 +10,8 @@ [ext_resource type="AudioStream" uid="uid://bqm6rchwtelxj" path="res://audio/sfx/UI/SFX_ItemPickUp_03.wav" id="8_kflfw"] [ext_resource type="AudioStream" uid="uid://brsufnpmig5fv" path="res://audio/sfx/UI/SFX_ItemPickUp_04.wav" id="9_dltn0"] [ext_resource type="Script" uid="uid://dx25g14a7xi4w" path="res://scripts/CSharp/Common/Audio/AudioPlayer.cs" id="10_clbey"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="11_kflfw"] +[ext_resource type="Resource" uid="uid://78t0o27g6aq6" path="res://resources/low code/interactables/event_PickedUpInteractable.tres" id="12_dltn0"] [sub_resource type="Theme" id="Theme_tlhp6"] default_font_size = 80 @@ -74,6 +76,10 @@ bus = &"SFX" playback_type = 2 script = ExtResource("10_clbey") +[node name="PickUpEventRaiser" type="Node" parent="."] +script = ExtResource("11_kflfw") +_eventResources = Array[Object]([ExtResource("12_dltn0")]) + [connection signal="Interacted" from="PickupInteractionArea" to="." method="TryPickUp"] [connection signal="Interacted" from="PickupInteractionArea" to="SFX/PickUpSound" method="PlayOneShot"] diff --git a/project.godot b/project.godot index 30e30a1..b456426 100644 --- a/project.godot +++ b/project.godot @@ -144,6 +144,7 @@ directories/tres_directory={ "default_bus_layout": "res://audio/default_bus_layout.tres", "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", +"event_PickedUpInteractable": "res://resources/low code/interactables/event_PickedUpInteractable.tres", "event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", "event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres", "event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", @@ -214,10 +215,6 @@ folder_colors={ "res://shader/": "pink" } -[global_group] - -Pickup="" - [input] move_left={ diff --git a/resources/low code/interactables/event_PickedUpInteractable.tres b/resources/low code/interactables/event_PickedUpInteractable.tres new file mode 100644 index 0000000..9865d84 --- /dev/null +++ b/resources/low code/interactables/event_PickedUpInteractable.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://78t0o27g6aq6"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_acx84"] + +[resource] +script = ExtResource("1_acx84") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scripts/CSharp/Common/Items/NonInventoryPickup.cs b/scripts/CSharp/Common/Items/NonInventoryPickup.cs deleted file mode 100644 index 1124923..0000000 --- a/scripts/CSharp/Common/Items/NonInventoryPickup.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Babushka.scripts.CSharp.Common.Animation; -using Godot; - -namespace Babushka.scripts.CSharp.Common.Items; - -public partial class NonInventoryPickup : Node2D -{ - public void PlayPickupAnimation() - { - // todo: replace with EventBus implementation as soon as this is possible - GetTree().CallGroup("Pickup", VesnaAnimations.MethodName.PlayPickUpAnimation); - } -} \ No newline at end of file diff --git a/scripts/CSharp/Common/Items/NonInventoryPickup.cs.uid b/scripts/CSharp/Common/Items/NonInventoryPickup.cs.uid deleted file mode 100644 index 699a9ee..0000000 --- a/scripts/CSharp/Common/Items/NonInventoryPickup.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dkk1vjijvgrd7 -- 2.36.3 From 63fd81e54d648c487f3e55eac8d783bb3a8a3008 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 31 Oct 2025 12:38:48 +0100 Subject: [PATCH 03/29] :fire: removed no longer needed scene call group --- prefabs/characters/Player2D.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index fc8ae04..bcb282b 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -2106,7 +2106,7 @@ position = Vector2(-24, -13) shape = SubResource("CircleShape2D_ssqtd") debug_color = Color(0.923708, 0.202722, 0.475262, 0.42) -[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles") groups=["Pickup"]] +[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles")] position = Vector2(0, -374) script = ExtResource("3_f6xmn") _sprite = NodePath("Animated Sprites") -- 2.36.3 From 6ba26c360dc62800ec3be41b112677fa5513e20a Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 31 Oct 2025 14:08:55 +0100 Subject: [PATCH 04/29] :construction: reworking Fieldservice --- Babushka.sln.DotSettings.user | 1 + prefabs/farm/plants/beet_plant.tscn | 5 +- .../Common/Farming/FarmingControls2D.cs | 5 ++ .../CSharp/Common/Farming/FieldBehaviour2D.cs | 2 + scripts/CSharp/Common/Farming/FieldService.cs | 77 +++++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 scripts/CSharp/Common/Farming/FieldService.cs diff --git a/Babushka.sln.DotSettings.user b/Babushka.sln.DotSettings.user index 225a89d..146655c 100644 --- a/Babushka.sln.DotSettings.user +++ b/Babushka.sln.DotSettings.user @@ -10,6 +10,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/prefabs/farm/plants/beet_plant.tscn b/prefabs/farm/plants/beet_plant.tscn index 8f6dedc..8bdd8ed 100644 --- a/prefabs/farm/plants/beet_plant.tscn +++ b/prefabs/farm/plants/beet_plant.tscn @@ -12,7 +12,7 @@ radius = 300.0 resource_local_to_scene = true radius = 300.0 -[node name="Beet2" instance=ExtResource("1_2u3jr")] +[node name="Beet" instance=ExtResource("1_2u3jr")] [node name="Seed1" parent="Seeds" index="0"] texture = ExtResource("2_agmuy") @@ -47,6 +47,9 @@ shape = SubResource("CircleShape2D_hiixr") [node name="SpawnWithItem" parent="ReadyPlantInventoryItem" index="0"] _blueprint = ExtResource("3_agmuy") +[node name="PickupInteractionArea" parent="ReadyPlantInventoryItem" index="3"] +_active = false + [node name="CollisionShape3D" parent="ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_ae08q") diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index c9e259c..f737bb1 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -56,6 +56,7 @@ public partial class FarmingControls2D : Node2D && _toolId == WateringCanState.WATERING_CAN_ID && WateringCanState.GetFillState() > 0) { + GD.Print("Trying to use the watering can."); Vector2I adjustedPosition = GetAdjustedMousePosition(); WaterTheField(adjustedPosition); } @@ -117,11 +118,15 @@ public partial class FarmingControls2D : Node2D { FieldBehaviour2D field = FieldService.Get(fieldPosition); if (field == null || field.FieldState == FieldState.Watered) + { + GD.Print($"The field at position {fieldPosition} is null!"); return; + } field.Water(); _wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset); WateringCanState.Water(); + GD.Print($"Watered the field at {fieldPosition}."); EmitSignal(SignalName.WateringField); } diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 30d8f4d..98adfe3 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -20,11 +20,13 @@ public partial class FieldBehaviour2D : Sprite2D public Vector2 FieldPosition; + public FieldService2D FieldService; [Signal] public delegate void PlantedEventHandler(); public override void _Ready() { + UpdateFieldState(FieldState); int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs new file mode 100644 index 0000000..a5b594f --- /dev/null +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Common.Farming; + +public partial class FieldService : Node2D +{ + private Dictionary? fieldsPerScene; + + + + [Signal] public delegate void FieldCreatedEventHandler(); + + //Create + public bool TryAddEntry(PackedScene scene, Vector2I key, FieldBehaviour2D field) + { + if (!fieldsPerScene.ContainsKey(scene)) + { + FieldsInScene fieldInstance = new FieldsInScene(); + fieldsPerScene.Add(scene, fieldInstance); + EmitSignal(SignalName.FieldCreated); + return true; + } + return false; + } + + // Read + public FieldBehaviour2D Get(PackedScene key, Vector2I fieldPosition) + { + if (fieldsPerScene.TryGetValue(key, out FieldsInScene field)) + { + if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D fieldInstance)) + return fieldInstance; + } + + return null; + } + + //todo: + // - Make this a singleton + // - Let this interact with the FarmingControls and the FieldBehaviours + // - Replace FieldService2D and remove it from scenes. + + + /* + //Update + public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour2D state) + { + + if (fields.ContainsKey(fieldPosition)) + { + fields[fieldPosition] = state; + } + else + { + TryAddEntry(fieldPosition, state); + } + } + + //Delete + + public void RemoveEntry(Vector2I fieldPosition) + { + if (fields.ContainsKey(fieldPosition)) + { + fields.Remove(fieldPosition); + } + } + */ +} + +internal class FieldsInScene +{ + public Dictionary fields; +} + + -- 2.36.3 From 8d616735f4c19356df02dff80ef23249dcb46a9f Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 4 Nov 2025 16:40:19 +0100 Subject: [PATCH 05/29] :truck: moved Animationfix script --- AnimationFix.gd => scripts/GdScript/AnimationFix.gd | 0 AnimationFix.gd.uid => scripts/GdScript/AnimationFix.gd.uid | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename AnimationFix.gd => scripts/GdScript/AnimationFix.gd (100%) rename AnimationFix.gd.uid => scripts/GdScript/AnimationFix.gd.uid (100%) diff --git a/AnimationFix.gd b/scripts/GdScript/AnimationFix.gd similarity index 100% rename from AnimationFix.gd rename to scripts/GdScript/AnimationFix.gd diff --git a/AnimationFix.gd.uid b/scripts/GdScript/AnimationFix.gd.uid similarity index 100% rename from AnimationFix.gd.uid rename to scripts/GdScript/AnimationFix.gd.uid -- 2.36.3 From 8b77ca9bc58aec869adba1a072b620b3065276ea Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 4 Nov 2025 17:20:15 +0100 Subject: [PATCH 06/29] :recycle: migrated the InteractionAreas currently used to the new format and removed the old code --- ...inventory_dependent_interactable_test.tscn | 5 +- prefabs/Interactables/trash_object.tscn | 4 +- prefabs/characters/Chugar.tscn | 8 ++- prefabs/characters/Player2D.tscn | 4 +- prefabs/characters/Yeli.tscn | 4 +- prefabs/farm/animals/duck.tscn | 4 +- prefabs/farm/base_field.tscn | 7 +-- .../generic_item_on_ground_2d.tscn | 4 +- project.godot | 12 +++-- scenes/Babushka_scene_farm_outside_2d.tscn | 17 +++---- scenes/Babushka_scene_indoor_common_room.tscn | 16 +++--- scenes/Babushka_scene_indoor_vesnas_room.tscn | 4 +- scenes/Babushka_scene_outside_beets.tscn | 42 ++++++++++++--- .../CharacterControls/InteractionArea2D.cs | 20 ++------ scripts/CSharp/Common/Util/NodeExtension.cs | 51 +++++++++++++++++++ 15 files changed, 132 insertions(+), 70 deletions(-) diff --git a/prefabs/Interactables/inventory_dependent_interactable_test.tscn b/prefabs/Interactables/inventory_dependent_interactable_test.tscn index ae82d35..357b7f2 100644 --- a/prefabs/Interactables/inventory_dependent_interactable_test.tscn +++ b/prefabs/Interactables/inventory_dependent_interactable_test.tscn @@ -10,9 +10,8 @@ script = ExtResource("1_cu47d") _interactionArea = NodePath("InteractionArea") _itemsToReactTo = Array[Object]([ExtResource("2_s5peo")]) -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("3_wsetd")] -_active = false -_spriteToOutline = NodePath("../Sprite2D") +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("3_wsetd")] +_spritesToOutline = [NodePath("../Sprite2D")] [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.5, 0.5) diff --git a/prefabs/Interactables/trash_object.tscn b/prefabs/Interactables/trash_object.tscn index fc5f532..a5fc1bf 100644 --- a/prefabs/Interactables/trash_object.tscn +++ b/prefabs/Interactables/trash_object.tscn @@ -37,9 +37,9 @@ offset = Vector2(1, -215) region_enabled = true region_rect = Rect2(44, 479, 356, 503) -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("2_gcgfd")] +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("2_gcgfd")] position = Vector2(0, -172) -_spriteToOutline = NodePath("..") +_spritesToOutline = [NodePath("..")] [node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."] stream = SubResource("AudioStreamRandomizer_dich4") diff --git a/prefabs/characters/Chugar.tscn b/prefabs/characters/Chugar.tscn index 6bf8903..581e735 100644 --- a/prefabs/characters/Chugar.tscn +++ b/prefabs/characters/Chugar.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=9 format=3 uid="uid://ddpl8cbck7e6s"] +[gd_scene load_steps=8 format=3 uid="uid://ddpl8cbck7e6s"] [ext_resource type="Script" uid="uid://d0kgxh4ykuv23" path="res://scripts/CSharp/Common/NPC/TalkingCharacter.cs" id="1_xix7p"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="2_udjjv"] [ext_resource type="Texture2D" uid="uid://bgba1uv0muxat" path="res://art/characters/chugeist_tmp.png" id="3_42og6"] -[ext_resource type="Material" uid="uid://blch5kdhkbj75" path="res://art/materials/simple_interactable_outline.tres" id="3_kd44q"] [ext_resource type="Script" uid="uid://d2486x6upmwqq" path="res://scripts/GdScript/dialogic_starter.gd" id="43_xooq4"] [ext_resource type="Script" uid="uid://cvkw4qd2hxksi" path="res://scripts/GdScript/dialogic_toggle.gd" id="44_v6w16"] @@ -21,11 +20,10 @@ z_index = 1 y_sort_enabled = true script = ExtResource("1_xix7p") -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("2_udjjv")] +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("2_udjjv")] position = Vector2(0, -450) scale = Vector2(2.805, 2.805) -_outlineMaterial = ExtResource("3_kd44q") -_spriteToOutline = NodePath("../TalkingControl/Visual") +_spritesToOutline = [NodePath("../TalkingControl/Visual")] [node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"] position = Vector2(-4.99109, 63.4581) diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index bcb282b..3388b8a 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=485 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=486 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -280,6 +280,7 @@ [ext_resource type="Texture2D" uid="uid://dsjj23763pej5" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0014.png" id="470_bmmei"] [ext_resource type="AudioStream" uid="uid://ce5mxs2yrwgrh" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_01_R.wav" id="470_dnm27"] [ext_resource type="Script" uid="uid://dx25g14a7xi4w" path="res://scripts/CSharp/Common/Audio/AudioPlayer.cs" id="471_2f15g"] +[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="471_83c4i"] [ext_resource type="AudioStream" uid="uid://fihv17va3r58" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_02_R.wav" id="471_e04c3"] [ext_resource type="AudioStream" uid="uid://cvvjd2i6x047n" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_03_R.wav" id="472_g32y8"] [ext_resource type="Texture2D" uid="uid://blh0t2ofqj2uq" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0016.png" id="472_wdxsr"] @@ -2155,6 +2156,7 @@ _eventResources = Array[Object]([ExtResource("469_t1d6r")]) [node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_wateringParticles")] script = ExtResource("817_6nrw3") +_sceneKeyProvider = ExtResource("471_83c4i") _fieldPrefab = ExtResource("818_16w6h") _movingPlayer = NodePath("../CharacterBody2D") _wateringParticles = NodePath("../pouring water vfx") diff --git a/prefabs/characters/Yeli.tscn b/prefabs/characters/Yeli.tscn index 2e4ac29..d32fd51 100644 --- a/prefabs/characters/Yeli.tscn +++ b/prefabs/characters/Yeli.tscn @@ -206,9 +206,9 @@ y_sort_enabled = true script = ExtResource("1_hn8at") _sprite = NodePath("TalkingControl/AnimatedSprite") -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("42_ahrat")] +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("42_ahrat")] position = Vector2(0, -450) -_spriteToOutline = NodePath("../TalkingControl/AnimatedSprite") +_spritesToOutline = [NodePath("../TalkingControl/AnimatedSprite")] [node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_at1n1") diff --git a/prefabs/farm/animals/duck.tscn b/prefabs/farm/animals/duck.tscn index 042f9e0..d3c0ff5 100644 --- a/prefabs/farm/animals/duck.tscn +++ b/prefabs/farm/animals/duck.tscn @@ -160,9 +160,9 @@ libraries = { &"": SubResource("AnimationLibrary_54k4r") } -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("15_uo3dh")] +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("15_uo3dh")] position = Vector2(18, -250) -_spriteToOutline = NodePath("../Duck rendered") +_spritesToOutline = [NodePath("../Duck rendered")] [node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_uo3dh") diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 43b27a3..1234b5e 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -36,10 +36,11 @@ texture = ExtResource("5_wx561") [node name="PlantPlaceholder" type="Node2D" parent="FieldBehaviour"] -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("7_2eegd")] +[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")] position = Vector2(-16, -54) -_active = false -_spriteToOutline = NodePath("../FieldBehaviour/MaskedField/FieldTexture") +_useOutline = false +_outlineMaterial = null +_spritesToOutline = [NodePath("../FieldBehaviour/MaskedField")] [node name="PlantCreationEventRaiser" type="Node" parent="."] script = ExtResource("9_teirr") diff --git a/prefabs/interactions/generic_item_on_ground_2d.tscn b/prefabs/interactions/generic_item_on_ground_2d.tscn index 5282bd1..17b25e2 100644 --- a/prefabs/interactions/generic_item_on_ground_2d.tscn +++ b/prefabs/interactions/generic_item_on_ground_2d.tscn @@ -57,9 +57,9 @@ theme = SubResource("Theme_harr4") text = "thewe waf a pwoblem wiph picking up te item UWU" autowrap_mode = 3 -[node name="PickupInteractionArea" parent="." node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("4_xu8me")] +[node name="PickupInteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("4_xu8me")] _outlineMaterial = ExtResource("4_harr4") -_spriteToOutline = NodePath("../Icon") +_spritesToOutline = [NodePath("../Icon")] [node name="CollisionShape3D" parent="PickupInteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_tlhp6") diff --git a/project.godot b/project.godot index 742ff84..3a9b375 100644 --- a/project.godot +++ b/project.godot @@ -32,6 +32,7 @@ InputService="*res://scripts/CSharp/Common/Services/InputService.cs" QuestManager="*res://prefabs/quests/quest_manager_autoload.tscn" Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd" FightWorldAutoload="*res://prefabs/fight/fight_world_autoload.tscn" +FieldService="*res://scripts/CSharp/Common/Farming/FieldService.cs" [dialogic] @@ -172,6 +173,7 @@ directories/tres_directory={ "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", "var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", "var_Counter": "res://resources/low code/test/var_Counter.tres", +"var_sceneNameProvider": "res://resources/low code/farming/var_sceneNameProvider.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", "vn_textbox_name_label_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_name_label_panel.tres", @@ -207,11 +209,11 @@ folder_colors={ "res://audio/": "yellow", "res://dialog/": "green", "res://fonts/": "green", -"res://logos/": "green", -"res://prefabs/": "teal", -"res://resources/": "teal", -"res://scenes/": "blue", -"res://scripts/": "purple", +"res://logos/": "blue", +"res://prefabs/": "purple", +"res://resources/": "purple", +"res://scenes/": "purple", +"res://scripts/": "pink", "res://shader/": "pink" } diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 250ec57..8490cee 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1036,10 +1036,9 @@ position = Vector2(6403, 3362) _timelinesToPlay = PackedStringArray("yeli_quest_select") _retriggerSameTimeline = true -[node name="Vesna" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")] +[node name="Vesna" parent="YSorted" instance=ExtResource("1_7wfwe")] z_index = 1 position = Vector2(9322, 2018) -_fieldParent = NodePath("../Farm visuals/FieldParent") _hoe = ExtResource("28_6b2nr") [node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")] @@ -1064,10 +1063,8 @@ collision_mask = 4 position = Vector2(145.5, -224) shape = SubResource("RectangleShape2D_0sfl7") -[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("27_klb81")] -_active = false -_spriteToOutline = NodePath("..") -_id = 1 +[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")] +_spritesToOutline = [NodePath("..")] [node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"] position = Vector2(146, -130) @@ -1146,10 +1143,10 @@ collision_mask = 6 position = Vector2(-252.56, 231.32) polygon = PackedVector2Array(247.227, 43.5123, 44.7822, 43.5123, -87.2178, 45.123, -104.329, -55.2797, -154.107, -73.5347, -160.107, -380.38, -175.44, -400.783, -63.44, -512.461, 97.8934, -541.991, 261.671, -599.172, 374.782, -526.421, 502.338, -526.421, 637.893, -396.488, 598.56, -360.783, 596.338, -58.2327, 528.782, -58.2327, 501.449, 45.9283) -[node name="EnterHouseInteraction" parent="YSorted/Farm visuals/Static" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("27_klb81")] +[node name="EnterHouseInteraction" parent="YSorted/Farm visuals/Static" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")] position = Vector2(5834, 2354) scale = Vector2(2.425, 2.425) -_spriteToOutline = NodePath("DoorSprite") +_spritesToOutline = [NodePath("DoorSprite")] _id = 0 [node name="DoorSprite" type="Sprite2D" parent="YSorted/Farm visuals/Static/EnterHouseInteraction"] @@ -2139,9 +2136,9 @@ collision_mask = 4 position = Vector2(-106.663, 182.891) shape = SubResource("RectangleShape2D_ycj14") -[node name="InteractionArea" parent="YSorted/Blocker" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("27_klb81")] +[node name="InteractionArea" parent="YSorted/Blocker" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")] position = Vector2(11234, 1850) -_spriteToOutline = NodePath("Fence Door") +_spritesToOutline = [NodePath("Fence Door")] _id = 1 [node name="CollisionShape3D" parent="YSorted/Blocker/InteractionArea/Area2D" index="0"] diff --git a/scenes/Babushka_scene_indoor_common_room.tscn b/scenes/Babushka_scene_indoor_common_room.tscn index 5014960..a2023a6 100644 --- a/scenes/Babushka_scene_indoor_common_room.tscn +++ b/scenes/Babushka_scene_indoor_common_room.tscn @@ -309,10 +309,10 @@ texture = ExtResource("6_blyw3") region_enabled = true region_rect = Rect2(3161, 313, 679, 1050) -[node name="OutsideDoor" parent="BackWall/Room01DorrR" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] +[node name="OutsideDoor" parent="BackWall/Room01DorrR" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-7, 248) scale = Vector2(1.5, 1.5) -_spriteToOutline = NodePath("..") +_spritesToOutline = [NodePath("..")] _id = 1 [node name="Room01DoorL" type="Sprite2D" parent="BackWall"] @@ -322,9 +322,9 @@ texture = ExtResource("7_yd2gv") region_enabled = true region_rect = Rect2(0, 0, 3840, 2160) -[node name="VesnasRoomDoor" parent="BackWall/Room01DoorL" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] +[node name="VesnasRoomDoor" parent="BackWall/Room01DoorL" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-1559, -16) -_spriteToOutline = NodePath("..") +_spritesToOutline = [NodePath("..")] _id = 0 [node name="CollisionShape3D" parent="BackWall/Room01DoorL/VesnasRoomDoor/Area2D" index="0"] @@ -358,9 +358,9 @@ texture = ExtResource("10_xcryd") region_enabled = true region_rect = Rect2(2360, 864, 356, 251) -[node name="InteractionArea" parent="BackWall/Room01PechkaDoor" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] +[node name="InteractionArea" parent="BackWall/Room01PechkaDoor" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("11_gpagp")] position = Vector2(0, -3) -_spriteToOutline = NodePath("..") +_spritesToOutline = [NodePath("..")] [node name="CollisionShape3D" parent="BackWall/Room01PechkaDoor/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_gpagp") @@ -407,10 +407,10 @@ stream = SubResource("AudioStreamRandomizer_b6vf7") bus = &"SFX" script = ExtResource("22_tggq2") -[node name="InteractionArea" parent="BackWall/Katze" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("11_gpagp")] +[node name="InteractionArea" parent="BackWall/Katze" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("11_gpagp")] position = Vector2(-6.5, -44) scale = Vector2(0.5, 0.5) -_spriteToOutline = NodePath("..") +_spritesToOutline = [NodePath("..")] [node name="Room assets" type="Node" parent="BackWall"] diff --git a/scenes/Babushka_scene_indoor_vesnas_room.tscn b/scenes/Babushka_scene_indoor_vesnas_room.tscn index c2b4f8d..565e89e 100644 --- a/scenes/Babushka_scene_indoor_vesnas_room.tscn +++ b/scenes/Babushka_scene_indoor_vesnas_room.tscn @@ -98,7 +98,7 @@ _followNode = NodePath("../Vesna/CharacterBody2D") [node name="BedInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(-1429, 487) -_useSprite = false +_useOutline = false _id = 1 [node name="QuestCompleter" type="Node" parent="BedInteraction"] @@ -108,7 +108,7 @@ toStatus = 2 [node name="DoorInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(777, 201) -_useSprite = false +_useOutline = false _id = 0 [node name="CollisionShape3D" parent="DoorInteraction/Area2D" index="0"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index bbd17ac..527a852 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=85 format=3 uid="uid://b3ibx4resa1f3"] +[gd_scene load_steps=86 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"] @@ -41,6 +41,7 @@ [ext_resource type="Texture2D" uid="uid://badnnid7dgnpk" path="res://art/nature/grass/grass-4.png" id="42_7jeth"] [ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="43_dr6bm"] [ext_resource type="Texture2D" uid="uid://ct7ea8ikor5rf" path="res://art/nature/grass/grass-3.png" id="43_g8k4k"] +[ext_resource type="Material" uid="uid://blch5kdhkbj75" path="res://art/materials/simple_interactable_outline.tres" id="44_34r5t"] [ext_resource type="Texture2D" uid="uid://d3dwl6ph0pu1d" path="res://art/nature/grass/grass-6.png" id="44_jgrpl"] [ext_resource type="Script" uid="uid://dhxtdhfqx3bte" path="res://scripts/CSharp/Common/Farming/FieldService2D.cs" id="46_xkmgh"] [ext_resource type="Texture2D" uid="uid://blb3agipyxnal" path="res://art/farm/farming/farmobjekte/zaun/fence_door.png" id="47_xfjh2"] @@ -918,10 +919,9 @@ shape = SubResource("RectangleShape2D_0qu0h") z_index = 1 y_sort_enabled = true -[node name="Vesna" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("27_qtaxr")] +[node name="Vesna" parent="YSorted" instance=ExtResource("27_qtaxr")] z_index = 1 position = Vector2(2693, 1876) -_fieldParent = NodePath("../Farm visuals/FieldParent") _hoe = ExtResource("28_le48k") [node name="Animated Sprites" parent="YSorted/Vesna/CharacterBody2D/visuals" index="0"] @@ -956,9 +956,8 @@ collision_mask = 4 position = Vector2(145.5, -224) shape = SubResource("RectangleShape2D_0sfl7") -[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("31_xcb8u")] -_spriteToOutline = NodePath("..") -_id = 1 +[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("31_xcb8u")] +_spritesToOutline = [NodePath("..")] [node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"] position = Vector2(146, -130) @@ -1717,6 +1716,9 @@ scale = Vector2(1, 1.00622) _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField2" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) @@ -1728,6 +1730,9 @@ FieldState = 3 _state = 1 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField3" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) @@ -1739,6 +1744,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField4" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(2559, 2624.22) scale = Vector2(1, 1.00622) @@ -1750,6 +1758,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField5" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(3305, 2624.22) scale = Vector2(1, 1.00622) @@ -1761,6 +1772,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField6" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4033, 2618.18) scale = Vector2(1, 1.00622) @@ -1772,6 +1786,9 @@ FieldState = 3 _state = 1 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField7" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4755, 2630.26) scale = Vector2(1, 1.00622) @@ -1783,6 +1800,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField8" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4418, 3226.95) scale = Vector2(1, 1.00622) @@ -1794,6 +1814,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="BaseField9" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(5317, 3208.83) scale = Vector2(1, 1.00622) @@ -1805,11 +1828,14 @@ FieldState = 3 _state = 1 _field = NodePath("../..") +[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="1"] +_outlineMaterial = ExtResource("44_34r5t") + [node name="Blocker" type="Node2D" parent="YSorted"] -[node name="BackToFarm" parent="YSorted/Blocker" node_paths=PackedStringArray("_spriteToOutline") instance=ExtResource("31_xcb8u")] +[node name="BackToFarm" parent="YSorted/Blocker" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("31_xcb8u")] position = Vector2(3774, 2025) -_spriteToOutline = NodePath("Fence Door2") +_spritesToOutline = [NodePath("Fence Door2")] _id = 0 [node name="CollisionShape3D" parent="YSorted/Blocker/BackToFarm/Area2D" index="0"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index 6fcf84f..664cbb8 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -7,13 +7,13 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls; public partial class InteractionArea2D : Node2D { + [Export] private Area2D _area; [Export] private Label _label; [Export] private bool _active = true; [Export] private bool _useOutline = true; [Export] private ShaderMaterial _outlineMaterial; - [Export] private CanvasItem? _spriteToOutline; // keep to not break old usages. TODO: remove later - [Export] private CanvasItem[] _spritesToOutline; + [Export] private CanvasItem[] _spritesToOutline = []; [Export] private bool _showLabel = true; [Export] private int _id = -1; // TODO: remove @@ -38,21 +38,7 @@ public partial class InteractionArea2D : Node2D { if (_useOutline) { - try - { - // support old implementations of the script. If the sprite to outline is set, add it to the array - if (_spriteToOutline != null) - { - Array.Resize(ref _spritesToOutline, _spritesToOutline.Length + 1); - _spritesToOutline[^1] = _spriteToOutline; - } - - _backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray(); - } - catch (Exception exception) - { - GD.PrintErr($"No sprite to outline found on: {GetParent().Name}" + exception.Message); - } + _backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray(); } } diff --git a/scripts/CSharp/Common/Util/NodeExtension.cs b/scripts/CSharp/Common/Util/NodeExtension.cs index 07eaa81..52e8477 100644 --- a/scripts/CSharp/Common/Util/NodeExtension.cs +++ b/scripts/CSharp/Common/Util/NodeExtension.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Godot; namespace Babushka.scripts.CSharp.Common.Util; @@ -23,4 +24,54 @@ public static class NodeExtension } throw new Exception($"Parent of type {typeof(T)} not found for node {self.Name}"); } + + //acts like Unity's GetComponent / GetComponentInChildren + // only works with Godot's built-in types. + public static T GetChildByType(this Node node, bool recursive = true) + where T : Node + { + int childCount = node.GetChildCount(); + + for (int i = 0; i < childCount; i++) + { + Node child = node.GetChild(i); + if (child is T childT) + return childT; + + if (recursive && child.GetChildCount() > 0) + { + T recursiveResult = child.GetChildByType(true); + if (recursiveResult != null) + return recursiveResult; + } + } + + return null; + } + + /// + /// Another reimplementation of Unity's GetComponent. + /// Verified to work with all types, also derived ones, but only when used from within a scene and at runtime. + /// + /// + /// + /// + public static T GetComponent(Node node) + { + if (node is T) + { + return (T)(object)node; + } + + foreach (Node child in node.GetChildren()) + { + if (child is T) + { + return (T)(object)child; + } + } + + return (T)(object)null; + } + } -- 2.36.3 From f1b980cdb6ce614e4aa33551176810df9d137e39 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 5 Nov 2025 16:48:45 +0100 Subject: [PATCH 07/29] :bug: field creation at the same spot no longer possible, also watering works now. --- .../farming/var_sceneNameProvider.tres | 8 ++ scenes/Babushka_scene_farm_outside_2d.tscn | 15 +-- .../Common/Farming/FarmingControls2D.cs | 21 ++-- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 2 +- scripts/CSharp/Common/Farming/FieldService.cs | 102 ++++++++++++------ .../CSharp/Common/Farming/FieldService.cs.uid | 1 + .../CSharp/Common/Farming/VesnaBehaviour2D.cs | 2 - 7 files changed, 99 insertions(+), 52 deletions(-) create mode 100644 resources/low code/farming/var_sceneNameProvider.tres create mode 100644 scripts/CSharp/Common/Farming/FieldService.cs.uid diff --git a/resources/low code/farming/var_sceneNameProvider.tres b/resources/low code/farming/var_sceneNameProvider.tres new file mode 100644 index 0000000..0215ee7 --- /dev/null +++ b/resources/low code/farming/var_sceneNameProvider.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://tt3d166mntmi"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_m5pb0"] + +[resource] +script = ExtResource("1_m5pb0") +Payload = "farmOutside" +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 8490cee..549d7e2 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1044,7 +1044,7 @@ _hoe = ExtResource("28_6b2nr") [node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")] _camera = NodePath("../../../Camera2D") -[node name="Brünnen" type="Sprite2D" parent="YSorted" node_paths=PackedStringArray("_interactionArea")] +[node name="Well" type="Sprite2D" parent="YSorted" node_paths=PackedStringArray("_interactionArea")] z_index = 1 y_sort_enabled = true material = SubResource("ShaderMaterial_2vojv") @@ -1056,17 +1056,18 @@ region_rect = Rect2(0, 0, 1504, 1686) script = ExtResource("32_lbnqo") _interactionArea = NodePath("InteractionArea") -[node name="StaticBody2D" type="StaticBody2D" parent="YSorted/Brünnen"] +[node name="StaticBody2D" type="StaticBody2D" parent="YSorted/Well"] collision_mask = 4 -[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Brünnen/StaticBody2D"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Well/StaticBody2D"] position = Vector2(145.5, -224) shape = SubResource("RectangleShape2D_0sfl7") -[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")] +[node name="InteractionArea" parent="YSorted/Well" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")] _spritesToOutline = [NodePath("..")] +_id = 1 -[node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"] +[node name="CollisionShape3D" parent="YSorted/Well/InteractionArea/Area2D" index="0"] position = Vector2(146, -130) shape = SubResource("CircleShape2D_p6n74") @@ -2421,7 +2422,7 @@ timeline = "quest2_tomatoes_end" [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] [connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] -[connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] +[connection signal="InteractedTool" from="YSorted/Well/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] [connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"] @@ -2443,7 +2444,7 @@ timeline = "quest2_tomatoes_end" [connection signal="OnFulfilled" from="SpecialQuestTrigger/FieldWorkTrigger" to="SpecialQuestTrigger/FieldWorkTrigger/StartDialog" method="open"] [editable path="YSorted/Vesna"] -[editable path="YSorted/Brünnen/InteractionArea"] +[editable path="YSorted/Well/InteractionArea"] [editable path="YSorted/CanGenericPickup"] [editable path="YSorted/CanGenericPickup/PickupInteractionArea"] [editable path="YSorted/RakeGenericPickup"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index f737bb1..affe92d 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -1,3 +1,4 @@ +using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; using Godot.Collections; @@ -6,14 +7,13 @@ namespace Babushka.scripts.CSharp.Common.Farming; [GlobalClass] public partial class FarmingControls2D : Node2D { - [Export] private PackedScene _fieldPrefab; + [Export] private VariableResource _sceneKeyProvider; + [Export] private PackedScene? _fieldPrefab = null!; [Export] private Node2D _movingPlayer; [Export] private Camera2D _camera; [Export] private CpuParticles2D _wateringParticles; [Export] private float _wateringCanParticlesVerticalOffset = 50f; - public FieldService2D FieldService; - private int _toolId = -1; private bool _wateringCanFilled = false; @@ -116,7 +116,7 @@ public partial class FarmingControls2D : Node2D private void WaterTheField(Vector2I fieldPosition) { - FieldBehaviour2D field = FieldService.Get(fieldPosition); + FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition); if (field == null || field.FieldState == FieldState.Watered) { GD.Print($"The field at position {fieldPosition} is null!"); @@ -135,25 +135,30 @@ public partial class FarmingControls2D : Node2D #region FIELD CREATION private void MakeField(Vector2I fieldPosition) { - if(FieldService == null || _fieldPrefab == null) + if(_fieldPrefab == null) return; // only instantiate a field if there isn't one already. - if(FieldService.Get(fieldPosition) == null) + if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null) { + GD.Print($"FarmingControls: Creating a field at {fieldPosition}"); Node fieldInstance = _fieldPrefab.Instantiate(); if (fieldInstance is Node2D field2d) { // add dictionary entry for the field Array fields = field2d.FindChildren("*", nameof(FieldBehaviour2D)); if (fields.Count > 0) - FieldService.TryAddEntry(fieldPosition, fields[0] as FieldBehaviour2D); + FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D); // reposition and reparent the instance field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);; - FieldService.AddChild(fieldInstance); + FieldService.Instance.AddChild(fieldInstance); } } + else + { + GD.Print($"FarmingControls: Could not create a field at {fieldPosition}."); + } } private int AdjustValue(float value) diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 98adfe3..922ffbc 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,6 +1,7 @@ using System; using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; +using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; @@ -20,7 +21,6 @@ public partial class FieldBehaviour2D : Sprite2D public Vector2 FieldPosition; - public FieldService2D FieldService; [Signal] public delegate void PlantedEventHandler(); diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index a5b594f..538c64d 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -3,75 +3,109 @@ using Godot; namespace Babushka.scripts.CSharp.Common.Farming; -public partial class FieldService : Node2D +public partial class FieldService : Node { - private Dictionary? fieldsPerScene; - - - + private Dictionary? outerDict; + [Signal] public delegate void FieldCreatedEventHandler(); + public static FieldService Instance { get; private set; } = null!; + + public override void _EnterTree() + { + Instance = this; + outerDict = new Dictionary(); + } + + //Create - public bool TryAddEntry(PackedScene scene, Vector2I key, FieldBehaviour2D field) + public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field) { - if (!fieldsPerScene.ContainsKey(scene)) + GD.Print($"Fieldservice: Trying to add a new entry. SceneName: {sceneName} Position: {position}."); + if (outerDict != null ) { - FieldsInScene fieldInstance = new FieldsInScene(); - fieldsPerScene.Add(scene, fieldInstance); - EmitSignal(SignalName.FieldCreated); - return true; + FieldsInScene fieldsInScene; + bool outerDictEntryExists = outerDict.TryGetValue(sceneName, out fieldsInScene); + + if (!outerDictEntryExists) + { + fieldsInScene = new FieldsInScene(); + outerDict.Add(sceneName, fieldsInScene); + } + + if (!fieldsInScene.fields.ContainsKey(position)) + { + fieldsInScene.fields.Add(position, field); + EmitSignal(SignalName.FieldCreated); + GD.Print("Fieldservice: successfully added field to dictionary."); + return true; + } } + + GD.Print("Fieldservice: Either no outerdict found or there is already a field here!"); return false; } // Read - public FieldBehaviour2D Get(PackedScene key, Vector2I fieldPosition) + public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition) { - if (fieldsPerScene.TryGetValue(key, out FieldsInScene field)) + if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { - if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D fieldInstance)) + GD.Print($"Fieldservice: Successfully retrieved fieldsPerScene Dictionary. " + + $"OuterDict Count: {outerDict.Count} InnerDict Count {outerDict[key].fields.Count}"); + if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance)) + { + GD.Print($"Fieldservice: Successfully retrieved fieldInstance at position: {fieldPosition}."); return fieldInstance; + } } - + GD.Print("Fieldservice TryGet: No field found."); return null; } - //todo: - // - Make this a singleton - // - Let this interact with the FarmingControls and the FieldBehaviours - // - Replace FieldService2D and remove it from scenes. - - /* //Update - public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour2D state) + public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state) { - - if (fields.ContainsKey(fieldPosition)) - { - fields[fieldPosition] = state; - } - else + GD.Print($"FieldService: Updating entry at {fieldPosition}"); + if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { - TryAddEntry(fieldPosition, state); + if (field.fields.ContainsKey(fieldPosition)) + { + field.fields[fieldPosition] = state; + } + else + { + TryAddEntry(key, fieldPosition, state); + } } + + } //Delete - public void RemoveEntry(Vector2I fieldPosition) + public void RemoveEntry(string key, Vector2I fieldPosition) { - if (fields.ContainsKey(fieldPosition)) + GD.Print($"FieldService: Removing entry at {fieldPosition}."); + if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { - fields.Remove(fieldPosition); + if (field.fields.ContainsKey(fieldPosition)) + { + field.fields.Remove(fieldPosition); + } } } - */ } internal class FieldsInScene { - public Dictionary fields; + public Dictionary fields; + + public FieldsInScene() + { + fields = new Dictionary(); + } } diff --git a/scripts/CSharp/Common/Farming/FieldService.cs.uid b/scripts/CSharp/Common/Farming/FieldService.cs.uid new file mode 100644 index 0000000..42d3b36 --- /dev/null +++ b/scripts/CSharp/Common/Farming/FieldService.cs.uid @@ -0,0 +1 @@ +uid://slo0uydmmvnu diff --git a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs index 3bbe17c..46c9c19 100644 --- a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs @@ -9,7 +9,6 @@ namespace Babushka.scripts.CSharp.Common.Farming; public partial class VesnaBehaviour2D : Node { [ExportGroup("Farming")] - [Export] private FieldService2D _fieldParent; [Export] private FarmingControls2D _farmingControls; [Export] private PlayerMovement _player2d; [Export] private VesnaAnimations _vesnaAnimations; @@ -26,7 +25,6 @@ public partial class VesnaBehaviour2D : Node public override void _Ready() { - _farmingControls.FieldService = _fieldParent; _inventoryManager = InventoryManager.Instance; _inventoryInstance = _inventoryManager.playerInventory; _inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged; -- 2.36.3 From 1c5b585b3d0f14b215b4011c0362105f38be78d9 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 5 Nov 2025 16:50:41 +0100 Subject: [PATCH 08/29] :fire: removed print statements used for debugging --- scripts/CSharp/Common/Farming/FarmingControls2D.cs | 5 ----- scripts/CSharp/Common/Farming/FieldService.cs | 12 ------------ 2 files changed, 17 deletions(-) diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index affe92d..2cfe60e 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -141,7 +141,6 @@ public partial class FarmingControls2D : Node2D // only instantiate a field if there isn't one already. if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null) { - GD.Print($"FarmingControls: Creating a field at {fieldPosition}"); Node fieldInstance = _fieldPrefab.Instantiate(); if (fieldInstance is Node2D field2d) { @@ -155,10 +154,6 @@ public partial class FarmingControls2D : Node2D FieldService.Instance.AddChild(fieldInstance); } } - else - { - GD.Print($"FarmingControls: Could not create a field at {fieldPosition}."); - } } private int AdjustValue(float value) diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 538c64d..f7703e8 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -21,7 +21,6 @@ public partial class FieldService : Node //Create public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field) { - GD.Print($"Fieldservice: Trying to add a new entry. SceneName: {sceneName} Position: {position}."); if (outerDict != null ) { FieldsInScene fieldsInScene; @@ -37,12 +36,9 @@ public partial class FieldService : Node { fieldsInScene.fields.Add(position, field); EmitSignal(SignalName.FieldCreated); - GD.Print("Fieldservice: successfully added field to dictionary."); return true; } } - - GD.Print("Fieldservice: Either no outerdict found or there is already a field here!"); return false; } @@ -51,15 +47,11 @@ public partial class FieldService : Node { if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { - GD.Print($"Fieldservice: Successfully retrieved fieldsPerScene Dictionary. " + - $"OuterDict Count: {outerDict.Count} InnerDict Count {outerDict[key].fields.Count}"); if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance)) { - GD.Print($"Fieldservice: Successfully retrieved fieldInstance at position: {fieldPosition}."); return fieldInstance; } } - GD.Print("Fieldservice TryGet: No field found."); return null; } @@ -67,7 +59,6 @@ public partial class FieldService : Node //Update public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state) { - GD.Print($"FieldService: Updating entry at {fieldPosition}"); if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { if (field.fields.ContainsKey(fieldPosition)) @@ -79,15 +70,12 @@ public partial class FieldService : Node TryAddEntry(key, fieldPosition, state); } } - - } //Delete public void RemoveEntry(string key, Vector2I fieldPosition) { - GD.Print($"FieldService: Removing entry at {fieldPosition}."); if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) { if (field.fields.ContainsKey(fieldPosition)) -- 2.36.3 From 1d7f656ec49a3fe8e25654ac16098a13f5c5ac68 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 5 Nov 2025 19:25:46 +0100 Subject: [PATCH 09/29] :construction: WIP trying to fix a bug that won't let me have more than 9 fields. Dont ask me why. --- ...aracter_translations.en.translation-qwtWdW | 0 ...semi_cat_translation.en.translation-Br5qQE | 0 ...ime_line_translation.en.translation-q1xYHQ | 0 project.godot | 3 +- .../low code/farming/event_fieldCreated.tres | 7 ++++ .../Common/Farming/FarmingControls2D.cs | 39 ++++++++++++------- scripts/CSharp/Common/Farming/FieldService.cs | 38 ++++++++++-------- 7 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 dialog/translations/dialogic_character_translations.en.translation-qwtWdW create mode 100644 dialog/translations/dialogic_semi_cat_translation.en.translation-Br5qQE create mode 100644 dialog/translations/dialogic_test_time_line_translation.en.translation-q1xYHQ create mode 100644 resources/low code/farming/event_fieldCreated.tres diff --git a/dialog/translations/dialogic_character_translations.en.translation-qwtWdW b/dialog/translations/dialogic_character_translations.en.translation-qwtWdW new file mode 100644 index 0000000..e69de29 diff --git a/dialog/translations/dialogic_semi_cat_translation.en.translation-Br5qQE b/dialog/translations/dialogic_semi_cat_translation.en.translation-Br5qQE new file mode 100644 index 0000000..e69de29 diff --git a/dialog/translations/dialogic_test_time_line_translation.en.translation-q1xYHQ b/dialog/translations/dialogic_test_time_line_translation.en.translation-q1xYHQ new file mode 100644 index 0000000..e69de29 diff --git a/project.godot b/project.godot index 3a9b375..ba8ecf8 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Babushka" -run/main_scene="uid://bopv10dqm1knc" +run/main_scene="uid://c6wnoif01ltld" config/features=PackedStringArray("4.5", "C#", "Forward Plus") run/max_fps=120 boot_splash/fullsize=false @@ -147,6 +147,7 @@ directories/tres_directory={ "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", "event_PickedUpInteractable": "res://resources/low code/interactables/event_PickedUpInteractable.tres", "event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", +"event_fieldCreated": "res://resources/low code/farming/event_fieldCreated.tres", "event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres", "event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", diff --git a/resources/low code/farming/event_fieldCreated.tres b/resources/low code/farming/event_fieldCreated.tres new file mode 100644 index 0000000..9422781 --- /dev/null +++ b/resources/low code/farming/event_fieldCreated.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://cvgs0ojdo1jyu"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_x3jnq"] + +[resource] +script = ExtResource("1_x3jnq") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 2cfe60e..d0c4080 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -13,6 +13,7 @@ public partial class FarmingControls2D : Node2D [Export] private Camera2D _camera; [Export] private CpuParticles2D _wateringParticles; [Export] private float _wateringCanParticlesVerticalOffset = 50f; + [Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651); private int _toolId = -1; private bool _wateringCanFilled = false; @@ -20,6 +21,8 @@ public partial class FarmingControls2D : Node2D [Signal] public delegate void WateringFieldEventHandler(); + [Signal] public delegate void FieldCreatedEventHandler(); + #region Tools /// @@ -52,13 +55,22 @@ public partial class FarmingControls2D : Node2D public override void _Input(InputEvent @event) { - if (@event.IsActionPressed("click") - && _toolId == WateringCanState.WATERING_CAN_ID - && WateringCanState.GetFillState() > 0) + if (@event.IsActionPressed("click")) { - GD.Print("Trying to use the watering can."); - Vector2I adjustedPosition = GetAdjustedMousePosition(); - WaterTheField(adjustedPosition); + if (_toolId == WateringCanState.WATERING_CAN_ID + && WateringCanState.GetFillState() > 0) + { + GD.Print("Trying to use the watering can."); + Vector2I adjustedPosition = GetAdjustedMousePosition(); + WaterTheField(adjustedPosition); + } + + if (_toolId == 0) + { + GD.Print("Trying to create a field."); + Vector2I adjustedPosition = GetAdjustedMousePosition(); + MakeField(adjustedPosition); + } } } @@ -66,7 +78,7 @@ public partial class FarmingControls2D : Node2D { Vector2 mousePosition = _camera.GetGlobalMousePosition(); Vector2I mousePositionInteger = (Vector2I) mousePosition; - Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651)); + Vector2I adjustedPosition = AdjustValue(mousePositionInteger, _fieldOffsetVector); return adjustedPosition; } @@ -78,6 +90,9 @@ public partial class FarmingControls2D : Node2D /// public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex) { + // Bug is here: Whenever I use the collider to limit the farming area, Godot crashes after 10 fields. + /* + GD.Print($"Input event registered on {node.Name} as {inputEvent.GetType().Name}."); if (!inputEvent.IsPressed()) { return; @@ -103,6 +118,7 @@ public partial class FarmingControls2D : Node2D Vector2I adjustedPosition = GetAdjustedMousePosition(); MakeField(adjustedPosition); } + */ } #region WATERING @@ -152,18 +168,11 @@ public partial class FarmingControls2D : Node2D // reposition and reparent the instance field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);; FieldService.Instance.AddChild(fieldInstance); + EmitSignal(SignalName.FieldCreated); } } } - private int AdjustValue(float value) - { - float adjustedValue = value / 500; - adjustedValue = Mathf.RoundToInt(adjustedValue); - adjustedValue *= 500; - return (int)adjustedValue; - } - private Vector2I AdjustValue(Vector2I input, Vector2I step) { return input.Snapped(step); diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index f7703e8..0647892 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -5,37 +5,39 @@ namespace Babushka.scripts.CSharp.Common.Farming; public partial class FieldService : Node { - private Dictionary? outerDict; - - [Signal] public delegate void FieldCreatedEventHandler(); - + private Dictionary? _outerDict = null!; public static FieldService Instance { get; private set; } = null!; public override void _EnterTree() { Instance = this; - outerDict = new Dictionary(); + _outerDict = new Dictionary(); } - + + public override void _ExitTree() + { + Instance = null; + _outerDict = null; + } + //Create public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field) { - if (outerDict != null ) + if (_outerDict != null ) { - FieldsInScene fieldsInScene; - bool outerDictEntryExists = outerDict.TryGetValue(sceneName, out fieldsInScene); + FieldsInScene innerDict; + bool outerDictEntryExists = _outerDict.TryGetValue(sceneName, out innerDict); if (!outerDictEntryExists) { - fieldsInScene = new FieldsInScene(); - outerDict.Add(sceneName, fieldsInScene); + innerDict = new FieldsInScene(); + _outerDict.Add(sceneName, innerDict); } - if (!fieldsInScene.fields.ContainsKey(position)) + if (!innerDict.fields.ContainsKey(position)) { - fieldsInScene.fields.Add(position, field); - EmitSignal(SignalName.FieldCreated); + innerDict.fields.Add(position, field); return true; } } @@ -45,13 +47,15 @@ public partial class FieldService : Node // Read public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition) { - if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) + if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance)) { + GD.Print("Getting field..."); return fieldInstance; } } + GD.Print($"No field found for key: {key} and position: {fieldPosition} "); return null; } @@ -59,7 +63,7 @@ public partial class FieldService : Node //Update public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state) { - if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) + if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { if (field.fields.ContainsKey(fieldPosition)) { @@ -76,7 +80,7 @@ public partial class FieldService : Node public void RemoveEntry(string key, Vector2I fieldPosition) { - if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field)) + if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { if (field.fields.ContainsKey(fieldPosition)) { -- 2.36.3 From 6a2355cf97fc86050238f9d4f583f06b9be857fc Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 7 Nov 2025 18:18:05 +0100 Subject: [PATCH 10/29] :bug: fixed never more than 10 fields bug --- prefabs/characters/Player2D.tscn | 7 +- project.godot | 1 - .../low code/farming/event_fieldCreated.tres | 7 -- scenes/Babushka_scene_farm_outside_2d.tscn | 43 +++++------- .../Common/Farming/FarmingControls2D.cs | 65 ++++++------------- scripts/CSharp/Common/Farming/FieldService.cs | 2 - 6 files changed, 36 insertions(+), 89 deletions(-) delete mode 100644 resources/low code/farming/event_fieldCreated.tres diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index 3388b8a..52279ee 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -2086,6 +2086,7 @@ stream_6/stream = ExtResource("476_deeju") [node name="Vesna" type="Node2D" node_paths=PackedStringArray("_farmingControls", "_player2d", "_vesnaAnimations")] y_sort_enabled = true +position = Vector2(0, 2) script = ExtResource("1_yd5ep") _farmingControls = NodePath("FarmingControls") _player2d = NodePath("CharacterBody2D") @@ -2162,10 +2163,6 @@ _movingPlayer = NodePath("../CharacterBody2D") _wateringParticles = NodePath("../pouring water vfx") _wateringCanParticlesVerticalOffset = -100.0 -[node name="dialogic toggle" type="Node2D" parent="."] -position = Vector2(0, 374) -script = ExtResource("819_4na52") - [node name="pouring water vfx" type="CPUParticles2D" parent="."] position = Vector2(-652, -599) rotation = -0.333807 @@ -2209,7 +2206,5 @@ wait_time = 0.5 [connection signal="EventRaised" from="CharacterBody2D/PickedUpInteractableListener" to="CharacterBody2D/visuals" method="PlayPickUpAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] [connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/WateringCanUI" method="Water"] -[connection signal="timelineEnded" from="dialogic toggle" to="." method="EnableMovement"] -[connection signal="timelineStarted" from="dialogic toggle" to="." method="DisableMovement"] [connection signal="timelineStarted" from="DialogicToggle" to="SFX/FootstepsAudio/Timer" method="stop"] [connection signal="timeout" from="SFX/FootstepsAudio/Timer" to="SFX/FootstepsAudio" method="PlayOneShot"] diff --git a/project.godot b/project.godot index ba8ecf8..f394b07 100644 --- a/project.godot +++ b/project.godot @@ -147,7 +147,6 @@ directories/tres_directory={ "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", "event_PickedUpInteractable": "res://resources/low code/interactables/event_PickedUpInteractable.tres", "event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", -"event_fieldCreated": "res://resources/low code/farming/event_fieldCreated.tres", "event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres", "event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", diff --git a/resources/low code/farming/event_fieldCreated.tres b/resources/low code/farming/event_fieldCreated.tres deleted file mode 100644 index 9422781..0000000 --- a/resources/low code/farming/event_fieldCreated.tres +++ /dev/null @@ -1,7 +0,0 @@ -[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://cvgs0ojdo1jyu"] - -[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_x3jnq"] - -[resource] -script = ExtResource("1_x3jnq") -metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 549d7e2..792a193 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=117 format=3 uid="uid://gigb28qk8t12"] +[gd_scene load_steps=115 format=3 uid="uid://gigb28qk8t12"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"] [ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"] @@ -28,7 +28,6 @@ [ext_resource type="Texture2D" uid="uid://dg7rlugnq0t45" path="res://art/farm/farming/farmobjekte/brünnen.png" id="21_ualyd"] [ext_resource type="Texture2D" uid="uid://bcw6oeovkmiup" path="res://art/nature/baum märz 2025/sonnenblumeseamless.png" id="23_d77e7"] [ext_resource type="PackedScene" uid="uid://dfvgp1my5rydh" path="res://prefabs/characters/Yeli.tscn" id="24_wtdui"] -[ext_resource type="Script" uid="uid://dhxtdhfqx3bte" path="res://scripts/CSharp/Common/Farming/FieldService2D.cs" id="25_0qu0h"] [ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="25_hukxv"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="27_klb81"] [ext_resource type="Resource" uid="uid://dlcmqfjvgphqu" path="res://resources/items/rake.tres" id="28_6b2nr"] @@ -39,7 +38,6 @@ [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="35_64mdn"] [ext_resource type="Texture2D" uid="uid://65e44yde224q" path="res://art/farm/Babushka_house_01.png" id="36_e5b7x"] [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="36_fv1t2"] -[ext_resource type="Texture2D" uid="uid://b4krfobwq3r3h" path="res://art/test_tomatos.png" id="36_l7ekk"] [ext_resource type="AudioStream" uid="uid://cfqg50am0swb7" path="res://audio/Music/Farming_90BPM_69Bars_Loop.wav" id="37_8ey8m"] [ext_resource type="AudioStream" uid="uid://dku1rq5cocisg" path="res://audio/Music/Farming_90BPM_69Bars.wav" id="37_di1ed"] [ext_resource type="Shader" uid="uid://braevmqauoek7" path="res://shader/swaying_plant.gdshader" id="37_taxvr"] @@ -211,13 +209,13 @@ shader_parameter/tiling_scale = Vector2(1, 20) shader = ExtResource("13_kt1wx") shader_parameter/tiling_scale = Vector2(1, 25) -[sub_resource type="RectangleShape2D" id="RectangleShape2D_2nee2"] -size = Vector2(5782, 1176) - [sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"] resource_local_to_scene = true size = Vector2(7150, 1192) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_2nee2"] +size = Vector2(5782, 1176) + [sub_resource type="ShaderMaterial" id="ShaderMaterial_lwk6t"] shader = ExtResource("13_7p0hq") shader_parameter/hue_shift = 0.0 @@ -1106,10 +1104,6 @@ shape = SubResource("CircleShape2D_tm0yg") [node name="Icon" parent="YSorted/SeedPickup" index="4"] scale = Vector2(1, 1) -[node name="Sprite2D" type="Sprite2D" parent="YSorted/SeedPickup"] -texture = ExtResource("36_l7ekk") -region_enabled = true - [node name="SeedPickup2" parent="YSorted" instance=ExtResource("25_hukxv")] position = Vector2(10705, 2257) _finiteSupply = 3 @@ -2099,27 +2093,22 @@ rotation = 1.5708 scale = Vector2(0.1, 10.8) texture = ExtResource("21_if5vh") -[node name="FieldParent" type="Node2D" parent="YSorted/Farm visuals" node_paths=PackedStringArray("fields", "_allowedArea")] -position = Vector2(53, 20) +[node name="Area2D" type="Area2D" parent="YSorted/Farm visuals"] +position = Vector2(5, 4.098892) scale = Vector2(1, 0.993819) -script = ExtResource("25_0qu0h") -fields = {} -_allowedArea = NodePath("Area2D") -metadata/_custom_type_script = "uid://dhxtdhfqx3bte" - -[node name="Area2D" type="Area2D" parent="YSorted/Farm visuals/FieldParent"] -position = Vector2(-48, -16) collision_mask = 5 collision_priority = 10.0 -[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] -position = Vector2(2896, 2949) -shape = SubResource("RectangleShape2D_2nee2") - -[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] -position = Vector2(11914, 2960) +[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/Area2D"] +position = Vector2(11913.999, 2960) +scale = Vector2(0.99999994, 0.99999994) shape = SubResource("RectangleShape2D_p6n74") +[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/Area2D"] +position = Vector2(2895.9998, 2949) +scale = Vector2(0.99999994, 0.99999994) +shape = SubResource("RectangleShape2D_2nee2") + [node name="Blocker" type="Node2D" parent="YSorted"] [node name="Fence Door2" type="Sprite2D" parent="YSorted/Blocker"] @@ -2428,8 +2417,8 @@ timeline = "quest2_tomatoes_end" [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup2" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="InteractedTool" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadSceneAtIndex"] -[connection signal="FieldCreated" from="YSorted/Farm visuals/FieldParent" to="Audio/SFX/Farming SFX" method="PlayOneShot"] -[connection signal="input_event" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Vesna/FarmingControls" method="InputEventPressedOn"] +[connection signal="mouse_entered" from="YSorted/Farm visuals/Area2D" to="YSorted/Vesna/FarmingControls" method="CanCreateFields"] +[connection signal="mouse_exited" from="YSorted/Farm visuals/Area2D" to="YSorted/Vesna/FarmingControls" method="CannotCreateFields"] [connection signal="InteractedTool" from="YSorted/Blocker/InteractionArea" to="." method="LoadSceneAtIndex"] [connection signal="GoalReached" from="YSorted/ducks" to="YSorted/ducks/DialogicToggle" method="ToggleDialogue"] [connection signal="DuckCollected" from="YSorted/ducks/Duck2" to="YSorted/ducks" method="Increment"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index d0c4080..1a19e83 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -1,3 +1,4 @@ +using System; using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; using Godot.Collections; @@ -17,7 +18,7 @@ public partial class FarmingControls2D : Node2D private int _toolId = -1; private bool _wateringCanFilled = false; - + private bool _canCreateFields = false; [Signal] public delegate void WateringFieldEventHandler(); @@ -60,14 +61,12 @@ public partial class FarmingControls2D : Node2D if (_toolId == WateringCanState.WATERING_CAN_ID && WateringCanState.GetFillState() > 0) { - GD.Print("Trying to use the watering can."); Vector2I adjustedPosition = GetAdjustedMousePosition(); WaterTheField(adjustedPosition); } - if (_toolId == 0) + if (_canCreateFields && _toolId == 0) { - GD.Print("Trying to create a field."); Vector2I adjustedPosition = GetAdjustedMousePosition(); MakeField(adjustedPosition); } @@ -82,43 +81,19 @@ public partial class FarmingControls2D : Node2D return adjustedPosition; } - /// - /// Called by the allowed farming area collision area 2d. - /// - /// - /// - /// - public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex) + private Vector2I AdjustValue(Vector2I input, Vector2I step) { - // Bug is here: Whenever I use the collider to limit the farming area, Godot crashes after 10 fields. - /* - GD.Print($"Input event registered on {node.Name} as {inputEvent.GetType().Name}."); - if (!inputEvent.IsPressed()) - { - return; - } + return input.Snapped(step); + } + + public void CanCreateFields() + { + _canCreateFields = true; + } - if (!inputEvent.IsActionPressed("click")) - return; - - if (inputEvent is InputEventMouseButton inputEventMouseButton) - { - if (!inputEventMouseButton.Pressed) - { - return; - } - } - else - { - return; - } - - if (_toolId == 0) - { - Vector2I adjustedPosition = GetAdjustedMousePosition(); - MakeField(adjustedPosition); - } - */ + public void CannotCreateFields() + { + _canCreateFields = false; } #region WATERING @@ -135,14 +110,12 @@ public partial class FarmingControls2D : Node2D FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition); if (field == null || field.FieldState == FieldState.Watered) { - GD.Print($"The field at position {fieldPosition} is null!"); return; } field.Water(); _wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset); WateringCanState.Water(); - GD.Print($"Watered the field at {fieldPosition}."); EmitSignal(SignalName.WateringField); } @@ -163,20 +136,20 @@ public partial class FarmingControls2D : Node2D // add dictionary entry for the field Array fields = field2d.FindChildren("*", nameof(FieldBehaviour2D)); if (fields.Count > 0) + { FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D); + } // reposition and reparent the instance - field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);; + field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y); + FieldService.Instance.AddChild(fieldInstance); EmitSignal(SignalName.FieldCreated); } } } - private Vector2I AdjustValue(Vector2I input, Vector2I step) - { - return input.Snapped(step); - } + #endregion } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 0647892..80e4770 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -51,11 +51,9 @@ public partial class FieldService : Node { if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance)) { - GD.Print("Getting field..."); return fieldInstance; } } - GD.Print($"No field found for key: {key} and position: {fieldPosition} "); return null; } -- 2.36.3 From c7c6e184d64d9189f02ba6c2d2363116f8e3becf Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 7 Nov 2025 18:24:52 +0100 Subject: [PATCH 11/29] :bug: adjusted field positions --- prefabs/characters/Player2D.tscn | 1 + 1 file changed, 1 insertion(+) diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index 52279ee..b54d14c 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -2162,6 +2162,7 @@ _fieldPrefab = ExtResource("818_16w6h") _movingPlayer = NodePath("../CharacterBody2D") _wateringParticles = NodePath("../pouring water vfx") _wateringCanParticlesVerticalOffset = -100.0 +_fieldOffsetVector = Vector2i(735, 680) [node name="pouring water vfx" type="CPUParticles2D" parent="."] position = Vector2(-652, -599) -- 2.36.3 From 58c2be1db8e4df9a2698a27f95cf52ab67fde4f1 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 7 Nov 2025 18:27:21 +0100 Subject: [PATCH 12/29] :sparkles: plants no longer grow when just interacting with them --- prefabs/farm/plants/base_plant.tscn | 2 -- 1 file changed, 2 deletions(-) diff --git a/prefabs/farm/plants/base_plant.tscn b/prefabs/farm/plants/base_plant.tscn index 0b9ea30..d20e588 100644 --- a/prefabs/farm/plants/base_plant.tscn +++ b/prefabs/farm/plants/base_plant.tscn @@ -38,7 +38,6 @@ _bigPlants = [NodePath("BigPlant/01"), NodePath("BigPlant/02"), NodePath("BigPla _readyPlants = [NodePath("ReadyPlantInventoryItem/ReadyPlant/01"), NodePath("ReadyPlantInventoryItem/ReadyPlant/02"), NodePath("ReadyPlantInventoryItem/ReadyPlant/03")] _harvestablePlant = NodePath("ReadyPlantInventoryItem") _magicEffect = NodePath("magic vfx") -_magicWordNeeded = false [node name="Seeds" type="Node2D" parent="."] position = Vector2(0, 0.5) @@ -130,7 +129,6 @@ region_rect = Rect2(5416, 136, 647, 895) [node name="GrowingInteractionArea" parent="." instance=ExtResource("5_3j24b")] position = Vector2(0, 2.3) _useOutline = false -_useSprite = false [node name="CollisionShape3D" parent="GrowingInteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_vjw4j") -- 2.36.3 From c52bfc8017d0a57b8b9c156df014511056077a26 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 7 Nov 2025 19:47:23 +0100 Subject: [PATCH 13/29] :bug: fixed field outline --- art/masks/field_outline_1_outline.png | Bin 0 -> 6044 bytes art/masks/field_outline_1_outline.png.import | 40 ++++++++++++++++++ art/masks/field_outline_2_outline.png | Bin 0 -> 6841 bytes art/masks/field_outline_2_outline.png.import | 40 ++++++++++++++++++ art/masks/field_outline_3_outline.png | Bin 0 -> 7828 bytes art/masks/field_outline_3_outline.png.import | 40 ++++++++++++++++++ prefabs/farm/base_field.tscn | 21 ++++++--- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 5 ++- 8 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 art/masks/field_outline_1_outline.png create mode 100644 art/masks/field_outline_1_outline.png.import create mode 100644 art/masks/field_outline_2_outline.png create mode 100644 art/masks/field_outline_2_outline.png.import create mode 100644 art/masks/field_outline_3_outline.png create mode 100644 art/masks/field_outline_3_outline.png.import diff --git a/art/masks/field_outline_1_outline.png b/art/masks/field_outline_1_outline.png new file mode 100644 index 0000000000000000000000000000000000000000..ba71a6c090059b53d573596e3c3ab2abaaa148e5 GIT binary patch literal 6044 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 b_!k*|oSMPKk>G#*pR9MZ3~m+Nv Date: Fri, 7 Nov 2025 20:29:05 +0100 Subject: [PATCH 14/29] :sparkles: added InventoryListener and made field interaction area activate only when the right item (seed) is in the inventory --- prefabs/farm/base_field.tscn | 14 +++++- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 20 +++++++- .../Common/Inventory/InventoryListener.cs | 48 +++++++++++++++++++ .../Common/Inventory/InventoryListener.cs.uid | 1 + 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 scripts/CSharp/Common/Inventory/InventoryListener.cs create mode 100644 scripts/CSharp/Common/Inventory/InventoryListener.cs.uid diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index c35bcc9..89246a5 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=17 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"] @@ -13,10 +13,13 @@ [ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="9_teirr"] [ext_resource type="Texture2D" uid="uid://bovypw2hsn2nq" path="res://art/masks/field_outline_1_outline.png" id="9_wx561"] [ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"] +[ext_resource type="Script" uid="uid://3t0af586fimq" path="res://scripts/CSharp/Common/Inventory/InventoryListener.cs" id="14_w08sx"] +[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"] +[ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] [node name="BaseField" type="Node2D"] -[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder")] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea")] z_index = -1 scale = Vector2(0.9, 1) script = ExtResource("1_qa01x") @@ -30,6 +33,7 @@ Watered = ExtResource("6_7m4xq") PlantingInteraction = NodePath("../InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") +FieldInteractionArea = NodePath("../InteractionArea") [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 @@ -49,11 +53,17 @@ texture = ExtResource("9_wx561") [node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")] position = Vector2(-26, -57) +_active = false _spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")] [node name="PlantCreationEventRaiser" type="Node" parent="."] script = ExtResource("9_teirr") _eventResources = Array[Object]([ExtResource("10_wx561")]) +[node name="InventoryListener" type="Node" parent="."] +script = ExtResource("14_w08sx") +_itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource("16_i4qwg")]) + [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] +[connection signal="ItemInstanceActivated" from="InventoryListener" to="FieldBehaviour" method="ActivatedSeedInInventory"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 247304a..08a5e5a 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -19,15 +19,33 @@ public partial class FieldBehaviour2D : Sprite2D [Export] public InteractionArea2D PlantingInteraction; [Export] public Node2D PlantingPlaceholder; [Export] public ItemRepository ItemRepository; - + [Export] public InteractionArea2D FieldInteractionArea; public Vector2 FieldPosition; + private bool _seedsActive; + [Signal] public delegate void PlantedEventHandler(); + private void UpdateInteractionArea() + { + // fieldstate == tilled / watered && samen im Inventar + bool canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; + // fieldstate == tilled && watering can ausgewählt + bool canWater = false; + FieldInteractionArea.IsActive = canPlant || canWater; + } + + public void ActivatedSeedInInventory(bool activated) + { + _seedsActive = activated; + UpdateInteractionArea(); + } + public override void _Ready() { UpdateFieldState(FieldState); + UpdateInteractionArea(); int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; _outlineSprite.Texture = _maskOutlineTextures[randomIndex]; diff --git a/scripts/CSharp/Common/Inventory/InventoryListener.cs b/scripts/CSharp/Common/Inventory/InventoryListener.cs new file mode 100644 index 0000000..424ebb1 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryListener.cs @@ -0,0 +1,48 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.Inventory; + +public partial class InventoryListener : Node +{ + [Export] private ItemResource[] _itemResourcesToListenFor; + + [Signal] public delegate void ItemInstanceActivatedEventHandler(bool activated); + + public override void _Ready() + { + InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory; + InventoryManager.Instance.SlotIndexChanged += HandleNewItemInInventory; + } + + public override void _ExitTree() + { + InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory; + InventoryManager.Instance.SlotIndexChanged -= HandleNewItemInInventory; + } + + private void HandleNewItemInInventory(int newIndex) + { + HandleNewItemInInventory(); + } + + private void HandleNewItemInInventory() + { + int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex; + ItemInstance? instance = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance; + if (instance != null) + { + ItemResource? item = instance.blueprint; + + foreach (var res in _itemResourcesToListenFor) + { + if (item == res) + { + EmitSignal(SignalName.ItemInstanceActivated, true); + return; + } + } + } + + EmitSignal(SignalName.ItemInstanceActivated, false); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Inventory/InventoryListener.cs.uid b/scripts/CSharp/Common/Inventory/InventoryListener.cs.uid new file mode 100644 index 0000000..42f5a8b --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryListener.cs.uid @@ -0,0 +1 @@ +uid://3t0af586fimq -- 2.36.3 From fe1dd2bcc1688a24e18b93cf5efc077c652cecdf Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 7 Nov 2025 20:37:59 +0100 Subject: [PATCH 15/29] :sparkles: Added inventorylistener for watering can --- prefabs/farm/base_field.tscn | 12 +++++++++--- .../Common/CharacterControls/InteractionArea2D.cs | 3 --- scripts/CSharp/Common/Farming/FieldBehaviour2D.cs | 11 +++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 89246a5..ca0947d 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=18 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"] @@ -16,6 +16,7 @@ [ext_resource type="Script" uid="uid://3t0af586fimq" path="res://scripts/CSharp/Common/Inventory/InventoryListener.cs" id="14_w08sx"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"] [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] +[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="17_1mi0u"] [node name="BaseField" type="Node2D"] @@ -60,10 +61,15 @@ _spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")] script = ExtResource("9_teirr") _eventResources = Array[Object]([ExtResource("10_wx561")]) -[node name="InventoryListener" type="Node" parent="."] +[node name="InventoryListener Seeds" type="Node" parent="."] script = ExtResource("14_w08sx") _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource("16_i4qwg")]) +[node name="InventoryListener watering can" type="Node" parent="."] +script = ExtResource("14_w08sx") +_itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")]) + [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] -[connection signal="ItemInstanceActivated" from="InventoryListener" to="FieldBehaviour" method="ActivatedSeedInInventory"] +[connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] +[connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index 664cbb8..dd0d07a 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -62,9 +62,6 @@ public partial class InteractionArea2D : Node2D public void OnPlayerExited(Node2D player) { - if (!_active) - return; - _label.Hide(); if (!_useOutline) diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 08a5e5a..7d87c08 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -24,6 +24,7 @@ public partial class FieldBehaviour2D : Sprite2D public Vector2 FieldPosition; private bool _seedsActive; + private bool _wateringCanActive; [Signal] public delegate void PlantedEventHandler(); @@ -32,7 +33,7 @@ public partial class FieldBehaviour2D : Sprite2D // fieldstate == tilled / watered && samen im Inventar bool canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; // fieldstate == tilled && watering can ausgewählt - bool canWater = false; + bool canWater = FieldState == FieldState.Tilled && _wateringCanActive; FieldInteractionArea.IsActive = canPlant || canWater; } @@ -41,11 +42,16 @@ public partial class FieldBehaviour2D : Sprite2D _seedsActive = activated; UpdateInteractionArea(); } + + public void ActivateWateringCanInInventory(bool activated) + { + _wateringCanActive = activated; + UpdateInteractionArea(); + } public override void _Ready() { UpdateFieldState(FieldState); - UpdateInteractionArea(); int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; _outlineSprite.Texture = _maskOutlineTextures[randomIndex]; @@ -79,6 +85,7 @@ public partial class FieldBehaviour2D : Sprite2D FieldState = FieldState.NotFound; break; } + UpdateInteractionArea(); } -- 2.36.3 From 97dcadf07a6e2e2357464700783c74f7fc48bb06 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 12:15:30 +0100 Subject: [PATCH 16/29] :sparkles: Added sceneprovider reference to field scripts and made them register on ready. Also added VariableSetter. --- prefabs/characters/Player2D.tscn | 2 +- prefabs/farm/base_field.tscn | 4 +- scenes/Babushka_scene_farm_outside_2d.tscn | 40 +++++++++++------ scenes/Babushka_scene_outside_beets.tscn | 45 +++++-------------- .../Common/Farming/FarmingControls2D.cs | 5 +-- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 3 ++ scripts/CSharp/Common/Farming/FieldService.cs | 1 + .../Low Code/Variables/VariableSetter.cs | 14 ++++++ .../Low Code/Variables/VariableSetter.cs.uid | 1 + 9 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 scripts/CSharp/Low Code/Variables/VariableSetter.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariableSetter.cs.uid diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index b54d14c..d2004cc 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -2162,7 +2162,7 @@ _fieldPrefab = ExtResource("818_16w6h") _movingPlayer = NodePath("../CharacterBody2D") _wateringParticles = NodePath("../pouring water vfx") _wateringCanParticlesVerticalOffset = -100.0 -_fieldOffsetVector = Vector2i(735, 680) +_fieldOffsetVector = Vector2i(735, 600) [node name="pouring water vfx" type="CPUParticles2D" parent="."] position = Vector2(-652, -599) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index ca0947d..873170a 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=19 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"] @@ -13,6 +13,7 @@ [ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="9_teirr"] [ext_resource type="Texture2D" uid="uid://bovypw2hsn2nq" path="res://art/masks/field_outline_1_outline.png" id="9_wx561"] [ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"] +[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="11_cjahb"] [ext_resource type="Script" uid="uid://3t0af586fimq" path="res://scripts/CSharp/Common/Inventory/InventoryListener.cs" id="14_w08sx"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"] [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] @@ -35,6 +36,7 @@ PlantingInteraction = NodePath("../InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") FieldInteractionArea = NodePath("../InteractionArea") +_sceneKeyProvider = ExtResource("11_cjahb") [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 792a193..b3d63df 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=115 format=3 uid="uid://gigb28qk8t12"] +[gd_scene load_steps=117 format=3 uid="uid://gigb28qk8t12"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"] [ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"] @@ -73,8 +73,10 @@ [ext_resource type="Resource" uid="uid://5t8g0firdif0" path="res://resources/quests/demo/5_talk_yeli_3.tres" id="69_l4wxt"] [ext_resource type="Script" uid="uid://bhbldab74vmhy" path="res://scripts/CSharp/Common/QuestBehaviour/DetectFieldWork.cs" id="74_fv1t2"] [ext_resource type="Resource" uid="uid://h05jgxqtq37m" path="res://resources/quests/demo/6_till_and_water.tres" id="75_l7ekk"] +[ext_resource type="Script" uid="uid://dfpyjxivcuidr" path="res://scripts/CSharp/Low Code/Variables/VariableSetter.cs" id="76_l7ekk"] [ext_resource type="Resource" uid="uid://byjqeukpibkvi" path="res://resources/quests/demo/7_talk_yeli_inside_1.tres" id="76_xcwle"] [ext_resource type="Script" uid="uid://dih1b0opgc3f7" path="res://scripts/GdScript/dialogic_start_specific.gd" id="77_l7ekk"] +[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="77_xcwle"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wtdui"] shader = ExtResource("13_7p0hq") @@ -211,10 +213,10 @@ shader_parameter/tiling_scale = Vector2(1, 25) [sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"] resource_local_to_scene = true -size = Vector2(7150, 1192) +size = Vector2(7150, 941.9418) [sub_resource type="RectangleShape2D" id="RectangleShape2D_2nee2"] -size = Vector2(5782, 1176) +size = Vector2(5782, 896.7792) [sub_resource type="ShaderMaterial" id="ShaderMaterial_lwk6t"] shader = ExtResource("13_7p0hq") @@ -602,7 +604,7 @@ texture = ExtResource("13_0qu0h") [node name="JelenaMockupBg03" type="Sprite2D" parent="ParallaxBackground/background layer 4"] z_index = -200 material = SubResource("ShaderMaterial_wtdui") -position = Vector2(7923, 727) +position = Vector2(7893.0005, 727) scale = Vector2(2.75, 2.75) texture = ExtResource("13_0qu0h") @@ -1039,8 +1041,9 @@ z_index = 1 position = Vector2(9322, 2018) _hoe = ExtResource("28_6b2nr") -[node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")] +[node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera", "_fieldParent")] _camera = NodePath("../../../Camera2D") +_fieldParent = NodePath("../../FieldParent") [node name="Well" type="Sprite2D" parent="YSorted" node_paths=PackedStringArray("_interactionArea")] z_index = 1 @@ -1117,6 +1120,9 @@ shape = SubResource("CircleShape2D_tm0yg") [node name="Icon" parent="YSorted/SeedPickup2" index="4"] scale = Vector2(1, 1) +[node name="FieldParent" type="Node2D" parent="YSorted"] +position = Vector2(0, -200) + [node name="Farm visuals" type="Node2D" parent="YSorted"] position = Vector2(-60, 122) @@ -2093,20 +2099,20 @@ rotation = 1.5708 scale = Vector2(0.1, 10.8) texture = ExtResource("21_if5vh") -[node name="Area2D" type="Area2D" parent="YSorted/Farm visuals"] +[node name="Farming Colliders" type="Area2D" parent="YSorted/Farm visuals"] position = Vector2(5, 4.098892) scale = Vector2(1, 0.993819) collision_mask = 5 collision_priority = 10.0 -[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/Area2D"] -position = Vector2(11913.999, 2960) -scale = Vector2(0.99999994, 0.99999994) +[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"] +position = Vector2(11913.995, 3085.0288) +scale = Vector2(0.9999998, 0.9999998) shape = SubResource("RectangleShape2D_p6n74") -[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/Area2D"] -position = Vector2(2895.9998, 2949) -scale = Vector2(0.99999994, 0.99999994) +[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"] +position = Vector2(2895.9988, 3088.6096) +scale = Vector2(0.9999998, 0.9999998) shape = SubResource("RectangleShape2D_2nee2") [node name="Blocker" type="Node2D" parent="YSorted"] @@ -2409,6 +2415,11 @@ _toNextQuest = ExtResource("76_xcwle") script = ExtResource("77_l7ekk") timeline = "quest2_tomatoes_end" +[node name="SceneNameSetter" type="Node" parent="."] +script = ExtResource("76_l7ekk") +_variableResource = ExtResource("77_xcwle") +_payloadToSet = "farmOutside" + [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] [connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Well/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] @@ -2417,8 +2428,8 @@ timeline = "quest2_tomatoes_end" [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup2" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="InteractedTool" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadSceneAtIndex"] -[connection signal="mouse_entered" from="YSorted/Farm visuals/Area2D" to="YSorted/Vesna/FarmingControls" method="CanCreateFields"] -[connection signal="mouse_exited" from="YSorted/Farm visuals/Area2D" to="YSorted/Vesna/FarmingControls" method="CannotCreateFields"] +[connection signal="mouse_entered" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CanCreateFields"] +[connection signal="mouse_exited" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CannotCreateFields"] [connection signal="InteractedTool" from="YSorted/Blocker/InteractionArea" to="." method="LoadSceneAtIndex"] [connection signal="GoalReached" from="YSorted/ducks" to="YSorted/ducks/DialogicToggle" method="ToggleDialogue"] [connection signal="DuckCollected" from="YSorted/ducks/Duck2" to="YSorted/ducks" method="Increment"] @@ -2431,6 +2442,7 @@ timeline = "quest2_tomatoes_end" [connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"] [connection signal="ready" from="SpecialQuestTrigger/QuestInstantStart" to="SpecialQuestTrigger/QuestInstantStart/QuestTrigger" method="Trigger"] [connection signal="OnFulfilled" from="SpecialQuestTrigger/FieldWorkTrigger" to="SpecialQuestTrigger/FieldWorkTrigger/StartDialog" method="open"] +[connection signal="tree_entered" from="SceneNameSetter" to="SceneNameSetter" method="Set"] [editable path="YSorted/Vesna"] [editable path="YSorted/Well/InteractionArea"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 527a852..8406460 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -41,16 +41,16 @@ [ext_resource type="Texture2D" uid="uid://badnnid7dgnpk" path="res://art/nature/grass/grass-4.png" id="42_7jeth"] [ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="43_dr6bm"] [ext_resource type="Texture2D" uid="uid://ct7ea8ikor5rf" path="res://art/nature/grass/grass-3.png" id="43_g8k4k"] -[ext_resource type="Material" uid="uid://blch5kdhkbj75" path="res://art/materials/simple_interactable_outline.tres" id="44_34r5t"] [ext_resource type="Texture2D" uid="uid://d3dwl6ph0pu1d" path="res://art/nature/grass/grass-6.png" id="44_jgrpl"] -[ext_resource type="Script" uid="uid://dhxtdhfqx3bte" path="res://scripts/CSharp/Common/Farming/FieldService2D.cs" id="46_xkmgh"] [ext_resource type="Texture2D" uid="uid://blb3agipyxnal" path="res://art/farm/farming/farmobjekte/zaun/fence_door.png" id="47_xfjh2"] [ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="52_gwhnv"] [ext_resource type="AudioStream" uid="uid://dku1rq5cocisg" path="res://audio/Music/Farming_90BPM_69Bars.wav" id="53_2tfpr"] [ext_resource type="Script" uid="uid://clxb3n668oud3" path="res://scripts/CSharp/Common/Audio/AudioDebugger.cs" id="54_pn8sy"] [ext_resource type="AudioStream" uid="uid://cfqg50am0swb7" path="res://audio/Music/Farming_90BPM_69Bars_Loop.wav" id="55_aq24k"] +[ext_resource type="Script" uid="uid://dfpyjxivcuidr" path="res://scripts/CSharp/Low Code/Variables/VariableSetter.cs" id="56_34r5t"] [ext_resource type="AudioStream" uid="uid://vcftvrpi6c7k" path="res://audio/sfx/Farming/SFX_Harke_03_Solo.wav" id="56_vojpc"] [ext_resource type="AudioStream" uid="uid://bxh5m04vdo0sr" path="res://audio/sfx/Farming/SFX_Harke_04_Solo.wav" id="57_euap5"] +[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="57_hpgl7"] [ext_resource type="Script" uid="uid://cfnrd5k1k0gxw" path="res://scripts/CSharp/Common/AudioPlayer2D.cs" id="58_m3hs4"] [ext_resource type="AudioStream" uid="uid://dapsknn486aee" path="res://audio/sfx/Farming/SFX_WateringPlants_01.wav" id="59_km2vg"] [ext_resource type="AudioStream" uid="uid://dnyne8wov50so" path="res://audio/sfx/Farming/SFX_WateringPlants_02.wav" id="60_qi2gu"] @@ -1701,12 +1701,9 @@ rotation = 1.5708 scale = Vector2(0.1, 8.7) texture = ExtResource("26_bwvai") -[node name="FieldParent" type="Node2D" parent="YSorted/Farm visuals" node_paths=PackedStringArray("fields")] +[node name="FieldParent" type="Node2D" parent="YSorted/Farm visuals"] 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/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(651, 2630.26) @@ -1716,9 +1713,6 @@ scale = Vector2(1, 1.00622) _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField2" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) @@ -1727,12 +1721,9 @@ scale = Vector2(1, 1.00622) FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] -_state = 1 +_state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField3" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) @@ -1744,9 +1735,6 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField4" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(2559, 2624.22) scale = Vector2(1, 1.00622) @@ -1758,9 +1746,6 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField5" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(3305, 2624.22) scale = Vector2(1, 1.00622) @@ -1772,9 +1757,6 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField6" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4033, 2618.18) scale = Vector2(1, 1.00622) @@ -1786,9 +1768,6 @@ FieldState = 3 _state = 1 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField7" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4755, 2630.26) scale = Vector2(1, 1.00622) @@ -1800,9 +1779,6 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField8" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4418, 3226.95) scale = Vector2(1, 1.00622) @@ -1814,9 +1790,6 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="BaseField9" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(5317, 3208.83) scale = Vector2(1, 1.00622) @@ -1828,9 +1801,6 @@ FieldState = 3 _state = 1 _field = NodePath("../..") -[node name="InteractionArea" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="1"] -_outlineMaterial = ExtResource("44_34r5t") - [node name="Blocker" type="Node2D" parent="YSorted"] [node name="BackToFarm" parent="YSorted/Blocker" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("31_xcb8u")] @@ -1936,12 +1906,17 @@ max_distance = 20000000.0 playback_type = 2 script = ExtResource("58_m3hs4") +[node name="SceneNameSetter" type="Node" parent="."] +script = ExtResource("56_34r5t") +_variableResource = ExtResource("57_hpgl7") +_payloadToSet = "beetRootScene" + [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] [connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] -[connection signal="FieldCreated" from="YSorted/Farm visuals/FieldParent" to="Audio/SFX/Farming SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Blocker/BackToFarm" to="." method="LoadSceneAtIndex"] [connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"] +[connection signal="tree_entered" from="SceneNameSetter" to="SceneNameSetter" method="Set"] [editable path="YSorted/Vesna"] [editable path="YSorted/Vesna/GenericItemOnGround"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 1a19e83..f0e1f21 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -15,6 +15,7 @@ public partial class FarmingControls2D : Node2D [Export] private CpuParticles2D _wateringParticles; [Export] private float _wateringCanParticlesVerticalOffset = 50f; [Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651); + [Export] private Node2D _fieldParent; private int _toolId = -1; private bool _wateringCanFilled = false; @@ -143,13 +144,11 @@ public partial class FarmingControls2D : Node2D // reposition and reparent the instance field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y); - FieldService.Instance.AddChild(fieldInstance); + _fieldParent.AddChild(fieldInstance); EmitSignal(SignalName.FieldCreated); } } } - - #endregion } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 7d87c08..c76b51c 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,6 +1,7 @@ using System; using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; +using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; @@ -20,6 +21,7 @@ public partial class FieldBehaviour2D : Sprite2D [Export] public Node2D PlantingPlaceholder; [Export] public ItemRepository ItemRepository; [Export] public InteractionArea2D FieldInteractionArea; + [Export] public VariableResource _sceneKeyProvider; public Vector2 FieldPosition; @@ -52,6 +54,7 @@ public partial class FieldBehaviour2D : Sprite2D public override void _Ready() { UpdateFieldState(FieldState); + FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), (Vector2I) GlobalPosition, this); int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; _outlineSprite.Texture = _maskOutlineTextures[randomIndex]; diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 80e4770..1405f99 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -24,6 +24,7 @@ public partial class FieldService : Node //Create public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field) { + GD.Print("Trying to add a field at: " + position); if (_outerDict != null ) { FieldsInScene innerDict; diff --git a/scripts/CSharp/Low Code/Variables/VariableSetter.cs b/scripts/CSharp/Low Code/Variables/VariableSetter.cs new file mode 100644 index 0000000..cdde4cf --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableSetter.cs @@ -0,0 +1,14 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +public partial class VariableSetter : Node +{ + [Export] private VariableResource _variableResource; + [Export] private Variant _payloadToSet; + + public void Set() + { + _variableResource.Payload = _payloadToSet; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableSetter.cs.uid b/scripts/CSharp/Low Code/Variables/VariableSetter.cs.uid new file mode 100644 index 0000000..34c1435 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableSetter.cs.uid @@ -0,0 +1 @@ +uid://dfpyjxivcuidr -- 2.36.3 From 55f0d2a77e3aeb35e836bf5c4ba12050df573c00 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 14:02:03 +0100 Subject: [PATCH 17/29] :construction: reworked farming system to work with indices instead of positions --- prefabs/characters/Player2D.tscn | 4 +- prefabs/farm/base_field.tscn | 30 +++++++++++- project.godot | 1 + .../low code/farming/var_cursorOnField.tres | 8 ++++ scenes/Babushka_scene_farm_outside_2d.tscn | 29 ++---------- scenes/Babushka_scene_outside_beets.tscn | 8 ++++ .../Common/Farming/FarmingControls2D.cs | 47 ++++--------------- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 5 +- scripts/CSharp/Common/Farming/FieldService.cs | 41 +++++++++------- .../CSharp/Low Code/Variables/VariableNode.cs | 8 ++++ .../Low Code/Variables/VariableNode.cs.uid | 1 + 11 files changed, 98 insertions(+), 84 deletions(-) create mode 100644 resources/low code/farming/var_cursorOnField.tres create mode 100644 scripts/CSharp/Low Code/Variables/VariableNode.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariableNode.cs.uid diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index d2004cc..7456f16 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=486 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=487 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -286,6 +286,7 @@ [ext_resource type="Texture2D" uid="uid://blh0t2ofqj2uq" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0016.png" id="472_wdxsr"] [ext_resource type="AudioStream" uid="uid://dymoalptxmge" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_04_R.wav" id="473_8hbu5"] [ext_resource type="Texture2D" uid="uid://l5ym7gi82l1b" path="res://art/ui/UI/Watercan-ui/Tropfen-ui-6.png" id="473_g32y8"] +[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="474_ogmln"] [ext_resource type="AudioStream" uid="uid://4555a4w30tda" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_05_R.wav" id="474_t1d6r"] [ext_resource type="Texture2D" uid="uid://3t1m2xi4ks75" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0018.png" id="474_tu801"] [ext_resource type="AudioStream" uid="uid://dpqvnogggvgea" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_06_R.wav" id="475_83c4i"] @@ -2163,6 +2164,7 @@ _movingPlayer = NodePath("../CharacterBody2D") _wateringParticles = NodePath("../pouring water vfx") _wateringCanParticlesVerticalOffset = -100.0 _fieldOffsetVector = Vector2i(735, 600) +_cursorOnField = ExtResource("474_ogmln") [node name="pouring water vfx" type="CPUParticles2D" parent="."] position = Vector2(-652, -599) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 873170a..680e200 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=19 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=23 format=3 uid="uid://b1d2e7ely6hyw"] +[ext_resource type="Script" uid="uid://j2mhvb45egej" path="res://scripts/CSharp/Low Code/Variables/VariableNode.cs" id="1_4mg73"] [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"] [ext_resource type="Texture2D" uid="uid://50qn027e5lvh" path="res://art/masks/field_outline_2_outline.png" id="3_2eegd"] @@ -18,10 +19,17 @@ [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"] [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="17_1mi0u"] +[ext_resource type="Script" uid="uid://dfpyjxivcuidr" path="res://scripts/CSharp/Low Code/Variables/VariableSetter.cs" id="19_lgya6"] +[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="20_lgya6"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_57jmp"] +size = Vector2(600, 400) [node name="BaseField" type="Node2D"] +script = ExtResource("1_4mg73") +Payload = 0 -[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea")] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex")] z_index = -1 scale = Vector2(0.9, 1) script = ExtResource("1_qa01x") @@ -37,6 +45,7 @@ PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") FieldInteractionArea = NodePath("../InteractionArea") _sceneKeyProvider = ExtResource("11_cjahb") +_fieldIndex = NodePath("..") [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 @@ -71,7 +80,24 @@ _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource( script = ExtResource("14_w08sx") _itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")]) +[node name="FieldCreationBlocker" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="FieldCreationBlocker"] +shape = SubResource("RectangleShape2D_57jmp") + +[node name="CursorOnFieldSetter" type="Node" parent="FieldCreationBlocker"] +script = ExtResource("19_lgya6") +_variableResource = ExtResource("20_lgya6") +_payloadToSet = true + +[node name="CursorNotOnFieldSetter" type="Node" parent="FieldCreationBlocker"] +script = ExtResource("19_lgya6") +_variableResource = ExtResource("20_lgya6") +_payloadToSet = false + [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] [connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] +[connection signal="mouse_entered" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorOnFieldSetter" method="Set"] +[connection signal="mouse_exited" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorNotOnFieldSetter" method="Set"] diff --git a/project.godot b/project.godot index f394b07..debd9c1 100644 --- a/project.godot +++ b/project.godot @@ -173,6 +173,7 @@ directories/tres_directory={ "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", "var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", "var_Counter": "res://resources/low code/test/var_Counter.tres", +"var_cursorOnField": "res://resources/low code/farming/var_cursorOnField.tres", "var_sceneNameProvider": "res://resources/low code/farming/var_sceneNameProvider.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", diff --git a/resources/low code/farming/var_cursorOnField.tres b/resources/low code/farming/var_cursorOnField.tres new file mode 100644 index 0000000..8af7715 --- /dev/null +++ b/resources/low code/farming/var_cursorOnField.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://fnb0n0w2ktuc"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_nm02e"] + +[resource] +script = ExtResource("1_nm02e") +Payload = false +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index b3d63df..16626c1 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=117 format=3 uid="uid://gigb28qk8t12"] +[gd_scene load_steps=115 format=3 uid="uid://gigb28qk8t12"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"] [ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"] @@ -211,13 +211,6 @@ shader_parameter/tiling_scale = Vector2(1, 20) shader = ExtResource("13_kt1wx") shader_parameter/tiling_scale = Vector2(1, 25) -[sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"] -resource_local_to_scene = true -size = Vector2(7150, 941.9418) - -[sub_resource type="RectangleShape2D" id="RectangleShape2D_2nee2"] -size = Vector2(5782, 896.7792) - [sub_resource type="ShaderMaterial" id="ShaderMaterial_lwk6t"] shader = ExtResource("13_7p0hq") shader_parameter/hue_shift = 0.0 @@ -2099,22 +2092,6 @@ rotation = 1.5708 scale = Vector2(0.1, 10.8) texture = ExtResource("21_if5vh") -[node name="Farming Colliders" type="Area2D" parent="YSorted/Farm visuals"] -position = Vector2(5, 4.098892) -scale = Vector2(1, 0.993819) -collision_mask = 5 -collision_priority = 10.0 - -[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"] -position = Vector2(11913.995, 3085.0288) -scale = Vector2(0.9999998, 0.9999998) -shape = SubResource("RectangleShape2D_p6n74") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"] -position = Vector2(2895.9988, 3088.6096) -scale = Vector2(0.9999998, 0.9999998) -shape = SubResource("RectangleShape2D_2nee2") - [node name="Blocker" type="Node2D" parent="YSorted"] [node name="Fence Door2" type="Sprite2D" parent="YSorted/Blocker"] @@ -2156,6 +2133,7 @@ position = Vector2(-113.561, 193.035) shape = SubResource("RectangleShape2D_2vojv") [node name="ducks" type="Node2D" parent="YSorted"] +visible = false z_index = 1 y_sort_enabled = true script = ExtResource("49_uxa2m") @@ -2232,6 +2210,7 @@ position = Vector2(-4659, 2897) position = Vector2(-5016, 3361) [node name="trash" type="Node2D" parent="YSorted"] +visible = false z_index = 1 y_sort_enabled = true @@ -2428,8 +2407,6 @@ _payloadToSet = "farmOutside" [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/SeedPickup2" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="InteractedTool" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadSceneAtIndex"] -[connection signal="mouse_entered" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CanCreateFields"] -[connection signal="mouse_exited" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CannotCreateFields"] [connection signal="InteractedTool" from="YSorted/Blocker/InteractionArea" to="." method="LoadSceneAtIndex"] [connection signal="GoalReached" from="YSorted/ducks" to="YSorted/ducks/DialogicToggle" method="ToggleDialogue"] [connection signal="DuckCollected" from="YSorted/ducks/Duck2" to="YSorted/ducks" method="Increment"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 8406460..1f4e0d9 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1716,6 +1716,7 @@ _field = NodePath("../..") [node name="BaseField2" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) +Payload = 1 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="0"] FieldState = 3 @@ -1727,6 +1728,7 @@ _field = NodePath("../..") [node name="BaseField3" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) +Payload = 2 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="0"] FieldState = 3 @@ -1738,6 +1740,7 @@ _field = NodePath("../..") [node name="BaseField4" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(2559, 2624.22) scale = Vector2(1, 1.00622) +Payload = 3 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="0"] FieldState = 3 @@ -1749,6 +1752,7 @@ _field = NodePath("../..") [node name="BaseField5" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(3305, 2624.22) scale = Vector2(1, 1.00622) +Payload = 4 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="0"] FieldState = 3 @@ -1760,6 +1764,7 @@ _field = NodePath("../..") [node name="BaseField6" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4033, 2618.18) scale = Vector2(1, 1.00622) +Payload = 5 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="0"] FieldState = 3 @@ -1771,6 +1776,7 @@ _field = NodePath("../..") [node name="BaseField7" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4755, 2630.26) scale = Vector2(1, 1.00622) +Payload = 6 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="0"] FieldState = 3 @@ -1782,6 +1788,7 @@ _field = NodePath("../..") [node name="BaseField8" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4418, 3226.95) scale = Vector2(1, 1.00622) +Payload = 7 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="0"] FieldState = 3 @@ -1793,6 +1800,7 @@ _field = NodePath("../..") [node name="BaseField9" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(5317, 3208.83) scale = Vector2(1, 1.00622) +Payload = 8 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="0"] FieldState = 3 diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index f0e1f21..3a28cc3 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -9,17 +9,16 @@ namespace Babushka.scripts.CSharp.Common.Farming; public partial class FarmingControls2D : Node2D { [Export] private VariableResource _sceneKeyProvider; - [Export] private PackedScene? _fieldPrefab = null!; [Export] private Node2D _movingPlayer; [Export] private Camera2D _camera; [Export] private CpuParticles2D _wateringParticles; [Export] private float _wateringCanParticlesVerticalOffset = 50f; [Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651); [Export] private Node2D _fieldParent; + [Export] private VariableResource _cursorOnField; private int _toolId = -1; private bool _wateringCanFilled = false; - private bool _canCreateFields = false; [Signal] public delegate void WateringFieldEventHandler(); @@ -59,6 +58,7 @@ public partial class FarmingControls2D : Node2D { if (@event.IsActionPressed("click")) { + bool cursorOnField = _cursorOnField.Payload.AsBool(); if (_toolId == WateringCanState.WATERING_CAN_ID && WateringCanState.GetFillState() > 0) { @@ -66,7 +66,7 @@ public partial class FarmingControls2D : Node2D WaterTheField(adjustedPosition); } - if (_canCreateFields && _toolId == 0) + if ( _toolId == 0) { Vector2I adjustedPosition = GetAdjustedMousePosition(); MakeField(adjustedPosition); @@ -86,16 +86,6 @@ public partial class FarmingControls2D : Node2D { return input.Snapped(step); } - - public void CanCreateFields() - { - _canCreateFields = true; - } - - public void CannotCreateFields() - { - _canCreateFields = false; - } #region WATERING public void FillWateringCan() @@ -108,7 +98,8 @@ public partial class FarmingControls2D : Node2D private void WaterTheField(Vector2I fieldPosition) { - FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition); + int potentialFieldIndex = FieldService.Instance.PositionToIndex(fieldPosition); + FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex); if (field == null || field.FieldState == FieldState.Watered) { return; @@ -123,31 +114,11 @@ public partial class FarmingControls2D : Node2D #endregion #region FIELD CREATION - private void MakeField(Vector2I fieldPosition) + private void MakeField(Vector2I mousePosition) { - if(_fieldPrefab == null) - return; - - // only instantiate a field if there isn't one already. - if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null) - { - Node fieldInstance = _fieldPrefab.Instantiate(); - if (fieldInstance is Node2D field2d) - { - // add dictionary entry for the field - Array fields = field2d.FindChildren("*", nameof(FieldBehaviour2D)); - if (fields.Count > 0) - { - FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D); - } - - // reposition and reparent the instance - field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y); - - _fieldParent.AddChild(fieldInstance); - EmitSignal(SignalName.FieldCreated); - } - } + int potentialFieldIndex = FieldService.Instance.PositionToIndex(mousePosition); + if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex) == null) + EmitSignal(SignalName.FieldCreated); } #endregion diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index c76b51c..89bb9d2 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -22,6 +22,8 @@ public partial class FieldBehaviour2D : Sprite2D [Export] public ItemRepository ItemRepository; [Export] public InteractionArea2D FieldInteractionArea; [Export] public VariableResource _sceneKeyProvider; + [Export] private VariableNode _fieldIndex; + public Vector2 FieldPosition; @@ -54,7 +56,7 @@ public partial class FieldBehaviour2D : Sprite2D public override void _Ready() { UpdateFieldState(FieldState); - FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), (Vector2I) GlobalPosition, this); + FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(),_fieldIndex.Payload.AsInt32(), this); int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; _outlineSprite.Texture = _maskOutlineTextures[randomIndex]; @@ -139,5 +141,6 @@ public partial class FieldBehaviour2D : Sprite2D return success; } + } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 1405f99..0e41dc8 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -22,9 +22,9 @@ public partial class FieldService : Node //Create - public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field) + public bool TryAddEntry(string sceneName, int fieldIndex, FieldBehaviour2D field) { - GD.Print("Trying to add a field at: " + position); + GD.Print("Trying to add a field at: " + fieldIndex); if (_outerDict != null ) { FieldsInScene innerDict; @@ -36,21 +36,25 @@ public partial class FieldService : Node _outerDict.Add(sceneName, innerDict); } - if (!innerDict.fields.ContainsKey(position)) + if (!innerDict.fields.ContainsKey(fieldIndex)) { - innerDict.fields.Add(position, field); + innerDict.fields.Add(fieldIndex, field); return true; } + else + { + GD.PrintErr("Duplicate field at: " + fieldIndex); + } } return false; } // Read - public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition) + public FieldBehaviour2D? TryGet(string key, int fieldIndex) { if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { - if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance)) + if (field.fields.TryGetValue(fieldIndex, out FieldBehaviour2D? fieldInstance)) { return fieldInstance; } @@ -60,42 +64,47 @@ public partial class FieldService : Node //Update - public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state) + public void UpdateEntry(string key, int fieldIndex, FieldBehaviour2D state) { if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { - if (field.fields.ContainsKey(fieldPosition)) + if (field.fields.ContainsKey(fieldIndex)) { - field.fields[fieldPosition] = state; + field.fields[fieldIndex] = state; } else { - TryAddEntry(key, fieldPosition, state); + TryAddEntry(key, fieldIndex, state); } } } //Delete - - public void RemoveEntry(string key, Vector2I fieldPosition) + public void RemoveEntry(string key, int fieldIndex) { if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field)) { - if (field.fields.ContainsKey(fieldPosition)) + if (field.fields.ContainsKey(fieldIndex)) { - field.fields.Remove(fieldPosition); + field.fields.Remove(fieldIndex); } } } + + public int PositionToIndex(Vector2 position) + { + // some awesome code here + return 0; + } } internal class FieldsInScene { - public Dictionary fields; + public Dictionary fields; public FieldsInScene() { - fields = new Dictionary(); + fields = new Dictionary(); } } diff --git a/scripts/CSharp/Low Code/Variables/VariableNode.cs b/scripts/CSharp/Low Code/Variables/VariableNode.cs new file mode 100644 index 0000000..e165e9b --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableNode.cs @@ -0,0 +1,8 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +public partial class VariableNode : Node +{ + [Export] public Variant Payload { get; set; } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableNode.cs.uid b/scripts/CSharp/Low Code/Variables/VariableNode.cs.uid new file mode 100644 index 0000000..a777d02 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableNode.cs.uid @@ -0,0 +1 @@ +uid://j2mhvb45egej -- 2.36.3 From d51cc461f76066dbea35caae230fd5572302b47d Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 14:27:56 +0100 Subject: [PATCH 18/29] :construction: made preplaced fields show plants --- prefabs/farm/base_field.tscn | 12 ++++++------ scenes/Babushka_scene_outside_beets.tscn | 6 ------ .../CSharp/Common/Farming/PlantBehaviour2D.cs | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 680e200..b9865a4 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -80,17 +80,17 @@ _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource( script = ExtResource("14_w08sx") _itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")]) -[node name="FieldCreationBlocker" type="Area2D" parent="."] +[node name="CursorOnFieldCollider" type="Area2D" parent="."] -[node name="CollisionShape2D" type="CollisionShape2D" parent="FieldCreationBlocker"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="CursorOnFieldCollider"] shape = SubResource("RectangleShape2D_57jmp") -[node name="CursorOnFieldSetter" type="Node" parent="FieldCreationBlocker"] +[node name="CursorOnFieldSetter" type="Node" parent="CursorOnFieldCollider"] script = ExtResource("19_lgya6") _variableResource = ExtResource("20_lgya6") _payloadToSet = true -[node name="CursorNotOnFieldSetter" type="Node" parent="FieldCreationBlocker"] +[node name="CursorNotOnFieldSetter" type="Node" parent="CursorOnFieldCollider"] script = ExtResource("19_lgya6") _variableResource = ExtResource("20_lgya6") _payloadToSet = false @@ -99,5 +99,5 @@ _payloadToSet = false [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] [connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] -[connection signal="mouse_entered" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorOnFieldSetter" method="Set"] -[connection signal="mouse_exited" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorNotOnFieldSetter" method="Set"] +[connection signal="mouse_entered" from="CursorOnFieldCollider" to="CursorOnFieldCollider/CursorOnFieldSetter" method="Set"] +[connection signal="mouse_exited" from="CursorOnFieldCollider" to="CursorOnFieldCollider/CursorNotOnFieldSetter" method="Set"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 1f4e0d9..34e4664 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1718,9 +1718,6 @@ position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) Payload = 1 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="0"] -FieldState = 3 - [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") @@ -1730,9 +1727,6 @@ position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) Payload = 2 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="0"] -FieldState = 3 - [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField3/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index ca8bc30..910a5f3 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -1,12 +1,9 @@ using System; -using Babushka.scripts.CSharp.Common.Animation; using Babushka.scripts.CSharp.Common.Inventory; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; - - /// /// Determines the behaviour of a plant in Babushka. /// @@ -23,8 +20,9 @@ public partial class PlantBehaviour2D : Node2D [Export] private bool _magicWordNeeded = true; private string _magicWordDialogicEventName = "MagicWord"; - private Sprite2D _currentPlantSprite = null; + private Sprite2D? _currentPlantSprite = null; private bool _magicWordSaid = false; + private bool _calledOnReady = false; /// /// public accessor for the field reference @@ -37,6 +35,7 @@ public partial class PlantBehaviour2D : Node2D public override void _Ready() { + GD.Print($"Ready: {Name}"); if (_state == PlantState.None) { _state = PlantState.Planted; @@ -45,6 +44,8 @@ public partial class PlantBehaviour2D : Node2D } else { + GD.Print("plant state not none."); + _calledOnReady = true; GrowPlant(); } } @@ -60,9 +61,13 @@ public partial class PlantBehaviour2D : Node2D /// public void GrowPlant() { - if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded) - return; + if (!_calledOnReady) + { + if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded) + return; + } + GD.Print("Growing plant."); switch (_state) { case PlantState.None: @@ -105,6 +110,7 @@ public partial class PlantBehaviour2D : Node2D _field.UpdateFieldState(FieldState.Tilled); _magicWordSaid = false; + _calledOnReady = false; } private Sprite2D GetRandomSprite(Sprite2D[] sprites) -- 2.36.3 From b00b466045ad8ad14245910800515a39fa1eca80 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 15:51:15 +0100 Subject: [PATCH 19/29] :construction: watering fields kinda works now --- prefabs/characters/Player2D.tscn | 42 ++++------------- prefabs/farm/base_field.tscn | 47 ++++++++++--------- prefabs/interactions/detection_cross.tscn | 2 +- prefabs/interactions/detector.tscn | 2 +- project.godot | 3 +- .../low code/farming/event_watering.tres | 7 +++ ...eld.tres => var_wateredFieldPosition.tres} | 8 ++-- scenes/Babushka_scene_outside_beets.tscn | 2 +- .../Common/Animation/VesnaAnimations.cs | 3 -- .../Common/Farming/FarmingControls2D.cs | 28 +---------- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 22 +++++++-- 11 files changed, 69 insertions(+), 97 deletions(-) create mode 100644 resources/low code/farming/event_watering.tres rename resources/low code/farming/{var_cursorOnField.tres => var_wateredFieldPosition.tres} (53%) diff --git a/prefabs/characters/Player2D.tscn b/prefabs/characters/Player2D.tscn index 7456f16..cff4237 100644 --- a/prefabs/characters/Player2D.tscn +++ b/prefabs/characters/Player2D.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=487 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=485 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -285,8 +285,6 @@ [ext_resource type="AudioStream" uid="uid://cvvjd2i6x047n" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_03_R.wav" id="472_g32y8"] [ext_resource type="Texture2D" uid="uid://blh0t2ofqj2uq" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0016.png" id="472_wdxsr"] [ext_resource type="AudioStream" uid="uid://dymoalptxmge" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_04_R.wav" id="473_8hbu5"] -[ext_resource type="Texture2D" uid="uid://l5ym7gi82l1b" path="res://art/ui/UI/Watercan-ui/Tropfen-ui-6.png" id="473_g32y8"] -[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="474_ogmln"] [ext_resource type="AudioStream" uid="uid://4555a4w30tda" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_05_R.wav" id="474_t1d6r"] [ext_resource type="Texture2D" uid="uid://3t1m2xi4ks75" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0018.png" id="474_tu801"] [ext_resource type="AudioStream" uid="uid://dpqvnogggvgea" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_06_R.wav" id="475_83c4i"] @@ -295,6 +293,7 @@ [ext_resource type="Texture2D" uid="uid://d3rdsclnqbx7" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0001.png" id="477_qko58"] [ext_resource type="Texture2D" uid="uid://dqubvx1a08kn4" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0002.png" id="478_5myrm"] [ext_resource type="Texture2D" uid="uid://dystt4hyqad74" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0004.png" id="480_wnay3"] +[ext_resource type="Resource" uid="uid://cmqapbvv0hev2" path="res://resources/low code/farming/event_watering.tres" id="481_t1d6r"] [ext_resource type="Texture2D" uid="uid://bopxv06co1osl" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0006.png" id="482_wfdif"] [ext_resource type="Texture2D" uid="uid://coyggdfwgkeru" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0008.png" id="484_32thn"] [ext_resource type="Texture2D" uid="uid://du6x1h42smp6m" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0010.png" id="486_kobao"] @@ -481,7 +480,6 @@ [ext_resource type="Texture2D" uid="uid://b0v61all3tsny" path="res://art/animation/Vesna2D/Vesna Anims Tools/S02-Walk-Gießkanne/0018.png" id="812_sf8kv"] [ext_resource type="Texture2D" uid="uid://cao7vqax8cblo" path="res://art/animation/Vesna2D/Vesna Anims Tools/S02-Walk-Gießkanne/0020.png" id="814_3uq4g"] [ext_resource type="Script" uid="uid://bcskt5ckh3rqa" path="res://scripts/CSharp/Common/Farming/FarmingControls2D.cs" id="817_6nrw3"] -[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field.tscn" id="818_16w6h"] [ext_resource type="Script" uid="uid://cvkw4qd2hxksi" path="res://scripts/GdScript/dialogic_toggle.gd" id="819_4na52"] [sub_resource type="CircleShape2D" id="CircleShape2D_ssqtd"] @@ -2087,7 +2085,6 @@ stream_6/stream = ExtResource("476_deeju") [node name="Vesna" type="Node2D" node_paths=PackedStringArray("_farmingControls", "_player2d", "_vesnaAnimations")] y_sort_enabled = true -position = Vector2(0, 2) script = ExtResource("1_yd5ep") _farmingControls = NodePath("FarmingControls") _player2d = NodePath("CharacterBody2D") @@ -2109,11 +2106,10 @@ position = Vector2(-24, -13) shape = SubResource("CircleShape2D_ssqtd") debug_color = Color(0.923708, 0.202722, 0.475262, 0.42) -[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles")] +[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite")] position = Vector2(0, -374) script = ExtResource("3_f6xmn") _sprite = NodePath("Animated Sprites") -_wateringParticles = NodePath("../../pouring water vfx") [node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"] position = Vector2(0, 450) @@ -2156,34 +2152,12 @@ _eventResources = Array[Object]([ExtResource("468_t1d6r")]) script = ExtResource("467_8hbu5") _eventResources = Array[Object]([ExtResource("469_t1d6r")]) -[node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_wateringParticles")] +[node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer")] script = ExtResource("817_6nrw3") _sceneKeyProvider = ExtResource("471_83c4i") -_fieldPrefab = ExtResource("818_16w6h") _movingPlayer = NodePath("../CharacterBody2D") -_wateringParticles = NodePath("../pouring water vfx") _wateringCanParticlesVerticalOffset = -100.0 _fieldOffsetVector = Vector2i(735, 600) -_cursorOnField = ExtResource("474_ogmln") - -[node name="pouring water vfx" type="CPUParticles2D" parent="."] -position = Vector2(-652, -599) -rotation = -0.333807 -emitting = false -amount = 20 -texture = ExtResource("473_g32y8") -lifetime = 0.5 -randomness = 1.0 -local_coords = true -draw_order = 1 -emission_shape = 2 -emission_sphere_radius = 128.0 -linear_accel_min = 44.07 -linear_accel_max = 78.81 -scale_amount_min = 0.4 -scale_amount_max = 0.8 -color = Color(0.400601, 0.62444, 0.791217, 1) -hue_variation_max = 0.4 [node name="DialogicToggle" type="Node2D" parent="." node_paths=PackedStringArray("itemToToggle")] scale = Vector2(0.7, 0.7) @@ -2200,6 +2174,10 @@ script = ExtResource("471_2f15g") [node name="Timer" type="Timer" parent="SFX/FootstepsAudio"] wait_time = 0.5 +[node name="WateringEventListener" type="Node" parent="."] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("481_t1d6r")]) + [connection signal="FilledWateringCan" from="." to="CharacterBody2D/WateringCanUI" method="Refill"] [connection signal="InventorySelectionChanged" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] [connection signal="PickedUpTool" from="." to="CharacterBody2D/visuals" method="ActivateTool"] @@ -2207,7 +2185,7 @@ wait_time = 0.5 [connection signal="LookDirection" from="CharacterBody2D/visuals" to="CharacterBody2D/DetectionCross" method="SetDirection"] [connection signal="EventRaised" from="CharacterBody2D/PlantCreatedEventListener" to="CharacterBody2D/visuals" method="PlayFarmingAnimation"] [connection signal="EventRaised" from="CharacterBody2D/PickedUpInteractableListener" to="CharacterBody2D/visuals" method="PlayPickUpAnimation"] -[connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] -[connection signal="WateringField" from="FarmingControls" to="CharacterBody2D/WateringCanUI" method="Water"] [connection signal="timelineStarted" from="DialogicToggle" to="SFX/FootstepsAudio/Timer" method="stop"] [connection signal="timeout" from="SFX/FootstepsAudio/Timer" to="SFX/FootstepsAudio" method="PlayOneShot"] +[connection signal="EventRaised" from="WateringEventListener" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] +[connection signal="EventRaised" from="WateringEventListener" to="CharacterBody2D/WateringCanUI" method="Water"] diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index b9865a4..3221f16 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=22 format=3 uid="uid://b1d2e7ely6hyw"] [ext_resource type="Script" uid="uid://j2mhvb45egej" path="res://scripts/CSharp/Low Code/Variables/VariableNode.cs" id="1_4mg73"] [ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"] @@ -15,21 +15,18 @@ [ext_resource type="Texture2D" uid="uid://bovypw2hsn2nq" path="res://art/masks/field_outline_1_outline.png" id="9_wx561"] [ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"] [ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="11_cjahb"] +[ext_resource type="Resource" uid="uid://cmqapbvv0hev2" path="res://resources/low code/farming/event_watering.tres" id="14_57jmp"] [ext_resource type="Script" uid="uid://3t0af586fimq" path="res://scripts/CSharp/Common/Inventory/InventoryListener.cs" id="14_w08sx"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"] [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="17_1mi0u"] -[ext_resource type="Script" uid="uid://dfpyjxivcuidr" path="res://scripts/CSharp/Low Code/Variables/VariableSetter.cs" id="19_lgya6"] -[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="20_lgya6"] - -[sub_resource type="RectangleShape2D" id="RectangleShape2D_57jmp"] -size = Vector2(600, 400) +[ext_resource type="Texture2D" uid="uid://l5ym7gi82l1b" path="res://art/ui/UI/Watercan-ui/Tropfen-ui-6.png" id="21_4mg73"] [node name="BaseField" type="Node2D"] script = ExtResource("1_4mg73") Payload = 0 -[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex")] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex", "_wateringParticles")] z_index = -1 scale = Vector2(0.9, 1) script = ExtResource("1_qa01x") @@ -46,6 +43,8 @@ ItemRepository = ExtResource("7_w8caw") FieldInteractionArea = NodePath("../InteractionArea") _sceneKeyProvider = ExtResource("11_cjahb") _fieldIndex = NodePath("..") +_wateringParticles = NodePath("../pouring water vfx") +_wateringEvent = ExtResource("14_57jmp") [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 @@ -80,24 +79,26 @@ _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource( script = ExtResource("14_w08sx") _itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")]) -[node name="CursorOnFieldCollider" type="Area2D" parent="."] - -[node name="CollisionShape2D" type="CollisionShape2D" parent="CursorOnFieldCollider"] -shape = SubResource("RectangleShape2D_57jmp") - -[node name="CursorOnFieldSetter" type="Node" parent="CursorOnFieldCollider"] -script = ExtResource("19_lgya6") -_variableResource = ExtResource("20_lgya6") -_payloadToSet = true - -[node name="CursorNotOnFieldSetter" type="Node" parent="CursorOnFieldCollider"] -script = ExtResource("19_lgya6") -_variableResource = ExtResource("20_lgya6") -_payloadToSet = false +[node name="pouring water vfx" type="CPUParticles2D" parent="."] +position = Vector2(0, -300) +emitting = false +amount = 25 +texture = ExtResource("21_4mg73") +one_shot = true +randomness = 1.0 +local_coords = true +draw_order = 1 +emission_shape = 2 +emission_sphere_radius = 128.0 +gravity = Vector2(0, 500) +linear_accel_min = 44.07 +linear_accel_max = 78.81 +scale_amount_min = 0.4 +scale_amount_max = 0.8 +color = Color(0.400601, 0.62444, 0.791217, 1) +hue_variation_max = 0.4 [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] [connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] -[connection signal="mouse_entered" from="CursorOnFieldCollider" to="CursorOnFieldCollider/CursorOnFieldSetter" method="Set"] -[connection signal="mouse_exited" from="CursorOnFieldCollider" to="CursorOnFieldCollider/CursorNotOnFieldSetter" method="Set"] diff --git a/prefabs/interactions/detection_cross.tscn b/prefabs/interactions/detection_cross.tscn index 57930bc..5814bea 100644 --- a/prefabs/interactions/detection_cross.tscn +++ b/prefabs/interactions/detection_cross.tscn @@ -6,7 +6,7 @@ [node name="DetectionCross" type="Node2D" node_paths=PackedStringArray("_detector")] script = ExtResource("1_va8tx") _detector = NodePath("detector") -_xOffset = 300.0 +_xOffset = 400.0 _yOffset = 300.0 [node name="detector" parent="." instance=ExtResource("2_8hh05")] diff --git a/prefabs/interactions/detector.tscn b/prefabs/interactions/detector.tscn index 2b4626e..967829b 100644 --- a/prefabs/interactions/detector.tscn +++ b/prefabs/interactions/detector.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" uid="uid://c3pd60biootsx" path="res://scripts/CSharp/Common/CharacterControls/Detector.cs" id="1_6pib0"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_qwv4c"] -size = Vector2(100, 200) +size = Vector2(100, 400) [node name="detector" type="Area2D"] collision_layer = 4 diff --git a/project.godot b/project.godot index debd9c1..58a2bec 100644 --- a/project.godot +++ b/project.godot @@ -149,6 +149,7 @@ directories/tres_directory={ "event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", "event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres", "event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", +"event_watering": "res://resources/low code/farming/event_watering.tres", "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", @@ -173,8 +174,8 @@ directories/tres_directory={ "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", "var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", "var_Counter": "res://resources/low code/test/var_Counter.tres", -"var_cursorOnField": "res://resources/low code/farming/var_cursorOnField.tres", "var_sceneNameProvider": "res://resources/low code/farming/var_sceneNameProvider.tres", +"var_wateredFieldPosition": "res://resources/low code/farming/var_wateredFieldPosition.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", "vn_textbox_name_label_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_name_label_panel.tres", diff --git a/resources/low code/farming/event_watering.tres b/resources/low code/farming/event_watering.tres new file mode 100644 index 0000000..9179160 --- /dev/null +++ b/resources/low code/farming/event_watering.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://cmqapbvv0hev2"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_qophu"] + +[resource] +script = ExtResource("1_qophu") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/low code/farming/var_cursorOnField.tres b/resources/low code/farming/var_wateredFieldPosition.tres similarity index 53% rename from resources/low code/farming/var_cursorOnField.tres rename to resources/low code/farming/var_wateredFieldPosition.tres index 8af7715..81b720a 100644 --- a/resources/low code/farming/var_cursorOnField.tres +++ b/resources/low code/farming/var_wateredFieldPosition.tres @@ -1,8 +1,8 @@ -[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://fnb0n0w2ktuc"] +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://svfgwtb3xosj"] -[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_nm02e"] +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_qoiop"] [resource] -script = ExtResource("1_nm02e") -Payload = false +script = ExtResource("1_qoiop") +Payload = Vector2(0, 0) metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 34e4664..18d6654 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -958,6 +958,7 @@ shape = SubResource("RectangleShape2D_0sfl7") [node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("31_xcb8u")] _spritesToOutline = [NodePath("..")] +_id = 1 [node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"] position = Vector2(146, -130) @@ -1914,7 +1915,6 @@ _variableResource = ExtResource("57_hpgl7") _payloadToSet = "beetRootScene" [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] -[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] [connection signal="InteractedTool" from="YSorted/Blocker/BackToFarm" to="." method="LoadSceneAtIndex"] [connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"] diff --git a/scripts/CSharp/Common/Animation/VesnaAnimations.cs b/scripts/CSharp/Common/Animation/VesnaAnimations.cs index 797490c..1881d2d 100644 --- a/scripts/CSharp/Common/Animation/VesnaAnimations.cs +++ b/scripts/CSharp/Common/Animation/VesnaAnimations.cs @@ -8,7 +8,6 @@ namespace Babushka.scripts.CSharp.Common.Animation; public partial class VesnaAnimations : Node { [Export] private AnimatedSprite2D _sprite; - [Export] private CpuParticles2D _wateringParticles; private bool anyActionPressed; private string _toolString; @@ -144,7 +143,6 @@ public partial class VesnaAnimations : Node _sprite.Animation = "diagonal wateringcan"; _sprite.Play(); InputService.Instance.InputEnabled = false; - _wateringParticles.Emitting = true; Task.Run(DelayedInputHandlerReset); } } @@ -152,7 +150,6 @@ public partial class VesnaAnimations : Node private async Task DelayedInputHandlerReset() { await Task.Delay(1000); - _wateringParticles.Emitting = false; InputService.Instance.InputEnabled = true; } diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 3a28cc3..0031f5b 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -11,17 +11,14 @@ public partial class FarmingControls2D : Node2D [Export] private VariableResource _sceneKeyProvider; [Export] private Node2D _movingPlayer; [Export] private Camera2D _camera; - [Export] private CpuParticles2D _wateringParticles; + [Export] private float _wateringCanParticlesVerticalOffset = 50f; [Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651); [Export] private Node2D _fieldParent; - [Export] private VariableResource _cursorOnField; private int _toolId = -1; private bool _wateringCanFilled = false; - [Signal] public delegate void WateringFieldEventHandler(); - [Signal] public delegate void FieldCreatedEventHandler(); #region Tools @@ -58,14 +55,6 @@ public partial class FarmingControls2D : Node2D { if (@event.IsActionPressed("click")) { - bool cursorOnField = _cursorOnField.Payload.AsBool(); - if (_toolId == WateringCanState.WATERING_CAN_ID - && WateringCanState.GetFillState() > 0) - { - Vector2I adjustedPosition = GetAdjustedMousePosition(); - WaterTheField(adjustedPosition); - } - if ( _toolId == 0) { Vector2I adjustedPosition = GetAdjustedMousePosition(); @@ -95,21 +84,6 @@ public partial class FarmingControls2D : Node2D WateringCanState.Fill(); } } - - private void WaterTheField(Vector2I fieldPosition) - { - int potentialFieldIndex = FieldService.Instance.PositionToIndex(fieldPosition); - FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex); - if (field == null || field.FieldState == FieldState.Watered) - { - return; - } - - field.Water(); - _wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset); - WateringCanState.Water(); - EmitSignal(SignalName.WateringField); - } #endregion diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 89bb9d2..5b19662 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,6 +1,7 @@ using System; using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; +using Babushka.scripts.CSharp.Low_Code.Events; using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; @@ -23,6 +24,8 @@ public partial class FieldBehaviour2D : Sprite2D [Export] public InteractionArea2D FieldInteractionArea; [Export] public VariableResource _sceneKeyProvider; [Export] private VariableNode _fieldIndex; + [Export] private CpuParticles2D _wateringParticles; + [Export] private EventResource _wateringEvent; public Vector2 FieldPosition; @@ -30,15 +33,18 @@ public partial class FieldBehaviour2D : Sprite2D private bool _seedsActive; private bool _wateringCanActive; + private bool _canPlant; + private bool _canWater; + [Signal] public delegate void PlantedEventHandler(); private void UpdateInteractionArea() { // fieldstate == tilled / watered && samen im Inventar - bool canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; + _canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; // fieldstate == tilled && watering can ausgewählt - bool canWater = FieldState == FieldState.Tilled && _wateringCanActive; - FieldInteractionArea.IsActive = canPlant || canWater; + _canWater = FieldState == FieldState.Tilled && _wateringCanActive; + FieldInteractionArea.IsActive = _canPlant || _canWater; } public void ActivatedSeedInInventory(bool activated) @@ -97,6 +103,9 @@ public partial class FieldBehaviour2D : Sprite2D public void Water() { UpdateFieldState(FieldState.Watered); + _wateringParticles.Emitting = true; + WateringCanState.Water(); + _wateringEvent.Raise(); } /// @@ -104,11 +113,16 @@ public partial class FieldBehaviour2D : Sprite2D /// public void Farm() { - if (TryPlant()) + if (_canPlant || TryPlant()) { EmitSignal(SignalName.Planted); UpdateFieldState(FieldState.Planted); } + + if (_canWater) + { + Water(); + } } private bool TryPlant() -- 2.36.3 From 4705d1ee2f1c3f1c7129343cd4f5ce8521998f37 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 15:54:09 +0100 Subject: [PATCH 20/29] :bug: can no longer water fields when watering can is empty --- scripts/CSharp/Common/Farming/FieldBehaviour2D.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 5b19662..809aee2 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -102,10 +102,13 @@ public partial class FieldBehaviour2D : Sprite2D public void Water() { - UpdateFieldState(FieldState.Watered); - _wateringParticles.Emitting = true; - WateringCanState.Water(); - _wateringEvent.Raise(); + if (WateringCanState.GetFillState() > 0) + { + UpdateFieldState(FieldState.Watered); + _wateringParticles.Emitting = true; + WateringCanState.Water(); + _wateringEvent.Raise(); + } } /// -- 2.36.3 From 554a319428e2cd463cc53c68ba5ff966ca953704 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 16:39:47 +0100 Subject: [PATCH 21/29] :construction: farming rework part 2: you can now kinda "create" fields --- prefabs/farm/base_field.tscn | 28 +++++- scenes/Babushka_scene_outside_beets.tscn | 93 ++++++++++++++++++- .../CSharp/Common/Farming/FieldActivator.cs | 27 ++++++ .../Common/Farming/FieldActivator.cs.uid | 1 + 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 scripts/CSharp/Common/Farming/FieldActivator.cs create mode 100644 scripts/CSharp/Common/Farming/FieldActivator.cs.uid diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 3221f16..43016c8 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=25 format=3 uid="uid://b1d2e7ely6hyw"] [ext_resource type="Script" uid="uid://j2mhvb45egej" path="res://scripts/CSharp/Low Code/Variables/VariableNode.cs" id="1_4mg73"] [ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"] @@ -21,6 +21,12 @@ [ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="17_1mi0u"] [ext_resource type="Texture2D" uid="uid://l5ym7gi82l1b" path="res://art/ui/UI/Watercan-ui/Tropfen-ui-6.png" id="21_4mg73"] +[ext_resource type="Resource" uid="uid://dlcmqfjvgphqu" path="res://resources/items/rake.tres" id="21_68xcd"] +[ext_resource type="Script" uid="uid://dlbjjgbs0n4b0" path="res://scripts/CSharp/Common/Farming/FieldActivator.cs" id="22_57jmp"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_57jmp"] +resource_local_to_scene = true +radius = 325.2599 [node name="BaseField" type="Node2D"] script = ExtResource("1_4mg73") @@ -66,6 +72,7 @@ texture = ExtResource("9_wx561") position = Vector2(-26, -57) _active = false _spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")] +_showLabel = false [node name="PlantCreationEventRaiser" type="Node" parent="."] script = ExtResource("9_teirr") @@ -79,6 +86,10 @@ _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource( script = ExtResource("14_w08sx") _itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")]) +[node name="InventoryListener rake" type="Node" parent="."] +script = ExtResource("14_w08sx") +_itemResourcesToListenFor = Array[Object]([ExtResource("21_68xcd")]) + [node name="pouring water vfx" type="CPUParticles2D" parent="."] position = Vector2(0, -300) emitting = false @@ -98,7 +109,22 @@ scale_amount_max = 0.8 color = Color(0.400601, 0.62444, 0.791217, 1) hue_variation_max = 0.4 +[node name="FieldActivator" type="Node2D" parent="." node_paths=PackedStringArray("_field")] +script = ExtResource("22_57jmp") +_field = NodePath("../FieldBehaviour") + +[node name="InteractionArea" parent="FieldActivator" instance=ExtResource("7_2eegd")] +_useOutline = false + +[node name="CollisionShape3D" parent="FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_57jmp") + [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] [connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] [connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] +[connection signal="ItemInstanceActivated" from="InventoryListener rake" to="FieldActivator" method="RakeActivated"] +[connection signal="Interacted" from="FieldActivator/InteractionArea" to="FieldActivator/InteractionArea" method="ToggleActive"] +[connection signal="Interacted" from="FieldActivator/InteractionArea" to="FieldActivator" method="ActivateField"] + +[editable path="FieldActivator/InteractionArea"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 18d6654..79d6c14 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=86 format=3 uid="uid://b3ibx4resa1f3"] +[gd_scene load_steps=96 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"] @@ -170,6 +170,42 @@ shader_parameter/offset = 0.0 shader = ExtResource("24_anpd4") shader_parameter/tiling_scale = Vector2(1, 20) +[sub_resource type="CircleShape2D" id="CircleShape2D_qavgq"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_njxly"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_54ty3"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_gbxtf"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_6krrk"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_4ktoi"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_aaup4"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_v10dc"] +resource_local_to_scene = true +radius = 325.2599 + +[sub_resource type="CircleShape2D" id="CircleShape2D_4pibb"] +resource_local_to_scene = true +radius = 325.2599 + [sub_resource type="CircleShape2D" id="CircleShape2D_dr6bm"] resource_local_to_scene = true radius = 335.72162 @@ -185,6 +221,10 @@ shader_parameter/contrast_mult = 1.0 [sub_resource type="RectangleShape2D" id="RectangleShape2D_ycj14"] size = Vector2(707.116, 604.111) +[sub_resource type="CircleShape2D" id="CircleShape2D_hpgl7"] +resource_local_to_scene = true +radius = 294.02722 + [sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_ceriq"] loop = false stream_count = 1 @@ -1714,6 +1754,9 @@ scale = Vector2(1, 1.00622) _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_qavgq") + [node name="BaseField2" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) @@ -1723,6 +1766,9 @@ Payload = 1 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_njxly") + [node name="BaseField3" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) @@ -1732,6 +1778,9 @@ Payload = 2 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField3/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_54ty3") + [node name="BaseField4" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(2559, 2624.22) scale = Vector2(1, 1.00622) @@ -1744,6 +1793,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField4/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_gbxtf") + [node name="BaseField5" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(3305, 2624.22) scale = Vector2(1, 1.00622) @@ -1756,6 +1808,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField5/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_6krrk") + [node name="BaseField6" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4033, 2618.18) scale = Vector2(1, 1.00622) @@ -1768,6 +1823,9 @@ FieldState = 3 _state = 1 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField6/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_4ktoi") + [node name="BaseField7" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4755, 2630.26) scale = Vector2(1, 1.00622) @@ -1780,6 +1838,9 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField7/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_aaup4") + [node name="BaseField8" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(4418, 3226.95) scale = Vector2(1, 1.00622) @@ -1792,18 +1853,25 @@ FieldState = 3 _state = 2 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField8/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_v10dc") + [node name="BaseField9" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")] position = Vector2(5317, 3208.83) scale = Vector2(1, 1.00622) Payload = 8 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="0"] +visible = false FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField9/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 1 _field = NodePath("../..") +[node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField9/FieldActivator/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_4pibb") + [node name="Blocker" type="Node2D" parent="YSorted"] [node name="BackToFarm" parent="YSorted/Blocker" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("31_xcb8u")] @@ -1847,6 +1915,18 @@ position = Vector2(14423, 5123) scale = Vector2(1.89667, 1) texture = ExtResource("23_s4721") +[node name="RakeGenericPickup" parent="YSorted" instance=ExtResource("43_dr6bm")] +position = Vector2(6401, 2602) + +[node name="SpawnWithItem" parent="YSorted/RakeGenericPickup" index="0"] +_blueprint = ExtResource("28_le48k") + +[node name="PickupInteractionArea" parent="YSorted/RakeGenericPickup" index="3"] +_id = 0 + +[node name="CollisionShape3D" parent="YSorted/RakeGenericPickup/PickupInteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_hpgl7") + [node name="CanvasLayer" parent="." instance=ExtResource("52_gwhnv")] [node name="Inventory" parent="CanvasLayer" index="1"] @@ -1925,13 +2005,24 @@ _payloadToSet = "beetRootScene" [editable path="YSorted/Vesna/GenericItemOnGround/PickupInteractionArea"] [editable path="YSorted/Brünnen/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField2"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField2/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField3"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField3/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField4"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField4/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField5"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField5/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField6"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField6/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField7"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField7/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField8"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField8/FieldActivator/InteractionArea"] [editable path="YSorted/Farm visuals/FieldParent/BaseField9"] +[editable path="YSorted/Farm visuals/FieldParent/BaseField9/FieldActivator/InteractionArea"] [editable path="YSorted/Blocker/BackToFarm"] +[editable path="YSorted/RakeGenericPickup"] +[editable path="YSorted/RakeGenericPickup/PickupInteractionArea"] [editable path="CanvasLayer"] diff --git a/scripts/CSharp/Common/Farming/FieldActivator.cs b/scripts/CSharp/Common/Farming/FieldActivator.cs new file mode 100644 index 0000000..a2e2ca5 --- /dev/null +++ b/scripts/CSharp/Common/Farming/FieldActivator.cs @@ -0,0 +1,27 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.Farming; + +public partial class FieldActivator : Node +{ + [Export] private Node2D _field; + + private bool _activated = false; + private bool _rakeInHand; + + public void ActivateField() + { + if (!_activated && _rakeInHand) + { + GD.Print("Tryina activate this field right here...."); + _field.Visible = true; + _activated = true; + } + } + + public void RakeActivated(bool activated) + { + _rakeInHand = activated; + } + +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldActivator.cs.uid b/scripts/CSharp/Common/Farming/FieldActivator.cs.uid new file mode 100644 index 0000000..d98ca61 --- /dev/null +++ b/scripts/CSharp/Common/Farming/FieldActivator.cs.uid @@ -0,0 +1 @@ +uid://dlbjjgbs0n4b0 -- 2.36.3 From 443741f5f1f77f42e3824f1cd72507092e9e14bb Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 12 Nov 2025 15:14:10 +0100 Subject: [PATCH 22/29] :bug: added preset fields to main outdoor scene and made them farmable --- prefabs/farm/base_field.tscn | 41 +++++++------ scenes/Babushka_scene_farm_outside_2d.tscn | 59 +++++++++++++++++- ..._scene_farm_outside_2d_ducksCollected.tscn | 1 - scenes/Babushka_scene_forest_fight_1_2d.tscn | 1 - scenes/Babushka_scene_outside_beets.tscn | 61 +++++++++++++++---- .../CharacterControls/InteractionArea2D.cs | 1 - .../CSharp/Common/Farming/FieldActivator.cs | 34 +++++++++-- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 8 +-- scripts/CSharp/Common/Farming/FieldService.cs | 1 - .../CSharp/Common/Farming/PlantBehaviour2D.cs | 1 - 10 files changed, 163 insertions(+), 45 deletions(-) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index 43016c8..cedce61 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -32,21 +32,29 @@ radius = 325.2599 script = ExtResource("1_4mg73") Payload = 0 +[node name="OutlineSprite" type="Sprite2D" parent="."] +self_modulate = Color(1, 1, 1, 0) +z_index = 1 +scale = Vector2(1.3499999, 1.5) +texture = ExtResource("9_wx561") + [node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex", "_wateringParticles")] +visible = false z_index = -1 scale = Vector2(0.9, 1) script = ExtResource("1_qa01x") _fieldSprite = NodePath("MaskedField/FieldTexture") _maskSprite = NodePath("MaskedField") -_outlineSprite = NodePath("OutlineSprite") +_outlineSprite = NodePath("../OutlineSprite") _maskOutlineTextures = Array[Texture2D]([ExtResource("9_wx561"), ExtResource("3_2eegd"), ExtResource("4_svbd7")]) _maskTexture = Array[Texture2D]([ExtResource("2_w8caw"), ExtResource("3_c014y"), ExtResource("4_teirr")]) Tilled = ExtResource("5_wx561") Watered = ExtResource("6_7m4xq") -PlantingInteraction = NodePath("../InteractionArea") +FieldState = 0 +PlantingInteraction = NodePath("InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") -FieldInteractionArea = NodePath("../InteractionArea") +FieldInteractionArea = NodePath("InteractionArea") _sceneKeyProvider = ExtResource("11_cjahb") _fieldIndex = NodePath("..") _wateringParticles = NodePath("../pouring water vfx") @@ -62,16 +70,11 @@ texture = ExtResource("5_wx561") [node name="PlantPlaceholder" type="Node2D" parent="FieldBehaviour"] -[node name="OutlineSprite" type="Sprite2D" parent="FieldBehaviour"] -self_modulate = Color(1, 1, 1, 0) -z_index = 1 -scale = Vector2(1.5, 1.5) -texture = ExtResource("9_wx561") - -[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")] -position = Vector2(-26, -57) +[node name="InteractionArea" parent="FieldBehaviour" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")] +position = Vector2(-28.88889, -57) +scale = Vector2(1.1111112, 1) _active = false -_spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")] +_spritesToOutline = [NodePath("../../OutlineSprite")] _showLabel = false [node name="PlantCreationEventRaiser" type="Node" parent="."] @@ -109,22 +112,26 @@ scale_amount_max = 0.8 color = Color(0.400601, 0.62444, 0.791217, 1) hue_variation_max = 0.4 -[node name="FieldActivator" type="Node2D" parent="." node_paths=PackedStringArray("_field")] +[node name="FieldActivator" type="Node2D" parent="." node_paths=PackedStringArray("_field", "_activatorArea")] script = ExtResource("22_57jmp") _field = NodePath("../FieldBehaviour") +_activatorArea = NodePath("InteractionArea") -[node name="InteractionArea" parent="FieldActivator" instance=ExtResource("7_2eegd")] -_useOutline = false +[node name="InteractionArea" parent="FieldActivator" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")] +_spritesToOutline = [NodePath("../../OutlineSprite")] [node name="CollisionShape3D" parent="FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_57jmp") +[node name="Marker2D" type="Marker2D" parent="."] +gizmo_extents = 157.0 + [connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"] -[connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"] +[connection signal="Interacted" from="FieldBehaviour/InteractionArea" to="FieldBehaviour" method="Farm"] [connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"] [connection signal="ItemInstanceActivated" from="InventoryListener rake" to="FieldActivator" method="RakeActivated"] -[connection signal="Interacted" from="FieldActivator/InteractionArea" to="FieldActivator/InteractionArea" method="ToggleActive"] [connection signal="Interacted" from="FieldActivator/InteractionArea" to="FieldActivator" method="ActivateField"] +[connection signal="Interacted" from="FieldActivator/InteractionArea" to="FieldActivator/InteractionArea" method="ToggleActive"] [editable path="FieldActivator/InteractionArea"] diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 16626c1..20f01ed 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=115 format=3 uid="uid://gigb28qk8t12"] +[gd_scene load_steps=116 format=3 uid="uid://gigb28qk8t12"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"] [ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"] @@ -77,6 +77,7 @@ [ext_resource type="Resource" uid="uid://byjqeukpibkvi" path="res://resources/quests/demo/7_talk_yeli_inside_1.tres" id="76_xcwle"] [ext_resource type="Script" uid="uid://dih1b0opgc3f7" path="res://scripts/GdScript/dialogic_start_specific.gd" id="77_l7ekk"] [ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="77_xcwle"] +[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field.tscn" id="78_xcwle"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wtdui"] shader = ExtResource("13_7p0hq") @@ -1116,6 +1117,61 @@ scale = Vector2(1, 1) [node name="FieldParent" type="Node2D" parent="YSorted"] position = Vector2(0, -200) +[node name="BaseField" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(8807, 3061) + +[node name="BaseField2" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(9335, 3562) +Payload = 1 + +[node name="BaseField3" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(9854, 3061) +Payload = 2 + +[node name="BaseField4" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(10499, 3536) +Payload = 3 + +[node name="BaseField5" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(11027, 3035) +Payload = 4 + +[node name="BaseField6" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(11394, 3617) +Payload = 5 + +[node name="BaseField7" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(11869, 3026) +Payload = 6 + +[node name="BaseField8" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(12353, 3554) +Payload = 7 + +[node name="BaseField9" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(12828, 2999) +Payload = 8 + +[node name="BaseField10" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(13285, 3536) +Payload = 9 + +[node name="BaseField11" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(13733, 2990) +Payload = 10 + +[node name="BaseField12" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(14261, 3474) +Payload = 11 + +[node name="BaseField13" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(14753, 2982) +Payload = 12 + +[node name="BaseField14" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +position = Vector2(15201, 3519) +Payload = 13 + [node name="Farm visuals" type="Node2D" parent="YSorted"] position = Vector2(-60, 122) @@ -2400,7 +2456,6 @@ _variableResource = ExtResource("77_xcwle") _payloadToSet = "farmOutside" [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] -[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Well/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] [connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] diff --git a/scenes/Babushka_scene_farm_outside_2d_ducksCollected.tscn b/scenes/Babushka_scene_farm_outside_2d_ducksCollected.tscn index 9cd1c59..bc363ac 100644 --- a/scenes/Babushka_scene_farm_outside_2d_ducksCollected.tscn +++ b/scenes/Babushka_scene_farm_outside_2d_ducksCollected.tscn @@ -2248,7 +2248,6 @@ playback_type = 2 script = ExtResource("59_0knno") [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] -[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] [connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] [connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"] diff --git a/scenes/Babushka_scene_forest_fight_1_2d.tscn b/scenes/Babushka_scene_forest_fight_1_2d.tscn index 860d079..5b218ae 100644 --- a/scenes/Babushka_scene_forest_fight_1_2d.tscn +++ b/scenes/Babushka_scene_forest_fight_1_2d.tscn @@ -2202,7 +2202,6 @@ makeActive = true [connection signal="FightStarted" from="Fight2/FightBaseScene" to="YSorted/Vesna" method="DisableMovement"] [connection signal="timelineEnded" from="YSorted/Chuga/Dialogic starter/DialogicToggle" to="YSorted/Chuga" method="set_position" binds= [Vector2(14579, 2951)]] [connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"] -[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"] [connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"] [connection signal="ready" from="SpecialQuestNodes/InstantStartQuest" to="SpecialQuestNodes/InstantStartQuest" method="Trigger"] diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 79d6c14..4d8cc2f 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -246,7 +246,7 @@ stream_0/stream = ExtResource("61_wy1mx") stream_1/stream = ExtResource("62_kmjnt") stream_2/stream = ExtResource("63_td2xu") -[node name="BabushkaSceneFarmOutside2d" type="Node2D"] +[node name="BabushkaSceneBeets" type="Node2D"] script = ExtResource("1_6krrk") _sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_farm_outside_2d.tscn") @@ -1750,10 +1750,16 @@ scale = Vector2(1, 0.993819) position = Vector2(651, 2630.26) scale = Vector2(1, 1.00622) +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField" index="1"] +visible = true + [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_qavgq") @@ -1762,10 +1768,16 @@ position = Vector2(1226, 3098.15) scale = Vector2(1, 1.00622) Payload = 1 +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="1"] +visible = true + [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_njxly") @@ -1774,10 +1786,16 @@ position = Vector2(1782, 2606.11) scale = Vector2(1, 1.00622) Payload = 2 +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="1"] +visible = true + [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField3/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField3/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_54ty3") @@ -1786,13 +1804,17 @@ position = Vector2(2559, 2624.22) scale = Vector2(1, 1.00622) Payload = 3 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="0"] +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="1"] +visible = true FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField4/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField4/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_gbxtf") @@ -1801,13 +1823,17 @@ position = Vector2(3305, 2624.22) scale = Vector2(1, 1.00622) Payload = 4 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="0"] +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="1"] +visible = true FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField5/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField5/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_6krrk") @@ -1816,13 +1842,17 @@ position = Vector2(4033, 2618.18) scale = Vector2(1, 1.00622) Payload = 5 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="0"] +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="1"] +visible = true FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField6/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 1 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField6/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_4ktoi") @@ -1831,13 +1861,17 @@ position = Vector2(4755, 2630.26) scale = Vector2(1, 1.00622) Payload = 6 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="0"] +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="1"] +visible = true FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField7/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField7/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_aaup4") @@ -1846,13 +1880,17 @@ position = Vector2(4418, 3226.95) scale = Vector2(1, 1.00622) Payload = 7 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="0"] +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="1"] +visible = true FieldState = 3 [node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField8/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] _state = 2 _field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="8"] +visible = false + [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField8/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_v10dc") @@ -1861,13 +1899,11 @@ position = Vector2(5317, 3208.83) scale = Vector2(1, 1.00622) Payload = 8 -[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="0"] -visible = false -FieldState = 3 +[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="1"] +visible = true -[node name="Beet2" parent="YSorted/Farm visuals/FieldParent/BaseField9/FieldBehaviour/PlantPlaceholder" index="0" node_paths=PackedStringArray("_field") instance=ExtResource("41_vyqmy")] -_state = 1 -_field = NodePath("../..") +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="8"] +visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField9/FieldActivator/InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_4pibb") @@ -1880,6 +1916,7 @@ _spritesToOutline = [NodePath("Fence Door2")] _id = 0 [node name="CollisionShape3D" parent="YSorted/Blocker/BackToFarm/Area2D" index="0"] +position = Vector2(-37, -208) shape = SubResource("CircleShape2D_dr6bm") [node name="Fence Door2" type="Sprite2D" parent="YSorted/Blocker/BackToFarm"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index dd0d07a..9a421cd 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -112,7 +112,6 @@ public partial class InteractionArea2D : Node2D public void SetSpriteActiveState(bool success, int id) // TODO: remove { - GD.PrintErr("SetSpriteActiveState is being called."); if (!_active) return; } diff --git a/scripts/CSharp/Common/Farming/FieldActivator.cs b/scripts/CSharp/Common/Farming/FieldActivator.cs index a2e2ca5..926098f 100644 --- a/scripts/CSharp/Common/Farming/FieldActivator.cs +++ b/scripts/CSharp/Common/Farming/FieldActivator.cs @@ -1,27 +1,51 @@ +using Babushka.scripts.CSharp.Common.CharacterControls; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; +/// +/// Enables a preset field in the scene sothat it can be used for farming. +/// public partial class FieldActivator : Node { - [Export] private Node2D _field; + [Export] private FieldBehaviour2D _field; + [Export] private InteractionArea2D _activatorArea; - private bool _activated = false; + private bool _used = false; private bool _rakeInHand; + public override void _Ready() + { + ToggleInteractionArea(); + } + + /// + /// Activates the fieldbehaviour node and sets it to the tilled state. + /// public void ActivateField() { - if (!_activated && _rakeInHand) + if (!_used && _rakeInHand) { - GD.Print("Tryina activate this field right here...."); _field.Visible = true; - _activated = true; + _field.UpdateFieldState(FieldState.Tilled); + _used = true; } } + /// + /// Reacts to changes in the inventory. + /// If setup correctly, the field activator interactable should only trigger when using the rake. + /// + /// public void RakeActivated(bool activated) { _rakeInHand = activated; + ToggleInteractionArea(); + } + + private void ToggleInteractionArea() + { + _activatorArea.IsActive = !_used && _rakeInHand; } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 809aee2..639d77d 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -43,7 +43,7 @@ public partial class FieldBehaviour2D : Sprite2D // fieldstate == tilled / watered && samen im Inventar _canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; // fieldstate == tilled && watering can ausgewählt - _canWater = FieldState == FieldState.Tilled && _wateringCanActive; + _canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive; FieldInteractionArea.IsActive = _canPlant || _canWater; } @@ -116,7 +116,7 @@ public partial class FieldBehaviour2D : Sprite2D /// public void Farm() { - if (_canPlant || TryPlant()) + if (_canPlant && TryPlant()) { EmitSignal(SignalName.Planted); UpdateFieldState(FieldState.Planted); @@ -133,7 +133,7 @@ public partial class FieldBehaviour2D : Sprite2D bool success = false; int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex; ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance; - + if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0) return success; @@ -155,7 +155,7 @@ public partial class FieldBehaviour2D : Sprite2D InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex); success = true; } - + return success; } diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 0e41dc8..5bc1aee 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -24,7 +24,6 @@ public partial class FieldService : Node //Create public bool TryAddEntry(string sceneName, int fieldIndex, FieldBehaviour2D field) { - GD.Print("Trying to add a field at: " + fieldIndex); if (_outerDict != null ) { FieldsInScene innerDict; diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 910a5f3..9a87166 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -67,7 +67,6 @@ public partial class PlantBehaviour2D : Node2D return; } - GD.Print("Growing plant."); switch (_state) { case PlantState.None: -- 2.36.3 From 5cc65bc3f45b361fa45aad47c3fd355f5974321b Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 12 Nov 2025 15:20:21 +0100 Subject: [PATCH 23/29] :wrench: filled up main outdoor scene with fields --- scenes/Babushka_scene_farm_outside_2d.tscn | 89 +++++++++++++++++----- 1 file changed, 71 insertions(+), 18 deletions(-) diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 20f01ed..321ddbe 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1117,61 +1117,114 @@ scale = Vector2(1, 1) [node name="FieldParent" type="Node2D" parent="YSorted"] position = Vector2(0, -200) -[node name="BaseField" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="right" type="Node2D" parent="YSorted/FieldParent"] + +[node name="BaseField" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(8807, 3061) -[node name="BaseField2" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField2" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(9335, 3562) Payload = 1 -[node name="BaseField3" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] -position = Vector2(9854, 3061) +[node name="BaseField3" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] +position = Vector2(9854, 3071) Payload = 2 -[node name="BaseField4" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] -position = Vector2(10499, 3536) +[node name="BaseField4" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] +position = Vector2(10361, 3536) Payload = 3 -[node name="BaseField5" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] -position = Vector2(11027, 3035) +[node name="BaseField5" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] +position = Vector2(10948, 3025) Payload = 4 -[node name="BaseField6" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] -position = Vector2(11394, 3617) +[node name="BaseField6" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] +position = Vector2(11296, 3607) Payload = 5 -[node name="BaseField7" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField7" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(11869, 3026) Payload = 6 -[node name="BaseField8" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField8" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(12353, 3554) Payload = 7 -[node name="BaseField9" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField9" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(12828, 2999) Payload = 8 -[node name="BaseField10" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField10" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(13285, 3536) Payload = 9 -[node name="BaseField11" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField11" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(13733, 2990) Payload = 10 -[node name="BaseField12" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField12" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(14261, 3474) Payload = 11 -[node name="BaseField13" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField13" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(14753, 2982) Payload = 12 -[node name="BaseField14" parent="YSorted/FieldParent" instance=ExtResource("78_xcwle")] +[node name="BaseField14" parent="YSorted/FieldParent/right" instance=ExtResource("78_xcwle")] position = Vector2(15201, 3519) Payload = 13 +[node name="left" type="Node2D" parent="YSorted/FieldParent"] +position = Vector2(-8661, -143) + +[node name="BaseField" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(8807, 3061) +Payload = 14 + +[node name="BaseField2" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(9227, 3562) +Payload = 15 + +[node name="BaseField3" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(9756, 3111) +Payload = 16 + +[node name="BaseField4" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(10322, 3536) +Payload = 17 + +[node name="BaseField5" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(10810, 3055) +Payload = 18 + +[node name="BaseField6" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(11266, 3607) +Payload = 19 + +[node name="BaseField7" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(11741, 3026) +Payload = 20 + +[node name="BaseField8" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(12255, 3593) +Payload = 21 + +[node name="BaseField9" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(12690, 3019) +Payload = 22 + +[node name="BaseField10" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(13216, 3556) +Payload = 23 + +[node name="BaseField11" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(13684, 3000) +Payload = 24 + +[node name="BaseField12" parent="YSorted/FieldParent/left" instance=ExtResource("78_xcwle")] +position = Vector2(14143, 3523) +Payload = 25 + [node name="Farm visuals" type="Node2D" parent="YSorted"] position = Vector2(-60, 122) -- 2.36.3 From 3fcb34c04deb540ec4c3e2774ab5b8dfd5799b6c Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 12 Nov 2025 18:46:30 +0100 Subject: [PATCH 24/29] :construction: saving of field parameters as json implemented --- .../.idea.Babushka/.idea/libraries/GdSdk.xml | 9 +++ .../.idea/libraries/GdSdk_Master.xml | 10 --- prefabs/farm/base_field.tscn | 11 +-- prefabs/farm/plants/beet_plant.tscn | 1 + prefabs/farm/plants/tomato_plant.tscn | 1 + project.godot | 1 + savegame/savegame.json | 37 +++++++++ scenes/Babushka_scene_outside_beets.tscn | 18 ++--- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 78 +++++++++++++++---- scripts/CSharp/Common/Farming/FieldService.cs | 5 +- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 9 ++- scripts/CSharp/Common/Savegame/SaveData.cs | 16 ++++ .../CSharp/Common/Savegame/SaveData.cs.uid | 1 + .../CSharp/Common/Savegame/SavegameService.cs | 34 ++++++++ .../Common/Savegame/SavegameService.cs.uid | 1 + scripts/CSharp/Common/SceneTransition.cs | 3 + .../CSharp/Low Code/Variables/VariableNode.cs | 3 + 17 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 .idea/.idea.Babushka/.idea/libraries/GdSdk.xml delete mode 100644 .idea/.idea.Babushka/.idea/libraries/GdSdk_Master.xml create mode 100644 savegame/savegame.json create mode 100644 scripts/CSharp/Common/Savegame/SaveData.cs create mode 100644 scripts/CSharp/Common/Savegame/SaveData.cs.uid create mode 100644 scripts/CSharp/Common/Savegame/SavegameService.cs create mode 100644 scripts/CSharp/Common/Savegame/SavegameService.cs.uid diff --git a/.idea/.idea.Babushka/.idea/libraries/GdSdk.xml b/.idea/.idea.Babushka/.idea/libraries/GdSdk.xml new file mode 100644 index 0000000..0059883 --- /dev/null +++ b/.idea/.idea.Babushka/.idea/libraries/GdSdk.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Babushka/.idea/libraries/GdSdk_Master.xml b/.idea/.idea.Babushka/.idea/libraries/GdSdk_Master.xml deleted file mode 100644 index 8b941bb..0000000 --- a/.idea/.idea.Babushka/.idea/libraries/GdSdk_Master.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index cedce61..f000cf4 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -38,11 +38,15 @@ z_index = 1 scale = Vector2(1.3499999, 1.5) texture = ExtResource("9_wx561") -[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex", "_wateringParticles")] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldIndex", "_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "FieldInteractionArea", "PlantingPlaceholder", "_wateringParticles")] visible = false z_index = -1 scale = Vector2(0.9, 1) script = ExtResource("1_qa01x") +SaveId = "field" +_fieldIndex = NodePath("..") +_sceneKeyProvider = ExtResource("11_cjahb") +FieldState = 0 _fieldSprite = NodePath("MaskedField/FieldTexture") _maskSprite = NodePath("MaskedField") _outlineSprite = NodePath("../OutlineSprite") @@ -50,13 +54,10 @@ _maskOutlineTextures = Array[Texture2D]([ExtResource("9_wx561"), ExtResource("3_ _maskTexture = Array[Texture2D]([ExtResource("2_w8caw"), ExtResource("3_c014y"), ExtResource("4_teirr")]) Tilled = ExtResource("5_wx561") Watered = ExtResource("6_7m4xq") -FieldState = 0 PlantingInteraction = NodePath("InteractionArea") +FieldInteractionArea = NodePath("InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") -FieldInteractionArea = NodePath("InteractionArea") -_sceneKeyProvider = ExtResource("11_cjahb") -_fieldIndex = NodePath("..") _wateringParticles = NodePath("../pouring water vfx") _wateringEvent = ExtResource("14_57jmp") diff --git a/prefabs/farm/plants/beet_plant.tscn b/prefabs/farm/plants/beet_plant.tscn index 8bdd8ed..035f1fb 100644 --- a/prefabs/farm/plants/beet_plant.tscn +++ b/prefabs/farm/plants/beet_plant.tscn @@ -13,6 +13,7 @@ resource_local_to_scene = true radius = 300.0 [node name="Beet" instance=ExtResource("1_2u3jr")] +_prefabPath = "res://prefabs/farm/plants/beet_plant.tscn" [node name="Seed1" parent="Seeds" index="0"] texture = ExtResource("2_agmuy") diff --git a/prefabs/farm/plants/tomato_plant.tscn b/prefabs/farm/plants/tomato_plant.tscn index 5df96ea..190d616 100644 --- a/prefabs/farm/plants/tomato_plant.tscn +++ b/prefabs/farm/plants/tomato_plant.tscn @@ -12,6 +12,7 @@ resource_local_to_scene = true radius = 300.0 [node name="TomatoPlant" instance=ExtResource("1_ooshk")] +_prefabPath = "res://prefabs/farm/plants/tomato_plant.tscn" [node name="Seed1" parent="Seeds" index="0"] texture = ExtResource("2_gdicx") diff --git a/project.godot b/project.godot index 58a2bec..455bb40 100644 --- a/project.godot +++ b/project.godot @@ -214,6 +214,7 @@ folder_colors={ "res://logos/": "blue", "res://prefabs/": "purple", "res://resources/": "purple", +"res://savegame/": "purple", "res://scenes/": "purple", "res://scripts/": "pink", "res://shader/": "pink" diff --git a/savegame/savegame.json b/savegame/savegame.json new file mode 100644 index 0000000..f1cf059 --- /dev/null +++ b/savegame/savegame.json @@ -0,0 +1,37 @@ +{ + "beetRootScene_field0": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field1": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field2": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field3": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field4": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field5": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 2,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field6": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field7": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", + "beetRootScene_field8": "{\n\t\"field_state\": 0\n}", + "farmOutside_field0": "{\n\t\"field_state\": 0\n}", + "farmOutside_field1": "{\n\t\"field_state\": 0\n}", + "farmOutside_field10": "{\n\t\"field_state\": 0\n}", + "farmOutside_field11": "{\n\t\"field_state\": 0\n}", + "farmOutside_field12": "{\n\t\"field_state\": 0\n}", + "farmOutside_field13": "{\n\t\"field_state\": 0\n}", + "farmOutside_field14": "{\n\t\"field_state\": 0\n}", + "farmOutside_field15": "{\n\t\"field_state\": 0\n}", + "farmOutside_field16": "{\n\t\"field_state\": 0\n}", + "farmOutside_field17": "{\n\t\"field_state\": 0\n}", + "farmOutside_field18": "{\n\t\"field_state\": 0\n}", + "farmOutside_field19": "{\n\t\"field_state\": 0\n}", + "farmOutside_field2": "{\n\t\"field_state\": 0\n}", + "farmOutside_field20": "{\n\t\"field_state\": 0\n}", + "farmOutside_field21": "{\n\t\"field_state\": 0\n}", + "farmOutside_field22": "{\n\t\"field_state\": 0\n}", + "farmOutside_field23": "{\n\t\"field_state\": 0\n}", + "farmOutside_field24": "{\n\t\"field_state\": 0\n}", + "farmOutside_field25": "{\n\t\"field_state\": 0\n}", + "farmOutside_field3": "{\n\t\"field_state\": 0\n}", + "farmOutside_field4": "{\n\t\"field_state\": 0\n}", + "farmOutside_field5": "{\n\t\"field_state\": 0\n}", + "farmOutside_field6": "{\n\t\"field_state\": 0\n}", + "farmOutside_field7": "{\n\t\"field_state\": 0\n}", + "farmOutside_field8": "{\n\t\"field_state\": 0\n}", + "farmOutside_field9": "{\n\t\"field_state\": 0\n}" +} \ No newline at end of file diff --git a/scenes/Babushka_scene_outside_beets.tscn b/scenes/Babushka_scene_outside_beets.tscn index 4d8cc2f..a259778 100644 --- a/scenes/Babushka_scene_outside_beets.tscn +++ b/scenes/Babushka_scene_outside_beets.tscn @@ -1757,7 +1757,7 @@ visible = true _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1775,7 +1775,7 @@ visible = true _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField2/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1793,7 +1793,7 @@ visible = true _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField3/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1812,7 +1812,7 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField4/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1831,7 +1831,7 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField5/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1850,7 +1850,7 @@ FieldState = 3 _state = 1 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField6/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1869,7 +1869,7 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField7/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1888,7 +1888,7 @@ FieldState = 3 _state = 2 _field = NodePath("../..") -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField8/FieldActivator/InteractionArea/Area2D" index="0"] @@ -1902,7 +1902,7 @@ Payload = 8 [node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="1"] visible = true -[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="8"] +[node name="FieldActivator" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="7"] visible = false [node name="CollisionShape3D" parent="YSorted/Farm visuals/FieldParent/BaseField9/FieldActivator/InteractionArea/Area2D" index="0"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 639d77d..6b8b68f 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,15 +1,27 @@ using System; using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; +using Babushka.scripts.CSharp.Common.Savegame; using Babushka.scripts.CSharp.Low_Code.Events; using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; +using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Farming; +/// +/// Defines the behaviour of the field, i.e. interactions, states and effects. +/// [GlobalClass] public partial class FieldBehaviour2D : Sprite2D { + [ExportGroup("Persistence")] + [Export] public string SaveId = ""; + [Export] private VariableNode _fieldIndex; + [Export] public VariableResource _sceneKeyProvider; + [Export] public FieldState FieldState = FieldState.Tilled; + + [ExportGroup("Field Visuals")] [Export] private Sprite2D _fieldSprite; [Export] private Sprite2D _maskSprite; [Export] private Sprite2D _outlineSprite; @@ -17,25 +29,25 @@ public partial class FieldBehaviour2D : Sprite2D [Export] private Texture2D[] _maskTexture; [Export] private Texture2D Tilled; [Export] private Texture2D Watered; - [Export] public FieldState FieldState = FieldState.Tilled; + + [ExportGroup("Field Interactions")] [Export] public InteractionArea2D PlantingInteraction; + [Export] public InteractionArea2D FieldInteractionArea; + + [ExportGroup("Configuration")] [Export] public Node2D PlantingPlaceholder; [Export] public ItemRepository ItemRepository; - [Export] public InteractionArea2D FieldInteractionArea; - [Export] public VariableResource _sceneKeyProvider; - [Export] private VariableNode _fieldIndex; [Export] private CpuParticles2D _wateringParticles; [Export] private EventResource _wateringEvent; - - public Vector2 FieldPosition; - private bool _seedsActive; private bool _wateringCanActive; private bool _canPlant; private bool _canWater; + private PlantBehaviour2D? _currentPlant; + [Signal] public delegate void PlantedEventHandler(); private void UpdateInteractionArea() @@ -58,11 +70,16 @@ public partial class FieldBehaviour2D : Sprite2D _wateringCanActive = activated; UpdateInteractionArea(); } - + public override void _Ready() { + + if(PlantingPlaceholder.GetChildCount() > 0) + _currentPlant = PlantingPlaceholder.GetChild(0); UpdateFieldState(FieldState); + FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(),_fieldIndex.Payload.AsInt32(), this); + int randomIndex = new Random().Next(0, _maskTexture.Length); _maskSprite.Texture = _maskTexture[randomIndex]; _outlineSprite.Texture = _maskOutlineTextures[randomIndex]; @@ -97,6 +114,7 @@ public partial class FieldBehaviour2D : Sprite2D break; } UpdateInteractionArea(); + UpdateSaveData(); } @@ -137,19 +155,19 @@ public partial class FieldBehaviour2D : Sprite2D if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0) return success; - string prefabPath = ItemRepository.TryGetPrefabPath(item.blueprint); + string plantPrefabPath = ItemRepository.TryGetPrefabPath(item.blueprint); - if (prefabPath != null) + if (!string.IsNullOrEmpty(plantPrefabPath)) { - PackedScene prefab = ResourceLoader.Load(prefabPath, nameof(PackedScene)); + PackedScene prefab = ResourceLoader.Load(plantPrefabPath, nameof(PackedScene)); Node2D plant2d = prefab.Instantiate(); PlantingPlaceholder.AddChild(plant2d); plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition; - PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D; + _currentPlant = plant2d as PlantBehaviour2D; - if (plantBehaviour != null) + if (_currentPlant != null) { - plantBehaviour.Field = this; + _currentPlant.Field = this; } InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex); @@ -158,6 +176,34 @@ public partial class FieldBehaviour2D : Sprite2D return success; } - -} \ No newline at end of file + + public void UpdateSaveData() + { + var saveData = new SaveData(); + + saveData.SceneName = _sceneKeyProvider.Payload.AsString(); + saveData.Id = SaveId + _fieldIndex.Payload.AsString(); + var payloadData = new Dictionary + { + { "field_state", (int)FieldState } + }; + + if (_currentPlant != null) + { + payloadData.Add( + "plant_data", new Dictionary() + { + { "prefab_path", _currentPlant.PrefabPath }, + { "plant_state", (int)_currentPlant.State }, + { "plant_days_growing", _currentPlant.DaysGrowing } + } + ); + } + + saveData.JsonPayload = Json.Stringify(payloadData, indent: "\t"); + + SavegameService.AppendSave(saveData); + } + +} diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 5bc1aee..3a6a395 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Babushka.scripts.CSharp.Common.Services; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; @@ -40,10 +41,6 @@ public partial class FieldService : Node innerDict.fields.Add(fieldIndex, field); return true; } - else - { - GD.PrintErr("Duplicate field at: " + fieldIndex); - } } return false; } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 9a87166..ab8e6cf 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -9,6 +9,7 @@ namespace Babushka.scripts.CSharp.Common.Farming; /// public partial class PlantBehaviour2D : Node2D { + [Export] private string _prefabPath; [Export] private Sprite2D[] _seeds; [Export] private Sprite2D[] _smallPlants; [Export] private Sprite2D[] _bigPlants; @@ -24,6 +25,12 @@ public partial class PlantBehaviour2D : Node2D private bool _magicWordSaid = false; private bool _calledOnReady = false; + public PlantState State => _state; + + public int DaysGrowing { get; set; } + + public string PrefabPath => _prefabPath; + /// /// public accessor for the field reference /// @@ -35,7 +42,6 @@ public partial class PlantBehaviour2D : Node2D public override void _Ready() { - GD.Print($"Ready: {Name}"); if (_state == PlantState.None) { _state = PlantState.Planted; @@ -44,7 +50,6 @@ public partial class PlantBehaviour2D : Node2D } else { - GD.Print("plant state not none."); _calledOnReady = true; GrowPlant(); } diff --git a/scripts/CSharp/Common/Savegame/SaveData.cs b/scripts/CSharp/Common/Savegame/SaveData.cs new file mode 100644 index 0000000..4e00e30 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SaveData.cs @@ -0,0 +1,16 @@ +using System; + +namespace Babushka.scripts.CSharp.Common.Savegame; + +[Serializable] +public class SaveData +{ + public string SceneName; + public string Id; + public string JsonPayload; + + public string ToString() + { + return SceneName + " " + Id + " " + JsonPayload; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Savegame/SaveData.cs.uid b/scripts/CSharp/Common/Savegame/SaveData.cs.uid new file mode 100644 index 0000000..e46f0d7 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SaveData.cs.uid @@ -0,0 +1 @@ +uid://bkftl5mj33eah diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs new file mode 100644 index 0000000..4a8c234 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -0,0 +1,34 @@ +using Godot; +using Godot.Collections; +using FileAccess = Godot.FileAccess; + +namespace Babushka.scripts.CSharp.Common.Savegame; + +public static class SavegameService +{ + public static readonly string SavePath = "res://savegame/savegame.json"; + + public static Dictionary SaveDatas = new (); + + public static void AppendSave(SaveData saveData) + { + string key = string.Concat(saveData.SceneName, "_", saveData.Id); + + if (SaveDatas.TryGetValue(key, out var value)) + { + SaveDatas[key] = saveData.JsonPayload; + } + else + { + SaveDatas.Add(key, saveData.JsonPayload); + } + } + + public static void Save() + { + string json = Json.Stringify(SaveDatas, indent: "\t"); + using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write); + file.StoreString(json); + GD.Print($"Game saved to {file}"); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs.uid b/scripts/CSharp/Common/Savegame/SavegameService.cs.uid new file mode 100644 index 0000000..e793998 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs.uid @@ -0,0 +1 @@ +uid://rm23q50boqe5 diff --git a/scripts/CSharp/Common/SceneTransition.cs b/scripts/CSharp/Common/SceneTransition.cs index e6c5426..d36a488 100644 --- a/scripts/CSharp/Common/SceneTransition.cs +++ b/scripts/CSharp/Common/SceneTransition.cs @@ -1,4 +1,6 @@ +using Babushka.scripts.CSharp.Common.Savegame; using Babushka.scripts.CSharp.Common.SceneManagement; +using Babushka.scripts.CSharp.Common.Services; using Godot; namespace Babushka.scripts.CSharp.Common; @@ -16,6 +18,7 @@ public partial class SceneTransition : Node public void LoadSceneAtIndex(int index) { + SavegameService.Save(); string sceneName = _sceneNamesToLoad[index]; SceneTransitionThreaded.Instance.ChangeSceneToFileThreaded(sceneName); UnloadAfterDelay(); diff --git a/scripts/CSharp/Low Code/Variables/VariableNode.cs b/scripts/CSharp/Low Code/Variables/VariableNode.cs index e165e9b..a979ee0 100644 --- a/scripts/CSharp/Low Code/Variables/VariableNode.cs +++ b/scripts/CSharp/Low Code/Variables/VariableNode.cs @@ -2,6 +2,9 @@ using Godot; namespace Babushka.scripts.CSharp.Low_Code.Variables; +/// +/// A Node type that carries a Variant payload. +/// public partial class VariableNode : Node { [Export] public Variant Payload { get; set; } -- 2.36.3 From 6613e5465815bf040ac48091f6736445b3d578b9 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sat, 15 Nov 2025 22:15:02 +0100 Subject: [PATCH 25/29] :sparkles: Implemented Loading function on fields and plants --- project.godot | 1 + savegame/savegame.json | 10 +-- scenes/Babushka_scene_farm_outside_2d.tscn | 2 +- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 79 ++++++++++++++++--- scripts/CSharp/Common/Farming/FieldService.cs | 1 - .../CSharp/Common/Farming/PlantBehaviour2D.cs | 6 +- scripts/CSharp/Common/Savegame/SaveData.cs | 2 +- .../CSharp/Common/Savegame/SaveGameManager.cs | 19 +++++ .../Common/Savegame/SaveGameManager.cs.uid | 1 + .../CSharp/Common/Savegame/SavegameService.cs | 45 ++++++++++- scripts/CSharp/Common/SceneTransition.cs | 1 - 11 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 scripts/CSharp/Common/Savegame/SaveGameManager.cs create mode 100644 scripts/CSharp/Common/Savegame/SaveGameManager.cs.uid diff --git a/project.godot b/project.godot index 455bb40..df595f1 100644 --- a/project.godot +++ b/project.godot @@ -33,6 +33,7 @@ QuestManager="*res://prefabs/quests/quest_manager_autoload.tscn" Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd" FightWorldAutoload="*res://prefabs/fight/fight_world_autoload.tscn" FieldService="*res://scripts/CSharp/Common/Farming/FieldService.cs" +SaveGameManager="*res://scripts/CSharp/Common/Savegame/SaveGameManager.cs" [dialogic] diff --git a/savegame/savegame.json b/savegame/savegame.json index f1cf059..f6cf423 100644 --- a/savegame/savegame.json +++ b/savegame/savegame.json @@ -8,8 +8,8 @@ "beetRootScene_field6": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", "beetRootScene_field7": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", "beetRootScene_field8": "{\n\t\"field_state\": 0\n}", - "farmOutside_field0": "{\n\t\"field_state\": 0\n}", - "farmOutside_field1": "{\n\t\"field_state\": 0\n}", + "farmOutside_field0": "{\n\t\"field_state\": 3\n}", + "farmOutside_field1": "{\n\t\"field_state\": 3\n}", "farmOutside_field10": "{\n\t\"field_state\": 0\n}", "farmOutside_field11": "{\n\t\"field_state\": 0\n}", "farmOutside_field12": "{\n\t\"field_state\": 0\n}", @@ -20,15 +20,15 @@ "farmOutside_field17": "{\n\t\"field_state\": 0\n}", "farmOutside_field18": "{\n\t\"field_state\": 0\n}", "farmOutside_field19": "{\n\t\"field_state\": 0\n}", - "farmOutside_field2": "{\n\t\"field_state\": 0\n}", + "farmOutside_field2": "{\n\t\"field_state\": 3,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 1,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", "farmOutside_field20": "{\n\t\"field_state\": 0\n}", "farmOutside_field21": "{\n\t\"field_state\": 0\n}", "farmOutside_field22": "{\n\t\"field_state\": 0\n}", "farmOutside_field23": "{\n\t\"field_state\": 0\n}", "farmOutside_field24": "{\n\t\"field_state\": 0\n}", "farmOutside_field25": "{\n\t\"field_state\": 0\n}", - "farmOutside_field3": "{\n\t\"field_state\": 0\n}", - "farmOutside_field4": "{\n\t\"field_state\": 0\n}", + "farmOutside_field3": "{\n\t\"field_state\": 2,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 1,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/tomato_plant.tscn\"\n\t}\n}", + "farmOutside_field4": "{\n\t\"field_state\": 1\n}", "farmOutside_field5": "{\n\t\"field_state\": 0\n}", "farmOutside_field6": "{\n\t\"field_state\": 0\n}", "farmOutside_field7": "{\n\t\"field_state\": 0\n}", diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 321ddbe..82183f1 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1956,7 +1956,7 @@ region_rect = Rect2(332, 194, 179, 154) [node name="grass3" type="Sprite2D" parent="YSorted/Farm visuals/Static/greenery/grass"] modulate = Color(0.954868, 0.882599, 0.798501, 1) z_index = -5 -position = Vector2(18189, 1960) +position = Vector2(18165, 1966) scale = Vector2(5.77602, 3.87779) texture = ExtResource("42_loeum") region_enabled = true diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 6b8b68f..31157cb 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -73,7 +73,7 @@ public partial class FieldBehaviour2D : Sprite2D public override void _Ready() { - + LoadFromSaveData(); if(PlantingPlaceholder.GetChildCount() > 0) _currentPlant = PlantingPlaceholder.GetChild(0); UpdateFieldState(FieldState); @@ -159,17 +159,7 @@ public partial class FieldBehaviour2D : Sprite2D if (!string.IsNullOrEmpty(plantPrefabPath)) { - PackedScene prefab = ResourceLoader.Load(plantPrefabPath, nameof(PackedScene)); - Node2D plant2d = prefab.Instantiate(); - PlantingPlaceholder.AddChild(plant2d); - plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition; - _currentPlant = plant2d as PlantBehaviour2D; - - if (_currentPlant != null) - { - _currentPlant.Field = this; - } - + PlantPrefab(plantPrefabPath); InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex); success = true; } @@ -177,6 +167,21 @@ public partial class FieldBehaviour2D : Sprite2D return success; } + private void PlantPrefab(string prefabPath) + { + PackedScene prefab = ResourceLoader.Load(prefabPath, nameof(PackedScene)); + Node2D plant2d = prefab.Instantiate(); + PlantingPlaceholder.AddChild(plant2d); + plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition; + _currentPlant = plant2d as PlantBehaviour2D; + + if (_currentPlant != null) + { + _currentPlant.Field = this; + } + + } + public void UpdateSaveData() { @@ -206,4 +211,54 @@ public partial class FieldBehaviour2D : Sprite2D SavegameService.AppendSave(saveData); } + public void LoadFromSaveData() + { + var sceneName = _sceneKeyProvider.Payload.AsString(); + var id = SaveId + _fieldIndex.Payload.AsString(); + string jsonPayload = SavegameService.GetSaveData(sceneName, id); + Dictionary save = Json.ParseString(jsonPayload).AsGodotDictionary(); + + if (save.Count > 0) + { + if (save.TryGetValue("field_state", out Variant fieldStateVar)) + { + int fieldStateInt = fieldStateVar.AsInt32(); + FieldState = (FieldState) fieldStateInt; + + if (fieldStateInt != 0) + { + Visible = true; + UpdateFieldState(FieldState); + } + } + + if (save.TryGetValue("plant_data", out Variant plantDataVar)) + { + Dictionary plantDataDict = plantDataVar.AsGodotDictionary(); + + if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar)) + { + PlantPrefab(prefabPathVar.AsString()); + } + else + { + return; + } + + if (plantDataDict.TryGetValue("plant_state", out Variant plantStateVar) && _currentPlant != null) + { + _currentPlant.State = (PlantState) plantStateVar.AsInt32(); + _currentPlant.GrowPlant(); + } + + if (plantDataDict.TryGetValue("plant_days_growing", out Variant plantDaysGrowingVar) && _currentPlant != null) + { + _currentPlant.DaysGrowing = plantDaysGrowingVar.AsInt32(); + } + + } + } + + } + } diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index 3a6a395..a280d34 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Babushka.scripts.CSharp.Common.Services; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index ab8e6cf..82cdeaf 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -25,7 +25,11 @@ public partial class PlantBehaviour2D : Node2D private bool _magicWordSaid = false; private bool _calledOnReady = false; - public PlantState State => _state; + public PlantState State + { + get => _state; + set => _state = value; + } public int DaysGrowing { get; set; } diff --git a/scripts/CSharp/Common/Savegame/SaveData.cs b/scripts/CSharp/Common/Savegame/SaveData.cs index 4e00e30..f7970f2 100644 --- a/scripts/CSharp/Common/Savegame/SaveData.cs +++ b/scripts/CSharp/Common/Savegame/SaveData.cs @@ -5,7 +5,7 @@ namespace Babushka.scripts.CSharp.Common.Savegame; [Serializable] public class SaveData { - public string SceneName; + public string SceneName; public string Id; public string JsonPayload; diff --git a/scripts/CSharp/Common/Savegame/SaveGameManager.cs b/scripts/CSharp/Common/Savegame/SaveGameManager.cs new file mode 100644 index 0000000..9d53244 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SaveGameManager.cs @@ -0,0 +1,19 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.Savegame; + +/// +/// This class manages the loading of the savegame throughout the gameplay flow. +/// +public partial class SaveGameManager : Node +{ + public static SaveGameManager? Instance { get; private set; } = null!; + + public override void _EnterTree() + { + Instance = this; + + SavegameService.Load(); + } + +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Savegame/SaveGameManager.cs.uid b/scripts/CSharp/Common/Savegame/SaveGameManager.cs.uid new file mode 100644 index 0000000..8c4c6e5 --- /dev/null +++ b/scripts/CSharp/Common/Savegame/SaveGameManager.cs.uid @@ -0,0 +1 @@ +uid://c1srnefvhigef diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs index 4a8c234..9e12b18 100644 --- a/scripts/CSharp/Common/Savegame/SavegameService.cs +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -1,3 +1,4 @@ +using System; using Godot; using Godot.Collections; using FileAccess = Godot.FileAccess; @@ -8,7 +9,10 @@ public static class SavegameService { public static readonly string SavePath = "res://savegame/savegame.json"; - public static Dictionary SaveDatas = new (); + public static Dictionary SaveDatas = new (); + + public static bool _loaded = false; + public static void AppendSave(SaveData saveData) { @@ -23,12 +27,49 @@ public static class SavegameService SaveDatas.Add(key, saveData.JsonPayload); } } + + + public static string GetSaveData(string sceneName, string id) + { + string saveData = ""; + + string key = string.Concat(sceneName, "_", id); + + if (!_loaded) + { + GD.Print("SavegameService: SaveFile not loaded."); + return saveData; + } + + if (SaveDatas.ContainsKey(key)) + { + saveData = SaveDatas[key]; + } + + return saveData; + } + public static void Save() { string json = Json.Stringify(SaveDatas, indent: "\t"); using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write); file.StoreString(json); - GD.Print($"Game saved to {file}"); + } + + public static void Load() + { + try + { + string saveDataJson = FileAccess.GetFileAsString(SavePath); + SaveDatas = Json.ParseString(saveDataJson).AsGodotDictionary(); + } + catch(Exception e) + { + GD.PrintRich(e.Message); + return; + } + + _loaded = true; } } \ No newline at end of file diff --git a/scripts/CSharp/Common/SceneTransition.cs b/scripts/CSharp/Common/SceneTransition.cs index d36a488..7709acb 100644 --- a/scripts/CSharp/Common/SceneTransition.cs +++ b/scripts/CSharp/Common/SceneTransition.cs @@ -1,6 +1,5 @@ using Babushka.scripts.CSharp.Common.Savegame; using Babushka.scripts.CSharp.Common.SceneManagement; -using Babushka.scripts.CSharp.Common.Services; using Godot; namespace Babushka.scripts.CSharp.Common; -- 2.36.3 From c9f97c25713d60a479028fb2964bdaa3253aa3e0 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sat, 15 Nov 2025 22:27:26 +0100 Subject: [PATCH 26/29] :memo: added documentation comments --- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 8 +++---- scripts/CSharp/Common/Savegame/SaveData.cs | 4 ++++ .../CSharp/Common/Savegame/SavegameService.cs | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 31157cb..80a1254 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -179,9 +179,9 @@ public partial class FieldBehaviour2D : Sprite2D { _currentPlant.Field = this; } - } - + + #region SAVE AND LOAD public void UpdateSaveData() { @@ -258,7 +258,7 @@ public partial class FieldBehaviour2D : Sprite2D } } - } - +#endregion + } diff --git a/scripts/CSharp/Common/Savegame/SaveData.cs b/scripts/CSharp/Common/Savegame/SaveData.cs index f7970f2..1a7e3a8 100644 --- a/scripts/CSharp/Common/Savegame/SaveData.cs +++ b/scripts/CSharp/Common/Savegame/SaveData.cs @@ -2,6 +2,10 @@ using System; namespace Babushka.scripts.CSharp.Common.Savegame; +/// +/// Central structure for SaveData entries. +/// SceneName and ID are later combined and used as keys for the save system. +/// [Serializable] public class SaveData { diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs index 9e12b18..c3c8b9f 100644 --- a/scripts/CSharp/Common/Savegame/SavegameService.cs +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -5,6 +5,11 @@ using FileAccess = Godot.FileAccess; namespace Babushka.scripts.CSharp.Common.Savegame; +/// +/// Handles the saving and loading of game states. +/// Holds the central SaveData object that serves as a temporary SaveFile. +/// Automatically writes to disk on every scene change. +/// public static class SavegameService { public static readonly string SavePath = "res://savegame/savegame.json"; @@ -14,6 +19,10 @@ public static class SavegameService public static bool _loaded = false; + /// + /// Adds or overwrites an entry in the SaveData dictionary. + /// + /// public static void AppendSave(SaveData saveData) { string key = string.Concat(saveData.SceneName, "_", saveData.Id); @@ -29,6 +38,13 @@ public static class SavegameService } + /// + /// Checks the SaveData dictionary for an entry and returns the jsondata as a string for it. + /// Requires the scenename and object ID for lookup. + /// + /// + /// + /// public static string GetSaveData(string sceneName, string id) { string saveData = ""; @@ -50,6 +66,9 @@ public static class SavegameService } + /// + /// Writes the contents of the current SaveData dictionary to disk as a json file. + /// public static void Save() { string json = Json.Stringify(SaveDatas, indent: "\t"); @@ -57,6 +76,9 @@ public static class SavegameService file.StoreString(json); } + /// + /// Loads the current savegame file from disk and parses it into the SaveData dictionary. + /// public static void Load() { try -- 2.36.3 From c5f8b157ad6f30da12cecdee0209cd9a67013105 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 18 Nov 2025 15:55:31 +0100 Subject: [PATCH 27/29] :bug: changed savegame location to user-space instead of project-space --- project.godot | 1 - savegame/savegame.json | 37 ------------------- scenes/Babushka_scene_startMenu.tscn | 2 +- .../CSharp/Common/Savegame/SavegameService.cs | 2 +- 4 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 savegame/savegame.json diff --git a/project.godot b/project.godot index df595f1..acc1824 100644 --- a/project.godot +++ b/project.godot @@ -215,7 +215,6 @@ folder_colors={ "res://logos/": "blue", "res://prefabs/": "purple", "res://resources/": "purple", -"res://savegame/": "purple", "res://scenes/": "purple", "res://scripts/": "pink", "res://shader/": "pink" diff --git a/savegame/savegame.json b/savegame/savegame.json deleted file mode 100644 index f6cf423..0000000 --- a/savegame/savegame.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "beetRootScene_field0": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field1": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field2": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field3": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field4": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field5": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 2,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field6": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field7": "{\n\t\"field_state\": 1,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 3,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "beetRootScene_field8": "{\n\t\"field_state\": 0\n}", - "farmOutside_field0": "{\n\t\"field_state\": 3\n}", - "farmOutside_field1": "{\n\t\"field_state\": 3\n}", - "farmOutside_field10": "{\n\t\"field_state\": 0\n}", - "farmOutside_field11": "{\n\t\"field_state\": 0\n}", - "farmOutside_field12": "{\n\t\"field_state\": 0\n}", - "farmOutside_field13": "{\n\t\"field_state\": 0\n}", - "farmOutside_field14": "{\n\t\"field_state\": 0\n}", - "farmOutside_field15": "{\n\t\"field_state\": 0\n}", - "farmOutside_field16": "{\n\t\"field_state\": 0\n}", - "farmOutside_field17": "{\n\t\"field_state\": 0\n}", - "farmOutside_field18": "{\n\t\"field_state\": 0\n}", - "farmOutside_field19": "{\n\t\"field_state\": 0\n}", - "farmOutside_field2": "{\n\t\"field_state\": 3,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 1,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/beet_plant.tscn\"\n\t}\n}", - "farmOutside_field20": "{\n\t\"field_state\": 0\n}", - "farmOutside_field21": "{\n\t\"field_state\": 0\n}", - "farmOutside_field22": "{\n\t\"field_state\": 0\n}", - "farmOutside_field23": "{\n\t\"field_state\": 0\n}", - "farmOutside_field24": "{\n\t\"field_state\": 0\n}", - "farmOutside_field25": "{\n\t\"field_state\": 0\n}", - "farmOutside_field3": "{\n\t\"field_state\": 2,\n\t\"plant_data\": {\n\t\t\"plant_days_growing\": 0,\n\t\t\"plant_state\": 1,\n\t\t\"prefab_path\": \"res://prefabs/farm/plants/tomato_plant.tscn\"\n\t}\n}", - "farmOutside_field4": "{\n\t\"field_state\": 1\n}", - "farmOutside_field5": "{\n\t\"field_state\": 0\n}", - "farmOutside_field6": "{\n\t\"field_state\": 0\n}", - "farmOutside_field7": "{\n\t\"field_state\": 0\n}", - "farmOutside_field8": "{\n\t\"field_state\": 0\n}", - "farmOutside_field9": "{\n\t\"field_state\": 0\n}" -} \ No newline at end of file diff --git a/scenes/Babushka_scene_startMenu.tscn b/scenes/Babushka_scene_startMenu.tscn index f4ea948..262a257 100644 --- a/scenes/Babushka_scene_startMenu.tscn +++ b/scenes/Babushka_scene_startMenu.tscn @@ -6,7 +6,7 @@ [node name="BabushkaSceneStartMenu" type="Node2D"] script = ExtResource("1_fj2fh") -_sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_disclaimer.tscn") +_sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_farm_outside_2d.tscn") [node name="CanvasLayer" type="CanvasLayer" parent="."] diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs index c3c8b9f..d3a3fef 100644 --- a/scripts/CSharp/Common/Savegame/SavegameService.cs +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -12,7 +12,7 @@ namespace Babushka.scripts.CSharp.Common.Savegame; /// public static class SavegameService { - public static readonly string SavePath = "res://savegame/savegame.json"; + public static readonly string SavePath = "user://babushka_savegame.json"; public static Dictionary SaveDatas = new (); -- 2.36.3 From 02cbc761bcbfec93558ae5173f9547967ea85f1e Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 18 Nov 2025 16:41:55 +0100 Subject: [PATCH 28/29] reverted changed start scene in project godot --- project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.godot b/project.godot index acc1824..759b354 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Babushka" -run/main_scene="uid://c6wnoif01ltld" +run/main_scene="uid://bopv10dqm1knc" config/features=PackedStringArray("4.5", "C#", "Forward Plus") run/max_fps=120 boot_splash/fullsize=false -- 2.36.3 From d17e58bcd38a8486eaa6ad0673f16a7c169a12b4 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 18 Nov 2025 17:17:42 +0100 Subject: [PATCH 29/29] :bug: removed stub code and unused signal from FarmingControls2D --- .../Common/Farming/FarmingControls2D.cs | 23 +------------------ .../CSharp/Common/Farming/FieldActivator.cs | 3 +++ scripts/CSharp/Common/Farming/FieldService.cs | 6 ----- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 0031f5b..10014e5 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -19,7 +19,6 @@ public partial class FarmingControls2D : Node2D private int _toolId = -1; private bool _wateringCanFilled = false; - [Signal] public delegate void FieldCreatedEventHandler(); #region Tools @@ -50,18 +49,7 @@ public partial class FarmingControls2D : Node2D } #endregion - - public override void _Input(InputEvent @event) - { - if (@event.IsActionPressed("click")) - { - if ( _toolId == 0) - { - Vector2I adjustedPosition = GetAdjustedMousePosition(); - MakeField(adjustedPosition); - } - } - } + private Vector2I GetAdjustedMousePosition() { @@ -87,13 +75,4 @@ public partial class FarmingControls2D : Node2D #endregion - #region FIELD CREATION - private void MakeField(Vector2I mousePosition) - { - int potentialFieldIndex = FieldService.Instance.PositionToIndex(mousePosition); - if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex) == null) - EmitSignal(SignalName.FieldCreated); - } - - #endregion } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldActivator.cs b/scripts/CSharp/Common/Farming/FieldActivator.cs index 926098f..f324176 100644 --- a/scripts/CSharp/Common/Farming/FieldActivator.cs +++ b/scripts/CSharp/Common/Farming/FieldActivator.cs @@ -13,6 +13,8 @@ public partial class FieldActivator : Node private bool _used = false; private bool _rakeInHand; + + [Signal] public delegate void FieldCreatedEventHandler(); public override void _Ready() { @@ -28,6 +30,7 @@ public partial class FieldActivator : Node { _field.Visible = true; _field.UpdateFieldState(FieldState.Tilled); + EmitSignal(SignalName.FieldCreated, _field); _used = true; } } diff --git a/scripts/CSharp/Common/Farming/FieldService.cs b/scripts/CSharp/Common/Farming/FieldService.cs index a280d34..197e7c9 100644 --- a/scripts/CSharp/Common/Farming/FieldService.cs +++ b/scripts/CSharp/Common/Farming/FieldService.cs @@ -85,12 +85,6 @@ public partial class FieldService : Node } } } - - public int PositionToIndex(Vector2 position) - { - // some awesome code here - return 0; - } } internal class FieldsInScene -- 2.36.3