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 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}"); } }