1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +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.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))

View File

@ -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)

View File

@ -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]

View File

@ -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<string, dynamic>
Statistics = new Dictionary<HitCount, dynamic>
{
{ "300", 50 },
{ "100", 20 },
{ "50", 50 },
{ "x", 1 }
{ HitCount.Great, 50 },
{ HitCount.Good, 20 },
{ HitCount.Meh, 50 },
{ HitCount.Miss, 1 }
},
User = new User
{

View File

@ -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);
}
}
}

View File

@ -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 }
},

View File

@ -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)

View File

@ -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<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.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<string, object> statistic;
private readonly KeyValuePair<HitCount, object> statistic;
public DrawableScoreStatistic(KeyValuePair<string, object> statistic)
public DrawableScoreStatistic(KeyValuePair<HitCount, object> 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,