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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-28 03:27:29 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-10-29 05:57:03 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2020-02-19 22:33:48 +08:00
|
|
|
|
using osu.Framework.IO.Network;
|
2020-05-13 04:04:39 +08:00
|
|
|
|
using osu.Game.Extensions;
|
2017-10-13 18:57:59 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2020-04-21 14:37:50 +08:00
|
|
|
|
using osu.Game.Overlays.BeatmapListing;
|
2017-10-13 18:57:59 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2020-10-29 04:35:08 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-13 18:57:59 +08:00
|
|
|
|
namespace osu.Game.Online.API.Requests
|
|
|
|
|
{
|
2018-10-23 17:04:38 +08:00
|
|
|
|
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
|
2017-10-13 18:57:59 +08:00
|
|
|
|
{
|
2021-03-26 06:20:10 +08:00
|
|
|
|
[CanBeNull]
|
|
|
|
|
public IReadOnlyCollection<SearchGeneral> General { get; }
|
|
|
|
|
|
2020-05-14 00:57:03 +08:00
|
|
|
|
public SearchCategory SearchCategory { get; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-05-14 00:57:03 +08:00
|
|
|
|
public SortCriteria SortCriteria { get; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-05-14 00:57:03 +08:00
|
|
|
|
public SortDirection SortDirection { get; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-05-14 00:57:03 +08:00
|
|
|
|
public SearchGenre Genre { get; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-05-14 00:57:03 +08:00
|
|
|
|
public SearchLanguage Language { get; }
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2020-10-29 05:57:03 +08:00
|
|
|
|
[CanBeNull]
|
2020-10-28 07:36:35 +08:00
|
|
|
|
public IReadOnlyCollection<SearchExtra> Extra { get; }
|
2020-10-28 01:13:18 +08:00
|
|
|
|
|
2020-10-28 02:30:53 +08:00
|
|
|
|
public SearchPlayed Played { get; }
|
|
|
|
|
|
2021-01-17 21:40:24 +08:00
|
|
|
|
public SearchExplicit ExplicitContent { get; }
|
2021-01-12 16:09:55 +08:00
|
|
|
|
|
2020-10-29 05:57:03 +08:00
|
|
|
|
[CanBeNull]
|
2020-10-29 04:35:08 +08:00
|
|
|
|
public IReadOnlyCollection<ScoreRank> Ranks { get; }
|
2020-10-28 04:14:48 +08:00
|
|
|
|
|
2017-10-13 18:57:59 +08:00
|
|
|
|
private readonly string query;
|
|
|
|
|
private readonly RulesetInfo ruleset;
|
2020-05-12 02:18:47 +08:00
|
|
|
|
private readonly Cursor cursor;
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
|
|
|
|
private string directionString => SortDirection == SortDirection.Descending ? @"desc" : @"asc";
|
|
|
|
|
|
2020-05-30 02:43:31 +08:00
|
|
|
|
public SearchBeatmapSetsRequest(
|
|
|
|
|
string query,
|
2020-05-30 00:44:53 +08:00
|
|
|
|
RulesetInfo ruleset,
|
|
|
|
|
Cursor cursor = null,
|
2021-03-26 06:20:10 +08:00
|
|
|
|
IReadOnlyCollection<SearchGeneral> general = null,
|
2020-05-30 00:44:53 +08:00
|
|
|
|
SearchCategory searchCategory = SearchCategory.Any,
|
|
|
|
|
SortCriteria sortCriteria = SortCriteria.Ranked,
|
|
|
|
|
SortDirection sortDirection = SortDirection.Descending,
|
|
|
|
|
SearchGenre genre = SearchGenre.Any,
|
2020-10-28 01:13:18 +08:00
|
|
|
|
SearchLanguage language = SearchLanguage.Any,
|
2020-10-28 07:36:35 +08:00
|
|
|
|
IReadOnlyCollection<SearchExtra> extra = null,
|
2020-10-29 04:35:08 +08:00
|
|
|
|
IReadOnlyCollection<ScoreRank> ranks = null,
|
2021-01-12 16:09:55 +08:00
|
|
|
|
SearchPlayed played = SearchPlayed.Any,
|
2021-01-17 21:40:24 +08:00
|
|
|
|
SearchExplicit explicitContent = SearchExplicit.Hide)
|
2017-10-13 18:57:59 +08:00
|
|
|
|
{
|
2021-07-25 16:06:39 +08:00
|
|
|
|
this.query = query;
|
2017-10-13 18:57:59 +08:00
|
|
|
|
this.ruleset = ruleset;
|
2020-05-12 02:18:47 +08:00
|
|
|
|
this.cursor = cursor;
|
2020-02-21 06:49:03 +08:00
|
|
|
|
|
2021-03-26 06:20:10 +08:00
|
|
|
|
General = general;
|
2020-05-12 02:18:47 +08:00
|
|
|
|
SearchCategory = searchCategory;
|
|
|
|
|
SortCriteria = sortCriteria;
|
|
|
|
|
SortDirection = sortDirection;
|
2020-05-30 00:44:53 +08:00
|
|
|
|
Genre = genre;
|
|
|
|
|
Language = language;
|
2020-10-28 01:13:18 +08:00
|
|
|
|
Extra = extra;
|
2020-10-28 04:14:48 +08:00
|
|
|
|
Ranks = ranks;
|
2020-10-28 02:30:53 +08:00
|
|
|
|
Played = played;
|
2021-01-17 21:40:24 +08:00
|
|
|
|
ExplicitContent = explicitContent;
|
2017-10-13 18:57:59 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-19 22:33:48 +08:00
|
|
|
|
protected override WebRequest CreateWebRequest()
|
|
|
|
|
{
|
|
|
|
|
var req = base.CreateWebRequest();
|
2021-07-25 16:06:39 +08:00
|
|
|
|
|
|
|
|
|
if (query != null)
|
|
|
|
|
req.AddParameter("q", query);
|
2020-02-19 22:33:48 +08:00
|
|
|
|
|
2021-03-26 06:20:10 +08:00
|
|
|
|
if (General != null && General.Any())
|
2022-06-20 21:02:15 +08:00
|
|
|
|
req.AddParameter("c", string.Join('.', General.Select(e => e.ToString().ToSnakeCase())));
|
2021-03-26 06:20:10 +08:00
|
|
|
|
|
2021-11-24 14:25:49 +08:00
|
|
|
|
if (ruleset.OnlineID >= 0)
|
|
|
|
|
req.AddParameter("m", ruleset.OnlineID.ToString());
|
2020-02-19 22:33:48 +08:00
|
|
|
|
|
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
|
|
|
|
|
2020-10-28 03:27:29 +08:00
|
|
|
|
if (Extra != null && Extra.Any())
|
2020-10-28 04:57:11 +08:00
|
|
|
|
req.AddParameter("e", string.Join('.', Extra.Select(e => e.ToString().ToLowerInvariant())));
|
2020-10-28 01:13:18 +08:00
|
|
|
|
|
2020-10-28 04:14:48 +08:00
|
|
|
|
if (Ranks != null && Ranks.Any())
|
2020-10-28 04:57:11 +08:00
|
|
|
|
req.AddParameter("r", string.Join('.', Ranks.Select(r => r.ToString())));
|
2020-10-28 04:14:48 +08:00
|
|
|
|
|
2020-10-28 02:30:53 +08:00
|
|
|
|
if (Played != SearchPlayed.Any)
|
|
|
|
|
req.AddParameter("played", Played.ToString().ToLowerInvariant());
|
|
|
|
|
|
2021-01-17 21:40:24 +08:00
|
|
|
|
req.AddParameter("nsfw", ExplicitContent == SearchExplicit.Show ? "true" : "false");
|
2021-01-12 16:09:55 +08:00
|
|
|
|
|
2022-06-30 23:29:49 +08:00
|
|
|
|
if (cursor != null)
|
|
|
|
|
req.AddCursor(cursor);
|
2020-10-28 03:27:29 +08:00
|
|
|
|
|
2020-02-19 22:33:48 +08:00
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string Target => @"beatmapsets/search";
|
2018-04-18 13:16:58 +08:00
|
|
|
|
}
|
2017-10-13 18:57:59 +08:00
|
|
|
|
}
|