修复歌曲按钮bug和最高分展示逻辑
This commit is contained in:
@@ -186,6 +186,94 @@ public class SongData : ScriptableObject
|
||||
return highest;
|
||||
}
|
||||
|
||||
// 更新指定难度的最高纪录 (只有当总分更高时才更新)
|
||||
public void UpdateDifficultyRecord(int difficulty, int pmScore, int idolScore)
|
||||
{
|
||||
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
|
||||
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
|
||||
|
||||
int currentBestTotal = GetPersonalRecord(difficulty) + GetIdolRecord(difficulty);
|
||||
int newTotal = pmScore + idolScore;
|
||||
|
||||
if (newTotal > currentBestTotal)
|
||||
{
|
||||
personalRecordMap[difficulty] = pmScore;
|
||||
idolRecordMap[difficulty] = idolScore;
|
||||
|
||||
// also update corresponding ChartFileEntry if exists
|
||||
var entry = chartFiles != null ? chartFiles.Find(e => e.difficulty == difficulty) : null;
|
||||
if (entry != null)
|
||||
{
|
||||
entry.chartPersonalRecordForThisDifficulty = pmScore;
|
||||
entry.idolPersonalRecordForThisDifficulty = idolScore;
|
||||
entry.totalPersonalRecordForThisDifficulty = newTotal;
|
||||
}
|
||||
|
||||
CalculateHighestPersonalRecord();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取全难度下的最高分及其对应的难度名称
|
||||
public void GetAbsoluteHighestScore(out int highestScore, out int bestDifficulty, out string bestDifficultyName)
|
||||
{
|
||||
highestScore = 0;
|
||||
bestDifficulty = -1;
|
||||
bestDifficultyName = "";
|
||||
|
||||
// 优先遍历 chartFiles 获取数据和名称
|
||||
if (chartFiles != null && chartFiles.Count > 0)
|
||||
{
|
||||
foreach (var entry in chartFiles)
|
||||
{
|
||||
if (entry == null) continue;
|
||||
|
||||
// 重新计算总分以确保准确
|
||||
int total = GetPersonalRecord(entry.difficulty) + GetIdolRecord(entry.difficulty);
|
||||
|
||||
// 如果字典里没数据,尝试用 entry 里的初始数据
|
||||
if (total <= 0) total = entry.totalPersonalRecordForThisDifficulty;
|
||||
if (total <= 0) total = entry.chartPersonalRecordForThisDifficulty + entry.idolPersonalRecordForThisDifficulty;
|
||||
|
||||
if (total > highestScore || bestDifficulty == -1)
|
||||
{
|
||||
highestScore = total;
|
||||
bestDifficulty = entry.difficulty;
|
||||
bestDifficultyName = !string.IsNullOrEmpty(entry.difficultyName) ? entry.difficultyName : GetDifficultyDefaultName(entry.difficulty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果 chartFiles 为空,检查字典作为备选
|
||||
if (bestDifficulty == -1 && personalRecordMap != null)
|
||||
{
|
||||
foreach (var kvp in personalRecordMap)
|
||||
{
|
||||
int diff = kvp.Key;
|
||||
int p = kvp.Value;
|
||||
int i = GetIdolRecord(diff);
|
||||
int combined = p + i;
|
||||
if (combined > highestScore || bestDifficulty == -1)
|
||||
{
|
||||
highestScore = combined;
|
||||
bestDifficulty = diff;
|
||||
bestDifficultyName = GetDifficultyDefaultName(diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDifficultyDefaultName(int difficulty)
|
||||
{
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0: return "Easy";
|
||||
case 1: return "Hard";
|
||||
case 2: return "Incredible";
|
||||
case 3: return "Impossible";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// 更新指定难度的谱面(个人)最高成绩
|
||||
public void UpdatePersonalRecord(int difficulty, int newScore)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user