1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 18:33:04 +08:00

Add game mode query to request.

- Also update scores when game mode is changed
This commit is contained in:
Unknown 2017-11-21 19:44:38 +05:30 committed by naoey
parent 487483eadd
commit 096e98b5d3
2 changed files with 48 additions and 10 deletions

View File

@ -11,6 +11,7 @@ using osu.Game.Users;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using System.Collections.Specialized;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
@ -18,14 +19,26 @@ namespace osu.Game.Online.API.Requests
{ {
private readonly BeatmapInfo beatmap; private readonly BeatmapInfo beatmap;
private readonly LeaderboardScope scope; private readonly LeaderboardScope scope;
private readonly RulesetInfo ruleset;
public GetScoresRequest(BeatmapInfo beatmap, LeaderboardScope scope = LeaderboardScope.Global) public GetScoresRequest(BeatmapInfo beatmap)
{
if (!beatmap.OnlineBeatmapID.HasValue)
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}.");
this.beatmap = beatmap;
Success += onSuccess;
}
public GetScoresRequest(BeatmapInfo beatmap, LeaderboardScope scope, RulesetInfo ruleset)
{ {
if (!beatmap.OnlineBeatmapID.HasValue) if (!beatmap.OnlineBeatmapID.HasValue)
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}."); throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}.");
this.beatmap = beatmap; this.beatmap = beatmap;
this.scope = scope; this.scope = scope;
this.ruleset = ruleset;
Success += onSuccess; Success += onSuccess;
} }
@ -41,20 +54,41 @@ namespace osu.Game.Online.API.Requests
switch(scope) switch(scope)
{ {
case LeaderboardScope.Global: case LeaderboardScope.Global:
return @"?type=global"; return @"type=global";
case LeaderboardScope.Friends: case LeaderboardScope.Friends:
return @"?type=friend"; return @"type=friend";
case LeaderboardScope.Country: case LeaderboardScope.Country:
return @"?type=country"; return @"type=country";
default: default:
return String.Empty; return String.Empty;
} }
} }
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{mapScopeToQuery()}"; private string mapRulesetToQuery()
{
switch(ruleset.Name)
{
case @"osu!":
return @"mode=osu";
case @"osu!taiko":
return @"mode=taiko";
case @"osu!catch":
return @"mode=catch";
case @"osu!mania":
return @"mode=mania";
default:
return String.Empty;
}
}
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores?{mapScopeToQuery()}&{mapRulesetToQuery()}";
} }
public class GetScoresResponse public class GetScoresResponse

View File

@ -146,6 +146,8 @@ namespace osu.Game.Screens.Select.Leaderboards
private BeatmapInfo beatmap; private BeatmapInfo beatmap;
private OsuGame osuGame;
private ScheduledDelegate pendingBeatmapSwitch; private ScheduledDelegate pendingBeatmapSwitch;
public BeatmapInfo Beatmap public BeatmapInfo Beatmap
@ -164,9 +166,12 @@ namespace osu.Game.Screens.Select.Leaderboards
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api) private void load(APIAccess api, OsuGame osuGame)
{ {
this.api = api; this.api = api;
this.osuGame = osuGame;
osuGame.Ruleset.ValueChanged += r => updateScores();
} }
private GetScoresRequest getScoresRequest; private GetScoresRequest getScoresRequest;
@ -176,7 +181,8 @@ namespace osu.Game.Screens.Select.Leaderboards
if (!IsLoaded) return; if (!IsLoaded) return;
Scores = null; Scores = null;
getScoresRequest?.Cancel();
if (api == null || Beatmap?.OnlineBeatmapID == null) return;
if (Scope == LeaderboardScope.Local) if (Scope == LeaderboardScope.Local)
{ {
@ -185,11 +191,9 @@ namespace osu.Game.Screens.Select.Leaderboards
return; return;
} }
if (api == null || Beatmap?.OnlineBeatmapID == null) return;
loading.Show(); loading.Show();
getScoresRequest = new GetScoresRequest(Beatmap, Scope); getScoresRequest = new GetScoresRequest(Beatmap, Scope, osuGame.Ruleset.Value);
getScoresRequest.Success += r => getScoresRequest.Success += r =>
{ {
Scores = r.Scores; Scores = r.Scores;