From b00b466045ad8ad14245910800515a39fa1eca80 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 11 Nov 2025 15:51:15 +0100 Subject: [PATCH] :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()