Files
ichni_Official/Assets/Scripts/Saving/SongStatusSave.cs
SoulliesOfficial 810d019619 剧情+对话完善
2026-07-21 15:24:42 -04:00

76 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
namespace Ichni.RhythmGame
{
/// <summary>
/// 单首歌曲的持久化容器。
/// <see cref="isTried"/> 表示玩家曾确认进入过该歌曲;<see cref="isCompleted"/> 只表示玩家曾完成过一次有效结算。
/// Story SongBlock 使用 isTried而具体难度的成绩、Revision 与 Max Combo
/// 由 <see cref="beatmapSavesByDifficultyId"/> 中对应稳定难度 ID 的 <see cref="BeatmapSave"/> 管理。
/// </summary>
public class SongStatusSave
{
/// <summary>
/// 玩家是否曾确认进入过本曲的 GameScene。
/// 该字段不代表结算成功,也不要求存在判定;它让 Story SongBlock 能在切场景、退出游戏或重新打开章节后,
/// 通过持久化的歌曲记录稳定恢复“已尝试”状态。
/// </summary>
public bool isTried;
/// <summary>至少有一次有效结算完成;谱面 Revision 变化不会回退该流程状态。</summary>
public bool isCompleted;
/// <summary>预留的歌曲级扩展字段;赋予新语义前须评估 Schema Version 是否需要递增。</summary>
public string additionalInfo;
/// <summary>
/// 以 <c>DifficultyData.saveDifficultyId</c> 为 Key 的谱面成绩。
/// Key 不依赖选曲列表位置,因此重排、隐藏或删除中间难度不会让其他难度的成绩错位。
/// 被内容定义移除的 Key 暂时保留在存档中,但 UI 与章节完成度只读取当前仍存在的难度。
/// </summary>
public Dictionary<int, BeatmapSave> beatmapSavesByDifficultyId = new();
public SongStatusSave()
{
}
public SongStatusSave(bool isCompleted, string additionalInfo, Dictionary<int, BeatmapSave> beatmapSavesByDifficultyId)
{
// 已拥有有效结算的歌曲必然也已尝试,避免两个状态出现矛盾。
isTried = isCompleted;
this.isCompleted = isCompleted;
this.additionalInfo = additionalInfo;
this.beatmapSavesByDifficultyId = beatmapSavesByDifficultyId;
}
/// <summary>只读查询当前定义的难度成绩;不会因 UI 展示而创建新的存档记录。</summary>
public bool TryGetBeatmapSave(int saveDifficultyId, out BeatmapSave beatmapSave)
{
beatmapSave = null;
return saveDifficultyId >= 0 && beatmapSavesByDifficultyId != null &&
beatmapSavesByDifficultyId.TryGetValue(saveDifficultyId, out beatmapSave) && beatmapSave != null;
}
/// <summary>
/// 获取或创建指定稳定难度 ID 的成绩容器。
/// 仅存档写入/内容对账可调用此方法;选曲 UI 应使用 <see cref="TryGetBeatmapSave"/>。
/// </summary>
public BeatmapSave GetOrCreateBeatmapSave(int saveDifficultyId)
{
if (saveDifficultyId < 0)
{
return null;
}
beatmapSavesByDifficultyId ??= new Dictionary<int, BeatmapSave>();
if (!beatmapSavesByDifficultyId.TryGetValue(saveDifficultyId, out BeatmapSave beatmapSave) || beatmapSave == null)
{
beatmapSave = new BeatmapSave(0f, false, false);
beatmapSavesByDifficultyId[saveDifficultyId] = beatmapSave;
}
return beatmapSave;
}
}
}