mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Apply currently selected mods to filter leaderboard scores
Modifies GetScoresRequest to build query string locally instead of using WebRequest.AddParameter since it doesn't support array parameters
This commit is contained in:
@ -5,8 +5,10 @@ using System;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Select.Leaderboards;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
@ -15,8 +17,9 @@ namespace osu.Game.Online.API.Requests
|
||||
private readonly BeatmapInfo beatmap;
|
||||
private readonly BeatmapLeaderboardScope scope;
|
||||
private readonly RulesetInfo ruleset;
|
||||
private readonly IEnumerable<Mod> mods;
|
||||
|
||||
public GetScoresRequest(BeatmapInfo beatmap, RulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global)
|
||||
public GetScoresRequest(BeatmapInfo beatmap, RulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global, IEnumerable<Mod> mods = null)
|
||||
{
|
||||
if (!beatmap.OnlineBeatmapID.HasValue)
|
||||
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}.");
|
||||
@ -27,6 +30,7 @@ namespace osu.Game.Online.API.Requests
|
||||
this.beatmap = beatmap;
|
||||
this.scope = scope;
|
||||
this.ruleset = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
|
||||
this.mods = mods ?? Array.Empty<Mod>();
|
||||
|
||||
Success += onSuccess;
|
||||
}
|
||||
@ -37,17 +41,19 @@ namespace osu.Game.Online.API.Requests
|
||||
score.Beatmap = beatmap;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{createQueryParameters()}";
|
||||
|
||||
private string createQueryParameters()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
StringBuilder query = new StringBuilder(@"?");
|
||||
|
||||
req.Timeout = 30000;
|
||||
req.AddParameter(@"type", scope.ToString().ToLowerInvariant());
|
||||
req.AddParameter(@"mode", ruleset.ShortName);
|
||||
query.Append($@"type={scope.ToString().ToLowerInvariant()}&");
|
||||
query.Append($@"mode={ruleset.ShortName}&");
|
||||
|
||||
return req;
|
||||
foreach (var mod in mods)
|
||||
query.Append($@"mods[]={mod.Acronym}&");
|
||||
|
||||
return query.ToString().TrimEnd('&');
|
||||
}
|
||||
|
||||
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user