44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
#nullable enable
|
|
|
|
using System.IO;
|
|
using Cysharp.Threading.Tasks;
|
|
using ShrinkSDK.Runtime;
|
|
|
|
namespace ShrinkDataSaver;
|
|
|
|
public sealed class ShrinkDataSaverRuntimeConfig
|
|
{
|
|
public string? RootPath { get; set; }
|
|
public string SaveFileExtension { get; set; } = ".sav";
|
|
public string SettingsFileName { get; set; } = "settings.json";
|
|
public int CurrentSaveVersion { get; set; } = 1;
|
|
public int MaxSlots { get; set; } = 3;
|
|
public float SettingsWriteDebounceSeconds { get; set; } = 0.35f;
|
|
public bool DontDestroyOnLoadDriver { get; set; }
|
|
}
|
|
|
|
public static class ShrinkDataSaverRuntime
|
|
{
|
|
public static bool IsInitialized { get; private set; }
|
|
|
|
public static void Initialize(ShrinkDataSaverRuntimeConfig? config = null)
|
|
{
|
|
if (IsInitialized) return;
|
|
config ??= new ShrinkDataSaverRuntimeConfig();
|
|
var root = string.IsNullOrWhiteSpace(config.RootPath)
|
|
? ShrinkRuntimeServices.Paths.PersistentDataPath
|
|
: config.RootPath!;
|
|
Directory.CreateDirectory(root);
|
|
var storage = new LocalStorageProvider(root);
|
|
ShrinkDataSaverPlatform.SettingsWriteDebounceSeconds = config.SettingsWriteDebounceSeconds;
|
|
ShrinkDataSaverPlatform.MaxSlots = config.MaxSlots;
|
|
ShrinkSettings.Initialize(storage, Path.Combine(root, config.SettingsFileName));
|
|
ShrinkSave.Initialize(storage, Path.Combine(root, "saves"), config.SaveFileExtension,
|
|
config.CurrentSaveVersion);
|
|
ShrinkSettings.LoadAsync().Forget();
|
|
IsInitialized = true;
|
|
ShrinkRuntimeServices.Logger.Log(ShrinkLogLevel.Information,
|
|
$"[ShrinkDataSaver] Runtime initialized. Root: {root}");
|
|
}
|
|
}
|