feat(save): 迁移存读档入口到槽位系统
将游戏流程接入 P2 槽位层: - SaveRestoreOrchestrator:SaveToAutoSlot / CreateManualSlot / RestoreFromSlot - GameManager:<<auto_save>> 调用新入口,新增 StartWithSlot 读档入口 保留 RestoreFromFile 旧档兼容路径。
This commit is contained in:
@@ -37,7 +37,7 @@ namespace AibisDream
|
||||
{
|
||||
// 管理游戏开始时各部分的初始化
|
||||
SettingLoader.Init();
|
||||
SnapshotBootstrap.EnsureInitialized();
|
||||
SnapshotRegistry.EnsureInitialized();
|
||||
// 场景So事件注册
|
||||
_currentTalkSceneSo = new BindProperty<TalkSceneSO>();
|
||||
|
||||
@@ -114,11 +114,24 @@ namespace AibisDream
|
||||
StartCoroutine(LoadFromSaveFile(fileName));
|
||||
}
|
||||
|
||||
public void StartWithSlot(int slotIndex)
|
||||
{
|
||||
// 游戏开始
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameStart);
|
||||
|
||||
StartCoroutine(LoadFromSlot(slotIndex));
|
||||
}
|
||||
|
||||
private IEnumerator LoadFromSaveFile(string fileName)
|
||||
{
|
||||
yield return SaveRestoreOrchestrator.RestoreFromFile(fileName);
|
||||
}
|
||||
|
||||
private IEnumerator LoadFromSlot(int slotIndex)
|
||||
{
|
||||
yield return SaveRestoreOrchestrator.RestoreFromSlot(slotIndex);
|
||||
}
|
||||
|
||||
private IEnumerator LoadFirstScene()
|
||||
{
|
||||
ChapterController.Instance.UnlockChapter(_currentTalkSceneSo.Value);
|
||||
@@ -348,7 +361,7 @@ namespace AibisDream
|
||||
[YarnCommand("auto_save")]
|
||||
public static void AutoSave()
|
||||
{
|
||||
SaveRestoreOrchestrator.SaveToTestPath();
|
||||
SaveRestoreOrchestrator.SaveToAutoSlot();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
@@ -9,16 +9,18 @@ using UnityEngine;
|
||||
namespace AibisDream.SaveSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 存读档流程编排层:连接 UI、<see cref="SnapshotService"/> 与 <see cref="SnapshotPersistence"/>。
|
||||
/// 存读档流程编排层:连接 UI、<see cref="SnapshotService"/> 与槽位系统。
|
||||
/// <para>
|
||||
/// 对外入口:<see cref="SaveToTestPath"/>(<<auto_save>>)、<see cref="RestoreFromFile"/>(读档)。
|
||||
/// P4 在此扩展淡入淡出与完整时序;P2 将替换测试路径为槽位 API。
|
||||
/// 对外入口:<see cref="SaveToAutoSlot"/>(<<auto_save>>)、
|
||||
/// <see cref="CreateManualSlot"/>(手动存档)、
|
||||
/// <see cref="RestoreFromSlot"/>(读档)、
|
||||
/// <see cref="RestoreFromFile"/>(旧档/调试)。
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class SaveRestoreOrchestrator
|
||||
{
|
||||
/// <summary>捕获快照并写入 P1 测试路径;含保存 Loading UI。</summary>
|
||||
public static void SaveToTestPath()
|
||||
/// <summary>捕获快照并写入自动档(slot 0);含保存 Loading UI。</summary>
|
||||
public static void SaveToAutoSlot()
|
||||
{
|
||||
var host = YarnVariableStorage.Instance;
|
||||
if (host == null)
|
||||
@@ -36,10 +38,30 @@ namespace AibisDream.SaveSystem
|
||||
using (new CodeTimer("SaveSnapshot"))
|
||||
{
|
||||
var snapshot = SnapshotService.Capture();
|
||||
SnapshotPersistence.Save(snapshot, SnapshotPersistence.GetTestFilePath());
|
||||
var thumbnail = SlotThumbnailCapture.CapturePng();
|
||||
SlotManager.SaveToAutoSlot(snapshot, thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>将当前自动档复制到指定手动档。</summary>
|
||||
public static void CreateManualSlot(int slotIndex)
|
||||
{
|
||||
SlotManager.CopyAutoToManual(slotIndex);
|
||||
}
|
||||
|
||||
/// <summary>从指定槽位读档并还原。</summary>
|
||||
public static IEnumerator RestoreFromSlot(int slotIndex)
|
||||
{
|
||||
var snapshot = SlotManager.LoadSnapshot(slotIndex);
|
||||
if (snapshot == null)
|
||||
{
|
||||
Debug.LogError($"[SaveRestoreOrchestrator] 槽位 {slotIndex} 不存在或读取失败");
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return RestoreSnapshot(snapshot);
|
||||
}
|
||||
|
||||
/// <summary>从文件读档并还原;自动区分新快照格式与 legacy 格式。</summary>
|
||||
public static IEnumerator RestoreFromFile(string savePath)
|
||||
{
|
||||
@@ -56,7 +78,7 @@ namespace AibisDream.SaveSystem
|
||||
snapshot = SnapshotPersistence.Load(savePath);
|
||||
}
|
||||
|
||||
yield return SnapshotService.Restore(snapshot);
|
||||
yield return RestoreSnapshot(snapshot);
|
||||
}
|
||||
|
||||
/// <summary>旧档:Yarn 变量 + DeepRepairDataRegistry systemData。</summary>
|
||||
@@ -72,6 +94,15 @@ namespace AibisDream.SaveSystem
|
||||
{
|
||||
yield return DeepRepairDataRegistry.LoadByJson(systemDataJson);
|
||||
}
|
||||
|
||||
// 旧档还原后自动固化为新格式,方便后续使用槽位系统
|
||||
var snapshot = SnapshotService.Capture();
|
||||
SlotManager.SaveToAutoSlot(snapshot, null);
|
||||
}
|
||||
|
||||
private static IEnumerator RestoreSnapshot(SaveSnapshot snapshot)
|
||||
{
|
||||
yield return SnapshotService.Restore(snapshot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user