1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:28:00 +08:00

Move GetDifficultyRating helper method to StarDifficulty

This commit is contained in:
Dean Herbert 2022-06-23 19:46:59 +09:00
parent b068df2149
commit ef258122d2
5 changed files with 33 additions and 33 deletions

View File

@ -157,7 +157,7 @@ namespace osu.Game.Tests.Beatmaps
[TestCase(8.3, DifficultyRating.ExpertPlus)] [TestCase(8.3, DifficultyRating.ExpertPlus)]
public void TestDifficultyRatingMapping(double starRating, DifficultyRating expectedBracket) public void TestDifficultyRatingMapping(double starRating, DifficultyRating expectedBracket)
{ {
var actualBracket = BeatmapDifficultyCache.GetDifficultyRating(starRating); var actualBracket = StarDifficulty.GetDifficultyRating(starRating);
Assert.AreEqual(expectedBracket, actualBracket); Assert.AreEqual(expectedBracket, actualBracket);
} }

View File

@ -13,7 +13,6 @@ using osu.Framework.Extensions;
using osu.Framework.Lists; using osu.Framework.Lists;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -165,34 +164,6 @@ namespace osu.Game.Beatmaps
updateScheduler); updateScheduler);
} }
/// <summary>
/// Retrieves the <see cref="DifficultyRating"/> that describes a star rating.
/// </summary>
/// <remarks>
/// For more information, see: https://osu.ppy.sh/help/wiki/Difficulties
/// </remarks>
/// <param name="starRating">The star rating.</param>
/// <returns>The <see cref="DifficultyRating"/> that best describes <paramref name="starRating"/>.</returns>
public static DifficultyRating GetDifficultyRating(double starRating)
{
if (Precision.AlmostBigger(starRating, 6.5, 0.005))
return DifficultyRating.ExpertPlus;
if (Precision.AlmostBigger(starRating, 5.3, 0.005))
return DifficultyRating.Expert;
if (Precision.AlmostBigger(starRating, 4.0, 0.005))
return DifficultyRating.Insane;
if (Precision.AlmostBigger(starRating, 2.7, 0.005))
return DifficultyRating.Hard;
if (Precision.AlmostBigger(starRating, 2.0, 0.005))
return DifficultyRating.Normal;
return DifficultyRating.Easy;
}
/// <summary> /// <summary>
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods. /// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
/// </summary> /// </summary>

View File

@ -128,7 +128,7 @@ namespace osu.Game.Beatmaps
public List<EFScoreInfo> Scores { get; set; } public List<EFScoreInfo> Scores { get; set; }
[JsonIgnore] [JsonIgnore]
public DifficultyRating DifficultyRating => BeatmapDifficultyCache.GetDifficultyRating(StarRating); public DifficultyRating DifficultyRating => StarDifficulty.GetDifficultyRating(StarRating);
public override string ToString() => this.GetDisplayTitle(); public override string ToString() => this.GetDisplayTitle();

View File

@ -4,6 +4,7 @@
#nullable disable #nullable disable
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Utils;
using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
@ -50,6 +51,34 @@ namespace osu.Game.Beatmaps
Attributes = null; Attributes = null;
} }
public DifficultyRating DifficultyRating => BeatmapDifficultyCache.GetDifficultyRating(Stars); public DifficultyRating DifficultyRating => GetDifficultyRating(Stars);
/// <summary>
/// Retrieves the <see cref="DifficultyRating"/> that describes a star rating.
/// </summary>
/// <remarks>
/// For more information, see: https://osu.ppy.sh/help/wiki/Difficulties
/// </remarks>
/// <param name="starRating">The star rating.</param>
/// <returns>The <see cref="DifficultyRating"/> that best describes <paramref name="starRating"/>.</returns>
public static DifficultyRating GetDifficultyRating(double starRating)
{
if (Precision.AlmostBigger(starRating, 6.5, 0.005))
return DifficultyRating.ExpertPlus;
if (Precision.AlmostBigger(starRating, 5.3, 0.005))
return DifficultyRating.Expert;
if (Precision.AlmostBigger(starRating, 4.0, 0.005))
return DifficultyRating.Insane;
if (Precision.AlmostBigger(starRating, 2.7, 0.005))
return DifficultyRating.Hard;
if (Precision.AlmostBigger(starRating, 2.0, 0.005))
return DifficultyRating.Normal;
return DifficultyRating.Easy;
}
} }
} }

View File

@ -31,7 +31,7 @@ namespace osu.Game.Screens.Edit.Verify
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InterpretedDifficulty.Default = BeatmapDifficultyCache.GetDifficultyRating(EditorBeatmap.BeatmapInfo.StarRating); InterpretedDifficulty.Default = StarDifficulty.GetDifficultyRating(EditorBeatmap.BeatmapInfo.StarRating);
InterpretedDifficulty.SetDefault(); InterpretedDifficulty.SetDefault();
Child = new Container Child = new Container