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
|
|
|
|
|
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;
|
2020-04-21 14:37:50 +08:00
|
|
|
|
using osu.Game.Overlays.BeatmapListing;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
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
|
|
|
|
{
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public SearchCategory SearchCategory { get; set; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-04-21 15:00:00 +08:00
|
|
|
|
public SortCriteria SortCriteria { get; set; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
|
|
|
|
public SortDirection SortDirection { get; set; }
|
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public SearchGenre Genre { get; set; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public SearchLanguage Language { get; set; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly string query;
|
|
|
|
|
private readonly RulesetInfo ruleset;
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
|
|
|
|
private string directionString => SortDirection == SortDirection.Descending ? @"desc" : @"asc";
|
|
|
|
|
|
|
|
|
|
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset)
|
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;
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
SearchCategory = SearchCategory.Any;
|
2020-04-21 15:00:00 +08:00
|
|
|
|
SortCriteria = SortCriteria.Ranked;
|
2020-02-21 06:49:03 +08:00
|
|
|
|
SortDirection = SortDirection.Descending;
|
2020-04-21 14:37:50 +08:00
|
|
|
|
Genre = SearchGenre.Any;
|
|
|
|
|
Language = SearchLanguage.Any;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
|
2020-02-21 06:49:03 +08:00
|
|
|
|
req.AddParameter("s", SearchCategory.ToString().ToLowerInvariant());
|
2020-02-20 22:40:45 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
if (Genre != SearchGenre.Any)
|
2020-02-21 06:49:03 +08:00
|
|
|
|
req.AddParameter("g", ((int)Genre).ToString());
|
2020-02-20 22:40:45 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
if (Language != SearchLanguage.Any)
|
2020-02-21 06:49:03 +08:00
|
|
|
|
req.AddParameter("l", ((int)Language).ToString());
|
2020-02-20 22:56:49 +08:00
|
|
|
|
|
2020-02-21 06:49:03 +08:00
|
|
|
|
req.AddParameter("sort", $"{SortCriteria.ToString().ToLowerInvariant()}_{directionString}");
|
2020-02-19 22:33:48 +08:00
|
|
|
|
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string Target => @"beatmapsets/search";
|
2018-04-18 13:16:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|