|
|
|
@ -45,9 +45,12 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
|
|
|
|
|
|
|
|
private bool _canPlant;
|
|
|
|
private bool _canPlant;
|
|
|
|
private bool _canWater;
|
|
|
|
private bool _canWater;
|
|
|
|
|
|
|
|
private int _currentDay;
|
|
|
|
|
|
|
|
|
|
|
|
private PlantBehaviour2D? _currentPlant;
|
|
|
|
private PlantBehaviour2D? _currentPlant;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const string DAY_COUNTER_SAVE_ID = "12c6da2e-fc71-4281-a04a-dfd3c7943975";
|
|
|
|
|
|
|
|
|
|
|
|
[Signal] public delegate void PlantedEventHandler();
|
|
|
|
[Signal] public delegate void PlantedEventHandler();
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateInteractionArea()
|
|
|
|
private void UpdateInteractionArea()
|
|
|
|
@ -176,6 +179,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
if (_currentPlant != null)
|
|
|
|
if (_currentPlant != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_currentPlant.Field = this;
|
|
|
|
_currentPlant.Field = this;
|
|
|
|
|
|
|
|
_currentPlant.DayPlanted = _currentDay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -194,7 +198,6 @@ 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_state", (int)_currentPlant.State },
|
|
|
|
|
|
|
|
{ "plant_start_day", _currentPlant.DayPlanted }
|
|
|
|
{ "plant_start_day", _currentPlant.DayPlanted }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -206,6 +209,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
|
|
|
|
|
|
|
|
public void LoadFromSaveData()
|
|
|
|
public void LoadFromSaveData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// Get field and plant data
|
|
|
|
string id = _saveIdHolder.GetMeta("SaveID").AsString();
|
|
|
|
string id = _saveIdHolder.GetMeta("SaveID").AsString();
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
|
|
|
Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
|
|
|
@ -236,25 +240,23 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (plantDataDict.TryGetValue("plant_state", out Variant plantStateVar) && _currentPlant != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_currentPlant.State = (PlantState) plantStateVar.AsInt32();
|
|
|
|
|
|
|
|
_currentPlant.GrowPlant();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantDaysGrowingVar) && _currentPlant != null)
|
|
|
|
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantDaysGrowingVar) && _currentPlant != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32();
|
|
|
|
_currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_currentPlant != null)
|
|
|
|
// Get current day count: Load only. Saving the day count is handled on the day and night prefab.
|
|
|
|
|
|
|
|
Dictionary<string, Variant> dayCountSave = SavegameService.GetSaveData(DAY_COUNTER_SAVE_ID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dayCountSave.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//todo: find out how to load the current day from save and provide it to the plant script
|
|
|
|
if (dayCountSave.TryGetValue("payload", out Variant dayCountVar))
|
|
|
|
_currentPlant.CurrentDayInCalendar = GD.RandRange(0, 12);
|
|
|
|
{
|
|
|
|
GD.Print($"Set current Day in calendar for plant {_currentPlant.Name} to {_currentPlant.CurrentDayInCalendar}");
|
|
|
|
_currentDay = dayCountVar.AsInt32();
|
|
|
|
|
|
|
|
if(_currentPlant != null)
|
|
|
|
|
|
|
|
_currentPlant.CurrentDayInCalendar = dayCountVar.AsInt32();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|