From 684131f49510820cb8eec9de9dc3d06ad78c36ba Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 26 Nov 2025 18:00:45 +0100 Subject: [PATCH 01/16] :sparkles: Make SaveableVariableNodes and a simple cheat to count up days --- project.godot | 5 ++ scenes/Babushka_scene_bootstrap.tscn | 25 +++++++++- .../Common/DayAndNight/CalendarController.cs | 19 ++++++++ .../DayAndNight/CalendarController.cs.uid | 1 + .../Variables/SaveableVariableNode.cs | 48 +++++++++++++++++++ .../Variables/SaveableVariableNode.cs.uid | 1 + .../CSharp/Low Code/Variables/VariableNode.cs | 20 +++++++- 7 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 scripts/CSharp/Common/DayAndNight/CalendarController.cs create mode 100644 scripts/CSharp/Common/DayAndNight/CalendarController.cs.uid create mode 100644 scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs create mode 100644 scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs.uid diff --git a/project.godot b/project.godot index a88b31e..0a69778 100644 --- a/project.godot +++ b/project.godot @@ -300,6 +300,11 @@ ui_inventory_journal_open_close={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":74,"key_label":0,"unicode":106,"location":0,"echo":false,"script":null) ] } +NextDayCheat={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +] +} [internationalization] diff --git a/scenes/Babushka_scene_bootstrap.tscn b/scenes/Babushka_scene_bootstrap.tscn index f567a1b..0124cb1 100644 --- a/scenes/Babushka_scene_bootstrap.tscn +++ b/scenes/Babushka_scene_bootstrap.tscn @@ -1,7 +1,11 @@ -[gd_scene load_steps=3 format=3 uid="uid://bopv10dqm1knc"] +[gd_scene load_steps=7 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"] [node name="BabushkaSceneBootstrap" type="Node2D"] @@ -11,3 +15,22 @@ [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"] +script = ExtResource("4_ocsjo") + +[node name="SaveIDProvider" type="Node" parent="SaveSystem"] +script = ExtResource("5_iyo8m") diff --git a/scripts/CSharp/Common/DayAndNight/CalendarController.cs b/scripts/CSharp/Common/DayAndNight/CalendarController.cs new file mode 100644 index 0000000..33185e2 --- /dev/null +++ b/scripts/CSharp/Common/DayAndNight/CalendarController.cs @@ -0,0 +1,19 @@ +using Babushka.scripts.CSharp.Low_Code.Variables; +using Godot; + +namespace Babushka.scripts.CSharp.Common.DayAndNight; + +public partial class CalendarController : Node +{ + [Export] private SaveableVariableNode _dayCounter; + + public override void _Input(InputEvent @event) + { + if (@event.IsActionPressed("NextDayCheat")) + { + int days = _dayCounter.Payload.AsInt32(); + days++; + _dayCounter.Payload = days; + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/DayAndNight/CalendarController.cs.uid b/scripts/CSharp/Common/DayAndNight/CalendarController.cs.uid new file mode 100644 index 0000000..4993549 --- /dev/null +++ b/scripts/CSharp/Common/DayAndNight/CalendarController.cs.uid @@ -0,0 +1 @@ +uid://du5facslfvg77 diff --git a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs new file mode 100644 index 0000000..c7f5389 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs @@ -0,0 +1,48 @@ +using Babushka.scripts.CSharp.Common.Savegame; +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +public partial class SaveableVariableNode : VariableNode, ISaveable +{ + public override void _Ready() + { + LoadFromSaveData(); + ValueChanged += UpdateSaveData; + } + + public override void _ExitTree() + { + ValueChanged -= UpdateSaveData; + } + + public void UpdateSaveData() + { + var payloadData = new Dictionary + { + { "payload", Payload }, + }; + + string id = GetMeta("SaveID").AsString(); + SavegameService.AppendDataToSave( id, payloadData); + } + + public void LoadFromSaveData() + { + string id = GetMeta("SaveID").AsString(); + Dictionary save = SavegameService.GetSaveData(id); + if (save.Count > 0) + { + if (Payload.VariantType == Variant.Type.Int) + { + Payload = save["payload"].AsInt32(); + + } + else + { + Payload = save["payload"]; + } + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs.uid b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs.uid new file mode 100644 index 0000000..af84b35 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs.uid @@ -0,0 +1 @@ +uid://d27xoo1reo5gu diff --git a/scripts/CSharp/Low Code/Variables/VariableNode.cs b/scripts/CSharp/Low Code/Variables/VariableNode.cs index a979ee0..fd83e51 100644 --- a/scripts/CSharp/Low Code/Variables/VariableNode.cs +++ b/scripts/CSharp/Low Code/Variables/VariableNode.cs @@ -7,5 +7,23 @@ namespace Babushka.scripts.CSharp.Low_Code.Variables; /// public partial class VariableNode : Node { - [Export] public Variant Payload { get; set; } + [Export] public Variant Payload + { + get + { + return _payload; + } + set + { + if (_payload.Equals(value)) + return; + + _payload = value; + EmitSignal(SignalName.ValueChanged); + } + } + + private Variant _payload; + + [Signal] public delegate void ValueChangedEventHandler(); } \ No newline at end of file From 67d5b67c21116b8112d1bb158d446f9446f8fbe5 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 26 Nov 2025 18:52:33 +0100 Subject: [PATCH 02/16] :lipstick: Added new game button that resets the savegame (also did some layouting) --- scenes/Babushka_scene_startMenu.tscn | 88 +++++++++++++++++----------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/scenes/Babushka_scene_startMenu.tscn b/scenes/Babushka_scene_startMenu.tscn index 262a257..02d132a 100644 --- a/scenes/Babushka_scene_startMenu.tscn +++ b/scenes/Babushka_scene_startMenu.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://c6wnoif01ltld"] +[gd_scene load_steps=5 format=3 uid="uid://c6wnoif01ltld"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_fj2fh"] +[ext_resource type="Script" uid="uid://iquhbkr7pqeg" path="res://scripts/CSharp/Common/Savegame/SaveCheats.cs" id="3_dl0t1"] [ext_resource type="Texture2D" uid="uid://c7atj6ohlmir3" path="res://art/ui/StartScreen/titlescreen.png" id="3_r0y6o"] [ext_resource type="Texture2D" uid="uid://du612t3xytly3" path="res://art/ui/StartScreen/babushkalog_white.png" id="4_dl0t1"] @@ -21,37 +22,6 @@ expand_mode = 2 stretch_mode = 6 metadata/_edit_use_anchors_ = true -[node name="Start" type="Button" parent="CanvasLayer/TextureRect"] -custom_minimum_size = Vector2(100, 30) -layout_mode = 1 -anchors_preset = 4 -anchor_top = 0.5 -anchor_bottom = 0.5 -offset_left = 200.0 -offset_top = -15.5 -offset_right = 400.0 -offset_bottom = 24.5 -grow_vertical = 2 -scale = Vector2(2, 2) -toggle_mode = true -text = "Start" - -[node name="Quit" type="Button" parent="CanvasLayer/TextureRect"] -custom_minimum_size = Vector2(100, 30) -layout_mode = 1 -anchors_preset = 4 -anchor_top = 0.5 -anchor_bottom = 0.5 -offset_left = 200.0 -offset_top = 97.0 -offset_right = 400.0 -offset_bottom = 137.0 -grow_vertical = 2 -scale = Vector2(2, 2) -toggle_mode = true -text = "Quit -" - [node name="Text" type="TextureRect" parent="CanvasLayer/TextureRect"] layout_mode = 1 offset_left = 50.0 @@ -62,5 +32,55 @@ scale = Vector2(0.5, 0.5) texture = ExtResource("4_dl0t1") stretch_mode = 3 -[connection signal="pressed" from="CanvasLayer/TextureRect/Start" to="." method="LoadScene"] -[connection signal="pressed" from="CanvasLayer/TextureRect/Quit" to="." method="Quit"] +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/TextureRect"] +custom_minimum_size = Vector2(500, 300) +layout_mode = 0 +offset_left = 204.0 +offset_top = 497.0 +offset_right = 704.0 +offset_bottom = 797.0 + +[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/TextureRect/VBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Continue" type="Button" parent="CanvasLayer/TextureRect/VBoxContainer/MarginContainer"] +custom_minimum_size = Vector2(100, 80) +layout_mode = 2 +theme_override_font_sizes/font_size = 36 +toggle_mode = true +text = "Continue +" + +[node name="MarginContainer2" type="MarginContainer" parent="CanvasLayer/TextureRect/VBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_bottom = 10 + +[node name="New Game" type="Button" parent="CanvasLayer/TextureRect/VBoxContainer/MarginContainer2"] +custom_minimum_size = Vector2(100, 80) +layout_mode = 2 +theme_override_font_sizes/font_size = 36 +toggle_mode = true +text = "New Game +" +script = ExtResource("3_dl0t1") + +[node name="MarginContainer3" type="MarginContainer" parent="CanvasLayer/TextureRect/VBoxContainer"] +layout_mode = 2 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Quit" type="Button" parent="CanvasLayer/TextureRect/VBoxContainer/MarginContainer3"] +custom_minimum_size = Vector2(100, 80) +layout_mode = 2 +theme_override_font_sizes/font_size = 36 +toggle_mode = true +text = "Quit +" + +[connection signal="pressed" from="CanvasLayer/TextureRect/VBoxContainer/MarginContainer/Continue" to="." method="LoadScene"] +[connection signal="pressed" from="CanvasLayer/TextureRect/VBoxContainer/MarginContainer2/New Game" to="." method="LoadScene"] +[connection signal="pressed" from="CanvasLayer/TextureRect/VBoxContainer/MarginContainer2/New Game" to="CanvasLayer/TextureRect/VBoxContainer/MarginContainer2/New Game" method="Reset"] +[connection signal="pressed" from="CanvasLayer/TextureRect/VBoxContainer/MarginContainer3/Quit" to="." method="Quit"] From a1fb71119fe2f0deee9cdc532c57062aa5992efe Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 26 Nov 2025 20:12:27 +0100 Subject: [PATCH 03/16] :construction: WIP binding the plant growth to the day count in the savefile --- prefabs/farm/plants/base_plant.tscn | 10 +++- .../Common/DayAndNight/CalendarController.cs | 1 + .../CSharp/Common/Farming/FieldBehaviour2D.cs | 15 ++++-- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 53 +++++++++++++++++-- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/prefabs/farm/plants/base_plant.tscn b/prefabs/farm/plants/base_plant.tscn index d20e588..eea69a7 100644 --- a/prefabs/farm/plants/base_plant.tscn +++ b/prefabs/farm/plants/base_plant.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://gishbn0a8eke"] +[gd_scene load_steps=12 format=3 uid="uid://gishbn0a8eke"] [ext_resource type="Script" uid="uid://cms357f23fmfy" path="res://scripts/CSharp/Common/Farming/PlantBehaviour2D.cs" id="1_66p1c"] [ext_resource type="Texture2D" uid="uid://mrnc81ukugh6" path="res://art/farm/farming/farmobjekte/plant_template.png" id="2_oyl0t"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="5_3j24b"] [ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="6_gdrin"] [ext_resource type="Resource" uid="uid://blr8tine5m0ma" path="res://resources/items/tomato.tres" id="7_vjw4j"] +[ext_resource type="Script" uid="uid://j2mhvb45egej" path="res://scripts/CSharp/Low Code/Variables/VariableNode.cs" id="8_3og52"] [ext_resource type="Texture2D" uid="uid://bleimj6jr1jka" path="res://art/general/rectangle.png" id="9_vjw4j"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_u4cty"] @@ -28,7 +29,7 @@ radius = 300.0 resource_local_to_scene = true radius = 300.0 -[node name="BasePlant" type="Node2D" node_paths=PackedStringArray("_seeds", "_smallPlants", "_bigPlants", "_readyPlants", "_harvestablePlant", "_magicEffect")] +[node name="BasePlant" type="Node2D" node_paths=PackedStringArray("_seeds", "_smallPlants", "_bigPlants", "_readyPlants", "_harvestablePlant", "_magicEffect", "_lifecycle")] z_index = 1 y_sort_enabled = true script = ExtResource("1_66p1c") @@ -38,6 +39,7 @@ _bigPlants = [NodePath("BigPlant/01"), NodePath("BigPlant/02"), NodePath("BigPla _readyPlants = [NodePath("ReadyPlantInventoryItem/ReadyPlant/01"), NodePath("ReadyPlantInventoryItem/ReadyPlant/02"), NodePath("ReadyPlantInventoryItem/ReadyPlant/03")] _harvestablePlant = NodePath("ReadyPlantInventoryItem") _magicEffect = NodePath("magic vfx") +_lifecycle = NodePath("LifeCycle") [node name="Seeds" type="Node2D" parent="."] position = Vector2(0, 0.5) @@ -206,6 +208,10 @@ scale_amount_max = 0.1 color = Color(0.400601, 0.62444, 0.791217, 1) hue_variation_max = 0.4 +[node name="LifeCycle" type="Node" parent="."] +script = ExtResource("8_3og52") +Payload = 3 + [connection signal="Interacted" from="GrowingInteractionArea" to="." method="Grow"] [connection signal="SuccessfulPickUp" from="ReadyPlantInventoryItem" to="." method="queue_free"] diff --git a/scripts/CSharp/Common/DayAndNight/CalendarController.cs b/scripts/CSharp/Common/DayAndNight/CalendarController.cs index 33185e2..ecea54b 100644 --- a/scripts/CSharp/Common/DayAndNight/CalendarController.cs +++ b/scripts/CSharp/Common/DayAndNight/CalendarController.cs @@ -14,6 +14,7 @@ public partial class CalendarController : Node int days = _dayCounter.Payload.AsInt32(); days++; _dayCounter.Payload = days; + } } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 52b02a5..6fe2a18 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -195,7 +195,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable { { "prefab_path", _currentPlant.PrefabPath }, { "plant_state", (int)_currentPlant.State }, - { "plant_days_growing", _currentPlant.DaysGrowing } + { "plant_start_day", _currentPlant.DayPlanted } } ); } @@ -243,11 +243,18 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable _currentPlant.GrowPlant(); } - if (plantDataDict.TryGetValue("plant_days_growing", out Variant plantDaysGrowingVar) && _currentPlant != null) + if (plantDataDict.TryGetValue("plant_start_day", out Variant plantDaysGrowingVar) && _currentPlant != null) { - _currentPlant.DaysGrowing = plantDaysGrowingVar.AsInt32(); + _currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32(); } - + + if (_currentPlant != null) + { + //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}"); + } + } } } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 82cdeaf..35c7166 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -1,6 +1,9 @@ using System; +using System.Diagnostics; using Babushka.scripts.CSharp.Common.Inventory; +using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; +using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Farming; @@ -9,7 +12,8 @@ namespace Babushka.scripts.CSharp.Common.Farming; /// public partial class PlantBehaviour2D : Node2D { - [Export] private string _prefabPath; + + [ExportGroup("Plant State")] [Export] private Sprite2D[] _seeds; [Export] private Sprite2D[] _smallPlants; [Export] private Sprite2D[] _bigPlants; @@ -19,11 +23,17 @@ public partial class PlantBehaviour2D : Node2D [Export] private ItemOnGround2D _harvestablePlant; [Export] private CpuParticles2D _magicEffect; [Export] private bool _magicWordNeeded = true; + + [ExportGroup("PlantConfig")] + [Export] private string _prefabPath; + [Export] private VariableNode _lifecycle; private string _magicWordDialogicEventName = "MagicWord"; private Sprite2D? _currentPlantSprite = null; private bool _magicWordSaid = false; private bool _calledOnReady = false; + private int _dayPlanted; + private int _currentDay; public PlantState State { @@ -31,8 +41,45 @@ public partial class PlantBehaviour2D : Node2D set => _state = value; } - public int DaysGrowing { get; set; } - + public int DayPlanted { get; set; } + + public int CurrentDayInCalendar + { + get => _currentDay; + set + { + if (_currentDay == value) return; + _currentDay = value; + DaysGrowingChanged(); + } + } + + public void IncrementDaysGrowing() + { + DayPlanted++; + } + + private void DaysGrowingChanged() + { + int _daysGrowing = _currentDay - _dayPlanted; + int lifecycle = _lifecycle.Payload.AsInt32(); + Debug.Assert(lifecycle > 0); + + float growth = (float)_daysGrowing / lifecycle; + int growthFloor = Mathf.FloorToInt(growth); + + _state = growthFloor switch + { + 0 => PlantState.Planted, + 1 => PlantState.SmallPlant, + 2 => PlantState.BigPlant, + _ => PlantState.Ready + }; + + _calledOnReady = true; + Grow(); + } + public string PrefabPath => _prefabPath; /// From 41b30a4274d7d35e55da24f8b6886c68a9789e16 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Fri, 28 Nov 2025 20:25:47 +0100 Subject: [PATCH 04/16] :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 [Signal] public delegate void LookDirectionEventHandler(Vector2 direction); - - public override void _Ready() + + public override void _EnterTree() { InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory; } + public override void _ExitTree() + { + InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory; + } + private void HandleNewItemInInventory() { // for future Kathi: this does not, in fact, check if an item has been added only, but triggers on every content change! diff --git a/scripts/CSharp/Common/Inventory/InventoryUi.cs b/scripts/CSharp/Common/Inventory/InventoryUi.cs index 690d1f5..11d9cfd 100644 --- a/scripts/CSharp/Common/Inventory/InventoryUi.cs +++ b/scripts/CSharp/Common/Inventory/InventoryUi.cs @@ -28,6 +28,7 @@ public partial class InventoryUi : Control public override void _ExitTree() { + InventoryManager.Instance.playerInventory.InventoryContentsChanged -= SetSlotContent; UnsubscribeSlots(); } diff --git a/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs b/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs index c94599c..c13f4e8 100644 --- a/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs +++ b/scripts/CSharp/Common/Inventory/ItemOnGround2D.cs @@ -11,6 +11,7 @@ public partial class ItemOnGround2D : Node, ISaveable [Export] public bool IsActive = true; [Export] private bool _infiniteSupply = false; [Export] private int _finiteSupply = 1; + [Export] private bool _saveToDisk = true; private int pickUpCounter = 0; @@ -96,6 +97,9 @@ public partial class ItemOnGround2D : Node, ISaveable // todo: What do we do with instances that are created at runtime? public void UpdateSaveData() { + if (!_saveToDisk) + return; + var payloadData = new Dictionary { {"pickupCounter", pickUpCounter} @@ -107,6 +111,9 @@ public partial class ItemOnGround2D : Node, ISaveable public void LoadFromSaveData() { + if (!_saveToDisk) + return; + if (_infiniteSupply) return; From c7a4aea70be0edd2d3b79eeb5c3ef01a5c9269a4 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 2 Dec 2025 12:08:19 +0100 Subject: [PATCH 07/16] :sparkles: Starting a new game resets the inventory now --- .../CSharp/Common/Inventory/InventoryInstance.cs | 16 +++++++++++++++- .../CSharp/Common/Savegame/SavegameService.cs | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/CSharp/Common/Inventory/InventoryInstance.cs b/scripts/CSharp/Common/Inventory/InventoryInstance.cs index a05f778..55fb944 100644 --- a/scripts/CSharp/Common/Inventory/InventoryInstance.cs +++ b/scripts/CSharp/Common/Inventory/InventoryInstance.cs @@ -50,12 +50,14 @@ public partial class InventoryInstance : Node, ISaveable LoadFromSaveData(); InventoryContentsChanged += UpdateSaveData; SlotAmountChanged += UpdateSaveData; + SavegameService.OnSaveGameReset += SaveGameReset; } - + public override void _ExitTree() { InventoryContentsChanged -= UpdateSaveData; SlotAmountChanged -= UpdateSaveData; + SavegameService.OnSaveGameReset -= SaveGameReset; } public InventoryActionResult AddItem(ItemInstance newItem) @@ -216,5 +218,17 @@ public partial class InventoryInstance : Node, ISaveable } } } + + /// + /// Called when a new save is created. + /// Needs to do a runtime check because the InventoryInstance is already in existence at the beginning of the first scene. + /// + private void SaveGameReset() + { + foreach (var slot in _slots) + { + slot.itemInstance = null; + } + } #endregion } diff --git a/scripts/CSharp/Common/Savegame/SavegameService.cs b/scripts/CSharp/Common/Savegame/SavegameService.cs index 8def82e..66f9d47 100644 --- a/scripts/CSharp/Common/Savegame/SavegameService.cs +++ b/scripts/CSharp/Common/Savegame/SavegameService.cs @@ -18,6 +18,9 @@ public static class SavegameService public static Dictionary SaveDatas = new (); public static bool _loaded = false; + + public delegate void SaveGameDelegate(); + public static event SaveGameDelegate OnSaveGameReset = delegate {}; public static void AppendDataToSave( string id, Dictionary payload) @@ -130,5 +133,6 @@ public static class SavegameService { SaveDatas = new (); Save(); + OnSaveGameReset(); } } \ No newline at end of file From e65330786e534a7d7e6e65946f78c7210c7c159e Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 2 Dec 2025 15:45:44 +0100 Subject: [PATCH 08/16] :bug: fixed dayplanted confusion on plants --- .../Common/Animation/VesnaAnimations.cs | 2 +- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 30 ++++++++++++++----- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 7 ++++- .../Variables/SaveableVariableNode.cs | 18 ++++++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/scripts/CSharp/Common/Animation/VesnaAnimations.cs b/scripts/CSharp/Common/Animation/VesnaAnimations.cs index 0a1692a..372cf9f 100644 --- a/scripts/CSharp/Common/Animation/VesnaAnimations.cs +++ b/scripts/CSharp/Common/Animation/VesnaAnimations.cs @@ -19,7 +19,7 @@ public partial class VesnaAnimations : Node /// [Signal] public delegate void LookDirectionEventHandler(Vector2 direction); - public override void _EnterTree() + public override void _Ready() { InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory; } diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index b07bd7b..46de1e1 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -74,9 +74,13 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable UpdateInteractionArea(); } - public override void _Ready() + public override void _EnterTree() { LoadFromSaveData(); + } + + public override void _Ready() + { if(PlantingPlaceholder.GetChildCount() > 0) _currentPlant = PlantingPlaceholder.GetChild(0); UpdateFieldState(FieldState); @@ -169,6 +173,16 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable } private void PlantPrefab(string prefabPath) + { + InstantiatePlant(prefabPath); + + if (_currentPlant != null) + { + _currentPlant.DayPlanted = _currentDay; + } + } + + private void InstantiatePlant(string prefabPath) { PackedScene prefab = ResourceLoader.Load(prefabPath, nameof(PackedScene)); Node2D plant2d = prefab.Instantiate(); @@ -179,7 +193,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (_currentPlant != null) { _currentPlant.Field = this; - _currentPlant.DayPlanted = _currentDay; } } @@ -234,15 +247,16 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar)) { - PlantPrefab(prefabPathVar.AsString()); + InstantiatePlant(prefabPathVar.AsString()); } else { return; } - if (plantDataDict.TryGetValue("plant_start_day", out Variant plantDaysGrowingVar) && _currentPlant != null) + if (plantDataDict.TryGetValue("plant_start_day", out Variant plantStartDay) && _currentPlant != null) { - _currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32(); + _currentPlant.DayPlanted = plantStartDay.AsInt32(); + GD.Print($"Current plant {_currentPlant.Name} was planted on day: {_currentPlant.DayPlanted}"); } } @@ -254,8 +268,10 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (dayCountSave.TryGetValue("payload", out Variant dayCountVar)) { _currentDay = dayCountVar.AsInt32(); - if(_currentPlant != null) - _currentPlant.CurrentDayInCalendar = dayCountVar.AsInt32(); + if (_currentPlant != null) + { + _currentPlant.CurrentDayInCalendar = _currentDay; + } } } } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index 5829a4d..fcba992 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -44,7 +44,11 @@ public partial class PlantBehaviour2D : Node2D /// /// The day count at the day this plant was planted. /// - public int DayPlanted { get; set; } + public int DayPlanted + { + get => _dayPlanted; + set => _dayPlanted = value; + } public int CurrentDayInCalendar { @@ -65,6 +69,7 @@ public partial class PlantBehaviour2D : Node2D private void DaysGrowingChanged() { int _daysGrowing = _currentDay - _dayPlanted; + GD.Print($"Plant {Name} is growing for {_daysGrowing}. Day Planted was {_dayPlanted} and the current day is {_currentDay}."); int lifecycle = _lifecycle.Payload.AsInt32(); Debug.Assert(lifecycle > 0); diff --git a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs index c7f5389..56d7628 100644 --- a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs +++ b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs @@ -1,3 +1,4 @@ +using Babushka.scripts.CSharp.Common.Inventory; using Babushka.scripts.CSharp.Common.Savegame; using Godot; using Godot.Collections; @@ -6,15 +7,25 @@ namespace Babushka.scripts.CSharp.Low_Code.Variables; public partial class SaveableVariableNode : VariableNode, ISaveable { - public override void _Ready() + [Export] private bool _debug; + + public override void _EnterTree() { LoadFromSaveData(); ValueChanged += UpdateSaveData; + SavegameService.OnSaveGameReset += SaveGameReset; + } + + private void SaveGameReset() + { + Payload = default; + GD.Print($"Saveable Variable reset to {Payload}"); } public override void _ExitTree() { ValueChanged -= UpdateSaveData; + SavegameService.OnSaveGameReset -= SaveGameReset; } public void UpdateSaveData() @@ -43,6 +54,11 @@ public partial class SaveableVariableNode : VariableNode, ISaveable { Payload = save["payload"]; } + + if (_debug) + { + GD.Print($"SaveableVariable {Name} loaded payload: {Payload}."); + } } } } \ No newline at end of file From c288af296c69652cc7ea5fd546e489256075031f Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 2 Dec 2025 17:44:44 +0100 Subject: [PATCH 09/16] :sparkles: made plants only grow when watered --- scenes/Babushka_scene_farm_outside_2d.tscn | 1 + .../CSharp/Common/Farming/FieldBehaviour2D.cs | 70 ++++++++++++++----- .../CSharp/Common/Farming/PlantBehaviour2D.cs | 53 ++++++++------ 3 files changed, 84 insertions(+), 40 deletions(-) diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index cb14ed0..cb2e181 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1061,6 +1061,7 @@ position = Vector2(145.5, -224) shape = SubResource("RectangleShape2D_0sfl7") [node name="InteractionArea" parent="YSorted/Well" instance=ExtResource("27_klb81")] +_id = 1 metadata/SaveID = "b8f7b7fe-e057-4974-ba12-9134722998de" [node name="CollisionShape3D" parent="YSorted/Well/InteractionArea/Area2D" index="0"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 46de1e1..832fc2b 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -59,6 +59,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable _canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive; // fieldstate == tilled && watering can ausgewählt _canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive; + FieldInteractionArea.IsActive = _canPlant || _canWater; } @@ -91,7 +92,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable base._Ready(); } - public void UpdateFieldState(FieldState state) + public void UpdateFieldState(FieldState state, bool updateSaveAfter = true) { switch (state) { @@ -119,18 +120,25 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable break; } UpdateInteractionArea(); - UpdateSaveData(); + if(updateSaveAfter) + UpdateSaveData(); } public void Water() { - if (WateringCanState.GetFillState() > 0) + if (WateringCanState.GetFillState() > 0 && FieldState != FieldState.Watered) { UpdateFieldState(FieldState.Watered); _wateringParticles.Emitting = true; WateringCanState.Water(); _wateringEvent.Raise(); + + if (_currentPlant != null) + { + _currentPlant.DaysWatered++; + UpdateSaveData(); + } } } @@ -198,6 +206,9 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable #region SAVE AND LOAD + /// + /// Update save data as prep for scene transition (when data is saved and loaded from disk). + /// public void UpdateSaveData() { var payloadData = new Dictionary @@ -211,7 +222,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable "plant_data", new Dictionary() { { "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); } + /// + /// Loads on scene enter. + /// public void LoadFromSaveData() { // Get field and plant data @@ -229,18 +244,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (save.Count > 0) { - if (save.TryGetValue("field_state", out Variant fieldStateVar)) - { - int fieldStateInt = fieldStateVar.AsInt32(); - FieldState = (FieldState) fieldStateInt; - - if (fieldStateInt != 0) - { - Visible = true; - UpdateFieldState(FieldState); - } - } - + // get plant first because it's also relevant for the field state if (save.TryGetValue("plant_data", out Variant plantDataVar)) { Dictionary plantDataDict = plantDataVar.AsGodotDictionary(); @@ -256,7 +260,39 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable if (plantDataDict.TryGetValue("plant_start_day", out Variant plantStartDay) && _currentPlant != null) { _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); + } } } diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index fcba992..f28e87e 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -34,6 +34,7 @@ public partial class PlantBehaviour2D : Node2D private bool _calledOnReady = false; private int _dayPlanted; private int _currentDay; + private int _daysWatered; public PlantState State { @@ -66,28 +67,6 @@ public partial class PlantBehaviour2D : Node2D DayPlanted++; } - private void DaysGrowingChanged() - { - int _daysGrowing = _currentDay - _dayPlanted; - GD.Print($"Plant {Name} is growing for {_daysGrowing}. Day Planted was {_dayPlanted} and the current day is {_currentDay}."); - int lifecycle = _lifecycle.Payload.AsInt32(); - Debug.Assert(lifecycle > 0); - - float growth = (float)_daysGrowing / lifecycle; - int growthFloor = Mathf.FloorToInt(growth); - - _state = growthFloor switch - { - 0 => PlantState.None, - 1 => PlantState.Planted, - 2 => PlantState.SmallPlant, - _ => PlantState.BigPlant - }; - - _calledOnReady = true; - Grow(); - } - public string PrefabPath => _prefabPath; /// @@ -99,6 +78,15 @@ public partial class PlantBehaviour2D : Node2D set => _field = value; } + public int DaysWatered + { + get => _daysWatered; + set + { + _daysWatered = value; + } + } + public override void _Ready() { if (_state == PlantState.None) @@ -113,13 +101,32 @@ public partial class PlantBehaviour2D : Node2D GrowPlant(); } } + + private void DaysGrowingChanged() + { + int lifecycle = _lifecycle.Payload.AsInt32(); + Debug.Assert(lifecycle > 0); + + float growth = (float)_daysWatered / lifecycle; + int growthFloor = Mathf.FloorToInt(growth); + + _state = growthFloor switch + { + 0 => PlantState.None, + 1 => PlantState.Planted, + 2 => PlantState.SmallPlant, + _ => PlantState.BigPlant + }; + + _calledOnReady = true; + Grow(); + } public void Grow() { GrowPlant(); } - /// /// Transitions the plant to its next growth stage. /// From 0ecae5a4d9037dbbc7d70b1106438861989c0700 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 3 Dec 2025 17:04:38 +0100 Subject: [PATCH 10/16] :sparkles: watering can fillstate is saving and loading --- prefabs/characters/Vesna.tscn | 78 +++++++++++++------ .../Common/Farming/FarmingControls2D.cs | 2 - .../Common/Farming/WateringCanSaveHelper.cs | 33 ++++++++ .../Farming/WateringCanSaveHelper.cs.uid | 1 + .../CSharp/Common/Farming/WateringCanState.cs | 11 +++ .../Variables/SaveableVariableNode.cs | 6 +- 6 files changed, 103 insertions(+), 28 deletions(-) create mode 100644 scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs create mode 100644 scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs.uid diff --git a/prefabs/characters/Vesna.tscn b/prefabs/characters/Vesna.tscn index cff4237..b8070d8 100644 --- a/prefabs/characters/Vesna.tscn +++ b/prefabs/characters/Vesna.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=485 format=3 uid="uid://c25udixd5m6l0"] +[gd_scene load_steps=489 format=3 uid="uid://c25udixd5m6l0"] [ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"] [ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"] @@ -283,6 +283,7 @@ [ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="471_83c4i"] [ext_resource type="AudioStream" uid="uid://fihv17va3r58" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_02_R.wav" id="471_e04c3"] [ext_resource type="AudioStream" uid="uid://cvvjd2i6x047n" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_03_R.wav" id="472_g32y8"] +[ext_resource type="Script" uid="uid://dj1qjambsa4pg" path="res://scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs" id="472_kduih"] [ext_resource type="Texture2D" uid="uid://blh0t2ofqj2uq" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0016.png" id="472_wdxsr"] [ext_resource type="AudioStream" uid="uid://dymoalptxmge" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_04_R.wav" id="473_8hbu5"] [ext_resource type="AudioStream" uid="uid://4555a4w30tda" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_05_R.wav" id="474_t1d6r"] @@ -294,8 +295,11 @@ [ext_resource type="Texture2D" uid="uid://dqubvx1a08kn4" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0002.png" id="478_5myrm"] [ext_resource type="Texture2D" uid="uid://dystt4hyqad74" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0004.png" id="480_wnay3"] [ext_resource type="Resource" uid="uid://cmqapbvv0hev2" path="res://resources/low code/farming/event_watering.tres" id="481_t1d6r"] +[ext_resource type="Script" uid="uid://d27xoo1reo5gu" path="res://scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs" id="482_0ptfk"] [ext_resource type="Texture2D" uid="uid://bopxv06co1osl" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0006.png" id="482_wfdif"] +[ext_resource type="Script" uid="uid://iquhbkr7pqeg" path="res://scripts/CSharp/Common/Savegame/SaveCheats.cs" id="483_kduih"] [ext_resource type="Texture2D" uid="uid://coyggdfwgkeru" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0008.png" id="484_32thn"] +[ext_resource type="Script" uid="uid://ca4s0algeij1h" path="res://scripts/CSharp/Common/Savegame/SaveIDProviderTool.cs" id="484_upuan"] [ext_resource type="Texture2D" uid="uid://du6x1h42smp6m" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0010.png" id="486_kobao"] [ext_resource type="Texture2D" uid="uid://bras5gn8ov27l" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0012.png" id="488_ygjj5"] [ext_resource type="Texture2D" uid="uid://rjmsht4g8dvp" path="res://art/animation/Vesna2D/Vesna Anims Sequences/F02-Walk/0014.png" id="490_6603x"] @@ -2119,38 +2123,57 @@ frame = 7 frame_progress = 0.229832 offset = Vector2(0, -450) -[node name="WateringCanUI" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_slider")] -position = Vector2(0, -929) +[node name="DetectionCross" parent="CharacterBody2D" instance=ExtResource("466_e04c3")] +position = Vector2(0, -200) + +[node name="PlantCreatedEventListener" type="Node" parent="CharacterBody2D"] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("468_t1d6r")]) + +[node name="PickedUpInteractableListener" type="Node" parent="CharacterBody2D"] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("469_t1d6r")]) + +[node name="WateringCan" type="Node2D" parent="CharacterBody2D"] + +[node name="WateringCanFillState" type="Node" parent="CharacterBody2D/WateringCan" groups=["Saveable"]] +script = ExtResource("482_0ptfk") +Payload = 0 +metadata/SaveID = "2d2f153b-8a09-45a9-b114-79259c833f9f" + +[node name="WateringEventListener" type="Node" parent="CharacterBody2D/WateringCan"] +script = ExtResource("467_8hbu5") +_eventResources = Array[Object]([ExtResource("481_t1d6r")]) + +[node name="WateringCanUI" type="Node2D" parent="CharacterBody2D/WateringCan" node_paths=PackedStringArray("_slider")] +position = Vector2(0, -939) scale = Vector2(2, 2) script = ExtResource("467_j4m0f") _slider = NodePath("HSlider") -[node name="HSlider" type="HSlider" parent="CharacterBody2D/WateringCanUI"] +[node name="HSlider" type="HSlider" parent="CharacterBody2D/WateringCan/WateringCanUI"] visible = false modulate = Color(0.3515, 0.780425, 0.95, 1) custom_minimum_size = Vector2(150, 50) anchors_preset = 5 anchor_left = 0.5 anchor_right = 0.5 -offset_left = -43.0 -offset_right = 57.0 -offset_bottom = 64.0 +offset_left = -115.0 +offset_top = -33.999996 +offset_right = 35.0 +offset_bottom = 30.000004 grow_horizontal = 2 +scale = Vector2(1.4200003, 2.5611823) +size_flags_horizontal = 3 +size_flags_vertical = 2 max_value = 1.0 step = 0.0 editable = false scrollable = false -[node name="DetectionCross" parent="CharacterBody2D" instance=ExtResource("466_e04c3")] -position = Vector2(0, -200) - -[node name="PlantCreatedEventListener" type="Node" parent="CharacterBody2D"] -script = ExtResource("467_8hbu5") -_eventResources = Array[Object]([ExtResource("468_t1d6r")]) - -[node name="PickedUpInteractableListener" type="Node" parent="CharacterBody2D"] -script = ExtResource("467_8hbu5") -_eventResources = Array[Object]([ExtResource("469_t1d6r")]) +[node name="WateringCanSaveHelper" type="Node" parent="CharacterBody2D/WateringCan" node_paths=PackedStringArray("_wateringCanFillStateNode")] +script = ExtResource("472_kduih") +_wateringCanFillStateNode = NodePath("../WateringCanFillState") [node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer")] script = ExtResource("817_6nrw3") @@ -2174,18 +2197,23 @@ script = ExtResource("471_2f15g") [node name="Timer" type="Timer" parent="SFX/FootstepsAudio"] wait_time = 0.5 -[node name="WateringEventListener" type="Node" parent="."] -script = ExtResource("467_8hbu5") -_eventResources = Array[Object]([ExtResource("481_t1d6r")]) +[node name="SaveSystem" type="Node" parent="."] + +[node name="SaveGameCheat" type="Node" parent="SaveSystem"] +script = ExtResource("483_kduih") + +[node name="SaveIDProvider" type="Node" parent="SaveSystem"] +script = ExtResource("484_upuan") -[connection signal="FilledWateringCan" from="." to="CharacterBody2D/WateringCanUI" method="Refill"] -[connection signal="InventorySelectionChanged" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] +[connection signal="FilledWateringCan" from="." to="CharacterBody2D/WateringCan/WateringCanUI" method="Refill"] +[connection signal="InventorySelectionChanged" from="." to="CharacterBody2D/WateringCan/WateringCanUI" method="IsWateringCanActive"] [connection signal="PickedUpTool" from="." to="CharacterBody2D/visuals" method="ActivateTool"] -[connection signal="PickedUpTool" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] +[connection signal="PickedUpTool" from="." to="CharacterBody2D/WateringCan/WateringCanUI" method="IsWateringCanActive"] [connection signal="LookDirection" from="CharacterBody2D/visuals" to="CharacterBody2D/DetectionCross" method="SetDirection"] [connection signal="EventRaised" from="CharacterBody2D/PlantCreatedEventListener" to="CharacterBody2D/visuals" method="PlayFarmingAnimation"] [connection signal="EventRaised" from="CharacterBody2D/PickedUpInteractableListener" to="CharacterBody2D/visuals" method="PlayPickUpAnimation"] +[connection signal="OnLoadingComplete" from="CharacterBody2D/WateringCan/WateringCanFillState" to="CharacterBody2D/WateringCan/WateringCanSaveHelper" method="OnLoad"] +[connection signal="EventRaised" from="CharacterBody2D/WateringCan/WateringEventListener" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] +[connection signal="EventRaised" from="CharacterBody2D/WateringCan/WateringEventListener" to="CharacterBody2D/WateringCan/WateringCanUI" method="Water"] [connection signal="timelineStarted" from="DialogicToggle" to="SFX/FootstepsAudio/Timer" method="stop"] [connection signal="timeout" from="SFX/FootstepsAudio/Timer" to="SFX/FootstepsAudio" method="PlayOneShot"] -[connection signal="EventRaised" from="WateringEventListener" to="CharacterBody2D/visuals" method="PlayWateringAnimation"] -[connection signal="EventRaised" from="WateringEventListener" to="CharacterBody2D/WateringCanUI" method="Water"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 10014e5..163f07e 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -1,7 +1,5 @@ -using System; using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; -using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Farming; diff --git a/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs b/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs new file mode 100644 index 0000000..0086a57 --- /dev/null +++ b/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs @@ -0,0 +1,33 @@ +using Babushka.scripts.CSharp.Low_Code.Variables; +using Godot; + +namespace Babushka.scripts.CSharp.Common.Farming; + +public partial class WateringCanSaveHelper : Node +{ + [Export] private SaveableVariableNode _wateringCanFillStateNode; + + public override void _EnterTree() + { + WateringCanState.OnFill += SetFillState; + WateringCanState.OnWater += SetFillState; + } + + public override void _ExitTree() + { + WateringCanState.OnFill -= SetFillState; + WateringCanState.OnWater -= SetFillState; + } + + + public void SetFillState() + { + _wateringCanFillStateNode.Payload = WateringCanState.GetFillState(); + } + + private void OnLoad() + { + WateringCanState.SetFillState(_wateringCanFillStateNode.Payload.AsInt32()); + } + +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs.uid b/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs.uid new file mode 100644 index 0000000..da908bc --- /dev/null +++ b/scripts/CSharp/Common/Farming/WateringCanSaveHelper.cs.uid @@ -0,0 +1 @@ +uid://dj1qjambsa4pg diff --git a/scripts/CSharp/Common/Farming/WateringCanState.cs b/scripts/CSharp/Common/Farming/WateringCanState.cs index cc6bdaf..359ee6f 100644 --- a/scripts/CSharp/Common/Farming/WateringCanState.cs +++ b/scripts/CSharp/Common/Farming/WateringCanState.cs @@ -29,6 +29,7 @@ public static class WateringCanState public delegate void WateringCanDelegate(bool state); public static event WateringCanDelegate WateringCanActiveStateChanged; public static event Action? OnWater; + public static event Action? OnFill; @@ -38,6 +39,7 @@ public static class WateringCanState public static void Fill() { _fillstate = MAX_FILLSTATE; + OnFill?.Invoke(); } /// @@ -69,6 +71,15 @@ public static class WateringCanState return _fillstate; } + /// + /// Public setter. Used for saving and loading. + /// + /// + public static void SetFillState(int fillstate) + { + _fillstate = fillstate; + } + /// /// Sets the Active state of the watering can, i.e. if it is currently in hand and if the ui should be active. /// diff --git a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs index 56d7628..4836f63 100644 --- a/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs +++ b/scripts/CSharp/Low Code/Variables/SaveableVariableNode.cs @@ -1,4 +1,3 @@ -using Babushka.scripts.CSharp.Common.Inventory; using Babushka.scripts.CSharp.Common.Savegame; using Godot; using Godot.Collections; @@ -9,6 +8,9 @@ public partial class SaveableVariableNode : VariableNode, ISaveable { [Export] private bool _debug; + [Signal] + public delegate void OnLoadingCompleteEventHandler(); + public override void _EnterTree() { LoadFromSaveData(); @@ -60,5 +62,7 @@ public partial class SaveableVariableNode : VariableNode, ISaveable GD.Print($"SaveableVariable {Name} loaded payload: {Payload}."); } } + + EmitSignal(SignalName.OnLoadingComplete); } } \ No newline at end of file From b9a52dadccf8355d6bed18d57c4d0e274caa9680 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 3 Dec 2025 17:56:45 +0100 Subject: [PATCH 11/16] :sparkles: fields can now seperate "today" from any other day --- .../Common/DayAndNight/CalendarController.cs | 20 ++++++ .../CSharp/Common/Farming/FieldBehaviour2D.cs | 70 +++++++++++-------- 2 files changed, 60 insertions(+), 30 deletions(-) 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 From 8407ce4c1fe1563fcc214867ffd55c69aa7685ba Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 3 Dec 2025 18:18:54 +0100 Subject: [PATCH 12/16] :sparkles: Added Tab button mapping to inventory and fixed label descriptor --- prefabs/UI/Inventory/Inventory.tscn | 2 +- project.godot | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index 7a6d4da..87a6ea2 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -472,7 +472,7 @@ offset_right = 54.4142 offset_bottom = 207.286 grow_horizontal = 0 grow_vertical = 2 -text = "[I]" +text = "[i]" label_settings = SubResource("LabelSettings_l3npx") [node name="QuestLogRoot" parent="." instance=ExtResource("7_vvo7l")] diff --git a/project.godot b/project.godot index ceadb3e..75df3a1 100644 --- a/project.godot +++ b/project.godot @@ -269,6 +269,7 @@ interact={ ui_inventory_open_close={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } ui_inventory_advance={ From 229dd04bc1acb15291a03e52dc5d518717c19905 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 3 Dec 2025 18:55:45 +0100 Subject: [PATCH 13/16] :sparkles: Made bed interaction count up the days and verified that you can now play a full loop --- scenes/Babushka_scene_farm_outside_2d.tscn | 1 + scenes/Babushka_scene_indoor_common_room.tscn | 2 +- scenes/Babushka_scene_indoor_vesnas_room.tscn | 7 ++++++- .../CSharp/Common/DayAndNight/CalendarController.cs | 12 ++++++++---- .../CSharp/Common/DayAndNight/DayAndNightHelper.cs | 11 +++++++++++ .../Common/DayAndNight/DayAndNightHelper.cs.uid | 1 + 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs create mode 100644 scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs.uid diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index cb2e181..09d13c0 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1296,6 +1296,7 @@ polygon = PackedVector2Array(247.227, 43.5123, 44.7822, 43.5123, -87.2178, 45.12 [node name="EnterHouseInteraction" parent="YSorted/Farm visuals/Static" instance=ExtResource("27_klb81")] position = Vector2(5834, 2354) scale = Vector2(2.425, 2.425) +_id = 0 metadata/SaveID = "5a93071f-c1ab-4b4b-b74e-a6324d44ddf8" [node name="DoorSprite" type="Sprite2D" parent="YSorted/Farm visuals/Static/EnterHouseInteraction"] diff --git a/scenes/Babushka_scene_indoor_common_room.tscn b/scenes/Babushka_scene_indoor_common_room.tscn index a795518..b494ae5 100644 --- a/scenes/Babushka_scene_indoor_common_room.tscn +++ b/scenes/Babushka_scene_indoor_common_room.tscn @@ -218,7 +218,7 @@ radius = 400.0 z_index = 1 y_sort_enabled = true script = ExtResource("1_3vr4f") -_sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_indoor_vesnas_room.tscn", "res://scenes/Babushka_scene_farm_outside_2d_ducksCollected.tscn") +_sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_indoor_vesnas_room.tscn", "res://scenes/Babushka_scene_farm_outside_2d.tscn") [node name="Foreground" type="Node" parent="."] diff --git a/scenes/Babushka_scene_indoor_vesnas_room.tscn b/scenes/Babushka_scene_indoor_vesnas_room.tscn index 1e3b2cc..ebae355 100644 --- a/scenes/Babushka_scene_indoor_vesnas_room.tscn +++ b/scenes/Babushka_scene_indoor_vesnas_room.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://ceaa2qj2bmw43"] +[gd_scene load_steps=16 format=3 uid="uid://ceaa2qj2bmw43"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_c6eln"] [ext_resource type="Texture2D" uid="uid://cugtxcfuds31r" path="res://art/indoor/Babushka_bg_01.png" id="2_j25a2"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="8_phqdf"] [ext_resource type="Resource" uid="uid://csj15gnlx1jmx" path="res://resources/quests/demo/8_goto_bed.tres" id="9_heyef"] [ext_resource type="Script" uid="uid://puw74w6lmcvl" path="res://scripts/CSharp/Common/Fight/NightStarter.cs" id="10_j25a2"] +[ext_resource type="Script" uid="uid://jg4jryfus3bw" path="res://scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs" id="11_heyef"] [ext_resource type="Texture2D" uid="uid://cop1vjvhwlsec" path="res://art/indoor/room export/Room_01_shelf.png" id="13_11fdt"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Vesna.tscn" id="18_3gevq"] [ext_resource type="Script" uid="uid://bqomwxclsbhd3" path="res://scripts/CSharp/Common/Camera/CameraController.cs" id="23_408bg"] @@ -125,8 +126,12 @@ shape = SubResource("CircleShape2D_2spkc") script = ExtResource("10_j25a2") _sceneIndexToLoad = 1 +[node name="CountDayUp" type="Node" parent="NightStarter"] +script = ExtResource("11_heyef") + [connection signal="Interacted" from="BedInteraction" to="BedInteraction/QuestCompleter" method="Trigger"] [connection signal="Interacted" from="BedInteraction" to="NightStarter" method="StartNight"] +[connection signal="Interacted" from="BedInteraction" to="NightStarter/CountDayUp" method="IncreaseDayCount"] [connection signal="Interacted" from="DoorInteraction" to="." method="LoadScene"] [connection signal="LoadScene" from="NightStarter" to="." method="LoadSceneAtIndex"] diff --git a/scripts/CSharp/Common/DayAndNight/CalendarController.cs b/scripts/CSharp/Common/DayAndNight/CalendarController.cs index fed5dde..878ff02 100644 --- a/scripts/CSharp/Common/DayAndNight/CalendarController.cs +++ b/scripts/CSharp/Common/DayAndNight/CalendarController.cs @@ -31,10 +31,14 @@ public partial class CalendarController : Node { if (@event.IsActionPressed("NextDayCheat")) { - int days = _dayCounter.Payload.AsInt32(); - days++; - _dayCounter.Payload = days; - + GoToNextDay(); } } + + public void GoToNextDay() + { + int days = _dayCounter.Payload.AsInt32(); + days++; + _dayCounter.Payload = days; + } } \ No newline at end of file diff --git a/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs b/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs new file mode 100644 index 0000000..a51b4ee --- /dev/null +++ b/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs @@ -0,0 +1,11 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.DayAndNight; + +public partial class DayAndNightHelper : Node +{ + public void IncreaseDayCount() + { + CalendarController.Instance?.GoToNextDay(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs.uid b/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs.uid new file mode 100644 index 0000000..7b924fa --- /dev/null +++ b/scripts/CSharp/Common/DayAndNight/DayAndNightHelper.cs.uid @@ -0,0 +1 @@ +uid://jg4jryfus3bw From 1c865730a3ebf514218ba414d6a12f6fe898f10a Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Thu, 4 Dec 2025 22:05:33 +0100 Subject: [PATCH 14/16] :truck: renamed directory --- prefabs/{day and night => day_and_night}/day_and_night.tscn | 0 project.godot | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename prefabs/{day and night => day_and_night}/day_and_night.tscn (100%) diff --git a/prefabs/day and night/day_and_night.tscn b/prefabs/day_and_night/day_and_night.tscn similarity index 100% rename from prefabs/day and night/day_and_night.tscn rename to prefabs/day_and_night/day_and_night.tscn diff --git a/project.godot b/project.godot index 75df3a1..66ef019 100644 --- a/project.godot +++ b/project.godot @@ -34,7 +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" +DayAndNight="*res://prefabs/day_and_night/day_and_night.tscn" [dialogic] From 9f4cda0e6dac9c5628f0f6c14c23b4bd81b4eb44 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Thu, 4 Dec 2025 22:22:40 +0100 Subject: [PATCH 15/16] :recycle: Replaced _ready mit _entertree (while deferring) --- scripts/CSharp/Common/Animation/VesnaAnimations.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/CSharp/Common/Animation/VesnaAnimations.cs b/scripts/CSharp/Common/Animation/VesnaAnimations.cs index 372cf9f..f883252 100644 --- a/scripts/CSharp/Common/Animation/VesnaAnimations.cs +++ b/scripts/CSharp/Common/Animation/VesnaAnimations.cs @@ -19,7 +19,13 @@ public partial class VesnaAnimations : Node /// [Signal] public delegate void LookDirectionEventHandler(Vector2 direction); - public override void _Ready() + public override void _EnterTree() + { + // calling with a 1-frame delay to avoid race conditions. + CallDeferred(nameof(SetupSubscriptions)); + } + + private void SetupSubscriptions() { InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory; } From 9b8933e6982a43bb234a97c50e43df97a72a9a1d Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Thu, 4 Dec 2025 22:33:45 +0100 Subject: [PATCH 16/16] :recycle: removed no longer used method --- scripts/CSharp/Common/Farming/PlantBehaviour2D.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs index f28e87e..3b88dd9 100644 --- a/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/PlantBehaviour2D.cs @@ -62,11 +62,6 @@ public partial class PlantBehaviour2D : Node2D } } - public void IncrementDaysGrowing() - { - DayPlanted++; - } - public string PrefabPath => _prefabPath; ///