1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 21:47:25 +08:00
osu-lazer/osu.Game/Online/API/Requests/GetScoresRequest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.5 KiB
C#
Raw Normal View History

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