diff --git a/scripts/CSharp/Common/DayAndNight/CalendarController.cs b/scripts/CSharp/Common/DayAndNight/CalendarController.cs index ecea54b..fed5dde 100644 --- a/scripts/CSharp/Common/DayAndNight/CalendarController.cs +++ b/scripts/CSharp/Common/DayAndNight/CalendarController.cs @@ -7,6 +7,26 @@ public partial class CalendarController : Node { [Export] private SaveableVariableNode _dayCounter; + public static CalendarController? Instance; + + public int CurrentDay + { + get + { + if (Instance == null) + return 0; + return Instance._dayCounter.Payload.AsInt32(); + } + } + + public override void _Ready() + { + if (Instance == null) + { + Instance = this; + } + } + public override void _Input(InputEvent @event) { if (@event.IsActionPressed("NextDayCheat")) diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 832fc2b..bf9116f 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,5 +1,6 @@ using System; using Babushka.scripts.CSharp.Common.CharacterControls; +using Babushka.scripts.CSharp.Common.DayAndNight; using Babushka.scripts.CSharp.Common.Inventory; using Babushka.scripts.CSharp.Common.Savegame; using Babushka.scripts.CSharp.Low_Code.Events; @@ -213,7 +214,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable { var payloadData = new Dictionary { - { "field_state", (int)FieldState } + { "field_state", (int)FieldState }, + { "day_count_on_last_exit", _currentDay} }; if (_currentPlant != null) @@ -265,35 +267,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable { _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); - } - } } // Get current day count: Load only. Saving the day count is handled on the day and night prefab. @@ -310,6 +283,43 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable } } } + + // 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 (save.TryGetValue("day_count_on_last_exit", out Variant lastDayCountVar)) + { + int lastDayCount = lastDayCountVar.AsInt32(); + + // 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 (fieldStateInt == 3) + { + if (_currentPlant != null) + { + fieldStateInt = 2; + } + else + { + fieldStateInt = 1; + } + } + } + } + + FieldState = (FieldState) fieldStateInt; + UpdateFieldState(FieldState, false); + } + } } } #endregion