From 6dc0f3fd960cc5a4fd914123388a0585901e0243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 3 Feb 2022 18:14:30 +0100 Subject: [PATCH] Merge difficulty creation methods into one One of them wasn't really doing much anymore and was more obfuscating what was actually happening at this point. --- osu.Game/Beatmaps/BeatmapManager.cs | 14 +++++++++----- osu.Game/Beatmaps/BeatmapModelManager.cs | 13 ------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index d60cfdee9e..633eb8f15e 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -120,15 +120,19 @@ public virtual WorkingBeatmap CreateNewBlankDifficulty(BeatmapSetInfo beatmapSet // but cases where this isn't true seem rather rare / pathological. var referenceBeatmap = GetWorkingBeatmap(beatmapSetInfo.Beatmaps.First()); - var newBeatmap = new Beatmap - { - BeatmapInfo = new BeatmapInfo(rulesetInfo, new BeatmapDifficulty(), referenceBeatmap.Metadata.DeepClone()) - }; + var newBeatmapInfo = new BeatmapInfo(rulesetInfo, new BeatmapDifficulty(), referenceBeatmap.Metadata.DeepClone()); + // populate circular beatmap set info <-> beatmap info references manually. + // several places like `BeatmapModelManager.Save()` or `GetWorkingBeatmap()` + // rely on them being freely traversable in both directions for correct operation. + beatmapSetInfo.Beatmaps.Add(newBeatmapInfo); + newBeatmapInfo.BeatmapSet = beatmapSetInfo; + + var newBeatmap = new Beatmap { BeatmapInfo = newBeatmapInfo }; foreach (var timingPoint in referenceBeatmap.Beatmap.ControlPointInfo.TimingPoints) newBeatmap.ControlPointInfo.Add(timingPoint.Time, timingPoint.DeepClone()); - beatmapModelManager.AddDifficultyToBeatmapSet(beatmapSetInfo, newBeatmap); + beatmapModelManager.Save(newBeatmapInfo, newBeatmap); workingBeatmapCache.Invalidate(beatmapSetInfo); return GetWorkingBeatmap(newBeatmap.BeatmapInfo); diff --git a/osu.Game/Beatmaps/BeatmapModelManager.cs b/osu.Game/Beatmaps/BeatmapModelManager.cs index b9f0af8833..4c680bbcc9 100644 --- a/osu.Game/Beatmaps/BeatmapModelManager.cs +++ b/osu.Game/Beatmaps/BeatmapModelManager.cs @@ -90,19 +90,6 @@ public void Save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin? beatma WorkingBeatmapCache?.Invalidate(beatmapInfo); } - /// - /// Add a new difficulty to the beatmap set represented by the provided . - /// - public void AddDifficultyToBeatmapSet(BeatmapSetInfo beatmapSetInfo, Beatmap beatmap) - { - var beatmapInfo = beatmap.BeatmapInfo; - - beatmapSetInfo.Beatmaps.Add(beatmapInfo); - beatmapInfo.BeatmapSet = beatmapSetInfo; - - Save(beatmapInfo, beatmap); - } - private static string getFilename(BeatmapInfo beatmapInfo) { var metadata = beatmapInfo.Metadata;