From 29bf1637b9f1fba88b2e72ad1c44a0ca088b27ac Mon Sep 17 00:00:00 2001 From: Givikap120 Date: Mon, 19 Aug 2024 17:44:05 +0300 Subject: [PATCH] fixed mentioned issues --- .../Difficulty/OsuDifficultyCalculator.cs | 22 +++---------- osu.Game/Beatmaps/Beatmap.cs | 20 +++++++++++ osu.Game/Beatmaps/IBeatmap.cs | 31 ++++++----------- .../Difficulty/DifficultyCalculator.cs | 33 +++++++++---------- osu.Game/Screens/Edit/EditorBeatmap.cs | 4 +++ 5 files changed, 53 insertions(+), 57 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs index 08141b684b..0610075898 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs @@ -82,25 +82,11 @@ namespace osu.Game.Rulesets.Osu.Difficulty double preempt = IBeatmapDifficultyInfo.DifficultyRange(beatmap.Difficulty.ApproachRate, 1800, 1200, 450) / clockRate; double drainRate = beatmap.Difficulty.DrainRate; - int maxCombo; - int hitCirclesCount, sliderCount, spinnerCount; + int maxCombo = beatmap.GetMaxCombo(); - if (beatmap is ProgressiveCalculationBeatmap pcBeatmap) - { - maxCombo = pcBeatmap.GetMaxCombo(); - - hitCirclesCount = pcBeatmap.GetHitObjectCountOf(typeof(HitCircle)); - sliderCount = pcBeatmap.GetHitObjectCountOf(typeof(Slider)); - spinnerCount = pcBeatmap.GetHitObjectCountOf(typeof(Spinner)); - } - else - { - maxCombo = beatmap.GetMaxCombo(); - - hitCirclesCount = beatmap.HitObjects.Count(h => h is HitCircle); - sliderCount = beatmap.HitObjects.Count(h => h is Slider); - spinnerCount = beatmap.HitObjects.Count(h => h is Spinner); - } + int hitCirclesCount = beatmap.GetHitObjectCountOf(typeof(HitCircle)); + int sliderCount = beatmap.GetHitObjectCountOf(typeof(Slider)); + int spinnerCount = beatmap.GetHitObjectCountOf(typeof(Spinner)); HitWindows hitWindows = new OsuHitWindows(); hitWindows.SetDifficulty(beatmap.Difficulty.OverallDifficulty); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 282f8fe794..a60e9cbd31 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -10,6 +10,7 @@ using osu.Game.Beatmaps.ControlPoints; using Newtonsoft.Json; using osu.Framework.Lists; using osu.Game.IO.Serialization.Converters; +using osu.Game.Rulesets.Scoring; namespace osu.Game.Beatmaps { @@ -115,6 +116,25 @@ namespace osu.Game.Beatmaps return mostCommon.beatLength; } + public int GetMaxCombo() + { + int combo = 0; + foreach (var h in HitObjects) + addCombo(h, ref combo); + return combo; + + static void addCombo(HitObject hitObject, ref int combo) + { + if (hitObject.Judgement.MaxResult.AffectsCombo()) + combo++; + + foreach (var nested in hitObject.NestedHitObjects) + addCombo(nested, ref combo); + } + } + + public int GetHitObjectCountOf(Type type) => HitObjects.Count(h => h.GetType() == type); + IBeatmap IBeatmap.Clone() => Clone(); public Beatmap Clone() => (Beatmap)MemberwiseClone(); diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 430a31769b..0f316a8147 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -8,7 +8,6 @@ using osu.Framework.Lists; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Scoring; namespace osu.Game.Beatmaps { @@ -74,6 +73,16 @@ namespace osu.Game.Beatmaps /// /// The shallow-cloned beatmap. IBeatmap Clone(); + + /// + /// Finds the maximum achievable combo by hitting all s in a beatmap. + /// + int GetMaxCombo(); + + /// + /// Finds amount of s that have given type. + /// + int GetHitObjectCountOf(Type type); } /// @@ -90,26 +99,6 @@ namespace osu.Game.Beatmaps public static class BeatmapExtensions { - /// - /// Finds the maximum achievable combo by hitting all s in a beatmap. - /// - public static int GetMaxCombo(this IBeatmap beatmap) - { - int combo = 0; - foreach (var h in beatmap.HitObjects) - addCombo(h, ref combo); - return combo; - - static void addCombo(HitObject hitObject, ref int combo) - { - if (hitObject.Judgement.MaxResult.AffectsCombo()) - combo++; - - foreach (var nested in hitObject.NestedHitObjects) - addCombo(nested, ref combo); - } - } - /// /// Find the total milliseconds between the first and last hittable objects. /// diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 8922dd9256..56b37d7c6a 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -303,6 +303,10 @@ namespace osu.Game.Rulesets.Difficulty this.baseBeatmap = baseBeatmap; } + private int maxCombo; + + public int GetMaxCombo() => maxCombo; + public void AddHitObject(HitObject hitObject) { hitObjects.Add(hitObject); @@ -311,6 +315,17 @@ namespace osu.Game.Rulesets.Difficulty if (!hitObjectsCounts.ContainsKey(objectType)) hitObjectsCounts[objectType] = 0; // Initialize to 0 if not present hitObjectsCounts[objectType]++; + + addCombo(hitObject); + + void addCombo(HitObject hitObject) + { + if (hitObject.Judgement.MaxResult.AffectsCombo()) + maxCombo++; + + foreach (var nested in hitObject.NestedHitObjects) + addCombo(nested); + }; } private readonly List hitObjects = new List(); @@ -321,24 +336,6 @@ namespace osu.Game.Rulesets.Difficulty IReadOnlyList IBeatmap.HitObjects => hitObjects; - private int comboObjectIndex, combo; - - public int GetMaxCombo() - { - for (; comboObjectIndex < hitObjects.Count; comboObjectIndex++) - addCombo(hitObjects[comboObjectIndex], ref combo); - return combo; - - static void addCombo(HitObject hitObject, ref int combo) - { - if (hitObject.Judgement.MaxResult.AffectsCombo()) - combo++; - - foreach (var nested in hitObject.NestedHitObjects) - addCombo(nested, ref combo); - } - } - #region Delegated IBeatmap implementation public BeatmapInfo BeatmapInfo diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index ad31c2ccc3..fc20e254e4 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -198,6 +198,10 @@ namespace osu.Game.Screens.Edit public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength(); + public int GetMaxCombo() => PlayableBeatmap.GetMaxCombo(); + + public int GetHitObjectCountOf(Type type) => PlayableBeatmap.GetHitObjectCountOf(type); + public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone(); private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects;