chore(m2): 保存功能验收及后续清理前检查点

This commit is contained in:
Liubing\LB
2026-10-10 20:40:27 +08:00
parent d3c5394a55
commit 144e7f739f
110 changed files with 12672 additions and 7514 deletions

View File

@@ -166,22 +166,28 @@ namespace GameCore
}
if (userService is KVUserService kvUser)
{
var store = kvUser.SaveStore;
var store = kvUser.SaveStore as KVPlayerSaveStore;
var writtenNames = new HashSet<string>(StringComparer.Ordinal);
bool accepted = false;
var data = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var statistic in Statistics)
{
if (!writtenNames.Add(statistic.StatisticName)) continue;
var write = store.Write(statistic.StatisticName, statistic.Value.ToString(CultureInfo.InvariantCulture));
if (write.Accepted) accepted = true;
else Debug.LogError("KV statistic write failed: " + statistic.StatisticName + ": " + write.Error);
if (!writtenNames.Add(statistic.StatisticName))
{
continue;
}
if (!KVSnapshot.ValidKey(statistic.StatisticName))
{
Debug.LogError("KV statistic write failed: " + statistic.StatisticName + ": Validation");
continue;
}
data.Add(statistic.StatisticName, statistic.Value.ToString(CultureInfo.InvariantCulture));
}
if (accepted)
if (data.Count > 0)
{
var confirmation = await store.FlushAsync();
if (confirmation.Status != PlayerSaveStatus.Confirmed)
Debug.LogError("KV statistic save not confirmed: " + string.Join(",", writtenNames) +
": " + confirmation.Status + ": " + confirmation.Error);
if (store == null || !await store.SyncDataImmidiate(data))
{
Debug.LogError("KV statistic save failed: " + string.Join(",", data.Keys));
}
}
return;
}
@@ -193,6 +199,35 @@ namespace GameCore
}
public async Task<GetLeaderboardResult> GetLeadboardData(string leaderboardNaem, int maxCount = 50)
{
if (userService is KVUserService)
{
var json = await customServerMgr.CustomServerPost("leaderboard/GetLeaderboard",
Newtonsoft.Json.JsonConvert.SerializeObject(new
{
statisticName = leaderboardNaem,
startPosition = 0,
maxResultsCount = maxCount
}));
if (string.IsNullOrEmpty(json))
{
return null;
}
try
{
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<KVLeaderboardResponse>(json);
if (response == null || response.Code != 1 || response.Leaderboard == null ||
response.Leaderboard.Any(entry => entry == null || entry.Profile == null))
{
return null;
}
return new GetLeaderboardResult { Leaderboard = response.Leaderboard };
}
catch (Newtonsoft.Json.JsonException ex)
{
Debug.LogError("KV leaderboard response failed: " + ex.GetType().Name);
return null;
}
}
GetLeaderboardRequest reques = new GetLeaderboardRequest()
{
StartPosition = 0,
@@ -209,6 +244,21 @@ namespace GameCore
return await PlayFabClientAsyncAPI.GetLeaderboardAsync(reques);
}
private sealed class KVLeaderboardResponse
{
public int Code
{
get;
set;
}
public List<PlayerLeaderboardEntry> Leaderboard
{
get;
set;
}
}
public async void SetLvData()
{
isRefreshing = true;