You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Savegame/SavegameService.cs

34 lines
926 B

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