From a845e96b7a8a6eb55615c38567e5a1716b334008 Mon Sep 17 00:00:00 2001
From: Salman Ahmed <frenzibyte@gmail.com>
Date: Wed, 17 Feb 2021 08:50:48 +0300
Subject: [PATCH] Replace `Ranks.Global` completely with a `GlobalRank`
 property

---
 osu.Desktop/DiscordRichPresence.cs               |  2 +-
 .../TestSceneMultiplayerParticipantsList.cs      | 10 ++--------
 .../Visual/Online/TestSceneRankGraph.cs          | 10 +++++-----
 .../Visual/Online/TestSceneUserProfileOverlay.cs |  3 ++-
 osu.Game.Tournament.Tests/TournamentTestScene.cs | 10 +++++-----
 osu.Game.Tournament/Models/TournamentTeam.cs     |  2 +-
 .../Screens/TeamIntro/SeedingScreen.cs           |  2 +-
 osu.Game.Tournament/TournamentGameBase.cs        |  2 +-
 .../Profile/Header/CentreHeaderContainer.cs      |  2 +-
 .../Profile/Header/DetailHeaderContainer.cs      |  2 +-
 .../Multiplayer/Participants/ParticipantPanel.cs |  2 +-
 osu.Game/Users/UserStatistics.cs                 | 16 +++++-----------
 12 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs
index 63b12fb84b..832d26b0ef 100644
--- a/osu.Desktop/DiscordRichPresence.cs
+++ b/osu.Desktop/DiscordRichPresence.cs
@@ -105,7 +105,7 @@ namespace osu.Desktop
             if (privacyMode.Value == DiscordRichPresenceMode.Limited)
                 presence.Assets.LargeImageText = string.Empty;
             else
-                presence.Assets.LargeImageText = $"{user.Value.Username}" + (user.Value.Statistics?.Ranks.Global > 0 ? $" (rank #{user.Value.Statistics.Ranks.Global:N0})" : string.Empty);
+                presence.Assets.LargeImageText = $"{user.Value.Username}" + (user.Value.Statistics?.GlobalRank > 0 ? $" (rank #{user.Value.Statistics.GlobalRank:N0})" : string.Empty);
 
             // update ruleset
             presence.Assets.SmallImageKey = ruleset.Value.ID <= 3 ? $"mode_{ruleset.Value.ID}" : "mode_custom";
diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs
index 1e14bbbbea..e713cff233 100644
--- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs
+++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs
@@ -160,10 +160,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
                         {
                             {
                                 Ruleset.Value.ShortName,
-                                new UserStatistics
-                                {
-                                    Ranks = new UserStatistics.UserRanks { Global = RNG.Next(1, 100000) }
-                                }
+                                new UserStatistics { GlobalRank = RNG.Next(1, 100000), }
                             }
                         },
                         CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
@@ -207,10 +204,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
                     {
                         {
                             Ruleset.Value.ShortName,
-                            new UserStatistics
-                            {
-                                Ranks = new UserStatistics.UserRanks { Global = RNG.Next(1, 100000) }
-                            }
+                            new UserStatistics { GlobalRank = RNG.Next(1, 100000), }
                         }
                     },
                     CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankGraph.cs b/osu.Game.Tests/Visual/Online/TestSceneRankGraph.cs
index 3b31192259..5bf9e31309 100644
--- a/osu.Game.Tests/Visual/Online/TestSceneRankGraph.cs
+++ b/osu.Game.Tests/Visual/Online/TestSceneRankGraph.cs
@@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Online
             {
                 graph.Statistics.Value = new UserStatistics
                 {
-                    Ranks = new UserStatistics.UserRanks { Global = 123456 },
+                    GlobalRank = 123456,
                     PP = 12345,
                 };
             });
@@ -79,7 +79,7 @@ namespace osu.Game.Tests.Visual.Online
             {
                 graph.Statistics.Value = new UserStatistics
                 {
-                    Ranks = new UserStatistics.UserRanks { Global = 89000 },
+                    GlobalRank = 89000,
                     PP = 12345,
                     RankHistory = new User.RankHistoryData
                     {
@@ -92,7 +92,7 @@ namespace osu.Game.Tests.Visual.Online
             {
                 graph.Statistics.Value = new UserStatistics
                 {
-                    Ranks = new UserStatistics.UserRanks { Global = 89000 },
+                    GlobalRank = 89000,
                     PP = 12345,
                     RankHistory = new User.RankHistoryData
                     {
@@ -105,7 +105,7 @@ namespace osu.Game.Tests.Visual.Online
             {
                 graph.Statistics.Value = new UserStatistics
                 {
-                    Ranks = new UserStatistics.UserRanks { Global = 12000 },
+                    GlobalRank = 12000,
                     PP = 12345,
                     RankHistory = new User.RankHistoryData
                     {
@@ -118,7 +118,7 @@ namespace osu.Game.Tests.Visual.Online
             {
                 graph.Statistics.Value = new UserStatistics
                 {
-                    Ranks = new UserStatistics.UserRanks { Global = 12000 },
+                    GlobalRank = 12000,
                     PP = 12345,
                     RankHistory = new User.RankHistoryData
                     {
diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserProfileOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneUserProfileOverlay.cs
index 7ade24f4de..b52cc6edb6 100644
--- a/osu.Game.Tests/Visual/Online/TestSceneUserProfileOverlay.cs
+++ b/osu.Game.Tests/Visual/Online/TestSceneUserProfileOverlay.cs
@@ -33,7 +33,8 @@ namespace osu.Game.Tests.Visual.Online
             ProfileOrder = new[] { "me" },
             Statistics = new UserStatistics
             {
-                Ranks = new UserStatistics.UserRanks { Global = 2148, Country = 1 },
+                GlobalRank = 2148,
+                Ranks = new UserStatistics.UserRanks { Country = 1, },
                 PP = 4567.89m,
                 Level = new UserStatistics.LevelInfo
                 {
diff --git a/osu.Game.Tournament.Tests/TournamentTestScene.cs b/osu.Game.Tournament.Tests/TournamentTestScene.cs
index 47d2160561..cdfd19c157 100644
--- a/osu.Game.Tournament.Tests/TournamentTestScene.cs
+++ b/osu.Game.Tournament.Tests/TournamentTestScene.cs
@@ -113,11 +113,11 @@ namespace osu.Game.Tournament.Tests
                     },
                     Players =
                     {
-                        new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 12 } } },
-                        new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 16 } } },
-                        new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 20 } } },
-                        new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 24 } } },
-                        new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 30 } } },
+                        new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 12 } },
+                        new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 16 } },
+                        new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 20 } },
+                        new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 24 } },
+                        new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 30 } },
                     }
                 }
             },
