|
|
|
@ -59,6 +59,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
|
|
|
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
|
|
|
// fieldstate == tilled && watering can ausgewählt
|
|
|
|
// fieldstate == tilled && watering can ausgewählt
|
|
|
|
_canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive;
|
|
|
|
_canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive;
|
|
|
|
|
|
|
|
|
|
|
|
FieldInteractionArea.IsActive = _canPlant || _canWater;
|
|
|
|
FieldInteractionArea.IsActive = _canPlant || _canWater;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +92,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
base._Ready();
|
|
|
|
base._Ready();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateFieldState(FieldState state)
|
|
|
|
public void UpdateFieldState(FieldState state, bool updateSaveAfter = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -119,18 +120,25 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateInteractionArea();
|
|
|
|
UpdateInteractionArea();
|
|
|
|
|
|
|
|
if(updateSaveAfter)
|
|
|
|
UpdateSaveData();
|
|
|
|
UpdateSaveData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Water()
|
|
|
|
public void Water()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (WateringCanState.GetFillState() > 0)
|
|
|
|
if (WateringCanState.GetFillState() > 0 && FieldState != FieldState.Watered)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UpdateFieldState(FieldState.Watered);
|
|
|
|
UpdateFieldState(FieldState.Watered);
|
|
|
|
_wateringParticles.Emitting = true;
|
|
|
|
_wateringParticles.Emitting = true;
|
|
|
|
WateringCanState.Water();
|
|
|
|
WateringCanState.Water();
|
|
|
|
_wateringEvent.Raise();
|
|
|
|
_wateringEvent.Raise();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_currentPlant != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_currentPlant.DaysWatered++;
|
|
|
|
|
|
|
|
UpdateSaveData();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -198,6 +206,9 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
|
|
|
|
|
|
|
|
#region SAVE AND LOAD
|
|
|
|
#region SAVE AND LOAD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Update save data as prep for scene transition (when data is saved and loaded from disk).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public void UpdateSaveData()
|
|
|
|
public void UpdateSaveData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var payloadData = new Dictionary<string, Variant>
|
|
|
|
var payloadData = new Dictionary<string, Variant>
|
|
|
|
@ -211,7 +222,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
"plant_data", new Dictionary<string, Variant>()
|
|
|
|
"plant_data", new Dictionary<string, Variant>()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "prefab_path", _currentPlant.PrefabPath },
|
|
|
|
{ "prefab_path", _currentPlant.PrefabPath },
|
|
|
|
{ "plant_start_day", _currentPlant.DayPlanted }
|
|
|
|
{ "plant_start_day", _currentPlant.DayPlanted },
|
|
|
|
|
|
|
|
{ "plant_watered_days", _currentPlant.DaysWatered }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -220,6 +232,9 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
SavegameService.AppendDataToSave(id, payloadData);
|
|
|
|
SavegameService.AppendDataToSave(id, payloadData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Loads on scene enter.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public void LoadFromSaveData()
|
|
|
|
public void LoadFromSaveData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Get field and plant data
|
|
|
|
// Get field and plant data
|
|
|
|
@ -229,18 +244,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
|
|
|
|
|
|
|
|
if (save.Count > 0)
|
|
|
|
if (save.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (save.TryGetValue("field_state", out Variant fieldStateVar))
|
|
|
|
// get plant first because it's also relevant for the field state
|
|
|
|
{
|
|
|
|
|
|
|
|
int fieldStateInt = fieldStateVar.AsInt32();
|
|
|
|
|
|
|
|
FieldState = (FieldState) fieldStateInt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fieldStateInt != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Visible = true;
|
|
|
|
|
|
|
|
UpdateFieldState(FieldState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (save.TryGetValue("plant_data", out Variant plantDataVar))
|
|
|
|
if (save.TryGetValue("plant_data", out Variant plantDataVar))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Dictionary<string, Variant> plantDataDict = plantDataVar.AsGodotDictionary<string, Variant>();
|
|
|
|
Dictionary<string, Variant> plantDataDict = plantDataVar.AsGodotDictionary<string, Variant>();
|
|
|
|
@ -256,7 +260,39 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantStartDay) && _currentPlant != null)
|
|
|
|
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantStartDay) && _currentPlant != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_currentPlant.DayPlanted = plantStartDay.AsInt32();
|
|
|
|
_currentPlant.DayPlanted = plantStartDay.AsInt32();
|
|
|
|
GD.Print($"Current plant {_currentPlant.Name} was planted on day: {_currentPlant.DayPlanted}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plantDataDict.TryGetValue("plant_watered_days", out Variant plantDaysWatered) && _currentPlant != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_currentPlant.DaysWatered = plantDaysWatered.AsInt32();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get field state
|
|
|
|
|
|
|
|
if (save.TryGetValue("field_state", out Variant fieldStateVar))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int fieldStateInt = fieldStateVar.AsInt32();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the field has been unlocked, make it visible.
|
|
|
|
|
|
|
|
if (fieldStateInt != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Visible = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the field was watered the day before, set it to tilled or planted.
|
|
|
|
|
|
|
|
if (fieldStateInt == 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_currentPlant != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fieldStateInt = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fieldStateInt = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FieldState = (FieldState) fieldStateInt;
|
|
|
|
|
|
|
|
UpdateFieldState(FieldState, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|