♻️ removed planted state from Fieldstate because it didn't make any sense.

pull/48/head
kziolkowski 4 weeks ago
parent 950731b225
commit 30750d2e3c

@ -47,6 +47,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
private bool _canWater;
private int _currentDay;
public bool IsPlanted;
private PlantBehaviour2D? _currentPlant;
private const string DAY_COUNTER_SAVE_ID = "12c6da2e-fc71-4281-a04a-dfd3c7943975";
@ -58,7 +60,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
// fieldstate == tilled / watered && samen im Inventar
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
// fieldstate == tilled && watering can ausgewählt
_canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive;
_canWater = (FieldState == FieldState.Tilled || IsPlanted) && _wateringCanActive;
PlantingInteraction.IsActive = _canPlant || _canWater;
}
@ -103,17 +105,14 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
case FieldState.Tilled:
FieldState = FieldState.Tilled;
_fieldSprite.Texture = Tilled;
PlantingInteraction.IsActive = true;
if(!IsPlanted)
PlantingInteraction.IsActive = true;
break;
case FieldState.Watered:
FieldState = FieldState.Watered;
_fieldSprite.Texture = Watered;
PlantingInteraction.IsActive = true;
break;
case FieldState.Planted:
FieldState = FieldState.Planted;
_fieldSprite.Texture = Tilled;
PlantingInteraction.IsActive = false;
if(!IsPlanted)
PlantingInteraction.IsActive = true;
break;
default:
FieldState = FieldState.NotFound;
@ -124,7 +123,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
UpdateSaveData();
}
public void Water()
{
if (WateringCanState.GetFillState() > 0 && FieldState != FieldState.Watered)
@ -150,7 +148,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
if (_canPlant && TryPlant())
{
EmitSignal(SignalName.Planted);
UpdateFieldState(FieldState.Planted);
UpdateSaveData();
}
if (_canWater)
@ -158,6 +156,17 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
Water();
}
}
public void ChangePlantedState()
{
GD.Print("Adding Plant.");
IsPlanted = true;
if(FieldState == FieldState.Tilled)
_fieldSprite.Texture = Tilled;
if(FieldState == FieldState.Watered)
_fieldSprite.Texture = Watered;
PlantingInteraction.IsActive = false;
}
private bool TryPlant()
{
@ -186,6 +195,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
if (_currentPlant != null)
{
ChangePlantedState();
_currentPlant.DayPlanted = _currentDay;
}
}
@ -208,6 +218,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
{
_currentPlant = null;
UpdateFieldState(FieldState.Empty, true);
IsPlanted = false;
}
#region SAVE AND LOAD
@ -220,11 +231,12 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
var payloadData = new Dictionary<string, Variant>
{
{ "field_state", (int)FieldState },
{ "day_count_on_last_exit", _currentDay}
{ "day_count_on_last_exit", _currentDay},
};
if (_currentPlant != null)
if (IsPlanted)
{
GD.Print("Saving plant data.");
payloadData.Add(
"plant_data", new Dictionary<string, Variant>()
{
@ -257,6 +269,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
// get plant first because it's also relevant for the field state
if (save.TryGetValue("plant_data", out Variant plantDataVar))
{
IsPlanted = true;
Dictionary<string, Variant> plantDataDict = plantDataVar.AsGodotDictionary<string, Variant>();
if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar))
@ -313,17 +326,10 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
// if day is today, then just use the provided field state as is.
if (CalendarController.Instance != null && _currentDay != lastDayCount)
{
// if the field was watered the day before, set it to tilled or planted.
// if the field was watered the day before, set it to tilled
if (fieldStateInt == 3)
{
if (_currentPlant != null)
{
fieldStateInt = 2;
}
else
{
fieldStateInt = 1;
}
fieldStateInt = 1;
}
}
}

@ -7,7 +7,6 @@ public enum FieldState
{
Empty = 0,
Tilled = 1,
Planted = 2,
Watered = 3,
NotFound = 99
}
Loading…
Cancel
Save