2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-09-08 10:21:35 +00:00
|
|
|
|
using System;
|
2017-07-26 04:22:46 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-09-14 11:05:43 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2017-11-20 05:06:26 +00:00
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
2018-06-08 02:41:54 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-07-03 11:34:20 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-15 05:06:05 +00:00
|
|
|
|
namespace osu.Game.Online.API.Requests
|
|
|
|
|
{
|
2021-10-28 08:48:56 +00:00
|
|
|
|
public class GetScoresRequest : APIRequest<APIScoresCollection>
|
2017-03-15 05:06:05 +00:00
|
|
|
|
{
|
2021-10-29 08:40:02 +00:00
|
|
|
|
private readonly IBeatmapInfo beatmapInfo;
|
2018-12-14 10:51:27 +00:00
|
|
|
|
private readonly BeatmapLeaderboardScope scope;
|
2021-10-29 08:40:02 +00:00
|
|
|
|
private readonly IRulesetInfo ruleset;
|
2021-09-10 03:43:21 +00:00
|
|
|
|
private readonly IEnumerable<IMod> mods;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-29 08:40:02 +00:00
|
|
|
|
public GetScoresRequest(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global, IEnumerable<IMod> mods = null)
|
2017-03-15 05:06:05 +00:00
|
|
|
|
{
|
2021-10-29 08:40:02 +00:00
|
|
|
|
if (beatmapInfo.OnlineID <= 0)
|
|
|
|
|
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(IBeatmapInfo.OnlineID)}.");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 10:51:27 +00:00
|
|
|
|
if (scope == BeatmapLeaderboardScope.Local)
|
2017-12-20 11:25:57 +00:00
|
|
|
|
throw new InvalidOperationException("Should not attempt to request online scores for a local scoped leaderboard");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-02 15:55:29 +00:00
|
|
|
|
this.beatmapInfo = beatmapInfo;
|
2017-11-20 05:06:26 +00:00
|
|
|
|
this.scope = scope;
|
2017-12-20 11:41:01 +00:00
|
|
|
|
this.ruleset = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
|
2021-09-10 03:43:21 +00:00
|
|
|
|
this.mods = mods ?? Array.Empty<IMod>();
|
2017-03-15 05:06:05 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-07-15 06:47:25 +00:00
|
|
|
|
protected override string Target => $@"beatmaps/{beatmapInfo.OnlineID}/solo-scores{createQueryParameters()}";
|
2019-07-03 11:34:20 +00:00
|
|
|
|
|
|
|
|
|
private string createQueryParameters()
|
2017-11-20 05:06:26 +00:00
|
|
|
|
{
|
2019-07-03 11:34:20 +00:00
|
|
|
|
StringBuilder query = new StringBuilder(@"?");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-05 03:16:17 +00:00
|
|
|
|
query.Append($@"type={scope.ToString().ToLowerInvariant()}");
|
|
|
|
|
query.Append($@"&mode={ruleset.ShortName}");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-03 11:34:20 +00:00
|
|
|
|
foreach (var mod in mods)
|
2019-07-05 03:16:17 +00:00
|
|
|
|
query.Append($@"&mods[]={mod.Acronym}");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-05 03:16:17 +00:00
|
|
|
|
return query.ToString();
|
2019-07-03 11:34:20 +00:00
|
|
|
|
}
|
2017-03-15 05:06:05 +00:00
|
|
|
|
}
|
2017-09-07 16:20:14 +00:00
|
|
|
|
}
|