// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using JetBrains.Annotations; using osu.Framework.Utils; using osu.Game.Rulesets.Difficulty; namespace osu.Game.Beatmaps { public readonly struct StarDifficulty { /// /// The star difficulty rating for the given beatmap. /// public readonly double Stars; /// /// The maximum combo achievable on the given beatmap. /// public readonly int MaxCombo; /// /// The difficulty attributes computed for the given beatmap. /// Might not be available if the star difficulty is associated with a beatmap that's not locally available. /// [CanBeNull] public readonly DifficultyAttributes Attributes; /// /// Creates a structure based on computed /// by a . /// public StarDifficulty([NotNull] DifficultyAttributes attributes) { Stars = attributes.StarRating; MaxCombo = attributes.MaxCombo; Attributes = attributes; // Todo: Add more members (BeatmapInfo.DifficultyRating? Attributes? Etc...) } /// /// Creates a structure with a pre-populated star difficulty and max combo /// in scenarios where computing is not feasible (i.e. when working with online sources). /// public StarDifficulty(double starDifficulty, int maxCombo) { Stars = starDifficulty; MaxCombo = maxCombo; Attributes = null; } public DifficultyRating DifficultyRating => GetDifficultyRating(Stars); /// /// Retrieves the that describes a star rating. /// /// /// For more information, see: https://osu.ppy.sh/help/wiki/Difficulties /// /// The star rating. /// The that best describes . 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; } } }