From 138d78309f3af57e27f363c806d8d78934986cd7 Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Sat, 30 Dec 2017 18:07:30 +0100 Subject: [PATCH] add HitCount enum and replace string usage with enum --- .../Scoring/OsuPerformanceCalculator.cs | 9 +++++---- .../Scoring/OsuScoreProcessor.cs | 12 ++++++------ .../Visual/TestCaseBeatmapScoresContainer.cs | 19 ++++++++++--------- osu.Game.Tests/Visual/TestCaseResults.cs | 11 ++++++----- .../Online/API/Requests/GetScoresRequest.cs | 14 +++++++------- .../BeatmapSet/Scores/DrawableScore.cs | 3 ++- .../BeatmapSet/Scores/DrawableTopScore.cs | 3 ++- osu.Game/Rulesets/Scoring/Score.cs | 18 +++++++++++++++++- osu.Game/Screens/Ranking/ResultsPageScore.cs | 8 +++++--- 9 files changed, 60 insertions(+), 37 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuPerformanceCalculator.cs b/osu.Game.Rulesets.Osu/Scoring/OsuPerformanceCalculator.cs index 2cf321da50..0d9dc0e43b 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuPerformanceCalculator.cs @@ -10,6 +10,7 @@ using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Scoring; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Rulesets.Osu.Scoring { @@ -41,10 +42,10 @@ namespace osu.Game.Rulesets.Osu.Scoring mods = Score.Mods; accuracy = Score.Accuracy; scoreMaxCombo = Score.MaxCombo; - count300 = Convert.ToInt32(Score.Statistics["300"]); - count100 = Convert.ToInt32(Score.Statistics["100"]); - count50 = Convert.ToInt32(Score.Statistics["50"]); - countMiss = Convert.ToInt32(Score.Statistics["x"]); + count300 = Convert.ToInt32(Score.Statistics[HitCount.Great]); + count100 = Convert.ToInt32(Score.Statistics[HitCount.Good]); + count50 = Convert.ToInt32(Score.Statistics[HitCount.Meh]); + countMiss = Convert.ToInt32(Score.Statistics[HitCount.Miss]); // Don't count scores made with supposedly unranked mods if (mods.Any(m => !m.Ranked)) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index ad9737af52..1c376d7c63 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -12,6 +12,7 @@ using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Rulesets.Osu.Scoring { @@ -33,8 +34,7 @@ namespace osu.Game.Rulesets.Osu.Scoring foreach (var obj in beatmap.HitObjects) { - var slider = obj as Slider; - if (slider != null) + if (obj is Slider slider) { // Head AddJudgement(new OsuJudgement { Result = HitResult.Great }); @@ -64,10 +64,10 @@ namespace osu.Game.Rulesets.Osu.Scoring { base.PopulateScore(score); - score.Statistics[@"300"] = scoreResultCounts.GetOrDefault(HitResult.Great); - score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(HitResult.Good); - score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(HitResult.Meh); - score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(HitResult.Miss); + score.Statistics[HitCount.Great] = scoreResultCounts.GetOrDefault(HitResult.Great); + score.Statistics[HitCount.Good] = scoreResultCounts.GetOrDefault(HitResult.Good); + score.Statistics[HitCount.Meh] = scoreResultCounts.GetOrDefault(HitResult.Meh); + score.Statistics[HitCount.Miss] = scoreResultCounts.GetOrDefault(HitResult.Miss); } protected override void OnNewJudgement(Judgement judgement) diff --git a/osu.Game.Tests/Visual/TestCaseBeatmapScoresContainer.cs b/osu.Game.Tests/Visual/TestCaseBeatmapScoresContainer.cs index cef8797f20..75ec0481e8 100644 --- a/osu.Game.Tests/Visual/TestCaseBeatmapScoresContainer.cs +++ b/osu.Game.Tests/Visual/TestCaseBeatmapScoresContainer.cs @@ -14,6 +14,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Users; using System.Collections.Generic; using osu.Framework.Graphics.Containers; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Tests.Visual { @@ -160,9 +161,9 @@ namespace osu.Game.Tests.Visual }; foreach(var s in scores) { - s.Statistics.Add("300", RNG.Next(2000)); - s.Statistics.Add("100", RNG.Next(2000)); - s.Statistics.Add("50", RNG.Next(2000)); + s.Statistics.Add(HitCount.Great, RNG.Next(2000)); + s.Statistics.Add(HitCount.Good, RNG.Next(2000)); + s.Statistics.Add(HitCount.Meh, RNG.Next(2000)); } anotherScores = new[] @@ -272,9 +273,9 @@ namespace osu.Game.Tests.Visual }; foreach (var s in anotherScores) { - s.Statistics.Add("300", RNG.Next(2000)); - s.Statistics.Add("100", RNG.Next(2000)); - s.Statistics.Add("50", RNG.Next(2000)); + s.Statistics.Add(HitCount.Great, RNG.Next(2000)); + s.Statistics.Add(HitCount.Good, RNG.Next(2000)); + s.Statistics.Add(HitCount.Meh, RNG.Next(2000)); } topScore = new OnlineScore @@ -299,9 +300,9 @@ namespace osu.Game.Tests.Visual TotalScore = 987654321, Accuracy = 0.8487, }; - topScore.Statistics.Add("300", RNG.Next(2000)); - topScore.Statistics.Add("100", RNG.Next(2000)); - topScore.Statistics.Add("50", RNG.Next(2000)); + topScore.Statistics.Add(HitCount.Great, RNG.Next(2000)); + topScore.Statistics.Add(HitCount.Good, RNG.Next(2000)); + topScore.Statistics.Add(HitCount.Meh, RNG.Next(2000)); } [BackgroundDependencyLoader] diff --git a/osu.Game.Tests/Visual/TestCaseResults.cs b/osu.Game.Tests/Visual/TestCaseResults.cs index d0c5aa4939..5190baff4e 100644 --- a/osu.Game.Tests/Visual/TestCaseResults.cs +++ b/osu.Game.Tests/Visual/TestCaseResults.cs @@ -8,6 +8,7 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Ranking; using osu.Game.Users; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Tests.Visual { @@ -41,12 +42,12 @@ namespace osu.Game.Tests.Visual MaxCombo = 123, Rank = ScoreRank.A, Date = DateTimeOffset.Now, - Statistics = new Dictionary + Statistics = new Dictionary { - { "300", 50 }, - { "100", 20 }, - { "50", 50 }, - { "x", 1 } + { HitCount.Great, 50 }, + { HitCount.Good, 20 }, + { HitCount.Meh, 50 }, + { HitCount.Miss, 1 } }, User = new User { diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 065c770738..9e5aa6d93f 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -122,26 +122,26 @@ namespace osu.Game.Online.API.Requests { foreach (var kvp in value) { - string key = kvp.Key; - switch (key) + HitCount newKey; + switch (kvp.Key) { case @"count_300": - key = @"300"; + newKey = HitCount.Great; break; case @"count_100": - key = @"100"; + newKey = HitCount.Good; break; case @"count_50": - key = @"50"; + newKey = HitCount.Meh; break; case @"count_miss": - key = @"x"; + newKey = HitCount.Miss; break; default: continue; } - Statistics.Add(key, kvp.Value); + Statistics.Add(newKey, kvp.Value); } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs index 8b407ac208..301c62ee77 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs @@ -15,6 +15,7 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -104,7 +105,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, - Text = $"{score.Statistics["300"]}/{score.Statistics["100"]}/{score.Statistics["50"]}", + Text = $"{score.Statistics[HitCount.Great]}/{score.Statistics[HitCount.Good]}/{score.Statistics[HitCount.Meh]}", Font = @"Exo2.0-RegularItalic", Margin = new MarginPadding { Right = side_margin } }, diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs index 66bf89bbac..612728ff4c 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs @@ -18,6 +18,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; +using static osu.Game.Rulesets.Scoring.Score; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -58,7 +59,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores totalScore.Value = $@"{score.TotalScore:N0}"; accuracy.Value = $@"{score.Accuracy:P2}"; - statistics.Value = $"{score.Statistics["300"]}/{score.Statistics["100"]}/{score.Statistics["50"]}"; + statistics.Value = $"{score.Statistics[HitCount.Great]}/{score.Statistics[HitCount.Good]}/{score.Statistics[HitCount.Meh]}"; modsContainer.Clear(); foreach (Mod mod in score.Mods) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 6a06f364c6..56c7bc583f 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -7,6 +7,7 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; using osu.Game.Users; using osu.Game.Rulesets.Replays; +using System.ComponentModel; namespace osu.Game.Rulesets.Scoring { @@ -40,6 +41,21 @@ namespace osu.Game.Rulesets.Scoring public DateTimeOffset Date; - public Dictionary Statistics = new Dictionary(); + public Dictionary Statistics = new Dictionary(); + + public enum HitCount + { + [Description("300")] + Great, + + [Description("100")] + Good, + + [Description("50")] + Meh, + + [Description("x")] + Miss + } } } diff --git a/osu.Game/Screens/Ranking/ResultsPageScore.cs b/osu.Game/Screens/Ranking/ResultsPageScore.cs index 25a42cae1c..e2de44ab14 100644 --- a/osu.Game/Screens/Ranking/ResultsPageScore.cs +++ b/osu.Game/Screens/Ranking/ResultsPageScore.cs @@ -23,6 +23,8 @@ using osu.Game.Screens.Play; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; using osu.Framework.Graphics.Shapes; +using static osu.Game.Rulesets.Scoring.Score; +using osu.Framework.Extensions; namespace osu.Game.Screens.Ranking { @@ -186,9 +188,9 @@ namespace osu.Game.Screens.Ranking private class DrawableScoreStatistic : Container { - private readonly KeyValuePair statistic; + private readonly KeyValuePair statistic; - public DrawableScoreStatistic(KeyValuePair statistic) + public DrawableScoreStatistic(KeyValuePair statistic) { this.statistic = statistic; @@ -209,7 +211,7 @@ namespace osu.Game.Screens.Ranking Origin = Anchor.TopCentre, }, new OsuSpriteText { - Text = statistic.Key, + Text = statistic.Key.GetDescription(), Colour = colours.Gray7, Font = @"Exo2.0-Bold", Y = 26,