refactor(kv): 整理存档接线并清理迁移冗余实现
This commit is contained in:
@@ -32,54 +32,52 @@ namespace game
|
||||
}
|
||||
public class ClubService //: IClubService
|
||||
{
|
||||
[Inject] public PlayerDataStorage.IPlayerSaveStore SaveStore { get; set; }
|
||||
[Inject] public Core.KV.IPlayerSaveStore SaveStore { get; set; }
|
||||
// BEGIN B01 fixed prompt owner
|
||||
readonly bool requiresFormalKV;
|
||||
PlayerDataStorage.PlayerKVGameSessionHandle promptOwner;
|
||||
internal PlayerDataStorage.PlayerKVEditResult LastPromptEdit { get; private set; }
|
||||
private readonly bool requiresFormalKV;
|
||||
private Core.KV.KvSessionOwner promptOwner;
|
||||
public ClubService() : this(RequireFrozenSelection()) { }
|
||||
static bool RequireFrozenSelection()
|
||||
private static bool RequireFrozenSelection()
|
||||
{
|
||||
var selection = GContext.container.Resolve<PlayerDataStorage.PlayerKVRuntimeSelection>();
|
||||
var selection = GContext.container.Resolve<game.KV.KvRuntimeSelection>();
|
||||
if (selection == null) throw DefaultSettingService.PromptFailure("IsOpenClubRed: startup selection missing.");
|
||||
return selection.IsKV;
|
||||
}
|
||||
internal ClubService(bool formalKV) { requiresFormalKV = formalKV; }
|
||||
internal ClubService(PlayerDataStorage.PlayerKVGameSessionHandle owner) : this(true)
|
||||
{
|
||||
promptOwner = owner ?? throw new ArgumentNullException(nameof(owner));
|
||||
RequirePromptOwner();
|
||||
}
|
||||
// The constructor captures the registered startup selection, never a later mutable config value.
|
||||
internal void PreflightFormalPromptOwner(PlayerDataStorage.PlayerKVGameSessionHandle owner)
|
||||
internal void PreflightFormalPromptOwner(Core.KV.KvSessionOwner owner)
|
||||
{
|
||||
if (!requiresFormalKV || owner == null || (promptOwner != null && !ReferenceEquals(promptOwner, owner)))
|
||||
{
|
||||
throw DefaultSettingService.PromptFailure("IsOpenClubRed: formal owner mismatch.");
|
||||
var read = KVMgr.ReadKV(owner, "IsOpenClubRed");
|
||||
}
|
||||
var read = game.KV.KvSaveStore.ReadKV(owner, "IsOpenClubRed");
|
||||
if (!read.Success)
|
||||
{
|
||||
throw DefaultSettingService.PromptFailure($"IsOpenClubRed owner={owner.OwnerInstanceId}: {read.Error}");
|
||||
}
|
||||
}
|
||||
internal void BindFormalPromptOwner(PlayerDataStorage.PlayerKVGameSessionHandle owner)
|
||||
internal void BindFormalPromptOwner(Core.KV.KvSessionOwner owner)
|
||||
{
|
||||
PreflightFormalPromptOwner(owner);
|
||||
if (promptOwner == null) promptOwner = owner;
|
||||
if (promptOwner == null)
|
||||
{
|
||||
promptOwner = owner;
|
||||
}
|
||||
RequirePromptOwner();
|
||||
}
|
||||
internal bool HasFormalPromptOwner(PlayerDataStorage.PlayerKVGameSessionHandle owner) =>
|
||||
requiresFormalKV && ReferenceEquals(promptOwner, owner);
|
||||
|
||||
internal void ReleaseFailedPromptOwner(PlayerDataStorage.PlayerKVGameSessionHandle owner)
|
||||
internal void ReleaseFailedPromptOwner(Core.KV.KvSessionOwner owner)
|
||||
{
|
||||
if (promptOwner == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!ReferenceEquals(promptOwner, owner) || owner.Status != PlayerDataStorage.PlayerKVSyncStatus.Closed)
|
||||
if (!ReferenceEquals(promptOwner, owner) || owner.Status != Core.KV.KVSyncStatus.Closed)
|
||||
{
|
||||
throw DefaultSettingService.PromptFailure("IsOpenClubRed: failed owner has not closed.");
|
||||
}
|
||||
promptOwner = null;
|
||||
LastPromptEdit = null;
|
||||
}
|
||||
internal void RequirePromptOwner()
|
||||
{
|
||||
@@ -87,9 +85,9 @@ namespace game
|
||||
else if (requiresFormalKV)
|
||||
throw DefaultSettingService.PromptFailure("IsOpenClubRed: formal owner not handed off.");
|
||||
}
|
||||
private PlayerDataStorage.PlayerKVKeyReadResult ReadPrompt()
|
||||
private Core.KV.PlayerSaveReadResult ReadPrompt()
|
||||
{
|
||||
var read = KVMgr.ReadKV(promptOwner, "IsOpenClubRed");
|
||||
var read = game.KV.KvSaveStore.ReadKV(promptOwner, "IsOpenClubRed");
|
||||
if (!read.Success)
|
||||
{
|
||||
throw DefaultSettingService.PromptFailure($"IsOpenClubRed owner={promptOwner.OwnerInstanceId}: {read.Error}");
|
||||
@@ -213,10 +211,10 @@ namespace game
|
||||
{
|
||||
IsOpenClubRed = false;
|
||||
SetClubRed();
|
||||
LastPromptEdit = KVMgr.WriteKV(promptOwner, "IsOpenClubRed", "1");
|
||||
if (!LastPromptEdit.Accepted)
|
||||
var promptEdit = game.KV.KvSaveStore.WriteKV(promptOwner, "IsOpenClubRed", "1");
|
||||
if (!promptEdit.Success)
|
||||
{
|
||||
throw DefaultSettingService.PromptFailure($"IsOpenClubRed owner={promptOwner.OwnerInstanceId}: {LastPromptEdit.StateResult.Error}; uncertain={LastPromptEdit.StateResult.LocalCommitMayHaveSucceeded}");
|
||||
throw DefaultSettingService.PromptFailure($"IsOpenClubRed owner={promptOwner.OwnerInstanceId}: {promptEdit.Error}; uncertain={promptEdit.LocalCommitMayHaveSucceeded}");
|
||||
}
|
||||
}
|
||||
RequirePromptOwner();
|
||||
|
||||
Reference in New Issue
Block a user