diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index ae77e4adcf..d12ff59198 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -8,6 +8,7 @@ using System.Linq; using osu.Game.Beatmaps.ControlPoints; using Newtonsoft.Json; +using osu.Framework.Lists; using osu.Game.IO.Serialization.Converters; namespace osu.Game.Beatmaps @@ -61,7 +62,7 @@ public Beatmap() public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo(); - public List Breaks { get; set; } = new List(); + public SortedList Breaks { get; set; } = new SortedList(); public List UnhandledEventLines { get; set; } = new List(); diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index 676eb1b159..c43bd494e9 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.Lists; +using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; @@ -50,7 +52,8 @@ public IBeatmap Convert(CancellationToken cancellationToken = default) original.ControlPointInfo = original.ControlPointInfo.DeepClone(); // Used in osu!mania conversion. - original.Breaks = original.Breaks.ToList(); + original.Breaks = new SortedList(Comparer.Default); + original.Breaks.AddRange(Beatmap.Breaks); return ConvertBeatmap(original, cancellationToken); } diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 176738489a..430a31769b 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using osu.Framework.Lists; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Objects; @@ -40,7 +41,7 @@ public interface IBeatmap /// /// The breaks in this beatmap. /// - List Breaks { get; set; } + SortedList Breaks { get; set; } /// /// All lines from the [Events] section which aren't handled in the encoding process yet. diff --git a/osu.Game/Beatmaps/Timing/BreakPeriod.cs b/osu.Game/Beatmaps/Timing/BreakPeriod.cs index d8b500227a..921cfe9c51 100644 --- a/osu.Game/Beatmaps/Timing/BreakPeriod.cs +++ b/osu.Game/Beatmaps/Timing/BreakPeriod.cs @@ -6,7 +6,7 @@ namespace osu.Game.Beatmaps.Timing { - public class BreakPeriod : IEquatable + public class BreakPeriod : IEquatable, IComparable { /// /// The minimum gap between the start of the break and the previous object. @@ -76,5 +76,17 @@ public virtual bool Equals(BreakPeriod? other) => && EndTime == other.EndTime; public override int GetHashCode() => HashCode.Combine(StartTime, EndTime); + + public int CompareTo(BreakPeriod? other) + { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; + + int result = StartTime.CompareTo(other.StartTime); + if (result != 0) + return result; + + return EndTime.CompareTo(other.EndTime); + } } } diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 722263c58e..63b27243d0 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -10,6 +10,7 @@ using JetBrains.Annotations; using osu.Framework.Audio.Track; using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; @@ -327,7 +328,7 @@ public BeatmapDifficulty Difficulty set => baseBeatmap.Difficulty = value; } - public List Breaks + public SortedList 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 c8592b5bea..ad31c2ccc3 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -10,6 +10,7 @@ using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Legacy; @@ -111,7 +112,11 @@ public EditorBeatmap(IBeatmap playableBeatmap, ISkin beatmapSkin = null, Beatmap trackStartTime(obj); Breaks = new BindableList(playableBeatmap.Breaks); - Breaks.BindCollectionChanged((_, _) => playableBeatmap.Breaks = Breaks.ToList()); + Breaks.BindCollectionChanged((_, _) => + { + playableBeatmap.Breaks.Clear(); + playableBeatmap.Breaks.AddRange(Breaks); + }); PreviewTime = new BindableInt(BeatmapInfo.Metadata.PreviewTime); PreviewTime.BindValueChanged(s => @@ -177,7 +182,7 @@ public ControlPointInfo ControlPointInfo public readonly BindableList Breaks; - List IBeatmap.Breaks + SortedList IBeatmap.Breaks { get => PlayableBeatmap.Breaks; set => PlayableBeatmap.Breaks = value;