refactor(kv): 整理存档接线并清理迁移冗余实现
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Core.KV;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace game.PlayerDataStorage
|
||||
{
|
||||
public sealed class PlayFabSaveStore : IPlayerSaveStore
|
||||
{
|
||||
public Task<bool> SyncDataImmidiate(string key, string value)
|
||||
{
|
||||
return manager.SyncDataImmidiate(key, value);
|
||||
}
|
||||
|
||||
private readonly PlayFabMgr manager;
|
||||
private readonly CancellationToken lifetime;
|
||||
public PlayFabSaveStore(IUserService user)
|
||||
{
|
||||
var originalManager = PlayFabMgr.Instance;
|
||||
var originalLifetime = user.LoginLifetime;
|
||||
manager = originalManager;
|
||||
lifetime = originalLifetime;
|
||||
}
|
||||
public bool IsCurrent => manager != null && !lifetime.IsCancellationRequested;
|
||||
|
||||
public PlayerSaveReadResult Read(string key)
|
||||
{
|
||||
if (!IsCurrent)
|
||||
{
|
||||
return new PlayerSaveReadResult("StaleOrNotReady");
|
||||
}
|
||||
try
|
||||
{
|
||||
var value = manager.GetLocalData(key);
|
||||
return new PlayerSaveReadResult(value != null, value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new PlayerSaveReadResult(ex.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerSaveWriteResult Write(string key, string value, bool remoteStore = true)
|
||||
{
|
||||
if (!IsCurrent)
|
||||
{
|
||||
return new PlayerSaveWriteResult("StaleOrNotReady");
|
||||
}
|
||||
try
|
||||
{
|
||||
manager.UpdateUserDataValue(key, value, remoteStore);
|
||||
return new PlayerSaveWriteResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new PlayerSaveWriteResult(ex.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user