From 37992e99f9785f27540be781d76ce04bbf190568 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 16:04:06 +0300 Subject: [PATCH 1/4] API implementation --- .../Requests/GetSpotlightRankingsRequest.cs | 30 +++++++++++++++++++ .../Requests/GetSpotlightRankingsResponse.cs | 22 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 osu.Game/Online/API/Requests/GetSpotlightRankingsRequest.cs create mode 100644 osu.Game/Online/API/Requests/GetSpotlightRankingsResponse.cs diff --git a/osu.Game/Online/API/Requests/GetSpotlightRankingsRequest.cs b/osu.Game/Online/API/Requests/GetSpotlightRankingsRequest.cs new file mode 100644 index 0000000000..a279db134f --- /dev/null +++ b/osu.Game/Online/API/Requests/GetSpotlightRankingsRequest.cs @@ -0,0 +1,30 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.IO.Network; +using osu.Game.Rulesets; + +namespace osu.Game.Online.API.Requests +{ + public class GetSpotlightRankingsRequest : GetRankingsRequest + { + private readonly int spotlight; + + public GetSpotlightRankingsRequest(RulesetInfo ruleset, int spotlight) + : base(ruleset, 1) + { + this.spotlight = spotlight; + } + + protected override WebRequest CreateWebRequest() + { + var req = base.CreateWebRequest(); + + req.AddParameter("spotlight", spotlight.ToString()); + + return req; + } + + protected override string TargetPostfix() => "charts"; + } +} diff --git a/osu.Game/Online/API/Requests/GetSpotlightRankingsResponse.cs b/osu.Game/Online/API/Requests/GetSpotlightRankingsResponse.cs new file mode 100644 index 0000000000..2259314a9f --- /dev/null +++ b/osu.Game/Online/API/Requests/GetSpotlightRankingsResponse.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using Newtonsoft.Json; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; + +namespace osu.Game.Online.API.Requests +{ + public class GetSpotlightRankingsResponse + { + [JsonProperty("ranking")] + public List Users; + + [JsonProperty("spotlight")] + public APISpotlight Spotlight; + + [JsonProperty("beatmapsets")] + public List BeatmapSets; + } +} From f889f2435bc83cebb783c37a31d49319fac505d8 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 16:20:15 +0300 Subject: [PATCH 2/4] Add test step to TestSceneRankingsTable --- .../Visual/Online/TestSceneRankingsTables.cs | 15 +++++++++++++++ .../Overlays/Rankings/Tables/UserBasedTable.cs | 4 ++-- osu.Game/Users/UserStatistics.cs | 8 ++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs index ab174f303e..19ca63208e 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs @@ -68,6 +68,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Mania scores", () => createScoreTable(new ManiaRuleset().RulesetInfo)); AddStep("Taiko country scores", () => createCountryTable(new TaikoRuleset().RulesetInfo)); AddStep("Catch US performance page 10", () => createPerformanceTable(new CatchRuleset().RulesetInfo, "US", 10)); + AddStep("Osu 271 spotlight table", () => createSpotlightTable(new OsuRuleset().RulesetInfo, 271)); } private void createCountryTable(RulesetInfo ruleset, int page = 1) @@ -112,6 +113,20 @@ namespace osu.Game.Tests.Visual.Online api.Queue(request); } + private void createSpotlightTable(RulesetInfo ruleset, int spotlight) + { + onLoadStarted(); + + request = new GetSpotlightRankingsRequest(ruleset, spotlight); + ((GetSpotlightRankingsRequest)request).Success += rankings => Schedule(() => + { + var table = new ScoresTable(1, rankings.Users); + loadTable(table); + }); + + api.Queue(request); + } + private void onLoadStarted() { loading.Show(); diff --git a/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs b/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs index 351c4df6b7..e1395479f2 100644 --- a/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs +++ b/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs @@ -44,8 +44,8 @@ namespace osu.Game.Overlays.Rankings.Tables new ColoredRowText { Text = $@"{item.PlayCount:N0}", }, }.Concat(CreateUniqueContent(item)).Concat(new[] { - new ColoredRowText { Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}", }, - new ColoredRowText { Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}", }, + new ColoredRowText { Text = $@"{item.GradesCount.SS + (item.GradesCount.SSPlus ?? 0):N0}", }, + new ColoredRowText { Text = $@"{item.GradesCount.S + (item.GradesCount.SPlus ?? 0):N0}", }, new ColoredRowText { Text = $@"{item.GradesCount.A:N0}", } }).ToArray(); diff --git a/osu.Game/Users/UserStatistics.cs b/osu.Game/Users/UserStatistics.cs index e5e77821ab..8ce26074a8 100644 --- a/osu.Game/Users/UserStatistics.cs +++ b/osu.Game/Users/UserStatistics.cs @@ -30,7 +30,7 @@ namespace osu.Game.Users public decimal? PP; [JsonProperty(@"pp_rank")] // the API sometimes only returns this value in condensed user responses - private int rank + private int? rank { set => Ranks.Global = value; } @@ -71,13 +71,13 @@ namespace osu.Game.Users public struct Grades { [JsonProperty(@"ssh")] - public int SSPlus; + public int? SSPlus; [JsonProperty(@"ss")] public int SS; [JsonProperty(@"sh")] - public int SPlus; + public int? SPlus; [JsonProperty(@"s")] public int S; @@ -85,7 +85,7 @@ namespace osu.Game.Users [JsonProperty(@"a")] public int A; - public int this[ScoreRank rank] + public int? this[ScoreRank rank] { get { From a9cfade2f4a2af83c94b81132ff66a1cfa867dab Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 21:02:10 +0300 Subject: [PATCH 3/4] Adjust null handling --- osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs | 7 ++++--- osu.Game/Users/UserStatistics.cs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs b/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs index e1395479f2..0e77d7d764 100644 --- a/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs +++ b/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Users; +using osu.Game.Scoring; namespace osu.Game.Overlays.Rankings.Tables { @@ -44,9 +45,9 @@ namespace osu.Game.Overlays.Rankings.Tables new ColoredRowText { Text = $@"{item.PlayCount:N0}", }, }.Concat(CreateUniqueContent(item)).Concat(new[] { - new ColoredRowText { Text = $@"{item.GradesCount.SS + (item.GradesCount.SSPlus ?? 0):N0}", }, - new ColoredRowText { Text = $@"{item.GradesCount.S + (item.GradesCount.SPlus ?? 0):N0}", }, - new ColoredRowText { Text = $@"{item.GradesCount.A:N0}", } + new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.XH] + item.GradesCount[ScoreRank.X]:N0}", }, + new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.SH] + item.GradesCount[ScoreRank.S]:N0}", }, + new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.A]:N0}", } }).ToArray(); protected abstract TableColumn[] CreateUniqueHeaders(); diff --git a/osu.Game/Users/UserStatistics.cs b/osu.Game/Users/UserStatistics.cs index 8ce26074a8..8b7699d0ad 100644 --- a/osu.Game/Users/UserStatistics.cs +++ b/osu.Game/Users/UserStatistics.cs @@ -85,20 +85,20 @@ namespace osu.Game.Users [JsonProperty(@"a")] public int A; - public int? this[ScoreRank rank] + public int this[ScoreRank rank] { get { switch (rank) { case ScoreRank.XH: - return SSPlus; + return SSPlus ?? 0; case ScoreRank.X: return SS; case ScoreRank.SH: - return SPlus; + return SPlus ?? 0; case ScoreRank.S: return S; From f8ad9476efd7727945ee9b38f324555180d1e908 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 21:03:17 +0300 Subject: [PATCH 4/4] Adjust test step name --- osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs index 19ca63208e..656402e713 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsTables.cs @@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Mania scores", () => createScoreTable(new ManiaRuleset().RulesetInfo)); AddStep("Taiko country scores", () => createCountryTable(new TaikoRuleset().RulesetInfo)); AddStep("Catch US performance page 10", () => createPerformanceTable(new CatchRuleset().RulesetInfo, "US", 10)); - AddStep("Osu 271 spotlight table", () => createSpotlightTable(new OsuRuleset().RulesetInfo, 271)); + AddStep("Osu spotlight table (chart 271)", () => createSpotlightTable(new OsuRuleset().RulesetInfo, 271)); } private void createCountryTable(RulesetInfo ruleset, int page = 1)