fields can now seperate "today" from any other day

pull/34/head
kziolkowski 1 month ago
parent 0ecae5a4d9
commit b9a52dadcc

@ -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"))

@ -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<string, Variant>
{
{ "field_state", (int)FieldState }
{ "field_state", (int)FieldState },
{ "day_count_on_last_exit", _currentDay}
};
if (_currentPlant != null)
@ -265,18 +267,40 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
{
_currentPlant.DaysWatered = plantDaysWatered.AsInt32();
}
}
// 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)
{
if (dayCountSave.TryGetValue("payload", out Variant dayCountVar))
{
_currentDay = dayCountVar.AsInt32();
if (_currentPlant != null)
{
_currentPlant.CurrentDayInCalendar = _currentDay;
}
}
}
// 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)
{
@ -289,25 +313,11 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
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.
Dictionary<string, Variant> dayCountSave = SavegameService.GetSaveData(DAY_COUNTER_SAVE_ID);
if (dayCountSave.Count > 0)
{
if (dayCountSave.TryGetValue("payload", out Variant dayCountVar))
{
_currentDay = dayCountVar.AsInt32();
if (_currentPlant != null)
{
_currentPlant.CurrentDayInCalendar = _currentDay;
}
FieldState = (FieldState) fieldStateInt;
UpdateFieldState(FieldState, false);
}
}
}

Loading…
Cancel
Save