From 4cb58fbe474c3c0663fb19284ae6de23ca53b2d4 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 1 Jul 2024 14:58:32 +0900 Subject: [PATCH 1/9] Add failing test --- .../Mods/TestSceneManiaModInvert.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs index 2977241dc6..95fe73db50 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Mania.Mods; using osu.Game.Tests.Visual; @@ -17,5 +19,22 @@ public void TestInversion() => CreateModTest(new ModTestData Mod = new ManiaModInvert(), PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2 }); + + [Test] + public void TestBreaksPreservedOnOriginalBeatmap() + { + var beatmap = CreateBeatmap(new ManiaRuleset().RulesetInfo); + beatmap.Breaks.Clear(); + beatmap.Breaks.Add(new BreakPeriod(0, 1000)); + + var workingBeatmap = new FlatWorkingBeatmap(beatmap); + + var playableWithInvert = workingBeatmap.GetPlayableBeatmap(new ManiaRuleset().RulesetInfo, new[] { new ManiaModInvert() }); + Assert.That(playableWithInvert.Breaks.Count, Is.Zero); + + var playableWithoutInvert = workingBeatmap.GetPlayableBeatmap(new ManiaRuleset().RulesetInfo); + Assert.That(playableWithoutInvert.Breaks.Count, Is.Not.Zero); + Assert.That(playableWithoutInvert.Breaks[0], Is.EqualTo(new BreakPeriod(0, 1000))); + } } } From f942595829336ce1334ec86b88fb04be9068412c Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 1 Jul 2024 14:58:53 +0900 Subject: [PATCH 2/9] Fix `ManiaModInvert` permanently messing up the beatmap --- osu.Game/Beatmaps/BeatmapConverter.cs | 5 +++++ osu.Game/Beatmaps/IBeatmap.cs | 2 +- osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs | 7 ++++++- osu.Game/Screens/Edit/EditorBeatmap.cs | 6 +++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index b68c80d4b3..0ec8eab5d8 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -7,6 +7,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using osu.Framework.Bindables; +using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; @@ -49,6 +51,9 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) original.BeatmapInfo = original.BeatmapInfo.Clone(); original.ControlPointInfo = original.ControlPointInfo.DeepClone(); + // Used in osu!mania conversion. + original.Breaks = new BindableList(original.Breaks); + return ConvertBeatmap(original, cancellationToken); } diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 072e246a36..d8a2560559 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -41,7 +41,7 @@ public interface IBeatmap /// /// The breaks in this beatmap. /// - BindableList Breaks { get; } + BindableList Breaks { get; set; } /// /// All lines from the [Events] section which aren't handled in the encoding process yet. diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 4c6a4cc9c2..97037302c6 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -328,7 +328,12 @@ public BeatmapDifficulty Difficulty set => baseBeatmap.Difficulty = value; } - public BindableList Breaks => baseBeatmap.Breaks; + public BindableList Breaks + { + get => baseBeatmap.Breaks; + set => baseBeatmap.Breaks = value; + } + public List UnhandledEventLines => baseBeatmap.UnhandledEventLines; public double TotalBreakTime => baseBeatmap.TotalBreakTime; diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index ae0fd9130f..331da51888 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -172,7 +172,11 @@ public ControlPointInfo ControlPointInfo set => PlayableBeatmap.ControlPointInfo = value; } - public BindableList Breaks => PlayableBeatmap.Breaks; + public BindableList Breaks + { + get => PlayableBeatmap.Breaks; + set => PlayableBeatmap.Breaks = value; + } public List UnhandledEventLines => PlayableBeatmap.UnhandledEventLines; From 005af280f2ee8c05adb0bc0b5609b52eb40900fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Jul 2024 11:13:20 +0900 Subject: [PATCH 3/9] Isolate bindable breaks list to `EditorBeatmap` --- .../TestSceneEditorBeatmapProcessor.cs | 85 +++++++++++-------- osu.Game/Beatmaps/Beatmap.cs | 3 +- osu.Game/Beatmaps/BeatmapConverter.cs | 4 +- osu.Game/Beatmaps/IBeatmap.cs | 3 +- .../Difficulty/DifficultyCalculator.cs | 3 +- osu.Game/Screens/Edit/EditorBeatmap.cs | 8 +- .../Screens/Edit/EditorBeatmapProcessor.cs | 6 +- 7 files changed, 66 insertions(+), 46 deletions(-) diff --git a/osu.Game.Tests/Editing/TestSceneEditorBeatmapProcessor.cs b/osu.Game.Tests/Editing/TestSceneEditorBeatmapProcessor.cs index 1a3f0aa3df..251099c0e2 100644 --- a/osu.Game.Tests/Editing/TestSceneEditorBeatmapProcessor.cs +++ b/osu.Game.Tests/Editing/TestSceneEditorBeatmapProcessor.cs @@ -21,10 +21,11 @@ public void TestEmptyBeatmap() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, - }; + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -38,14 +39,15 @@ public void TestSingleObjectBeatmap() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -59,15 +61,16 @@ public void TestTwoObjectsCloseTogether() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, new HitCircle { StartTime = 2000 }, } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -81,14 +84,15 @@ public void TestHoldNote() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo }, HitObjects = { new HoldNote { StartTime = 1000, Duration = 10000 }, } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new ManiaRuleset()); beatmapProcessor.PreProcess(); @@ -102,16 +106,17 @@ public void TestHoldNoteWithOverlappingNote() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo }, HitObjects = { new HoldNote { StartTime = 1000, Duration = 10000 }, new Note { StartTime = 2000 }, new Note { StartTime = 12000 }, } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new ManiaRuleset()); beatmapProcessor.PreProcess(); @@ -125,15 +130,16 @@ public void TestTwoObjectsFarApart() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, new HitCircle { StartTime = 5000 }, } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -152,9 +158,10 @@ public void TestBreaksAreFused() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -165,7 +172,7 @@ public void TestBreaksAreFused() new BreakPeriod(1200, 4000), new BreakPeriod(5200, 8000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -184,9 +191,10 @@ public void TestBreaksAreSplit() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -197,7 +205,7 @@ public void TestBreaksAreSplit() { new BreakPeriod(1200, 8000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -218,9 +226,10 @@ public void TestBreaksAreNudged() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1100 }, @@ -230,7 +239,7 @@ public void TestBreaksAreNudged() { new BreakPeriod(1200, 8000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -249,9 +258,10 @@ public void TestManualBreaksAreNotFused() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -262,7 +272,7 @@ public void TestManualBreaksAreNotFused() new ManualBreakPeriod(1200, 4000), new ManualBreakPeriod(5200, 8000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -283,9 +293,10 @@ public void TestManualBreaksAreSplit() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -296,7 +307,7 @@ public void TestManualBreaksAreSplit() { new ManualBreakPeriod(1200, 8000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -317,9 +328,10 @@ public void TestManualBreaksAreNotNudged() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -329,7 +341,7 @@ public void TestManualBreaksAreNotNudged() { new ManualBreakPeriod(1200, 8800), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -348,9 +360,10 @@ public void TestBreaksAtEndOfBeatmapAreRemoved() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -360,7 +373,7 @@ public void TestBreaksAtEndOfBeatmapAreRemoved() { new BreakPeriod(10000, 15000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -374,9 +387,10 @@ public void TestManualBreaksAtEndOfBeatmapAreRemoved() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 1000 }, @@ -386,7 +400,7 @@ public void TestManualBreaksAtEndOfBeatmapAreRemoved() { new ManualBreakPeriod(10000, 15000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -400,9 +414,10 @@ public void TestManualBreaksAtEndOfBeatmapAreRemovedCorrectlyEvenWithConcurrentO { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HoldNote { StartTime = 1000, EndTime = 20000 }, @@ -412,7 +427,7 @@ public void TestManualBreaksAtEndOfBeatmapAreRemovedCorrectlyEvenWithConcurrentO { new ManualBreakPeriod(10000, 15000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -426,9 +441,10 @@ public void TestBreaksAtStartOfBeatmapAreRemoved() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 10000 }, @@ -438,7 +454,7 @@ public void TestBreaksAtStartOfBeatmapAreRemoved() { new BreakPeriod(0, 9000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); @@ -452,9 +468,10 @@ public void TestManualBreaksAtStartOfBeatmapAreRemoved() { var controlPoints = new ControlPointInfo(); controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 }); - var beatmap = new Beatmap + var beatmap = new EditorBeatmap(new Beatmap { ControlPointInfo = controlPoints, + BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo }, HitObjects = { new HitCircle { StartTime = 10000 }, @@ -464,7 +481,7 @@ public void TestManualBreaksAtStartOfBeatmapAreRemoved() { new ManualBreakPeriod(0, 9000), } - }; + }); var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset()); beatmapProcessor.PreProcess(); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 510410bc09..ae77e4adcf 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -8,7 +8,6 @@ using System.Linq; using osu.Game.Beatmaps.ControlPoints; using Newtonsoft.Json; -using osu.Framework.Bindables; using osu.Game.IO.Serialization.Converters; namespace osu.Game.Beatmaps @@ -62,7 +61,7 @@ public Beatmap() public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo(); - public BindableList Breaks { get; set; } = new BindableList(); + public List Breaks { get; set; } = new List(); public List UnhandledEventLines { get; set; } = new List(); diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index 0ec8eab5d8..676eb1b159 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -7,8 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using osu.Framework.Bindables; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; @@ -52,7 +50,7 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) original.ControlPointInfo = original.ControlPointInfo.DeepClone(); // Used in osu!mania conversion. - original.Breaks = new BindableList(original.Breaks); + original.Breaks = original.Breaks.ToList(); return ConvertBeatmap(original, cancellationToken); } diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index d8a2560559..0d39c1f977 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Bindables; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Objects; @@ -41,7 +40,7 @@ public interface IBeatmap /// /// The breaks in this beatmap. /// - BindableList Breaks { get; set; } + List Breaks { get; set; } /// /// All lines from the [Events] section which aren't handled in the encoding process yet. diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 97037302c6..722263c58e 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -9,7 +9,6 @@ using System.Threading; using JetBrains.Annotations; using osu.Framework.Audio.Track; -using osu.Framework.Bindables; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -328,7 +327,7 @@ public BeatmapDifficulty Difficulty set => baseBeatmap.Difficulty = value; } - public BindableList Breaks + public List Breaks { get => baseBeatmap.Breaks; set => baseBeatmap.Breaks = value; diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 331da51888..1ebd2e6337 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -110,6 +110,9 @@ public EditorBeatmap(IBeatmap playableBeatmap, ISkin beatmapSkin = null, Beatmap foreach (var obj in HitObjects) trackStartTime(obj); + Breaks = new BindableList(playableBeatmap.Breaks); + Breaks.BindCollectionChanged((_, _) => playableBeatmap.Breaks = Breaks.ToList()); + PreviewTime = new BindableInt(BeatmapInfo.Metadata.PreviewTime); PreviewTime.BindValueChanged(s => { @@ -172,7 +175,9 @@ public ControlPointInfo ControlPointInfo set => PlayableBeatmap.ControlPointInfo = value; } - public BindableList Breaks + public readonly BindableList Breaks; + + List IBeatmap.Breaks { get => PlayableBeatmap.Breaks; set => PlayableBeatmap.Breaks = value; @@ -191,6 +196,7 @@ public BindableList Breaks public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone(); private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects; + private IList mutableBreaks => (IList)PlayableBeatmap.Breaks; private readonly List batchPendingInserts = new List(); diff --git a/osu.Game/Screens/Edit/EditorBeatmapProcessor.cs b/osu.Game/Screens/Edit/EditorBeatmapProcessor.cs index 99c8c3572b..377e978c4a 100644 --- a/osu.Game/Screens/Edit/EditorBeatmapProcessor.cs +++ b/osu.Game/Screens/Edit/EditorBeatmapProcessor.cs @@ -12,11 +12,13 @@ namespace osu.Game.Screens.Edit { public class EditorBeatmapProcessor : IBeatmapProcessor { - public IBeatmap Beatmap { get; } + public EditorBeatmap Beatmap { get; } + + IBeatmap IBeatmapProcessor.Beatmap => Beatmap; private readonly IBeatmapProcessor? rulesetBeatmapProcessor; - public EditorBeatmapProcessor(IBeatmap beatmap, Ruleset ruleset) + public EditorBeatmapProcessor(EditorBeatmap beatmap, Ruleset ruleset) { Beatmap = beatmap; rulesetBeatmapProcessor = ruleset.CreateBeatmapProcessor(beatmap); From f694ae416eba180f03c55a0374018a2ccf53a593 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Jul 2024 11:47:40 +0900 Subject: [PATCH 4/9] Fix typo in xmldoc --- osu.Game/Beatmaps/IBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 0d39c1f977..176738489a 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -44,7 +44,7 @@ public interface IBeatmap /// /// All lines from the [Events] section which aren't handled in the encoding process yet. - /// These lines shoule be written out to the beatmap file on save or export. + /// These lines should be written out to the beatmap file on save or export. /// List UnhandledEventLines { get; } From 2c3b411bb5e77696a29abf5fdeb873b1d72c47a7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Jul 2024 11:59:24 +0900 Subject: [PATCH 5/9] Change breaks list to `IReadOnlyList` --- .../Mods/TestSceneManiaModInvert.cs | 7 +++++-- osu.Game/Beatmaps/Beatmap.cs | 6 ++++++ osu.Game/Beatmaps/BeatmapConverter.cs | 7 +++---- osu.Game/Beatmaps/IBeatmap.cs | 2 +- osu.Game/Database/LegacyBeatmapExporter.cs | 6 +++++- osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs | 2 +- osu.Game/Screens/Edit/EditorBeatmap.cs | 2 +- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs index 95fe73db50..576b07265b 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs @@ -1,6 +1,7 @@ // 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 NUnit.Framework; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Timing; @@ -24,8 +25,10 @@ public void TestInversion() => CreateModTest(new ModTestData public void TestBreaksPreservedOnOriginalBeatmap() { var beatmap = CreateBeatmap(new ManiaRuleset().RulesetInfo); - beatmap.Breaks.Clear(); - beatmap.Breaks.Add(new BreakPeriod(0, 1000)); + var breaks = (List)beatmap.Breaks; + + breaks.Clear(); + breaks.Add(new BreakPeriod(0, 1000)); var workingBeatmap = new FlatWorkingBeatmap(beatmap); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index ae77e4adcf..b185c1cd5a 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -61,6 +61,12 @@ public Beatmap() public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo(); + IReadOnlyList IBeatmap.Breaks + { + get => Breaks; + set => Breaks = new List(value); + } + public List Breaks { get; set; } = new List(); public List UnhandledEventLines { get; set; } = new List(); diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index 676eb1b159..e62de3e69b 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; @@ -49,9 +50,6 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) original.BeatmapInfo = original.BeatmapInfo.Clone(); original.ControlPointInfo = original.ControlPointInfo.DeepClone(); - // Used in osu!mania conversion. - original.Breaks = original.Breaks.ToList(); - return ConvertBeatmap(original, cancellationToken); } @@ -68,7 +66,8 @@ protected virtual Beatmap ConvertBeatmap(IBeatmap original, CancellationToken beatmap.BeatmapInfo = original.BeatmapInfo; beatmap.ControlPointInfo = original.ControlPointInfo; beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList(); - beatmap.Breaks = original.Breaks; + // Used in osu!mania conversion. + beatmap.Breaks = new List(original.Breaks); beatmap.UnhandledEventLines = original.UnhandledEventLines; return beatmap; diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 176738489a..151edc9ad8 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -40,7 +40,7 @@ public interface IBeatmap /// /// The breaks in this beatmap. /// - List Breaks { get; set; } + IReadOnlyList Breaks { get; set; } /// /// All lines from the [Events] section which aren't handled in the encoding process yet. diff --git a/osu.Game/Database/LegacyBeatmapExporter.cs b/osu.Game/Database/LegacyBeatmapExporter.cs index 17c2c8c88d..62f6f5d30d 100644 --- a/osu.Game/Database/LegacyBeatmapExporter.cs +++ b/osu.Game/Database/LegacyBeatmapExporter.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -64,8 +65,11 @@ public LegacyBeatmapExporter(Storage storage) foreach (var controlPoint in playableBeatmap.ControlPointInfo.AllControlPoints) controlPoint.Time = Math.Floor(controlPoint.Time); + var breaks = new List(playableBeatmap.Breaks.Count); for (int i = 0; i < playableBeatmap.Breaks.Count; i++) - playableBeatmap.Breaks[i] = new BreakPeriod(Math.Floor(playableBeatmap.Breaks[i].StartTime), Math.Floor(playableBeatmap.Breaks[i].EndTime)); + breaks.Add(new BreakPeriod(Math.Floor(playableBeatmap.Breaks[i].StartTime), Math.Floor(playableBeatmap.Breaks[i].EndTime))); + + playableBeatmap.Breaks = breaks; foreach (var hitObject in playableBeatmap.HitObjects) { diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 722263c58e..7262b9d1a8 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -327,7 +327,7 @@ public BeatmapDifficulty Difficulty set => baseBeatmap.Difficulty = value; } - public List Breaks + public IReadOnlyList Breaks { get => baseBeatmap.Breaks; set => baseBeatmap.Breaks = value; diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 1ebd2e6337..cc1d820427 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -177,7 +177,7 @@ public ControlPointInfo ControlPointInfo public readonly BindableList Breaks; - List IBeatmap.Breaks + IReadOnlyList IBeatmap.Breaks { get => PlayableBeatmap.Breaks; set => PlayableBeatmap.Breaks = value; From f69bc40a4b465a6f6902d2038fcf824fb7b638bb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Jul 2024 12:07:13 +0900 Subject: [PATCH 6/9] Move break cloning back to non-virtual method --- osu.Game/Beatmaps/BeatmapConverter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index e62de3e69b..5fd20d5aff 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -49,6 +49,8 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) // Can potentially be removed after `Beatmap.Difficulty` doesn't save back to `Beatmap.BeatmapInfo`. original.BeatmapInfo = original.BeatmapInfo.Clone(); original.ControlPointInfo = original.ControlPointInfo.DeepClone(); + // Used in osu!mania conversion. + original.Breaks = new List(original.Breaks); return ConvertBeatmap(original, cancellationToken); } @@ -66,8 +68,6 @@ protected virtual Beatmap ConvertBeatmap(IBeatmap original, CancellationToken beatmap.BeatmapInfo = original.BeatmapInfo; beatmap.ControlPointInfo = original.ControlPointInfo; beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList(); - // Used in osu!mania conversion. - beatmap.Breaks = new List(original.Breaks); beatmap.UnhandledEventLines = original.UnhandledEventLines; return beatmap; From db847112149ae8e27d5960f2a7909acb5c91f480 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 2 Jul 2024 12:16:10 +0900 Subject: [PATCH 7/9] Revert "Move break cloning back to non-virtual method" This reverts commit f69bc40a4b465a6f6902d2038fcf824fb7b638bb. --- osu.Game/Beatmaps/BeatmapConverter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index 5fd20d5aff..e62de3e69b 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -49,8 +49,6 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) // Can potentially be removed after `Beatmap.Difficulty` doesn't save back to `Beatmap.BeatmapInfo`. original.BeatmapInfo = original.BeatmapInfo.Clone(); original.ControlPointInfo = original.ControlPointInfo.DeepClone(); - // Used in osu!mania conversion. - original.Breaks = new List(original.Breaks); return ConvertBeatmap(original, cancellationToken); } @@ -68,6 +66,8 @@ protected virtual Beatmap ConvertBeatmap(IBeatmap original, CancellationToken beatmap.BeatmapInfo = original.BeatmapInfo; beatmap.ControlPointInfo = original.ControlPointInfo; beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList(); + // Used in osu!mania conversion. + beatmap.Breaks = new List(original.Breaks); beatmap.UnhandledEventLines = original.UnhandledEventLines; return beatmap; From 04da1209f7d4caff3bc5689bea9c53d4eb2e1c0a Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 2 Jul 2024 12:16:11 +0900 Subject: [PATCH 8/9] Revert "Change breaks list to `IReadOnlyList`" This reverts commit 2c3b411bb5e77696a29abf5fdeb873b1d72c47a7. --- .../Mods/TestSceneManiaModInvert.cs | 7 ++----- osu.Game/Beatmaps/Beatmap.cs | 6 ------ osu.Game/Beatmaps/BeatmapConverter.cs | 7 ++++--- osu.Game/Beatmaps/IBeatmap.cs | 2 +- osu.Game/Database/LegacyBeatmapExporter.cs | 6 +----- osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs | 2 +- osu.Game/Screens/Edit/EditorBeatmap.cs | 2 +- 7 files changed, 10 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs index 576b07265b..95fe73db50 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.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 System.Collections.Generic; using NUnit.Framework; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Timing; @@ -25,10 +24,8 @@ public void TestInversion() => CreateModTest(new ModTestData public void TestBreaksPreservedOnOriginalBeatmap() { var beatmap = CreateBeatmap(new ManiaRuleset().RulesetInfo); - var breaks = (List)beatmap.Breaks; - - breaks.Clear(); - breaks.Add(new BreakPeriod(0, 1000)); + beatmap.Breaks.Clear(); + beatmap.Breaks.Add(new BreakPeriod(0, 1000)); var workingBeatmap = new FlatWorkingBeatmap(beatmap); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index b185c1cd5a..ae77e4adcf 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -61,12 +61,6 @@ public Beatmap() public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo(); - IReadOnlyList IBeatmap.Breaks - { - get => Breaks; - set => Breaks = new List(value); - } - public List Breaks { get; set; } = new List(); public List UnhandledEventLines { get; set; } = new List(); diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index e62de3e69b..676eb1b159 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; @@ -50,6 +49,9 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) original.BeatmapInfo = original.BeatmapInfo.Clone(); original.ControlPointInfo = original.ControlPointInfo.DeepClone(); + // Used in osu!mania conversion. + original.Breaks = original.Breaks.ToList(); + return ConvertBeatmap(original, cancellationToken); } @@ -66,8 +68,7 @@ protected virtual Beatmap ConvertBeatmap(IBeatmap original, CancellationToken beatmap.BeatmapInfo = original.BeatmapInfo; beatmap.ControlPointInfo = original.ControlPointInfo; beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList(); - // Used in osu!mania conversion. - beatmap.Breaks = new List(original.Breaks); + beatmap.Breaks = original.Breaks; beatmap.UnhandledEventLines = original.UnhandledEventLines; return beatmap; diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 151edc9ad8..176738489a 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -40,7 +40,7 @@ public interface IBeatmap /// /// The breaks in this beatmap. /// - IReadOnlyList Breaks { get; set; } + List Breaks { get; set; } /// /// All lines from the [Events] section which aren't handled in the encoding process yet. diff --git a/osu.Game/Database/LegacyBeatmapExporter.cs b/osu.Game/Database/LegacyBeatmapExporter.cs index 62f6f5d30d..17c2c8c88d 100644 --- a/osu.Game/Database/LegacyBeatmapExporter.cs +++ b/osu.Game/Database/LegacyBeatmapExporter.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -65,11 +64,8 @@ public LegacyBeatmapExporter(Storage storage) foreach (var controlPoint in playableBeatmap.ControlPointInfo.AllControlPoints) controlPoint.Time = Math.Floor(controlPoint.Time); - var breaks = new List(playableBeatmap.Breaks.Count); for (int i = 0; i < playableBeatmap.Breaks.Count; i++) - breaks.Add(new BreakPeriod(Math.Floor(playableBeatmap.Breaks[i].StartTime), Math.Floor(playableBeatmap.Breaks[i].EndTime))); - - playableBeatmap.Breaks = breaks; + playableBeatmap.Breaks[i] = new BreakPeriod(Math.Floor(playableBeatmap.Breaks[i].StartTime), Math.Floor(playableBeatmap.Breaks[i].EndTime)); foreach (var hitObject in playableBeatmap.HitObjects) { diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 7262b9d1a8..722263c58e 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -327,7 +327,7 @@ public BeatmapDifficulty Difficulty set => baseBeatmap.Difficulty = value; } - public IReadOnlyList Breaks + public List Breaks { get => baseBeatmap.Breaks; set => baseBeatmap.Breaks = value; diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index cc1d820427..1ebd2e6337 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -177,7 +177,7 @@ public ControlPointInfo ControlPointInfo public readonly BindableList Breaks; - IReadOnlyList IBeatmap.Breaks + List IBeatmap.Breaks { get => PlayableBeatmap.Breaks; set => PlayableBeatmap.Breaks = value; From 31edca866c6d921cc0f628f4074aece1a63f8c75 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 2 Jul 2024 12:21:24 +0900 Subject: [PATCH 9/9] Remove unused code --- osu.Game/Screens/Edit/EditorBeatmap.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 1ebd2e6337..c8592b5bea 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -196,7 +196,6 @@ List IBeatmap.Breaks public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone(); private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects; - private IList mutableBreaks => (IList)PlayableBeatmap.Breaks; private readonly List batchPendingInserts = new List();