🚧 saving of field parameters as json implemented
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user