Skip to content

Commit

Permalink
Re-sync judgement counter display after replay frame reset
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Sep 18, 2024
1 parent c46e9cb commit 8f49876
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
Expand Down Expand Up @@ -53,8 +52,40 @@ protected override void LoadComplete()
{
base.LoadComplete();

scoreProcessor.OnResetFromReplayFrame += updateAllCounts;
scoreProcessor.NewJudgement += judgement => updateCount(judgement, false);
scoreProcessor.JudgementReverted += judgement => updateCount(judgement, true);

updateAllCounts();
}

private void updateAllCounts()
{
// This flow is made to handle cases of watching from the middle of a replay / spectating session.
//
// Once we get an initial state, we can rely on `NewJudgement` and `JudgementReverted`, so
// as a preemptive optimisation, only do a full re-sync if we have all-zero counts.
bool hasCounts = false;

foreach (var r in results)
{
if (r.Value.ResultCount.Value > 0)
{
hasCounts = true;
break;
}
}

if (hasCounts)
return;

foreach (var kvp in scoreProcessor.Statistics)
{
if (!results.TryGetValue(kvp.Key, out var count))
continue;

count.ResultCount.Value = kvp.Value;
}
}

private void updateCount(JudgementResult judgement, bool revert)
Expand Down

0 comments on commit 8f49876

Please sign in to comment.