🚧 saving of field parameters as json implemented

This commit is contained in:
2025-11-12 18:46:30 +01:00
parent 5cc65bc3f4
commit 3fcb34c04d
17 changed files with 192 additions and 46 deletions
@@ -0,0 +1,34 @@
using Godot;
using Godot.Collections;
using FileAccess = Godot.FileAccess;
namespace Babushka.scripts.CSharp.Common.Savegame;
public static class SavegameService
{
public static readonly string SavePath = "res://savegame/savegame.json";
public static Dictionary<string, Variant> SaveDatas = new ();
public static void AppendSave(SaveData saveData)
{
string key = string.Concat(saveData.SceneName, "_", saveData.Id);
if (SaveDatas.TryGetValue(key, out var value))
{
SaveDatas[key] = saveData.JsonPayload;
}
else
{
SaveDatas.Add(key, saveData.JsonPayload);
}
}
public static void Save()
{
string json = Json.Stringify(SaveDatas, indent: "\t");
using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write);
file.StoreString(json);
GD.Print($"Game saved to {file}");
}
}