From 486cfb554631d3bf58fbad0ef264e09dfa06d8a0 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Thu, 17 Jul 2025 22:10:08 +0200 Subject: [PATCH] WIP trying to fix the last plant stage bug on repeated farming rounds --- prefabs/farm/tomato_field.tscn | 3 +++ prefabs/farm/tomato_plant.tscn | 4 +++- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 21 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/prefabs/farm/tomato_field.tscn b/prefabs/farm/tomato_field.tscn index 32598bf..23aa8b2 100644 --- a/prefabs/farm/tomato_field.tscn +++ b/prefabs/farm/tomato_field.tscn @@ -43,6 +43,9 @@ text = "[E] Grow [node name="CollisionShape3D" parent="FieldBehaviour/BasePlant2/ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_l0vvv") +[node name="Label" parent="FieldBehaviour/BasePlant2/ReadyPlantInventoryItem/PickupInteractionArea" index="1"] +text = "[E] Harvest" + [node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"] clip_children = 1 scale = Vector2(1.5, 1.5) diff --git a/prefabs/farm/tomato_plant.tscn b/prefabs/farm/tomato_plant.tscn index 5e01f82..b52936d 100644 --- a/prefabs/farm/tomato_plant.tscn +++ b/prefabs/farm/tomato_plant.tscn @@ -104,7 +104,7 @@ region_enabled = true region_rect = Rect2(228, 600, 85, 92) [node name="BigPlant" type="Node2D" parent="."] -position = Vector2(0, -400) +position = Vector2(0, -300) [node name="01" type="Sprite2D" parent="BigPlant"] visible = false @@ -156,6 +156,8 @@ _blueprint = ExtResource("7_di4m0") [node name="ItemLabel" parent="ReadyPlantInventoryItem" index="1"] visible = false +z_index = 100 +text = "[E] harvest" [node name="PickupErrorLabel" parent="ReadyPlantInventoryItem" index="2"] visible = false diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index f571d11..36ea630 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -42,9 +42,9 @@ public partial class PlantBehaviour2D : Node2D if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded) return; - GD.Print("Trying to grow something here."); GetTree().CallGroup("PlantGrowing", Player2D.MethodName.PlayFarmingAnimation); - + // todo: + // find out why the last plant stage is being skipped the second time around switch (_state) { case PlantState.None: @@ -68,13 +68,14 @@ public partial class PlantBehaviour2D : Node2D _state = PlantState.Ready; _currentPlantSprite.Visible = false; _currentPlantSprite = GetRandomSprite(_readyPlants); - _harvestablePlant.IsActive = true; _currentPlantSprite.Visible = true; + ActivatePickupAfterDelay(true); break; case PlantState.Ready: _state = PlantState.None; _currentPlantSprite.Visible = false; _currentPlantSprite = null; + ActivatePickupAfterDelay(false); break; default: break; @@ -89,7 +90,19 @@ public partial class PlantBehaviour2D : Node2D Random rand = new Random(); return sprites[rand.Next(sprites.Length)]; } - + + public async void ActivatePickupAfterDelay(bool activate) + { + await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); + SetActiveHarvestablePlant(activate); + } + + private void SetActiveHarvestablePlant(bool active) + { + _harvestablePlant.IsActive = active; + _harvestablePlant.UpdateVisuals(); + } + public void SayMagicWord(string wordEvent) { if (_magicWordDialogicEventName != wordEvent)