2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
2018-04-18 13:16:58 +08:00
|
|
|
|
using System.ComponentModel;
|
2020-02-19 22:33:48 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2018-10-23 17:04:38 +08:00
|
|
|
|
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly string query;
|
|
|
|
|
private readonly RulesetInfo ruleset;
|
2018-04-18 13:16:58 +08:00
|
|
|
|
private readonly BeatmapSearchCategory searchCategory;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly DirectSortCriteria sortCriteria;
|
|
|
|
|
private readonly SortDirection direction;
|
|
|
|
|
private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc";
|
|
|
|
|
|
2018-04-18 13:16:58 +08:00
|
|
|
|
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset, BeatmapSearchCategory searchCategory = BeatmapSearchCategory.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-11-13 10:49:36 +08:00
|
|
|
|
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
this.ruleset = ruleset;
|
2018-04-18 13:16:58 +08:00
|
|
|
|
this.searchCategory = searchCategory;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
this.sortCriteria = sortCriteria;
|
|
|
|
|
this.direction = direction;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 22:33:48 +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());
|
|
|
|
|
req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}");
|
|
|
|
|
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string Target => @"beatmapsets/search";
|
2018-04-18 13:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum BeatmapSearchCategory
|
|
|
|
|
{
|
2019-08-03 04:16:33 +08:00
|
|
|
|
Any,
|
2018-10-23 17:04:38 +08:00
|
|
|
|
|
2019-08-03 04:16:33 +08:00
|
|
|
|
[Description("Has Leaderboard")]
|
|
|
|
|
Leaderboard,
|
|
|
|
|
Ranked,
|
|
|
|
|
Qualified,
|
|
|
|
|
Loved,
|
|
|
|
|
Favourites,
|
2019-01-21 01:39:07 +08:00
|
|
|
|
|
|
|
|
|
[Description("Pending & WIP")]
|
2019-08-03 04:16:33 +08:00
|
|
|
|
Pending,
|
|
|
|
|
Graveyard,
|
2018-10-23 17:04:38 +08:00
|
|
|
|
|
2018-04-18 13:16:58 +08:00
|
|
|
|
[Description("My Maps")]
|
2019-08-03 04:16:33 +08:00
|
|
|
|
Mine,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|