made plants only grow when watered

This commit is contained in:
2025-12-02 17:44:44 +01:00
parent e65330786e
commit c288af296c
3 changed files with 84 additions and 40 deletions
@@ -34,6 +34,7 @@ public partial class PlantBehaviour2D : Node2D
private bool _calledOnReady = false;
private int _dayPlanted;
private int _currentDay;
private int _daysWatered;
public PlantState State
{
@@ -66,28 +67,6 @@ public partial class PlantBehaviour2D : Node2D
DayPlanted++;
}
private void DaysGrowingChanged()
{
int _daysGrowing = _currentDay - _dayPlanted;
GD.Print($"Plant {Name} is growing for {_daysGrowing}. Day Planted was {_dayPlanted} and the current day is {_currentDay}.");
int lifecycle = _lifecycle.Payload.AsInt32();
Debug.Assert(lifecycle > 0);
float growth = (float)_daysGrowing / lifecycle;
int growthFloor = Mathf.FloorToInt(growth);
_state = growthFloor switch
{
0 => PlantState.None,
1 => PlantState.Planted,
2 => PlantState.SmallPlant,
_ => PlantState.BigPlant
};
_calledOnReady = true;
Grow();
}
public string PrefabPath => _prefabPath;
/// <summary>
@@ -99,6 +78,15 @@ public partial class PlantBehaviour2D : Node2D
set => _field = value;
}
public int DaysWatered
{
get => _daysWatered;
set
{
_daysWatered = value;
}
}
public override void _Ready()
{
if (_state == PlantState.None)
@@ -113,13 +101,32 @@ public partial class PlantBehaviour2D : Node2D
GrowPlant();
}
}
private void DaysGrowingChanged()
{
int lifecycle = _lifecycle.Payload.AsInt32();
Debug.Assert(lifecycle > 0);
float growth = (float)_daysWatered / lifecycle;
int growthFloor = Mathf.FloorToInt(growth);
_state = growthFloor switch
{
0 => PlantState.None,
1 => PlantState.Planted,
2 => PlantState.SmallPlant,
_ => PlantState.BigPlant
};
_calledOnReady = true;
Grow();
}
public void Grow()
{
GrowPlant();
}
/// <summary>
/// Transitions the plant to its next growth stage.
/// </summary>