Skip to content

Commit

Permalink
Fix some issues with score database querying/caching, and allow selec…
Browse files Browse the repository at this point in the history
…ting whether high-score display searches all difficulties or only the highest difficulty (#953)

* Tidy up score database queries into a helper type

* Better represent results of queries which only pull song checksums

* Redo highest score/percentage queries to fix percentage and score not displaying independently on song list

* Allow selecting whether high-score display uses all difficulties or only the highest difficulty

* Re-query database when caching new high scores on song end, instead of manually checking score values

* Invalidate score cache when switching history modes

* Clearly indicate when percent and score on the song list come from different difficulties

* Don't show score difficulty badge when high score display is disabled
  • Loading branch information
TheNathannator authored Jan 29, 2025
1 parent dec8f5f commit 801f9e8
Show file tree
Hide file tree
Showing 9 changed files with 524 additions and 249 deletions.
71 changes: 31 additions & 40 deletions Assets/Script/Menu/MusicLibrary/ViewTypes/SongViewType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SongViewType : ViewType

private bool _fetchedScores;
private PlayerScoreRecord _playerScoreRecord;
private PlayerScoreRecord _playerPercentRecord;
private GameRecord _bandScoreRecord;

public SongViewType(MusicLibraryMenu musicLibrary, SongEntry songEntry)
Expand Down Expand Up @@ -67,7 +68,7 @@ public override string GetSideText(bool selected)
// Append the band score if the setting is enabled
if (SettingsManager.Settings.HighScoreInfo.Value == HighScoreInfoMode.Score)
{
builder.AppendFormat("<space=2em> {0:N0}", _bandScoreRecord.BandScore);
builder.AppendFormat("{0:N0}", _bandScoreRecord.BandScore);
}

return builder.ToString();
Expand All @@ -79,17 +80,31 @@ public override string GetSideText(bool selected)
return string.Empty;
}

var difficultySprite = _playerScoreRecord.Difficulty.ToString();
var percent = Mathf.Floor(_playerScoreRecord.GetPercent() * 100f);
var percentColor = _playerScoreRecord.IsFc ? "#fcd13c" : "#ffffff";
if (_playerPercentRecord is null)
{
YargLogger.Fail("Best Percentage score is missing!");
return "Score display error!";
}

var percentDifficulty = _playerPercentRecord.Difficulty;
var percent = Mathf.Floor(_playerPercentRecord.GetPercent() * 100f);
var percentColor = _playerPercentRecord.IsFc ? "#fcd13c" : "#ffffff";

builder.AppendFormat("<sprite name=\"{0}\"> <color={1}>{2:N0}%</color><space=0.5em>",
percentDifficulty, percentColor, percent);

builder.AppendFormat("<sprite name=\"{0}\"> <color={1}>{2:N0}%</color>",
difficultySprite, percentColor, percent);
var scoreInfoMode = SettingsManager.Settings.HighScoreInfo.Value;

// Percent and score could potentially come from separate difficulties depending on settings
if (scoreInfoMode != HighScoreInfoMode.Off && _playerScoreRecord.Difficulty != _playerPercentRecord.Difficulty)
{
builder.AppendFormat("|<space=0.5em><sprite name=\"{0}\"> ", _playerScoreRecord.Difficulty);
}

// Append the score if the setting is enabled
if (SettingsManager.Settings.HighScoreInfo.Value == HighScoreInfoMode.Score)
if (scoreInfoMode == HighScoreInfoMode.Score)
{
builder.AppendFormat("<space=2em> {0:N0}", _playerScoreRecord.Score);
builder.AppendFormat("{0:N0}", _playerScoreRecord.Score);
}

return builder.ToString();
Expand Down Expand Up @@ -178,42 +193,18 @@ private void FetchHighScores()

_fetchedScores = true;

_playerScoreRecord = GetHighScoreForSong(SongEntry);
_bandScoreRecord = GetBandHighScoreForSong(SongEntry);
}

private PlayerScoreRecord GetHighScoreForSong(SongEntry song)
{
if (!_musicLibrary.ShouldDisplaySoloHighScores)
{
return null;
}

var player = PlayerContainer.Players.First(e => !e.Profile.IsBot);

var result = ScoreContainer.GetHighScore(
song.Hash, player.Profile.Id, player.Profile.CurrentInstrument);

var percResult = ScoreContainer.GetBestPercentageScore(
song.Hash, player.Profile.Id, player.Profile.CurrentInstrument);

if (result is not null)
if (_musicLibrary.ShouldDisplaySoloHighScores)
{
YargLogger.Assert(percResult is not null, "Best Percentage score is missing!");
result.Percent = percResult.GetPercent();
var player = PlayerContainer.Players.First(e => !e.Profile.IsBot);
_playerScoreRecord = ScoreContainer.GetHighScore(
SongEntry.Hash, player.Profile.Id, player.Profile.CurrentInstrument);
_playerPercentRecord = ScoreContainer.GetBestPercentageScore(
SongEntry.Hash, player.Profile.Id, player.Profile.CurrentInstrument);
}

return result;
}

private GameRecord GetBandHighScoreForSong(SongEntry song)
{
if (_musicLibrary.ShouldDisplaySoloHighScores)
else
{
return null;
_bandScoreRecord = ScoreContainer.GetBandHighScore(SongEntry.Hash);
}

return ScoreContainer.GetBandHighScore(song.Hash);
}
}
}
57 changes: 0 additions & 57 deletions Assets/Script/Scores/ScoreContainer.Queries.cs

This file was deleted.

Loading

0 comments on commit 801f9e8

Please sign in to comment.