using System.Collections.Generic; using UnityEngine; public static class RecentPlayHistoryStore { private const string Category = "recent_play_history"; private const string Key = "runs_v1"; private const int MaxRecordCount = 100; private const string RecoverySlotKey = "recent_play_history_runs_v1"; public static IReadOnlyList GetRecords() { return LoadPayload().records; } public static void Push(RecentPlayRecord record) { if (record == null) { return; } var payload = LoadPayload(); if (payload.records == null) { payload.records = new List(); } payload.records.Insert(0, record); if (payload.records.Count > MaxRecordCount) { payload.records.RemoveRange(MaxRecordCount, payload.records.Count - MaxRecordCount); } SecureSaveVault.SaveJson(Category, Key, payload); LocalRecoveryMirror.SaveJson(RecoverySlotKey, payload); } public static void Clear() { SecureSaveVault.Delete(Category, Key); LocalRecoveryMirror.DeleteSlot(RecoverySlotKey); } private static RecentPlayHistoryPayload LoadPayload() { RecentPlayHistoryPayload payload; if (!SecureSaveVault.TryLoadJson(Category, Key, out payload) || payload == null) { if (!LocalRecoveryMirror.TryLoadJson(RecoverySlotKey, out payload) || payload == null) { payload = new RecentPlayHistoryPayload(); } else { SecureSaveVault.SaveJson(Category, Key, payload); } } if (payload.records == null) { payload.records = new List(); } return payload; } }