2017-05-28 13:26:25 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-06-07 21:40:18 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Direct;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API.Requests
|
|
|
|
|
{
|
|
|
|
|
public class GetBeatmapSetsRequest : APIRequest<IEnumerable<GetBeatmapSetsResponse>>
|
|
|
|
|
{
|
|
|
|
|
private readonly string query;
|
2017-06-07 22:00:05 +08:00
|
|
|
|
private readonly RulesetInfo ruleset;
|
2017-05-28 13:43:37 +08:00
|
|
|
|
private readonly RankStatus rankStatus;
|
2017-06-07 21:40:18 +08:00
|
|
|
|
private readonly DirectSortCriteria sortCriteria;
|
|
|
|
|
private readonly SortDirection direction;
|
|
|
|
|
private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc";
|
2017-05-28 13:26:25 +08:00
|
|
|
|
|
2017-06-07 22:00:05 +08:00
|
|
|
|
public GetBeatmapSetsRequest(string query, RulesetInfo ruleset, RankStatus rankStatus = RankStatus.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending)
|
2017-05-28 13:26:25 +08:00
|
|
|
|
{
|
|
|
|
|
this.query = System.Uri.EscapeDataString(query);
|
2017-06-07 22:00:05 +08:00
|
|
|
|
this.ruleset = ruleset;
|
2017-05-28 13:43:37 +08:00
|
|
|
|
this.rankStatus = rankStatus;
|
2017-06-07 21:40:18 +08:00
|
|
|
|
this.sortCriteria = sortCriteria;
|
|
|
|
|
this.direction = direction;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 22:00:05 +08:00
|
|
|
|
protected override string Target => $@"beatmapsets/search?q={query}&m={ruleset.ID ?? 0}&s={(int)rankStatus}&sort={sortCriteria.ToString().ToLower()}_{directionString}";
|
2017-05-28 13:26:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class GetBeatmapSetsResponse : BeatmapMetadata
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"covers")]
|
|
|
|
|
private BeatmapSetOnlineCovers covers { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"previewUrl")]
|
|
|
|
|
private string preview { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"play_count")]
|
|
|
|
|
private int playCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"favourite_count")]
|
|
|
|
|
private int favouriteCount { get; set; }
|
|
|
|
|
|
2017-08-24 19:14:35 +08:00
|
|
|
|
[JsonProperty(@"id")]
|
|
|
|
|
private int onlineId { get; set; }
|
|
|
|
|
|
2017-05-28 13:26:25 +08:00
|
|
|
|
[JsonProperty(@"beatmaps")]
|
|
|
|
|
private IEnumerable<GetBeatmapSetsBeatmapResponse> beatmaps { get; set; }
|
|
|
|
|
|
2017-07-27 15:56:41 +08:00
|
|
|
|
public BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets)
|
2017-05-28 13:26:25 +08:00
|
|
|
|
{
|
|
|
|
|
return new BeatmapSetInfo
|
|
|
|
|
{
|
2017-08-24 19:14:35 +08:00
|
|
|
|
OnlineBeatmapSetID = onlineId,
|
2017-05-28 13:26:25 +08:00
|
|
|
|
Metadata = this,
|
|
|
|
|
OnlineInfo = new BeatmapSetOnlineInfo
|
|
|
|
|
{
|
|
|
|
|
Covers = covers,
|
|
|
|
|
Preview = preview,
|
|
|
|
|
PlayCount = playCount,
|
|
|
|
|
FavouriteCount = favouriteCount,
|
|
|
|
|
},
|
|
|
|
|
Beatmaps = beatmaps.Select(b => b.ToBeatmap(rulesets)).ToList(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class GetBeatmapSetsBeatmapResponse : BeatmapMetadata
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"playcount")]
|
|
|
|
|
private int playCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"passcount")]
|
|
|
|
|
private int passCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"mode_int")]
|
|
|
|
|
private int ruleset { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"difficulty_rating")]
|
|
|
|
|
private double starDifficulty { get; set; }
|
|
|
|
|
|
2017-07-27 15:56:41 +08:00
|
|
|
|
public BeatmapInfo ToBeatmap(RulesetStore rulesets)
|
2017-05-28 13:26:25 +08:00
|
|
|
|
{
|
|
|
|
|
return new BeatmapInfo
|
|
|
|
|
{
|
|
|
|
|
Metadata = this,
|
|
|
|
|
Ruleset = rulesets.GetRuleset(ruleset),
|
|
|
|
|
StarDifficulty = starDifficulty,
|
|
|
|
|
OnlineInfo = new BeatmapOnlineInfo
|
|
|
|
|
{
|
|
|
|
|
PlayCount = playCount,
|
|
|
|
|
PassCount = passCount,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|