WIP trying to fix the last plant stage bug on repeated farming rounds

This commit is contained in:
2025-07-17 22:10:08 +02:00
parent b92eb909ad
commit 486cfb5546
3 changed files with 23 additions and 5 deletions
@@ -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)