30 lines
1.3 KiB
C#
30 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace game.PlayerDataStorage
|
|
{
|
|
public enum PlayerKVLocalReadError { None, StaleOrClosing, NotReady }
|
|
|
|
/// <summary>A detached snapshot. Failed reads have no data, never a pretend empty save.</summary>
|
|
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<string, string> Data { get; }
|
|
|
|
internal PlayerKVLocalReadResult(PlayerKVLocalReadError error, string ownerId,
|
|
string playerId, long epoch, IReadOnlyDictionary<string, string> 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<string, string>(StringComparer.Ordinal);
|
|
foreach (var item in data) copy.Add(item.Key, item.Value);
|
|
Data = new ReadOnlyDictionary<string, string>(copy);
|
|
}
|
|
}
|
|
} |