From 0e7f52b5ccb1ae1a14147d1df9877d22024fde6e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 16 Feb 2021 07:28:51 +0300 Subject: [PATCH] Always use JSON property `global_rank` for global ranks instead --- .../TestSceneMultiplayerParticipantsList.cs | 16 ++++++++++-- .../Participants/ParticipantPanel.cs | 2 +- osu.Game/Users/UserStatistics.cs | 25 ++++++++----------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs index a7398ebf02..1e14bbbbea 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs @@ -158,7 +158,13 @@ public void TestManyUsers() Username = $"User {i}", RulesetsStatistics = new Dictionary { - { Ruleset.Value.ShortName, new UserStatistics { GlobalRank = RNG.Next(1, 100000) } } + { + Ruleset.Value.ShortName, + new UserStatistics + { + Ranks = new UserStatistics.UserRanks { Global = RNG.Next(1, 100000) } + } + } }, CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", }); @@ -199,7 +205,13 @@ public void TestUserWithMods() Username = "User 0", RulesetsStatistics = new Dictionary { - { Ruleset.Value.ShortName, new UserStatistics { GlobalRank = RNG.Next(1, 100000) } } + { + Ruleset.Value.ShortName, + new UserStatistics + { + Ranks = new UserStatistics.UserRanks { Global = RNG.Next(1, 100000) } + } + } }, CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", }); diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs index 25bc314f1b..c4d11676e7 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs @@ -165,7 +165,7 @@ protected override void OnRoomUpdated() var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID); - var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank; + var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.Ranks.Global; userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty; userStateDisplay.UpdateStatus(User.State, User.BeatmapAvailability); diff --git a/osu.Game/Users/UserStatistics.cs b/osu.Game/Users/UserStatistics.cs index 6c069f674e..1fed908c39 100644 --- a/osu.Game/Users/UserStatistics.cs +++ b/osu.Game/Users/UserStatistics.cs @@ -3,7 +3,6 @@ using System; using Newtonsoft.Json; -using osu.Game.Online.API.Requests; using osu.Game.Scoring; using osu.Game.Utils; using static osu.Game.Users.User; @@ -27,24 +26,22 @@ public struct LevelInfo public int Progress; } - /// - /// This must only be used when coming from condensed user responses (e.g. from ), otherwise use Ranks.Global. - /// - // todo: this should likely be moved to a separate UserStatisticsCompact class at some point. + [JsonProperty(@"rank")] + public UserRanks Ranks; + + // eventually UserRanks object will be completely replaced with separate global and country rank properties, see https://github.com/ppy/osu-web/blob/cb79bb72186c8f1a25f6a6f5ef315123decb4231/app/Transformers/UserStatisticsTransformer.php#L53. + // but for now, always point UserRanks.Global to the global_rank property, as that is included solely for requests like GetUsersRequest. [JsonProperty(@"global_rank")] - public int? GlobalRank; - - [JsonProperty(@"pp")] - public decimal? PP; - - [JsonProperty(@"pp_rank")] // the API sometimes only returns this value in condensed user responses - private int? rank + private int? globalRank { set => Ranks.Global = value; } - [JsonProperty(@"rank")] - public UserRanks Ranks; + [JsonProperty(@"pp")] + public decimal? PP; + + [JsonProperty(@"pp_rank")] + public int PPRank; [JsonProperty(@"ranked_score")] public long RankedScore;