// 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 System.Linq; using osu.Game.Rulesets.Mania.Objects; namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns { /// /// Creates a pattern containing hit objects. /// internal class Pattern { private List hitObjects; private HashSet containedColumns; /// /// All the hit objects contained in this pattern. /// public IEnumerable HitObjects => hitObjects ?? Enumerable.Empty(); /// /// Check whether a column of this patterns contains a hit object. /// /// The column index. /// Whether the column with index contains a hit object. public bool ColumnHasObject(int column) => containedColumns?.Contains(column) == true; /// /// Amount of columns taken up by hit objects in this pattern. /// public int ColumnWithObjects => containedColumns?.Count ?? 0; /// /// Adds a hit object to this pattern. /// /// The hit object to add. public void Add(ManiaHitObject hitObject) { prepareStorage(); hitObjects.Add(hitObject); containedColumns.Add(hitObject.Column); } /// /// Copies hit object from another pattern to this one. /// /// The other pattern. public void Add(Pattern other) { prepareStorage(); if (other.hitObjects != null) { hitObjects.AddRange(other.hitObjects); foreach (var h in other.hitObjects) containedColumns.Add(h.Column); } } /// /// Clears this pattern, removing all hit objects. /// public void Clear() { hitObjects?.Clear(); containedColumns?.Clear(); } private void prepareStorage() { hitObjects ??= new List(); containedColumns ??= new HashSet(); } } }