From 684131f49510820cb8eec9de9dc3d06ad78c36ba Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 26 Nov 2025 18:00:45 +0100 Subject: [PATCH] :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