From 716bb5abf3e9763401da17508a3734f971ee020b Mon Sep 17 00:00:00 2001 From: StanR Date: Sat, 24 Jan 2026 15:24:37 +0500 Subject: [PATCH] Simplify ExtendedDifficultyCalculators usage --- .../ExtendedCatchDifficultyCalculator.cs | 17 +++++++++---- .../ExtendedManiaDifficultyCalculator.cs | 17 +++++++++---- .../ExtendedOsuDifficultyCalculator.cs | 17 +++++++++---- .../ExtendedTaikoDifficultyCalculator.cs | 17 +++++++++---- .../IExtendedDifficultyCalculator.cs | 3 +-- .../CatchObjectInspectorRuleset.cs | 23 ++++++++++++++---- .../ObjectInspection/ObjectInspector.cs | 13 +++------- .../OsuObjectInspectorRuleset.cs | 22 ++++++++++++++--- .../TaikoObjectInspectorRuleset.cs | 24 +++++++++++++++---- 9 files changed, 109 insertions(+), 44 deletions(-) diff --git a/PerformanceCalculatorGUI/ExtendedCatchDifficultyCalculator.cs b/PerformanceCalculatorGUI/ExtendedCatchDifficultyCalculator.cs index d7b65252d1..665b1e33a1 100644 --- a/PerformanceCalculatorGUI/ExtendedCatchDifficultyCalculator.cs +++ b/PerformanceCalculatorGUI/ExtendedCatchDifficultyCalculator.cs @@ -1,11 +1,11 @@ // 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 System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets; using osu.Game.Rulesets.Catch.Difficulty; -using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; @@ -15,6 +15,7 @@ namespace PerformanceCalculatorGUI public class ExtendedCatchDifficultyCalculator : CatchDifficultyCalculator, IExtendedDifficultyCalculator { private Skill[] skills = []; + private DifficultyHitObject[] difficultyHitObjects = []; public ExtendedCatchDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) @@ -22,12 +23,18 @@ public ExtendedCatchDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap b } public Skill[] GetSkills() => skills; - public DifficultyHitObject[] GetDifficultyHitObjects(IBeatmap beatmap, double clockRate) => CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + public DifficultyHitObject[] GetDifficultyHitObjects() => difficultyHitObjects; - protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) + protected override IEnumerable CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) { - this.skills = skills; - return base.CreateDifficultyAttributes(beatmap, mods, skills, clockRate); + difficultyHitObjects = base.CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + return difficultyHitObjects; + } + + protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) + { + skills = base.CreateSkills(beatmap, mods, clockRate); + return skills; } } } diff --git a/PerformanceCalculatorGUI/ExtendedManiaDifficultyCalculator.cs b/PerformanceCalculatorGUI/ExtendedManiaDifficultyCalculator.cs index 9126c6b8b5..ca68aa8763 100644 --- a/PerformanceCalculatorGUI/ExtendedManiaDifficultyCalculator.cs +++ b/PerformanceCalculatorGUI/ExtendedManiaDifficultyCalculator.cs @@ -1,10 +1,10 @@ // 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 System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets; -using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mania.Difficulty; @@ -15,6 +15,7 @@ namespace PerformanceCalculatorGUI public class ExtendedManiaDifficultyCalculator : ManiaDifficultyCalculator, IExtendedDifficultyCalculator { private Skill[] skills = []; + private DifficultyHitObject[] difficultyHitObjects = []; public ExtendedManiaDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) @@ -22,12 +23,18 @@ public ExtendedManiaDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap b } public Skill[] GetSkills() => skills; - public DifficultyHitObject[] GetDifficultyHitObjects(IBeatmap beatmap, double clockRate) => CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + public DifficultyHitObject[] GetDifficultyHitObjects() => difficultyHitObjects; - protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) + protected override IEnumerable CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) { - this.skills = skills; - return base.CreateDifficultyAttributes(beatmap, mods, skills, clockRate); + difficultyHitObjects = base.CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + return difficultyHitObjects; + } + + protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) + { + skills = base.CreateSkills(beatmap, mods, clockRate); + return skills; } } } diff --git a/PerformanceCalculatorGUI/ExtendedOsuDifficultyCalculator.cs b/PerformanceCalculatorGUI/ExtendedOsuDifficultyCalculator.cs index 5c9c8c5785..4ee2189eba 100644 --- a/PerformanceCalculatorGUI/ExtendedOsuDifficultyCalculator.cs +++ b/PerformanceCalculatorGUI/ExtendedOsuDifficultyCalculator.cs @@ -1,10 +1,10 @@ // 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 System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets; -using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; @@ -15,6 +15,7 @@ namespace PerformanceCalculatorGUI public class ExtendedOsuDifficultyCalculator : OsuDifficultyCalculator, IExtendedDifficultyCalculator { private Skill[] skills = []; + private DifficultyHitObject[] difficultyHitObjects = []; public ExtendedOsuDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) @@ -22,12 +23,18 @@ public ExtendedOsuDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap bea } public Skill[] GetSkills() => skills; - public DifficultyHitObject[] GetDifficultyHitObjects(IBeatmap beatmap, double clockRate) => CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + public DifficultyHitObject[] GetDifficultyHitObjects() => difficultyHitObjects; - protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) + protected override IEnumerable CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) { - this.skills = skills; - return base.CreateDifficultyAttributes(beatmap, mods, skills, clockRate); + difficultyHitObjects = base.CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + return difficultyHitObjects; + } + + protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) + { + skills = base.CreateSkills(beatmap, mods, clockRate); + return skills; } } } diff --git a/PerformanceCalculatorGUI/ExtendedTaikoDifficultyCalculator.cs b/PerformanceCalculatorGUI/ExtendedTaikoDifficultyCalculator.cs index 8c30700c4c..60f29017ec 100644 --- a/PerformanceCalculatorGUI/ExtendedTaikoDifficultyCalculator.cs +++ b/PerformanceCalculatorGUI/ExtendedTaikoDifficultyCalculator.cs @@ -1,10 +1,10 @@ // 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 System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets; -using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; @@ -15,6 +15,7 @@ namespace PerformanceCalculatorGUI public class ExtendedTaikoDifficultyCalculator : TaikoDifficultyCalculator, IExtendedDifficultyCalculator { private Skill[] skills = []; + private DifficultyHitObject[] difficultyHitObjects = []; public ExtendedTaikoDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) @@ -22,12 +23,18 @@ public ExtendedTaikoDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap b } public Skill[] GetSkills() => skills; - public DifficultyHitObject[] GetDifficultyHitObjects(IBeatmap beatmap, double clockRate) => CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + public DifficultyHitObject[] GetDifficultyHitObjects() => difficultyHitObjects; - protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) + protected override IEnumerable CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) { - this.skills = skills; - return base.CreateDifficultyAttributes(beatmap, mods, skills, clockRate); + difficultyHitObjects = base.CreateDifficultyHitObjects(beatmap, clockRate).ToArray(); + return difficultyHitObjects; + } + + protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) + { + skills = base.CreateSkills(beatmap, mods, clockRate); + return skills; } } } diff --git a/PerformanceCalculatorGUI/IExtendedDifficultyCalculator.cs b/PerformanceCalculatorGUI/IExtendedDifficultyCalculator.cs index 787502c470..f40fb45278 100644 --- a/PerformanceCalculatorGUI/IExtendedDifficultyCalculator.cs +++ b/PerformanceCalculatorGUI/IExtendedDifficultyCalculator.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Beatmaps; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; @@ -10,6 +9,6 @@ namespace PerformanceCalculatorGUI public interface IExtendedDifficultyCalculator { Skill[] GetSkills(); - DifficultyHitObject[] GetDifficultyHitObjects(IBeatmap beatmap, double clockRate); + DifficultyHitObject[] GetDifficultyHitObjects(); } } diff --git a/PerformanceCalculatorGUI/Screens/ObjectInspection/CatchObjectInspectorRuleset.cs b/PerformanceCalculatorGUI/Screens/ObjectInspection/CatchObjectInspectorRuleset.cs index 1bcc8a3bd8..0497f44559 100644 --- a/PerformanceCalculatorGUI/Screens/ObjectInspection/CatchObjectInspectorRuleset.cs +++ b/PerformanceCalculatorGUI/Screens/ObjectInspection/CatchObjectInspectorRuleset.cs @@ -4,26 +4,41 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Game.Beatmaps; using osu.Game.Rulesets; using osu.Game.Rulesets.Catch.Difficulty.Preprocessing; using osu.Game.Rulesets.Catch.Edit; +using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; namespace PerformanceCalculatorGUI.Screens.ObjectInspection { public partial class CatchObjectInspectorRuleset : DrawableCatchEditorRuleset { - private readonly CatchDifficultyHitObject[] difficultyHitObjects; + private CatchDifficultyHitObject[] difficultyHitObjects = []; [Resolved] private ObjectDifficultyValuesContainer objectDifficultyValuesContainer { get; set; } = null!; - public CatchObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods, ExtendedCatchDifficultyCalculator difficultyCalculator, double clockRate) + [Resolved] + private Bindable difficultyCalculator { get; set; } = null!; + + public CatchObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods) : base(ruleset, beatmap, mods) { - difficultyHitObjects = difficultyCalculator.GetDifficultyHitObjects(beatmap, clockRate) - .Cast().ToArray(); + } + + protected override void LoadComplete() + { + var extendedDifficultyCalculator = (IExtendedDifficultyCalculator?)difficultyCalculator.Value; + + if (extendedDifficultyCalculator != null) + { + difficultyHitObjects = extendedDifficultyCalculator.GetDifficultyHitObjects().Cast().ToArray(); + } + + base.LoadComplete(); } public override bool PropagatePositionalInputSubTree => false; diff --git a/PerformanceCalculatorGUI/Screens/ObjectInspection/ObjectInspector.cs b/PerformanceCalculatorGUI/Screens/ObjectInspection/ObjectInspector.cs index 17b2e5b1c4..98f9768dc9 100644 --- a/PerformanceCalculatorGUI/Screens/ObjectInspection/ObjectInspector.cs +++ b/PerformanceCalculatorGUI/Screens/ObjectInspection/ObjectInspector.cs @@ -18,7 +18,6 @@ using osu.Game.Rulesets.Catch.Beatmaps; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.UI; -using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; @@ -54,9 +53,6 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl [Resolved] private Bindable ruleset { get; set; } = null!; - [Resolved] - private Bindable difficultyCalculator { get; set; } = null!; - private readonly ProcessorWorkingBeatmap processorBeatmap; private EditorClock clock = null!; private Container rulesetContainer = null!; @@ -205,8 +201,7 @@ private void load(OverlayColourProvider colourProvider) RelativeSizeAxes = Axes.Both, PlayfieldBorderStyle = { Value = PlayfieldBorderStyle.Corners } }, - new OsuObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!, (difficultyCalculator.Value as ExtendedOsuDifficultyCalculator)!, - processorBeatmap.Track.Rate) + new OsuObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!) { RelativeSizeAxes = Axes.Both, Clock = clock, @@ -216,8 +211,7 @@ private void load(OverlayColourProvider colourProvider) }, "taiko" => new TaikoPlayfieldAdjustmentContainer { - Child = new TaikoObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!, (difficultyCalculator.Value as ExtendedTaikoDifficultyCalculator)!, - processorBeatmap.Track.Rate) + Child = new TaikoObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!) { RelativeSizeAxes = Axes.Both, Clock = clock, @@ -230,8 +224,7 @@ private void load(OverlayColourProvider colourProvider) Y = 100, Children = new Drawable[] { - new CatchObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!, (difficultyCalculator.Value as ExtendedCatchDifficultyCalculator)!, - processorBeatmap.Track.Rate) + new CatchObjectInspectorRuleset(rulesetInstance, playableBeatmap, modifiedMods!) { RelativeSizeAxes = Axes.Both, Clock = clock, diff --git a/PerformanceCalculatorGUI/Screens/ObjectInspection/OsuObjectInspectorRuleset.cs b/PerformanceCalculatorGUI/Screens/ObjectInspection/OsuObjectInspectorRuleset.cs index f975c0c949..081217cfd6 100644 --- a/PerformanceCalculatorGUI/Screens/ObjectInspection/OsuObjectInspectorRuleset.cs +++ b/PerformanceCalculatorGUI/Screens/ObjectInspection/OsuObjectInspectorRuleset.cs @@ -4,9 +4,11 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Rulesets; +using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; @@ -20,15 +22,29 @@ namespace PerformanceCalculatorGUI.Screens.ObjectInspection { public partial class OsuObjectInspectorRuleset : DrawableOsuEditorRuleset { - private readonly OsuDifficultyHitObject[] difficultyHitObjects; + private OsuDifficultyHitObject[] difficultyHitObjects = []; [Resolved] private ObjectDifficultyValuesContainer objectDifficultyValuesContainer { get; set; } = null!; - public OsuObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods, ExtendedOsuDifficultyCalculator difficultyCalculator, double clockRate) + [Resolved] + private Bindable difficultyCalculator { get; set; } = null!; + + public OsuObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods) : base(ruleset, beatmap, mods) { - difficultyHitObjects = difficultyCalculator.GetDifficultyHitObjects(beatmap, clockRate).Cast().ToArray(); + } + + protected override void LoadComplete() + { + var extendedDifficultyCalculator = (IExtendedDifficultyCalculator?)difficultyCalculator.Value; + + if (extendedDifficultyCalculator != null) + { + difficultyHitObjects = extendedDifficultyCalculator.GetDifficultyHitObjects().Cast().ToArray(); + } + + base.LoadComplete(); } protected override void Update() diff --git a/PerformanceCalculatorGUI/Screens/ObjectInspection/TaikoObjectInspectorRuleset.cs b/PerformanceCalculatorGUI/Screens/ObjectInspection/TaikoObjectInspectorRuleset.cs index b300ec58bd..bc4c89b061 100644 --- a/PerformanceCalculatorGUI/Screens/ObjectInspection/TaikoObjectInspectorRuleset.cs +++ b/PerformanceCalculatorGUI/Screens/ObjectInspection/TaikoObjectInspectorRuleset.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Game.Beatmaps; using osu.Game.Rulesets; +using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing; using osu.Game.Rulesets.Taiko.Edit; @@ -16,20 +18,32 @@ namespace PerformanceCalculatorGUI.Screens.ObjectInspection { public partial class TaikoObjectInspectorRuleset : DrawableTaikoEditorRuleset { - private readonly TaikoDifficultyHitObject[] difficultyHitObjects; + private TaikoDifficultyHitObject[] difficultyHitObjects = []; [Resolved] private ObjectDifficultyValuesContainer objectDifficultyValuesContainer { get; set; } = null!; - public TaikoObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods, ExtendedTaikoDifficultyCalculator difficultyCalculator, double clockRate) + [Resolved] + private Bindable difficultyCalculator { get; set; } = null!; + + public TaikoObjectInspectorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods) : base(ruleset, beatmap, mods) { - difficultyHitObjects = difficultyCalculator.GetDifficultyHitObjects(beatmap, clockRate) - .Cast().ToArray(); - ShowSpeedChanges.Value = true; } + protected override void LoadComplete() + { + var extendedDifficultyCalculator = (IExtendedDifficultyCalculator?)difficultyCalculator.Value; + + if (extendedDifficultyCalculator != null) + { + difficultyHitObjects = extendedDifficultyCalculator.GetDifficultyHitObjects().Cast().ToArray(); + } + + base.LoadComplete(); + } + public override bool PropagatePositionalInputSubTree => false; public override bool PropagateNonPositionalInputSubTree => false;