// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Objects; namespace osu.Game.Screens.Edit { public class EditorBeatmap : IEditorBeatmap where T : HitObject { public event Action HitObjectAdded; public event Action HitObjectRemoved; private readonly Beatmap beatmap; public EditorBeatmap(Beatmap beatmap) { this.beatmap = beatmap; } public BeatmapInfo BeatmapInfo { get => beatmap.BeatmapInfo; set => beatmap.BeatmapInfo = value; } public BeatmapMetadata Metadata => beatmap.Metadata; public ControlPointInfo ControlPointInfo => beatmap.ControlPointInfo; public List Breaks => beatmap.Breaks; public double TotalBreakTime => beatmap.TotalBreakTime; IReadOnlyList IBeatmap.HitObjects => beatmap.HitObjects; IReadOnlyList IBeatmap.HitObjects => beatmap.HitObjects; public IEnumerable GetStatistics() => beatmap.GetStatistics(); public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone(); /// /// Adds a to this . /// /// The to add. public void Add(T hitObject) { // Preserve existing sorting order in the beatmap var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime); beatmap.HitObjects.Insert(insertionIndex + 1, hitObject); HitObjectAdded?.Invoke(hitObject); } /// /// Removes a from this . /// /// The to add. public void Remove(T hitObject) { if (beatmap.HitObjects.Remove(hitObject)) HitObjectRemoved?.Invoke(hitObject); } /// /// Adds a to this . /// /// The to add. public void Add(HitObject hitObject) => Add((T)hitObject); /// /// Removes a from this . /// /// The to add. public void Remove(HitObject hitObject) => Remove((T)hitObject); } }