mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Move leaderboard update scheduling to a more central method
This commit is contained in:
@ -175,7 +175,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
private APIAccess api;
|
private APIAccess api;
|
||||||
private BeatmapInfo beatmap;
|
private BeatmapInfo beatmap;
|
||||||
|
|
||||||
private ScheduledDelegate pendingBeatmapSwitch;
|
private ScheduledDelegate pendingUpdateScores;
|
||||||
|
|
||||||
public BeatmapInfo Beatmap
|
public BeatmapInfo Beatmap
|
||||||
{
|
{
|
||||||
@ -188,8 +188,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
beatmap = value;
|
beatmap = value;
|
||||||
Scores = null;
|
Scores = null;
|
||||||
|
|
||||||
pendingBeatmapSwitch?.Cancel();
|
updateScores();
|
||||||
pendingBeatmapSwitch = Schedule(updateScores);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,51 +228,58 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
private void updateScores()
|
private void updateScores()
|
||||||
{
|
{
|
||||||
if (Scope == LeaderboardScope.Local)
|
getScoresRequest?.Cancel();
|
||||||
{
|
getScoresRequest = null;
|
||||||
// TODO: get local scores from wherever here.
|
|
||||||
PlaceholderState = PlaceholderState.NoScores;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Beatmap?.OnlineBeatmapID == null)
|
pendingUpdateScores?.Cancel();
|
||||||
|
pendingUpdateScores = Schedule(() =>
|
||||||
{
|
{
|
||||||
PlaceholderState = PlaceholderState.Unavailable;
|
if (Scope == LeaderboardScope.Local)
|
||||||
return;
|
{
|
||||||
}
|
// TODO: get local scores from wherever here.
|
||||||
|
PlaceholderState = PlaceholderState.NoScores;
|
||||||
if (api?.IsLoggedIn != true)
|
|
||||||
{
|
|
||||||
PlaceholderState = PlaceholderState.NotLoggedIn;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Scope != LeaderboardScope.Global && !api.LocalUser.Value.IsSupporter)
|
|
||||||
{
|
|
||||||
PlaceholderState = PlaceholderState.NotSupporter;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlaceholderState = PlaceholderState.Retrieving;
|
|
||||||
loading.Show();
|
|
||||||
|
|
||||||
getScoresRequest = new GetScoresRequest(Beatmap, osuGame?.Ruleset.Value ?? Beatmap.Ruleset, Scope);
|
|
||||||
getScoresRequest.Success += r => Schedule(() =>
|
|
||||||
{
|
|
||||||
Scores = r.Scores;
|
|
||||||
PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
|
|
||||||
});
|
|
||||||
|
|
||||||
getScoresRequest.Failure += e => Schedule(() =>
|
|
||||||
{
|
|
||||||
if (e is OperationCanceledException)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlaceholderState = PlaceholderState.NetworkFailure;
|
if (Beatmap?.OnlineBeatmapID == null)
|
||||||
Logger.Error(e, @"Couldn't fetch beatmap scores!");
|
{
|
||||||
|
PlaceholderState = PlaceholderState.Unavailable;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (api?.IsLoggedIn != true)
|
||||||
|
{
|
||||||
|
PlaceholderState = PlaceholderState.NotLoggedIn;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Scope != LeaderboardScope.Global && !api.LocalUser.Value.IsSupporter)
|
||||||
|
{
|
||||||
|
PlaceholderState = PlaceholderState.NotSupporter;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlaceholderState = PlaceholderState.Retrieving;
|
||||||
|
loading.Show();
|
||||||
|
|
||||||
|
getScoresRequest = new GetScoresRequest(Beatmap, ruleset.Value ?? Beatmap.Ruleset, Scope);
|
||||||
|
getScoresRequest.Success += r => Schedule(() =>
|
||||||
|
{
|
||||||
|
Scores = r.Scores;
|
||||||
|
PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
|
||||||
|
});
|
||||||
|
|
||||||
|
getScoresRequest.Failure += e => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (e is OperationCanceledException)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlaceholderState = PlaceholderState.NetworkFailure;
|
||||||
|
Logger.Error(e, @"Couldn't fetch beatmap scores!");
|
||||||
|
});
|
||||||
|
|
||||||
|
api.Queue(getScoresRequest);
|
||||||
});
|
});
|
||||||
|
|
||||||
api.Queue(getScoresRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Placeholder currentPlaceholder;
|
private Placeholder currentPlaceholder;
|
||||||
|
Reference in New Issue
Block a user