refactor(kv): 整理存档接线并清理迁移冗余实现
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using Core.KV;
|
||||
using game.KV;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using Game;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using game.PlayerDataStorage;
|
||||
|
||||
namespace game
|
||||
{
|
||||
@@ -29,9 +30,8 @@ namespace game
|
||||
int _unitOfWeight = 1;
|
||||
bool? _showNotice;
|
||||
|
||||
readonly bool requiresFormalKV;
|
||||
PlayerKVGameSessionHandle promptOwner;
|
||||
internal PlayerKVEditResult LastPromptEdit { get; private set; }
|
||||
private readonly bool requiresFormalKV;
|
||||
private KvSessionOwner promptOwner;
|
||||
internal bool HasKVPromptOwner => promptOwner != null;
|
||||
|
||||
// Preserve only our key/owner/error metadata across void UI boundaries, never platform payloads.
|
||||
@@ -46,41 +46,40 @@ namespace game
|
||||
|
||||
public DefaultSettingService() : this(false) { }
|
||||
internal DefaultSettingService(bool formalKV) { requiresFormalKV = formalKV; }
|
||||
internal DefaultSettingService(PlayerKVGameSessionHandle owner) : this(true)
|
||||
{
|
||||
promptOwner = owner ?? throw new ArgumentNullException(nameof(owner));
|
||||
RequirePromptOwner();
|
||||
}
|
||||
|
||||
// The frozen startup selection is supplied before login; this instance can never change owners.
|
||||
internal void PreflightFormalPromptOwner(PlayerKVGameSessionHandle owner)
|
||||
internal void PreflightFormalPromptOwner(KvSessionOwner owner)
|
||||
{
|
||||
if (!requiresFormalKV || owner == null || (promptOwner != null && !ReferenceEquals(promptOwner, owner)))
|
||||
{
|
||||
throw PromptFailure("ShowNotice: formal owner mismatch.");
|
||||
var read = KVMgr.ReadKV(owner, "ShowNotice");
|
||||
if (!read.Success) throw PromptFailure($"ShowNotice owner={owner.OwnerInstanceId}: {read.Error}");
|
||||
}
|
||||
var read = KvSaveStore.ReadKV(owner, "ShowNotice");
|
||||
if (!read.Success)
|
||||
{
|
||||
throw PromptFailure($"ShowNotice owner={owner.OwnerInstanceId}: {read.Error}");
|
||||
}
|
||||
}
|
||||
internal void BindFormalPromptOwner(PlayerKVGameSessionHandle owner)
|
||||
internal void BindFormalPromptOwner(KvSessionOwner owner)
|
||||
{
|
||||
PreflightFormalPromptOwner(owner);
|
||||
if (promptOwner == null) promptOwner = owner;
|
||||
if (promptOwner == null)
|
||||
{
|
||||
promptOwner = owner;
|
||||
}
|
||||
RequirePromptOwner();
|
||||
}
|
||||
internal bool HasFormalPromptOwner(PlayerKVGameSessionHandle owner) =>
|
||||
requiresFormalKV && ReferenceEquals(promptOwner, owner);
|
||||
|
||||
internal void ReleaseFailedPromptOwner(PlayerKVGameSessionHandle owner)
|
||||
internal void ReleaseFailedPromptOwner(KvSessionOwner owner)
|
||||
{
|
||||
if (promptOwner == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!ReferenceEquals(promptOwner, owner) || owner.Status != PlayerKVSyncStatus.Closed)
|
||||
if (!ReferenceEquals(promptOwner, owner) || owner.Status != KVSyncStatus.Closed)
|
||||
{
|
||||
throw PromptFailure("ShowNotice: failed owner has not closed.");
|
||||
}
|
||||
promptOwner = null;
|
||||
LastPromptEdit = null;
|
||||
_showNotice = null;
|
||||
}
|
||||
internal void RequirePromptOwner()
|
||||
@@ -89,9 +88,9 @@ namespace game
|
||||
else if (requiresFormalKV) throw PromptFailure("ShowNotice: formal owner not handed off.");
|
||||
}
|
||||
|
||||
private PlayerKVKeyReadResult ReadPrompt()
|
||||
private PlayerSaveReadResult ReadPrompt()
|
||||
{
|
||||
var read = KVMgr.ReadKV(promptOwner, "ShowNotice");
|
||||
var read = KvSaveStore.ReadKV(promptOwner, "ShowNotice");
|
||||
if (!read.Success)
|
||||
{
|
||||
throw PromptFailure($"ShowNotice owner={promptOwner.OwnerInstanceId}: {read.Error}");
|
||||
@@ -202,10 +201,10 @@ namespace game
|
||||
if (value != _showNotice)
|
||||
{
|
||||
_showNotice = value;
|
||||
LastPromptEdit = KVMgr.WriteKV(promptOwner, "ShowNotice", value ? "1" : "0");
|
||||
if (!LastPromptEdit.Accepted)
|
||||
var promptEdit = KvSaveStore.WriteKV(promptOwner, "ShowNotice", value ? "1" : "0");
|
||||
if (!promptEdit.Success)
|
||||
{
|
||||
throw PromptFailure($"ShowNotice owner={promptOwner.OwnerInstanceId}: {LastPromptEdit.StateResult.Error}; uncertain={LastPromptEdit.StateResult.LocalCommitMayHaveSucceeded}");
|
||||
throw PromptFailure($"ShowNotice owner={promptOwner.OwnerInstanceId}: {promptEdit.Error}; uncertain={promptEdit.LocalCommitMayHaveSucceeded}");
|
||||
}
|
||||
}
|
||||
RequirePromptOwner();
|
||||
|
||||
Reference in New Issue
Block a user