using System; using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace ShrinkDataSaver { [Serializable] public class SaveMeta { public int SlotIndex { get; set; } public string SlotName { get; set; } = "New Save"; public int SaveVersion { get; set; } = 1; public long LastModified { get; set; } public float PlaytimeSeconds { get; set; } public string ScreenshotBase64 { get; set; } public bool IsEncrypted { get; set; } [JsonIgnore] public DateTime LastModifiedTime => DateTimeOffset.FromUnixTimeSeconds(LastModified).LocalDateTime; } [Serializable] internal class SavePacket { public SaveMeta Meta { get; set; } public Dictionary Modules { get; set; } = new(); public string EncryptedModules { get; set; } } public interface ISaveModule { string Key { get; } object SerializeRaw(); void DeserializeRaw(JToken data); } public interface ISaveModule : ISaveModule { T Serialize(); void Deserialize(T data); object ISaveModule.SerializeRaw() => Serialize(); void ISaveModule.DeserializeRaw(JToken data) => Deserialize(data.ToObject()); } internal class LambdaSaveModule : ISaveModule { public string Key { get; } private readonly Func _serialize; private readonly Action _deserialize; public LambdaSaveModule(string key, Func serialize, Action deserialize) { Key = key; _serialize = serialize; _deserialize = deserialize; } public T Serialize() => _serialize(); public void Deserialize(T data) => _deserialize(data); } public class SaveOptions { public string SlotName = "New Save"; public bool CaptureScreenshot = false; #if UNITY_5_3_OR_NEWER public UnityEngine.Texture2D Screenshot = null; #else public byte[] Screenshot; #endif public bool Encrypt = false; public string EncryptionKey = null; } public class ModuleConfig { /// 是否参与云存档同步(设置模块应设为 false) public bool EnableCloudSync { get; set; } = true; /// 自动保存间隔(秒),0 表示不自动保存 public float AutoSaveIntervalSeconds { get; set; } = 0f; /// 是否为关键模块(关键模块序列化失败将中止整个保存操作) public bool CriticalModule { get; set; } = false; } public class SaveStartedEventArgs { public int SlotIndex { get; set; } public long Timestamp { get; set; } } public class SaveCompletedEventArgs { public int SlotIndex { get; set; } public string[] ModuleNames { get; set; } public long Timestamp { get; set; } } public class SaveFailedEventArgs { public int SlotIndex { get; set; } public string ErrorMessage { get; set; } } public class LoadStartedEventArgs { public int SlotIndex { get; set; } public long Timestamp { get; set; } } public class LoadCompletedEventArgs { public int SlotIndex { get; set; } public string[] ModuleNames { get; set; } public int Version { get; set; } public long Timestamp { get; set; } } public class LoadFailedEventArgs { public int SlotIndex { get; set; } public string ErrorMessage { get; set; } } public class MigrationCompletedEventArgs { public int SlotIndex { get; set; } public int FromVersion { get; set; } public int ToVersion { get; set; } } public class SlotDeletedEventArgs { public int SlotIndex { get; set; } } }