using System;
using Ichni.Menu;
using UnityEngine;
namespace Ichni.Story
{
///
/// 从剧情 SongBlock 进入选曲时携带的临时上下文。
/// 它只存在于 DontDestroyOnLoad 的 InformationTransistor 中,不写入存档:歌曲完成与
/// 剧情 Block 完成仍由各自正式存档负责;本类仅用于一次页面往返的目标校验与视口恢复。
///
[Serializable]
public class StorySongEntryContext
{
/// 是否正处于一次由剧情 SongBlock 发起、尚未结束的选曲流程。
public bool isActive;
/// 发起入口的章节 ID,用于防止跨章节同名歌曲被误判为目标歌曲。
public string chapterIndex;
/// 发起本次选曲的 SongBlock ID,目标歌曲确认后会完成此 Block。
public string sourceBlockId;
/// SongItemData.songName,对应 StoryBlockDefinition.songName 的稳定歌曲 ID。
public string targetSongId;
/// 离开剧情页时 StoryTree Content 的位置,用于返回后还原浏览位置。
public Vector2 storyTreeContentPosition;
/// 仅在确认进入目标歌曲后设为 true,决定 GameScene 返回剧情页而非普通选曲页。
public bool returnToStoryAfterGame;
/// 开始一次新的剧情歌曲入口,覆盖任何未完成的旧运行时上下文。
public void Begin(string chapterId, string blockId, string songId, Vector2 contentPosition)
{
isActive = true;
chapterIndex = chapterId;
sourceBlockId = blockId;
targetSongId = songId;
storyTreeContentPosition = contentPosition;
returnToStoryAfterGame = false;
}
///
/// 判断玩家当前确认进入的歌曲是否正是剧情入口指定的目标。
/// 必须同时比对章节与稳定歌曲 ID,不能仅使用显示名或对象引用。
///
public bool IsTargetSong(ChapterSelectionUnit chapter, SongItemData song)
{
return isActive && chapter != null && song != null &&
chapter.chapterIndex == chapterIndex && song.songName == targetSongId;
}
/// 结束本次页面往返并清除所有瞬时数据,避免影响后续普通选曲。
public void Clear()
{
isActive = false;
chapterIndex = null;
sourceBlockId = null;
targetSongId = null;
storyTreeContentPosition = Vector2.zero;
returnToStoryAfterGame = false;
}
}
}