1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 10:03:05 +08:00

add HitCount enum and replace string usage with enum

This commit is contained in:
Aergwyn 2017-12-30 18:07:30 +01:00
parent d5698374f0
commit 138d78309f
9 changed files with 60 additions and 37 deletions

View File

@ -10,6 +10,7 @@ using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Rulesets.Osu.Scoring namespace osu.Game.Rulesets.Osu.Scoring
{ {
@ -41,10 +42,10 @@ namespace osu.Game.Rulesets.Osu.Scoring
mods = Score.Mods; mods = Score.Mods;
accuracy = Score.Accuracy; accuracy = Score.Accuracy;
scoreMaxCombo = Score.MaxCombo; scoreMaxCombo = Score.MaxCombo;
count300 = Convert.ToInt32(Score.Statistics["300"]); count300 = Convert.ToInt32(Score.Statistics[HitCount.Great]);
count100 = Convert.ToInt32(Score.Statistics["100"]); count100 = Convert.ToInt32(Score.Statistics[HitCount.Good]);
count50 = Convert.ToInt32(Score.Statistics["50"]); count50 = Convert.ToInt32(Score.Statistics[HitCount.Meh]);
countMiss = Convert.ToInt32(Score.Statistics["x"]); countMiss = Convert.ToInt32(Score.Statistics[HitCount.Miss]);
// Don't count scores made with supposedly unranked mods // Don't count scores made with supposedly unranked mods
if (mods.Any(m => !m.Ranked)) if (mods.Any(m => !m.Ranked))

View File

@ -12,6 +12,7 @@ using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Rulesets.Osu.Scoring namespace osu.Game.Rulesets.Osu.Scoring
{ {
@ -33,8 +34,7 @@ namespace osu.Game.Rulesets.Osu.Scoring
foreach (var obj in beatmap.HitObjects) foreach (var obj in beatmap.HitObjects)
{ {
var slider = obj as Slider; if (obj is Slider slider)
if (slider != null)
{ {
// Head // Head
AddJudgement(new OsuJudgement { Result = HitResult.Great }); AddJudgement(new OsuJudgement { Result = HitResult.Great });
@ -64,10 +64,10 @@ namespace osu.Game.Rulesets.Osu.Scoring
{ {
base.PopulateScore(score); base.PopulateScore(score);
score.Statistics[@"300"] = scoreResultCounts.GetOrDefault(HitResult.Great); score.Statistics[HitCount.Great] = scoreResultCounts.GetOrDefault(HitResult.Great);
score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(HitResult.Good); score.Statistics[HitCount.Good] = scoreResultCounts.GetOrDefault(HitResult.Good);
score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(HitResult.Meh); score.Statistics[HitCount.Meh] = scoreResultCounts.GetOrDefault(HitResult.Meh);
score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(HitResult.Miss); score.Statistics[HitCount.Miss] = scoreResultCounts.GetOrDefault(HitResult.Miss);
} }
protected override void OnNewJudgement(Judgement judgement) protected override void OnNewJudgement(Judgement judgement)

View File

@ -14,6 +14,7 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Users; using osu.Game.Users;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -160,9 +161,9 @@ namespace osu.Game.Tests.Visual
}; };
foreach(var s in scores) foreach(var s in scores)
{ {
s.Statistics.Add("300", RNG.Next(2000)); s.Statistics.Add(HitCount.Great, RNG.Next(2000));
s.Statistics.Add("100", RNG.Next(2000)); s.Statistics.Add(HitCount.Good, RNG.Next(2000));
s.Statistics.Add("50", RNG.Next(2000)); s.Statistics.Add(HitCount.Meh, RNG.Next(2000));
} }
anotherScores = new[] anotherScores = new[]
@ -272,9 +273,9 @@ namespace osu.Game.Tests.Visual
}; };
foreach (var s in anotherScores) foreach (var s in anotherScores)
{ {
s.Statistics.Add("300", RNG.Next(2000)); s.Statistics.Add(HitCount.Great, RNG.Next(2000));
s.Statistics.Add("100", RNG.Next(2000)); s.Statistics.Add(HitCount.Good, RNG.Next(2000));
s.Statistics.Add("50", RNG.Next(2000)); s.Statistics.Add(HitCount.Meh, RNG.Next(2000));
} }
topScore = new OnlineScore topScore = new OnlineScore
@ -299,9 +300,9 @@ namespace osu.Game.Tests.Visual
TotalScore = 987654321, TotalScore = 987654321,
Accuracy = 0.8487, Accuracy = 0.8487,
}; };
topScore.Statistics.Add("300", RNG.Next(2000)); topScore.Statistics.Add(HitCount.Great, RNG.Next(2000));
topScore.Statistics.Add("100", RNG.Next(2000)); topScore.Statistics.Add(HitCount.Good, RNG.Next(2000));
topScore.Statistics.Add("50", RNG.Next(2000)); topScore.Statistics.Add(HitCount.Meh, RNG.Next(2000));
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -8,6 +8,7 @@ using osu.Game.Beatmaps;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Users; using osu.Game.Users;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -41,12 +42,12 @@ namespace osu.Game.Tests.Visual
MaxCombo = 123, MaxCombo = 123,
Rank = ScoreRank.A, Rank = ScoreRank.A,
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
Statistics = new Dictionary<string, dynamic> Statistics = new Dictionary<HitCount, dynamic>
{ {
{ "300", 50 }, { HitCount.Great, 50 },
{ "100", 20 }, { HitCount.Good, 20 },
{ "50", 50 }, { HitCount.Meh, 50 },
{ "x", 1 } { HitCount.Miss, 1 }
}, },
User = new User User = new User
{ {

View File

@ -122,26 +122,26 @@ namespace osu.Game.Online.API.Requests
{ {
foreach (var kvp in value) foreach (var kvp in value)
{ {
string key = kvp.Key; HitCount newKey;
switch (key) switch (kvp.Key)
{ {
case @"count_300": case @"count_300":
key = @"300"; newKey = HitCount.Great;
break; break;
case @"count_100": case @"count_100":
key = @"100"; newKey = HitCount.Good;
break; break;
case @"count_50": case @"count_50":
key = @"50"; newKey = HitCount.Meh;
break; break;
case @"count_miss": case @"count_miss":
key = @"x"; newKey = HitCount.Miss;
break; break;
default: default:
continue; continue;
} }
Statistics.Add(key, kvp.Value); Statistics.Add(newKey, kvp.Value);
} }
} }
} }

View File

@ -15,6 +15,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Users; using osu.Game.Users;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
@ -104,7 +105,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = 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", Font = @"Exo2.0-RegularItalic",
Margin = new MarginPadding { Right = side_margin } Margin = new MarginPadding { Right = side_margin }
}, },

