refactor(save-system): EyeSystem 与 PunchTape 迁移为显式 DTO 快照
This commit is contained in:
@@ -23,6 +23,10 @@ namespace AibisDream.Utility
|
||||
|
||||
public static readonly string SaveFilePath = Path.Combine(Application.persistentDataPath, "AllOurBrokenParts", "saves");
|
||||
|
||||
/// <summary>测试阶段自动存档历史目录;每次自动存档独立子文件夹,不覆盖正式槽位。</summary>
|
||||
public static readonly string TestAutoSaveArchivePath =
|
||||
Path.Combine(Application.persistentDataPath, "AllOurBrokenParts", "testsavs");
|
||||
|
||||
/// <summary>P2 槽位相关常量。</summary>
|
||||
public const int SaveSlotCount = 8;
|
||||
public const int SaveThumbnailWidth = 640;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.SaveSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 打孔带系统入口:收藏数据、存档注册、Yarn 命令、弹窗与收藏夹面板代理。
|
||||
/// 打孔带系统入口:收藏数据、Yarn 命令、弹窗与收藏夹面板代理。
|
||||
/// </summary>
|
||||
public class PunchTapeManager : Singleton<PunchTapeManager>
|
||||
{
|
||||
@@ -20,48 +19,54 @@ namespace AibisDream.FixSystem
|
||||
[SerializeField] private PunchTapePrinter punchTapePrinter;
|
||||
public PunchTapePrinter PunchTapePrinter => punchTapePrinter;
|
||||
|
||||
private readonly PunchTapeCollectionData _collectionData = new();
|
||||
private readonly List<PunchTape> _favorites = new();
|
||||
|
||||
private GameObject currentPunchTapeGO;
|
||||
|
||||
/// <summary>收藏列表变更时通知 <see cref="PunchTapeFavoritesPanel"/> 等订阅方。</summary>
|
||||
public event Action OnCollectionChanged;
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
DeepRepairDataRegistry.RegisterData(_collectionData);
|
||||
_collectionData.LoadEvent += OnCollectionDataLoaded;
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
_collectionData.LoadEvent -= OnCollectionDataLoaded;
|
||||
}
|
||||
|
||||
private void OnCollectionDataLoaded(PunchTapeCollectionData data)
|
||||
{
|
||||
OnCollectionChanged?.Invoke();
|
||||
}
|
||||
|
||||
public IReadOnlyList<PunchTape> GetFavorites()
|
||||
{
|
||||
return _collectionData.punchTapeFavorites;
|
||||
return _favorites;
|
||||
}
|
||||
|
||||
public PunchTapeSnapshotDto CapturePunchTapeSnapshot()
|
||||
{
|
||||
return new PunchTapeSnapshotDto
|
||||
{
|
||||
favorites = _favorites.Select(t => new PunchTape(t.Category, t.ClueName, t.MemoryIndex)
|
||||
{
|
||||
used = t.used
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void ApplyPunchTapeSnapshot(PunchTapeSnapshotDto dto)
|
||||
{
|
||||
_favorites.Clear();
|
||||
if (dto?.favorites != null)
|
||||
{
|
||||
_favorites.AddRange(dto.favorites);
|
||||
}
|
||||
|
||||
OnCollectionChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void AddPunchTape(PunchTape punchTape)
|
||||
{
|
||||
if (punchTape == null) return;
|
||||
if (_collectionData.punchTapeFavorites.Contains(punchTape))
|
||||
if (_favorites.Contains(punchTape))
|
||||
return;
|
||||
|
||||
_collectionData.punchTapeFavorites.Add(punchTape);
|
||||
_favorites.Add(punchTape);
|
||||
OnCollectionChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void RemovePunchTape(PunchTape punchTape)
|
||||
{
|
||||
if (punchTape == null) return;
|
||||
if (!_collectionData.punchTapeFavorites.Remove(punchTape))
|
||||
if (!_favorites.Remove(punchTape))
|
||||
return;
|
||||
|
||||
OnCollectionChanged?.Invoke();
|
||||
@@ -130,20 +135,4 @@ namespace AibisDream.FixSystem
|
||||
currentPunchTapeGO = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打孔带收藏列表的存档载体;由 <see cref="PunchTapeManager"/> 注册到 <see cref="DeepRepairDataRegistry"/>。
|
||||
/// </summary>
|
||||
public class PunchTapeCollectionData : IData
|
||||
{
|
||||
public List<PunchTape> punchTapeFavorites = new();
|
||||
|
||||
public event Action<PunchTapeCollectionData> LoadEvent;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
LoadEvent?.Invoke(this);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using AibisDream.FixSystem;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.SaveSystem;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.SaveSystem;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using Sequence = DG.Tweening.Sequence;
|
||||
|
||||
@@ -28,10 +28,19 @@ namespace AibisDream
|
||||
public GameObject eyeView;
|
||||
public ViewCameraManager cameraManager;
|
||||
private IEyeStateEffect eyeStateEffect;
|
||||
private EyeData _eyeData = new();
|
||||
private EyeColorState _currentState = EyeColorState.CannotImagineColor;
|
||||
|
||||
/// <summary>获取当前 Eye 颜色阶段。</summary>
|
||||
public EyeData.EyeColorState GetCurrentColorState() => _eyeData.currentState;
|
||||
public EyeColorState GetCurrentColorState() => _currentState;
|
||||
|
||||
public enum EyeColorState
|
||||
{
|
||||
CanImagineColor,
|
||||
CannotImagineColor,
|
||||
EyeDisorder,
|
||||
CanSeeColor,
|
||||
HaveChip
|
||||
}
|
||||
|
||||
private Tween hsvShiftTween;
|
||||
private MouseFollowAndZoom mouseFollowAndZoom;
|
||||
@@ -71,20 +80,29 @@ namespace AibisDream
|
||||
public void Init()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
DeepRepairDataRegistry.RegisterData(_eyeData);
|
||||
// 添加加载逻辑
|
||||
_eyeData.LoadEvent += LoadData;
|
||||
|
||||
// 确保 ViewCamera 默认不激活
|
||||
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData(EyeData eyedata)
|
||||
public EyeSnapshotDto CaptureEyeSnapshot()
|
||||
{
|
||||
SetEyeColorState(eyedata.currentState);
|
||||
return new EyeSnapshotDto { eyeColorState = _currentState.ToString() };
|
||||
}
|
||||
|
||||
public void ApplyEyeSnapshot(EyeSnapshotDto dto)
|
||||
{
|
||||
if (dto == null || string.IsNullOrEmpty(dto.eyeColorState))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Enum.TryParse(dto.eyeColorState, true, out EyeColorState state))
|
||||
{
|
||||
SetEyeColorState(state);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnter()
|
||||
@@ -141,7 +159,7 @@ namespace AibisDream
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetEyeColorState(_eyeData.currentState);
|
||||
SetEyeColorState(_currentState);
|
||||
|
||||
mouseFollowAndZoom = FindObjectOfType<MouseFollowAndZoom>();
|
||||
}
|
||||
@@ -265,7 +283,7 @@ namespace AibisDream
|
||||
public void SetEyeColorStateForYarn(string state)
|
||||
{
|
||||
// Try to parse the string as an EyeColorState
|
||||
if (!Enum.TryParse(state, true, out EyeData.EyeColorState eyeState))
|
||||
if (!Enum.TryParse(state, true, out EyeColorState eyeState))
|
||||
{
|
||||
throw new ArgumentException("Invalid eye state: " + state, nameof(state));
|
||||
}
|
||||
@@ -274,24 +292,24 @@ namespace AibisDream
|
||||
SetEyeColorState(eyeState);
|
||||
}
|
||||
|
||||
private void SetEyeColorState(EyeData.EyeColorState state)
|
||||
private void SetEyeColorState(EyeColorState state)
|
||||
{
|
||||
_eyeData.currentState = state;
|
||||
_currentState = state;
|
||||
switch (state)
|
||||
{
|
||||
case EyeData.EyeColorState.CanImagineColor:
|
||||
case EyeColorState.CanImagineColor:
|
||||
eyeStateEffect = new CanImagineColorEffect();
|
||||
break;
|
||||
case EyeData.EyeColorState.CannotImagineColor:
|
||||
case EyeColorState.CannotImagineColor:
|
||||
eyeStateEffect = new CannotImagineColorEffect();
|
||||
break;
|
||||
case EyeData.EyeColorState.EyeDisorder:
|
||||
case EyeColorState.EyeDisorder:
|
||||
eyeStateEffect = new EyeDisorderEffect();
|
||||
break;
|
||||
case EyeData.EyeColorState.CanSeeColor:
|
||||
case EyeColorState.CanSeeColor:
|
||||
eyeStateEffect = new CanSeeColorEffect();
|
||||
break;
|
||||
case EyeData.EyeColorState.HaveChip:
|
||||
case EyeColorState.HaveChip:
|
||||
eyeStateEffect = new HaveChip();
|
||||
break;
|
||||
default:
|
||||
@@ -471,7 +489,7 @@ namespace AibisDream
|
||||
[YarnCommand("EyeGetColor")]
|
||||
public void GetColor()
|
||||
{
|
||||
SetEyeColorState(EyeData.EyeColorState.CanImagineColor);
|
||||
SetEyeColorState(EyeColorState.CanImagineColor);
|
||||
// 对目标列表中的每个目标执行 ColorBack 方法
|
||||
foreach (EyeTarget target in targets)
|
||||
{
|
||||
@@ -481,25 +499,4 @@ namespace AibisDream
|
||||
// 切换到 CanImagineColorEffect 状态
|
||||
}
|
||||
}
|
||||
|
||||
public class EyeData : IData
|
||||
{
|
||||
public enum EyeColorState
|
||||
{
|
||||
CanImagineColor,
|
||||
CannotImagineColor,
|
||||
EyeDisorder,
|
||||
CanSeeColor,
|
||||
HaveChip
|
||||
}
|
||||
|
||||
public EyeColorState currentState = EyeColorState.CannotImagineColor;
|
||||
public event Action<EyeData> LoadEvent;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
LoadEvent?.Invoke(this);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user