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

pull/14/head
kziolkowski 6 months ago
parent b92eb909ad
commit 486cfb5546

@ -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)

@ -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

@ -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)

Loading…
Cancel
Save