View File

@ -18,6 +18,7 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Users; using osu.Game.Users;
using static osu.Game.Rulesets.Scoring.Score;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
@ -58,7 +59,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
totalScore.Value = $@"{score.TotalScore:N0}"; totalScore.Value = $@"{score.TotalScore:N0}";
accuracy.Value = $@"{score.Accuracy:P2}"; 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(); modsContainer.Clear();
foreach (Mod mod in score.Mods) foreach (Mod mod in score.Mods)

View File

@ -7,6 +7,7 @@ using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using System.ComponentModel;
namespace osu.Game.Rulesets.Scoring namespace osu.Game.Rulesets.Scoring
{ {
@ -40,6 +41,21 @@ namespace osu.Game.Rulesets.Scoring
public DateTimeOffset Date; public DateTimeOffset Date;
public Dictionary<string, object> Statistics = new Dictionary<string, object>(); public Dictionary<HitCount, object> Statistics = new Dictionary<HitCount, object>();
public enum HitCount
{
[Description("300")]
Great,
[Description("100")]
Good,
[Description("50")]
Meh,
[Description("x")]
Miss
}
} }
} }

View File

@ -23,6 +23,8 @@ using osu.Game.Screens.Play;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Users; using osu.Game.Users;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using static osu.Game.Rulesets.Scoring.Score;
using osu.Framework.Extensions;
namespace osu.Game.Screens.Ranking namespace osu.Game.Screens.Ranking
{ {
@ -186,9 +188,9 @@ namespace osu.Game.Screens.Ranking
private class DrawableScoreStatistic : Container private class DrawableScoreStatistic : Container
{ {
private readonly KeyValuePair<string, object> statistic; private readonly KeyValuePair<HitCount, object> statistic;
public DrawableScoreStatistic(KeyValuePair<string, object> statistic) public DrawableScoreStatistic(KeyValuePair<HitCount, object> statistic)
{ {
this.statistic = statistic; this.statistic = statistic;
@ -209,7 +211,7 @@ namespace osu.Game.Screens.Ranking
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
}, },
new OsuSpriteText { new OsuSpriteText {
Text = statistic.Key, Text = statistic.Key.GetDescription(),
Colour = colours.Gray7, Colour = colours.Gray7,
Font = @"Exo2.0-Bold", Font = @"Exo2.0-Bold",
Y = 26, Y = 26,