| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections.Generic;
- namespace DevilLink2.Persistence
- {
- // Only durable player data belongs here. No board or run state.
- public sealed class SaveData
- {
- public const int CurrentVersion = 4;
- public string Nickname { get; set; } = Gameplay.PlayerProfile.DefaultNickname;
- public string Avatar { get; set; } = Gameplay.PlayerProfile.DefaultAvatar;
- public int SchemaVersion { get; set; } = CurrentVersion;
- public long Coins { get; set; } = 2000;
- public long SpinTickets { get; set; }
- public int ClassicProgress { get; set; }
- public int TimeAttackProgress { get; set; }
- public int ZenProgress { get; set; }
- public int HintCount { get; set; } = 1;
- public int ShuffleCount { get; set; } = 1;
- public int TimeCount { get; set; }
- public List<CoinTransactionData> CoinLedger { get; set; } = new List<CoinTransactionData>();
- // Compact receipts outlive the 200 visible ledger records, preventing replay after restart.
- public List<Guid> ProcessedTransactionIds { get; set; } = new List<Guid>();
- public int NextCheckInDay { get; set; } = 1;
- public string LastCheckInDateUtc { get; set; }
- public string LastFreeSpinDateUtc { get; set; }
- public List<RewardOperationData> RewardOperations { get; set; } = new List<RewardOperationData>();
- public SaveData Copy()
- {
- var data = (SaveData)MemberwiseClone();
- data.CoinLedger = CoinLedger == null ? new List<CoinTransactionData>() : CoinLedger.ConvertAll(t => t?.Copy());
- data.ProcessedTransactionIds = ProcessedTransactionIds == null ? new List<Guid>() : new List<Guid>(ProcessedTransactionIds);
- data.RewardOperations = RewardOperations == null ? new List<RewardOperationData>() : RewardOperations.ConvertAll(t => t?.Copy());
- return data;
- }
- }
- public sealed class RewardOperationData
- {
- public Guid Id { get; set; }
- public int Kind { get; set; }
- public int Number { get; set; }
- public DateTimeOffset TimestampUtc { get; set; }
- public bool UsedTicket { get; set; }
- public long RemainingTicketsAfter { get; set; }
- public RewardOperationData Copy() => (RewardOperationData)MemberwiseClone();
- }
- public sealed class CoinTransactionData
- {
- public Guid Id { get; set; }
- public long Delta { get; set; }
- public int Category { get; set; }
- public DateTimeOffset TimestampUtc { get; set; }
- public string Description { get; set; }
- public CoinTransactionData Copy() => (CoinTransactionData)MemberwiseClone();
- }
- public sealed class UnsupportedSaveVersionException : Exception
- {
- public UnsupportedSaveVersionException(string version) : base("Unsupported save schema: " + version + ". Files were not overwritten.") { }
- }
- public sealed class SaveFormatException : Exception
- {
- public SaveFormatException(string message, Exception inner = null) : base(message, inner) { }
- }
- public sealed class DecodedSave
- {
- public SaveData Data { get; }
- public bool NeedsRewrite { get; }
- public DecodedSave(SaveData data, bool needsRewrite) { Data = data; NeedsRewrite = needsRewrite; }
- }
- public enum SaveLoadSource { Primary, Backup, Defaults }
- public sealed class SaveLoadResult
- {
- public SaveData Data { get; }
- public SaveLoadSource Source { get; }
- public bool WasRewritten { get; }
- public SaveLoadResult(SaveData data, SaveLoadSource source, bool rewritten)
- { Data = data; Source = source; WasRewritten = rewritten; }
- }
- }
|