1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 01:22:59 +08:00

fix flow on error states

This commit is contained in:
Wleter 2024-12-29 18:46:26 +01:00
parent 92f0beb350
commit 5cc7ad4cf1
4 changed files with 14 additions and 32 deletions

View File

@ -465,7 +465,11 @@ namespace osu.Game.Tests.Visual.SongSelect
private partial class FailableScoresProvider : BeatmapLeaderboardScoresProvider private partial class FailableScoresProvider : BeatmapLeaderboardScoresProvider
{ {
public new void SetErrorState(LeaderboardState state) => base.SetErrorState(state); public new void SetErrorState(LeaderboardState state) => base.SetErrorState(state);
public new void SetScores(IEnumerable<ScoreInfo>? scores, ScoreInfo? userScore = null) => base.SetScores(scores, userScore); public new void SetScores(IEnumerable<ScoreInfo>? scores, ScoreInfo? userScore = null)
{
SetState(LeaderboardState.Retrieving);
base.SetScores(scores, userScore);
}
} }
} }
} }

View File

@ -91,17 +91,9 @@ namespace osu.Game.Online.Leaderboards
LeaderboardScoresProvider.State.BindValueChanged(state => onStateChange(state.NewValue)); LeaderboardScoresProvider.State.BindValueChanged(state => onStateChange(state.NewValue));
} }
private void setNewScores(LeaderboardState state) private void onStateChange(LeaderboardState state)
{ {
// Non-delayed schedule may potentially run inline (due to IsMainThread check passing) after leaderboard is disposed. Schedule(applyNewScores);
// This is guarded against in BeatmapLeaderboard via web request cancellation, but let's be extra safe.
if (!IsDisposed)
{
// Schedule needs to be non-delayed here for the weird logic in refetchScores to work.
// If it is removed, the placeholder will be incorrectly updated to "no scores" rather than "retrieving".
// This whole flow should be refactored in the future.
Scheduler.Add(applyNewScores, false);
}
void applyNewScores() void applyNewScores()
{ {
@ -129,7 +121,7 @@ namespace osu.Game.Online.Leaderboards
.Expire(); .Expire();
scoreFlowContainer = null; scoreFlowContainer = null;
if (state == LeaderboardState.NoScores) if (!LeaderboardScoresProvider.Scores.Any())
{ {
setPlaceholder(state); setPlaceholder(state);
return; return;
@ -162,21 +154,6 @@ namespace osu.Game.Online.Leaderboards
}, (currentScoresAsyncLoadCancellationSource = new CancellationTokenSource()).Token); }, (currentScoresAsyncLoadCancellationSource = new CancellationTokenSource()).Token);
} }
private void onStateChange(LeaderboardState state)
{
switch (state)
{
case LeaderboardState.Success:
case LeaderboardState.NoScores:
setNewScores(state);
break;
default:
setPlaceholder(state);
break;
}
}
#region Placeholder handling #region Placeholder handling
private Placeholder? placeholder; private Placeholder? placeholder;

View File

@ -91,8 +91,7 @@ namespace osu.Game.Online.Leaderboards
{ {
Debug.Assert(ThreadSafety.IsUpdateThread); Debug.Assert(ThreadSafety.IsUpdateThread);
ClearScores(); PrepareScoresRetrieval();
SetState(LeaderboardState.Retrieving);
currentFetchCancellationSource = new CancellationTokenSource(); currentFetchCancellationSource = new CancellationTokenSource();
@ -138,10 +137,12 @@ namespace osu.Game.Online.Leaderboards
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns> /// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
protected abstract APIRequest? FetchScores(CancellationToken cancellationToken); protected abstract APIRequest? FetchScores(CancellationToken cancellationToken);
public void ClearScores() protected void PrepareScoresRetrieval()
{ {
cancelPendingWork(); cancelPendingWork();
SetScores(null);
scores.Clear();
SetState(LeaderboardState.Retrieving);
} }
private void cancelPendingWork() private void cancelPendingWork()

View File

@ -40,7 +40,7 @@ namespace osu.Game.Screens.Select.Leaderboards
// Refetch is scheduled, which can cause scores to be outdated if the leaderboard is not currently updating. // Refetch is scheduled, which can cause scores to be outdated if the leaderboard is not currently updating.
// As scores are potentially used by other components, clear them eagerly to ensure a more correct state. // As scores are potentially used by other components, clear them eagerly to ensure a more correct state.
SetScores(null); PrepareScoresRetrieval();
RefetchScores(); RefetchScores();
} }