mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Handle query params better.
This commit is contained in:
parent
096e98b5d3
commit
b6de1ce5b6
@ -12,6 +12,7 @@ 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;
|
using System.Collections.Specialized;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests
|
namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
@ -31,7 +32,7 @@ namespace osu.Game.Online.API.Requests
|
|||||||
Success += onSuccess;
|
Success += onSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetScoresRequest(BeatmapInfo beatmap, LeaderboardScope scope, RulesetInfo ruleset)
|
public GetScoresRequest(BeatmapInfo beatmap, RulesetInfo ruleset, LeaderboardScope scope = LeaderboardScope.Global)
|
||||||
{
|
{
|
||||||
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)}.");
|
||||||
@ -49,46 +50,53 @@ namespace osu.Game.Online.API.Requests
|
|||||||
score.ApplyBeatmap(beatmap);
|
score.ApplyBeatmap(beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string mapScopeToQuery()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
switch(scope)
|
switch(scope)
|
||||||
{
|
{
|
||||||
|
default:
|
||||||
case LeaderboardScope.Global:
|
case LeaderboardScope.Global:
|
||||||
return @"type=global";
|
req.AddParameter(@"type", @"global");
|
||||||
|
break;
|
||||||
|
|
||||||
case LeaderboardScope.Friends:
|
case LeaderboardScope.Friends:
|
||||||
return @"type=friend";
|
req.AddParameter(@"type", @"friend");
|
||||||
|
break;
|
||||||
|
|
||||||
case LeaderboardScope.Country:
|
case LeaderboardScope.Country:
|
||||||
return @"type=country";
|
req.AddParameter(@"type", @"country");
|
||||||
|
break;
|
||||||
default:
|
|
||||||
return String.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private string mapRulesetToQuery()
|
if (ruleset != null)
|
||||||
{
|
|
||||||
switch(ruleset.Name)
|
|
||||||
{
|
{
|
||||||
case @"osu!":
|
switch (ruleset.Name)
|
||||||
return @"mode=osu";
|
{
|
||||||
|
default:
|
||||||
|
case @"osu!":
|
||||||
|
req.AddParameter(@"mode", @"osu");
|
||||||
|
break;
|
||||||
|
|
||||||
case @"osu!taiko":
|
case @"osu!taiko":
|
||||||
return @"mode=taiko";
|
req.AddParameter(@"mode", @"taiko");
|
||||||
|
break;
|
||||||
case @"osu!catch":
|
|
||||||
return @"mode=catch";
|
|
||||||
|
|
||||||
case @"osu!mania":
|
|
||||||
return @"mode=mania";
|
|
||||||
|
|
||||||
default:
|
case @"osu!catch":
|
||||||
return String.Empty;
|
req.AddParameter(@"mode", @"catch");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case @"osu!mania":
|
||||||
|
req.AddParameter(@"mode", @"mania");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores?{mapScopeToQuery()}&{mapRulesetToQuery()}";
|
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetScoresResponse
|
public class GetScoresResponse
|
||||||
|
@ -193,7 +193,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
loading.Show();
|
loading.Show();
|
||||||
|
|
||||||
getScoresRequest = new GetScoresRequest(Beatmap, Scope, osuGame.Ruleset.Value);
|
getScoresRequest = new GetScoresRequest(Beatmap, osuGame.Ruleset.Value, Scope);
|
||||||
getScoresRequest.Success += r =>
|
getScoresRequest.Success += r =>
|
||||||
{
|
{
|
||||||
Scores = r.Scores;
|
Scores = r.Scores;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user