diff --git a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs index cc975c7def..8b339239a0 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs @@ -1,8 +1,6 @@ // 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 osu.Game.Rulesets.Mania.Objects; using System; using System.Linq; @@ -14,6 +12,7 @@ using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Mania.Beatmaps.Patterns; using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring.Legacy; using osu.Game.Utils; using osuTK; @@ -50,17 +49,21 @@ namespace osu.Game.Rulesets.Mania.Beatmaps private readonly int originalTargetColumns; // Internal for testing purposes - internal LegacyRandom Random { get; private set; } + internal readonly LegacyRandom Random; private Pattern lastPattern = new Pattern(); - private ManiaBeatmap beatmap; - public ManiaBeatmapConverter(IBeatmap beatmap, Ruleset ruleset) - : base(beatmap, ruleset) + : this(beatmap, LegacyBeatmapConversionDifficultyInfo.FromBeatmap(beatmap), ruleset) { - IsForCurrentRuleset = beatmap.BeatmapInfo.Ruleset.Equals(ruleset.RulesetInfo); - TargetColumns = GetColumnCount(LegacyBeatmapConversionDifficultyInfo.FromBeatmap(beatmap)); + } + + private ManiaBeatmapConverter(IBeatmap? beatmap, LegacyBeatmapConversionDifficultyInfo difficulty, Ruleset ruleset) + : base(beatmap!, ruleset) + { + IsForCurrentRuleset = difficulty.SourceRuleset.Equals(ruleset.RulesetInfo); + Random = new LegacyRandom((int)MathF.Round(difficulty.DrainRate + difficulty.CircleSize) * 20 + (int)(difficulty.OverallDifficulty * 41.2) + (int)MathF.Round(difficulty.ApproachRate)); + TargetColumns = getColumnCount(difficulty); if (IsForCurrentRuleset && TargetColumns > ManiaRuleset.MAX_STAGE_KEYS) { @@ -69,51 +72,57 @@ namespace osu.Game.Rulesets.Mania.Beatmaps } originalTargetColumns = TargetColumns; + + static int getColumnCount(LegacyBeatmapConversionDifficultyInfo difficulty) + { + double roundedCircleSize = Math.Round(difficulty.CircleSize); + + if (difficulty.SourceRuleset.ShortName == ManiaRuleset.SHORT_NAME) + return (int)Math.Max(1, roundedCircleSize); + + double roundedOverallDifficulty = Math.Round(difficulty.OverallDifficulty); + + if (difficulty.TotalObjectCount > 0 && difficulty.EndTimeObjectCount >= 0) + { + int countSliderOrSpinner = difficulty.EndTimeObjectCount; + + // In osu!stable, this division appears as if it happens on floats, but due to release-mode + // optimisations, it actually ends up happening on doubles. + double percentSpecialObjects = (double)countSliderOrSpinner / difficulty.TotalObjectCount; + + if (percentSpecialObjects < 0.2) + return 7; + if (percentSpecialObjects < 0.3 || roundedCircleSize >= 5) + return roundedOverallDifficulty > 5 ? 7 : 6; + if (percentSpecialObjects > 0.6) + return roundedOverallDifficulty > 4 ? 5 : 4; + } + + return Math.Max(4, Math.Min((int)roundedOverallDifficulty + 1, 7)); + } } - public static int GetColumnCount(LegacyBeatmapConversionDifficultyInfo difficulty) + public static int GetColumnCount(IBeatmapInfo beatmapInfo, IReadOnlyList? mods = null) + => GetColumnCount(LegacyBeatmapConversionDifficultyInfo.FromBeatmapInfo(beatmapInfo), mods); + + public static int GetColumnCount(LegacyBeatmapConversionDifficultyInfo difficulty, IReadOnlyList? mods = null) { - double roundedCircleSize = Math.Round(difficulty.CircleSize); + var converter = new ManiaBeatmapConverter(null, difficulty, new ManiaRuleset()); - if (difficulty.SourceRuleset.ShortName == ManiaRuleset.SHORT_NAME) - return (int)Math.Max(1, roundedCircleSize); - - double roundedOverallDifficulty = Math.Round(difficulty.OverallDifficulty); - - if (difficulty.TotalObjectCount > 0 && difficulty.EndTimeObjectCount >= 0) + if (mods != null) { - int countSliderOrSpinner = difficulty.EndTimeObjectCount; - - // In osu!stable, this division appears as if it happens on floats, but due to release-mode - // optimisations, it actually ends up happening on doubles. - double percentSpecialObjects = (double)countSliderOrSpinner / difficulty.TotalObjectCount; - - if (percentSpecialObjects < 0.2) - return 7; - if (percentSpecialObjects < 0.3 || roundedCircleSize >= 5) - return roundedOverallDifficulty > 5 ? 7 : 6; - if (percentSpecialObjects > 0.6) - return roundedOverallDifficulty > 4 ? 5 : 4; + foreach (var m in mods.OfType()) + m.ApplyToBeatmapConverter(converter); } - return Math.Max(4, Math.Min((int)roundedOverallDifficulty + 1, 7)); + return converter.TotalColumns; } public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasXPosition); - protected override Beatmap ConvertBeatmap(IBeatmap original, CancellationToken cancellationToken) - { - IBeatmapDifficultyInfo difficulty = original.Difficulty; - - int seed = (int)MathF.Round(difficulty.DrainRate + difficulty.CircleSize) * 20 + (int)(difficulty.OverallDifficulty * 41.2) + (int)MathF.Round(difficulty.ApproachRate); - Random = new LegacyRandom(seed); - - return base.ConvertBeatmap(original, cancellationToken); - } - protected override Beatmap CreateBeatmap() { - beatmap = new ManiaBeatmap(new StageDefinition(TargetColumns), originalTargetColumns); + ManiaBeatmap beatmap = new ManiaBeatmap(new StageDefinition(TargetColumns), originalTargetColumns); if (Dual) beatmap.Stages.Add(new StageDefinition(TargetColumns)); @@ -131,10 +140,6 @@ namespace osu.Game.Rulesets.Mania.Beatmaps } var objects = IsForCurrentRuleset ? generateSpecific(original, beatmap) : generateConverted(original, beatmap); - - if (objects == null) - yield break; - foreach (ManiaHitObject obj in objects) yield return obj; } diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 3d4803f1e4..77168dca68 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -423,8 +423,8 @@ namespace osu.Game.Rulesets.Mania public override DifficultySection CreateEditorDifficultySection() => new ManiaDifficultySection(); - public int GetKeyCount(IBeatmapInfo beatmapInfo) - => ManiaBeatmapConverter.GetColumnCount(LegacyBeatmapConversionDifficultyInfo.FromBeatmapInfo(beatmapInfo)); + public int GetKeyCount(IBeatmapInfo beatmapInfo, IReadOnlyList? mods = null) + => ManiaBeatmapConverter.GetColumnCount(beatmapInfo, mods); } public enum PlayfieldType diff --git a/osu.Game/Rulesets/ILegacyRuleset.cs b/osu.Game/Rulesets/ILegacyRuleset.cs index 18d86f477a..e116f7a1a3 100644 --- a/osu.Game/Rulesets/ILegacyRuleset.cs +++ b/osu.Game/Rulesets/ILegacyRuleset.cs @@ -1,7 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using osu.Game.Beatmaps; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring.Legacy; namespace osu.Game.Rulesets @@ -18,8 +20,7 @@ namespace osu.Game.Rulesets /// /// Retrieves the number of mania keys required to play the beatmap. /// - /// - int GetKeyCount(IBeatmapInfo beatmapInfo) => 0; + int GetKeyCount(IBeatmapInfo beatmapInfo, IReadOnlyList? mods = null) => 0; ILegacyScoreSimulator CreateLegacyScoreSimulator(); } diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index 01e58d4ab2..2752beb645 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -28,6 +28,7 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Resources.Localisation.Web; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osuTK; using osuTK.Graphics; @@ -75,6 +76,9 @@ namespace osu.Game.Screens.Select.Carousel [Resolved] private IBindable ruleset { get; set; } = null!; + [Resolved] + private IBindable>? mods { get; set; } = null!; + private IBindable starDifficultyBindable = null!; private CancellationTokenSource? starDifficultyCancellationSource; @@ -185,6 +189,7 @@ namespace osu.Game.Screens.Select.Carousel base.LoadComplete(); ruleset.BindValueChanged(_ => updateKeyCount()); + mods?.BindValueChanged(_ => updateKeyCount()); } protected override void Selected() @@ -255,7 +260,7 @@ namespace osu.Game.Screens.Select.Carousel ILegacyRuleset legacyRuleset = (ILegacyRuleset)ruleset.Value.CreateInstance(); keyCountText.Alpha = 1; - keyCountText.Text = $"[{legacyRuleset.GetKeyCount(beatmapInfo)}K]"; + keyCountText.Text = $"[{legacyRuleset.GetKeyCount(beatmapInfo, mods?.Value)}K]"; } else keyCountText.Alpha = 0; diff --git a/osu.Game/Screens/Select/Details/AdvancedStats.cs b/osu.Game/Screens/Select/Details/AdvancedStats.cs index 1aba977f44..cb820f4da9 100644 --- a/osu.Game/Screens/Select/Details/AdvancedStats.cs +++ b/osu.Game/Screens/Select/Details/AdvancedStats.cs @@ -199,7 +199,7 @@ namespace osu.Game.Screens.Select.Details // For the time being, the key count is static no matter what, because: // a) The method doesn't have knowledge of the active keymods. Doing so may require considerations for filtering. // b) Using the difficulty adjustment mod to adjust OD doesn't have an effect on conversion. - int keyCount = baseDifficulty == null ? 0 : legacyRuleset.GetKeyCount(BeatmapInfo); + int keyCount = baseDifficulty == null ? 0 : legacyRuleset.GetKeyCount(BeatmapInfo, mods.Value); FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania; FirstValue.Value = (keyCount, keyCount);