存档重构,游戏内容解锁机制;教程完善(未完成)
This commit is contained in:
@@ -24,29 +24,70 @@ namespace Ichni.Menu
|
||||
}
|
||||
}
|
||||
|
||||
public SongSelectionRecord GetRecordOfThisChapter()
|
||||
/// <summary>
|
||||
/// 取得当前 Chapter 的选曲缓存;缓存缺失时创建“第一首有效歌曲 + 难度位置 0”的默认记录。
|
||||
/// <para>此方法只保证缓存对象可用,不保证该歌曲或难度仍能游玩。歌曲失效与难度回退由选曲 UI 在
|
||||
/// 每次进入页面时完成,避免把运行期缓存变成持久化存档。</para>
|
||||
/// </summary>
|
||||
public bool TryGetRecordOfThisChapter(out SongSelectionRecord record)
|
||||
{
|
||||
record = null;
|
||||
ChapterSelectionUnit currentChapter = ChapterSelectionManager.instance.currentChapter;
|
||||
if (songSelectionRecords.TryGetValue(currentChapter, out SongSelectionRecord record))
|
||||
if (currentChapter == null || currentChapter.songs == null)
|
||||
{
|
||||
return record;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
if (songSelectionRecords.TryGetValue(currentChapter, out SongSelectionRecord cachedRecord) && cachedRecord != null)
|
||||
{
|
||||
return new SongSelectionRecord(currentChapter.songs[0], currentChapter.songs[0].difficultyDataList[0]);
|
||||
record = cachedRecord;
|
||||
return true;
|
||||
}
|
||||
|
||||
SongItemData firstValidSong = currentChapter.songs.Find(song => song != null);
|
||||
if (firstValidSong == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
record = new SongSelectionRecord(firstValidSong, 0);
|
||||
songSelectionRecords[currentChapter] = record;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将缓存修正为当前 Chapter 中实际存在的歌曲,并保留调用方提供的难度列表偏好位置。
|
||||
/// 这里只写内存缓存,玩家重启游戏后不会恢复该选择。
|
||||
/// </summary>
|
||||
public void SetRecordForChapter(ChapterSelectionUnit chapter, SongItemData song, int difficultyListIndex)
|
||||
{
|
||||
if (chapter == null || song == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
songSelectionRecords[chapter] = new SongSelectionRecord(song, difficultyListIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public class SongSelectionRecord
|
||||
{
|
||||
public SongItemData song;
|
||||
public int difficultyIndex;
|
||||
|
||||
public SongSelectionRecord(SongItemData song, DifficultyData difficulty)
|
||||
public int difficultyListIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 使用难度在歌曲列表中的位置构建缓存。
|
||||
/// 这是选曲 UI 的临时偏好,不等同于 DifficultyData.saveDifficultyId 的游戏记录稳定 ID。
|
||||
/// </summary>
|
||||
public SongSelectionRecord(SongItemData song, int difficultyListIndex)
|
||||
{
|
||||
this.song = song;
|
||||
difficultyIndex = song.difficultyDataList.IndexOf(difficulty);
|
||||
this.difficultyListIndex = difficultyListIndex;
|
||||
}
|
||||
|
||||
public SongSelectionRecord(SongItemData song, DifficultyData difficulty)
|
||||
: this(song, song?.difficultyDataList?.IndexOf(difficulty) ?? 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user