1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:07:24 +08:00
osu-lazer/osu.Game/Online/API/Requests/SearchBeatmapSetsRequest.cs

90 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
using System.ComponentModel;
using osu.Framework.IO.Network;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Direct;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests
{
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
2018-04-13 17:19:50 +08:00
{
private readonly string query;
private readonly RulesetInfo ruleset;
private readonly BeatmapSearchCategory searchCategory;
2018-04-13 17:19:50 +08:00
private readonly DirectSortCriteria sortCriteria;
private readonly SortDirection direction;
2020-02-20 22:40:45 +08:00
private readonly BeatmapSearchGenre genre;
2018-04-13 17:19:50 +08:00
private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc";
2020-02-20 22:40:45 +08:00
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset, BeatmapSearchCategory searchCategory = BeatmapSearchCategory.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending, BeatmapSearchGenre genre = BeatmapSearchGenre.Any)
2018-04-13 17:19:50 +08:00
{
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
2018-04-13 17:19:50 +08:00
this.ruleset = ruleset;
this.searchCategory = searchCategory;
2018-04-13 17:19:50 +08:00
this.sortCriteria = sortCriteria;
this.direction = direction;
2020-02-20 22:40:45 +08:00
this.genre = genre;
2018-04-13 17:19:50 +08:00
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("q", query);
if (ruleset.ID.HasValue)
req.AddParameter("m", ruleset.ID.Value.ToString());
req.AddParameter("s", searchCategory.ToString().ToLowerInvariant());
2020-02-20 22:40:45 +08:00
if (genre != BeatmapSearchGenre.Any)
req.AddParameter("g", ((int)genre).ToString());
req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}");
return req;
}
protected override string Target => @"beatmapsets/search";
}
public enum BeatmapSearchCategory
{
Any,
[Description("Has Leaderboard")]
Leaderboard,
Ranked,
Qualified,
Loved,
Favourites,
[Description("Pending & WIP")]
Pending,
Graveyard,
[Description("My Maps")]
Mine,
2018-04-13 17:19:50 +08:00
}
2020-02-20 22:40:45 +08:00
public enum BeatmapSearchGenre
{
Any,
Unspecified,
[Description("Video Game")]
Game,
Anime,
Rock,
Pop,
Other,
Novelty,
[Description("Hip Hop")]
Hiphop = 9,
Electronic
}
2018-04-13 17:19:50 +08:00
}