diff --git a/osu.Game.Tournament/Models/TournamentTeam.cs b/osu.Game.Tournament/Models/TournamentTeam.cs
index 7fca75cea4..7074ae413c 100644
--- a/osu.Game.Tournament/Models/TournamentTeam.cs
+++ b/osu.Game.Tournament/Models/TournamentTeam.cs
@@ -36,7 +36,7 @@ namespace osu.Game.Tournament.Models
         {
             get
             {
-                var ranks = Players.Select(p => p.Statistics?.Ranks.Global)
+                var ranks = Players.Select(p => p.Statistics?.GlobalRank)
                                    .Where(i => i.HasValue)
                                    .Select(i => i.Value)
                                    .ToArray();
diff --git a/osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs b/osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs
index 55fc80dba2..4f66d89b7f 100644
--- a/osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs
+++ b/osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs
@@ -250,7 +250,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro
                 };
 
                 foreach (var p in team.Players)
-                    fill.Add(new RowDisplay(p.Username, p.Statistics?.Ranks.Global?.ToString("\\##,0") ?? "-"));
+                    fill.Add(new RowDisplay(p.Username, p.Statistics?.GlobalRank?.ToString("\\##,0") ?? "-"));
             }
 
             internal class RowDisplay : CompositeDrawable
diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs
index 0b101f050f..3a2a880811 100644
--- a/osu.Game.Tournament/TournamentGameBase.cs
+++ b/osu.Game.Tournament/TournamentGameBase.cs
@@ -150,7 +150,7 @@ namespace osu.Game.Tournament
             {
                 foreach (var p in t.Players)
                 {
-                    if (string.IsNullOrEmpty(p.Username) || p.Statistics == null)
+                    if (string.IsNullOrEmpty(p.Username) || p.Statistics?.GlobalRank == null)
                     {
                         PopulateUser(p, immediate: true);
                         addedInfo = true;
diff --git a/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs
index 04a1040e06..9285e2d875 100644
--- a/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs
+++ b/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs
@@ -144,7 +144,7 @@ namespace osu.Game.Overlays.Profile.Header
 
         private void updateDisplay(User user)
         {
-            hiddenDetailGlobal.Content = user?.Statistics?.Ranks.Global?.ToString("\\##,##0") ?? "-";
+            hiddenDetailGlobal.Content = user?.Statistics?.GlobalRank?.ToString("\\##,##0") ?? "-";
             hiddenDetailCountry.Content = user?.Statistics?.Ranks.Country?.ToString("\\##,##0") ?? "-";
         }
     }
diff --git a/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs
index cf6ae1a3fc..05a0508e1f 100644
--- a/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs
+++ b/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs
@@ -176,7 +176,7 @@ namespace osu.Game.Overlays.Profile.Header
             foreach (var scoreRankInfo in scoreRankInfos)
                 scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0;
 
-            detailGlobalRank.Content = user?.Statistics?.Ranks.Global?.ToString("\\##,##0") ?? "-";
+            detailGlobalRank.Content = user?.Statistics?.GlobalRank?.ToString("\\##,##0") ?? "-";
             detailCountryRank.Content = user?.Statistics?.Ranks.Country?.ToString("\\##,##0") ?? "-";
 
             rankGraph.Statistics.Value = user?.Statistics;
diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs
index c4d11676e7..25bc314f1b 100644
--- a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs
+++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs
@@ -165,7 +165,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
 
             var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID);
 
-            var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.Ranks.Global;
+            var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank;
             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 1fed908c39..e50ca57d90 100644
--- a/osu.Game/Users/UserStatistics.cs
+++ b/osu.Game/Users/UserStatistics.cs
@@ -26,17 +26,14 @@ namespace osu.Game.Users
             public int Progress;
         }
 
+        [JsonProperty(@"global_rank")]
+        public int? GlobalRank;
+
+        // eventually UserRanks object will be completely replaced with separate global rank (exists) and country rank properties
+        // see https://github.com/ppy/osu-web/blob/cb79bb72186c8f1a25f6a6f5ef315123decb4231/app/Transformers/UserStatisticsTransformer.php#L53.
         [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")]
-        private int? globalRank
-        {
-            set => Ranks.Global = value;
-        }
-
         [JsonProperty(@"pp")]
         public decimal? PP;
 
@@ -120,9 +117,6 @@ namespace osu.Game.Users
 
         public struct UserRanks
         {
-            [JsonProperty(@"global")]
-            public int? Global;
-
             [JsonProperty(@"country")]
             public int? Country;
         }