From 41b30a4274d7d35e55da24f8b6886c68a9789e16 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 28 Nov 2025 20:25:47 +0100 Subject: [PATCH] :construction: days are counted, plants know which day it is, but harvestables are still broken --- prefabs/day and night/day_and_night.tscn | 15 ++++++++++ project.godot | 1 + scenes/Babushka_scene_bootstrap.tscn | 15 +--------- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 28 ++++++++++--------- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 11 +++++--- .../CSharp/Common/Inventory/ItemOnGround2D.cs | 2 ++ 6 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 prefabs/day and night/day_and_night.tscn diff --git a/prefabs/day and night/day_and_night.tscn b/prefabs/day and night/day_and_night.tscn new file mode 100644 index 0000000..5b6dfd1 --- /dev/null +++ b/prefabs/day and night/day_and_night.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://cqy831wnquvpc"] + +[ext_resource type="Script" uid="uid://d27xoo1reo5gu" path="res://scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs" id="1_386s0"] +[ext_resource type="Script" uid="uid://du5facslfvg77" path="res://scripts/CSharp/Common/DayAndNight/CalendarController.cs" id="2_bl8tj"] + +[node name="Day and Night" type="Node"] + +[node name="Controller" type="Node" parent="." node_paths=PackedStringArray("_dayCounter")] +script = ExtResource("2_bl8tj") +_dayCounter = NodePath("../DayCounter") + +[node name="DayCounter" type="Node" parent="." groups=["Saveable"]] +script = ExtResource("1_386s0") +Payload = 0 +metadata/SaveID = "12c6da2e-fc71-4281-a04a-dfd3c7943975" diff --git a/project.godot b/project.godot index 0a69778..ceadb3e 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,7 @@ Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd" FightWorldAutoload="*res://prefabs/fight/fight_world_autoload.tscn" SaveGameManager="*res://scripts/CSharp/Common/Savegame/SaveGameManager.cs" SettingsSaveController="*res://scripts/CSharp/Common/Savegame/SettingsSaveController.cs" +DayAndNight="*res://prefabs/day and night/day_and_night.tscn" [dialogic] diff --git a/scenes/Babushka_scene_bootstrap.tscn b/scenes/Babushka_scene_bootstrap.tscn index 0124cb1..cc284e0 100644 --- a/scenes/Babushka_scene_bootstrap.tscn +++ b/scenes/Babushka_scene_bootstrap.tscn @@ -1,9 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://bopv10dqm1knc"] +[gd_scene load_steps=5 format=3 uid="uid://bopv10dqm1knc"] [ext_resource type="PackedScene" uid="uid://c6wnoif01ltld" path="res://scenes/Babushka_scene_startMenu.tscn" id="1_15ton"] [ext_resource type="Script" uid="uid://bbp0dyddwdbl8" path="res://scripts/CSharp/Common/Savegame/WindowSettingsSync.cs" id="2_d3jfo"] -[ext_resource type="Script" uid="uid://d27xoo1reo5gu" path="res://scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs" id="3_ocsjo"] -[ext_resource type="Script" uid="uid://du5facslfvg77" path="res://scripts/CSharp/Common/DayAndNight/CalendarController.cs" id="4_iyo8m"] [ext_resource type="Script" uid="uid://iquhbkr7pqeg" path="res://scripts/CSharp/Common/Savegame/SaveCheats.cs" id="4_ocsjo"] [ext_resource type="Script" uid="uid://ca4s0algeij1h" path="res://scripts/CSharp/Common/Savegame/SaveIDProviderTool.cs" id="5_iyo8m"] @@ -16,17 +14,6 @@ [node name="WindowSettings" type="Node" parent="."] script = ExtResource("2_d3jfo") -[node name="Day and Night" type="Node" parent="."] - -[node name="DayCounter" type="Node" parent="Day and Night" groups=["Saveable"]] -script = ExtResource("3_ocsjo") -Payload = 0 -metadata/SaveID = "b46b67a2-427b-4f43-8066-4ffebf17b75f" - -[node name="Controller" type="Node" parent="Day and Night" node_paths=PackedStringArray("_dayCounter")] -script = ExtResource("4_iyo8m") -_dayCounter = NodePath("../DayCounter") - [node name="SaveSystem" type="Node" parent="."] [node name="SaveGameCheat" type="Node" parent="SaveSystem"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 6fe2a18..b07bd7b 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -45,8 +45,11 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable private bool _canPlant; private bool _canWater; + private int _currentDay; private PlantBehaviour2D? _currentPlant; + + private const string DAY_COUNTER_SAVE_ID = "12c6da2e-fc71-4281-a04a-dfd3c7943975"; [Signal] public delegate void PlantedEventHandler(); @@ -176,6 +179,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (_currentPlant != null) { _currentPlant.Field = this; + _currentPlant.DayPlanted = _currentDay; } } @@ -194,7 +198,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable "plant_data", new Dictionary() { { "prefab_path", _currentPlant.PrefabPath }, - { "plant_state", (int)_currentPlant.State }, { "plant_start_day", _currentPlant.DayPlanted } } ); @@ -206,6 +209,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable public void LoadFromSaveData() { + // Get field and plant data string id = _saveIdHolder.GetMeta("SaveID").AsString(); Dictionary save = SavegameService.GetSaveData(id); @@ -236,25 +240,23 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable { 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) { _currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32(); } + } + + // Get current day count: Load only. Saving the day count is handled on the day and night prefab. + Dictionary dayCountSave = SavegameService.GetSaveData(DAY_COUNTER_SAVE_ID); - if (_currentPlant != null) + if (dayCountSave.Count > 0) + { + if (dayCountSave.TryGetValue("payload", out Variant dayCountVar)) { - //todo: find out how to load the current day from save and provide it to the plant script - _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(); } - } } } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 35c7166..5829a4d 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -41,6 +41,9 @@ public partial class PlantBehaviour2D : Node2D set => _state = value; } + /// + /// The day count at the day this plant was planted. + /// public int DayPlanted { get; set; } public int CurrentDayInCalendar @@ -70,10 +73,10 @@ public partial class PlantBehaviour2D : Node2D _state = growthFloor switch { - 0 => PlantState.Planted, - 1 => PlantState.SmallPlant, - 2 => PlantState.BigPlant, - _ => PlantState.Ready + 0 => PlantState.None, + 1 => PlantState.Planted, + 2 => PlantState.SmallPlant, + _ => PlantState.BigPlant }; _calledOnReady = true; diff --git a/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs b/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs index 1dc21a1..c94599c 100644 --- a/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs +++ b/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs @@ -15,6 +15,7 @@ public partial class ItemOnGround2D : Node, ISaveable private int pickUpCounter = 0; [Signal] public delegate void SuccessfulPickUpEventHandler(); + private Label _itemLabel => GetNode