using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace game.PlayerDataStorage { public enum PlayerKVLocalReadError { None, StaleOrClosing, NotReady } /// A detached snapshot. Failed reads have no data, never a pretend empty save. public sealed class PlayerKVLocalReadResult { public bool Success => Error == PlayerKVLocalReadError.None; public PlayerKVLocalReadError Error { get; } public string OwnerInstanceId { get; } public string PlayerId { get; } public long Epoch { get; } public IReadOnlyDictionary Data { get; } internal PlayerKVLocalReadResult(PlayerKVLocalReadError error, string ownerId, string playerId, long epoch, IReadOnlyDictionary data = null) { Error = error; OwnerInstanceId = ownerId; PlayerId = playerId; Epoch = epoch; if (error != PlayerKVLocalReadError.None) return; if (data == null) throw new ArgumentNullException(nameof(data)); var copy = new Dictionary(StringComparer.Ordinal); foreach (var item in data) copy.Add(item.Key, item.Value); Data = new ReadOnlyDictionary(copy); } } }