1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 13:17:26 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Pattern.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Game.Rulesets.Mania.Objects;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
{
/// <summary>
/// Creates a pattern containing hit objects.
/// </summary>
internal class Pattern
{
private List<ManiaHitObject> hitObjects;
private HashSet<int> containedColumns;
2017-05-18 12:21:54 +08:00
/// <summary>
/// All the hit objects contained in this pattern.
2017-05-18 12:21:54 +08:00
/// </summary>
public IEnumerable<ManiaHitObject> HitObjects => hitObjects ?? Enumerable.Empty<ManiaHitObject>();
2018-04-13 17:19:50 +08:00
/// <summary>
2017-05-22 09:04:25 +08:00
/// Check whether a column of this patterns contains a hit object.
/// </summary>
/// <param name="column">The column index.</param>
2017-05-22 09:04:25 +08:00
/// <returns>Whether the column with index <paramref name="column"/> contains a hit object.</returns>
public bool ColumnHasObject(int column) => containedColumns?.Contains(column) == true;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Amount of columns taken up by hit objects in this pattern.
/// </summary>
public int ColumnWithObjects => containedColumns?.Count ?? 0;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Adds a hit object to this pattern.
/// </summary>
/// <param name="hitObject">The hit object to add.</param>
public void Add(ManiaHitObject hitObject)
{
prepareStorage();
hitObjects.Add(hitObject);
containedColumns.Add(hitObject.Column);
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Copies hit object from another pattern to this one.
2017-05-18 12:21:54 +08:00
/// </summary>
/// <param name="other">The other pattern.</param>
public void Add(Pattern other)
{
prepareStorage();
if (other.hitObjects != null)
{
hitObjects.AddRange(other.hitObjects);
2018-04-13 17:19:50 +08:00
foreach (var h in other.hitObjects)
containedColumns.Add(h.Column);
}
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Clears this pattern, removing all hit objects.
/// </summary>
public void Clear()
{
hitObjects?.Clear();
containedColumns?.Clear();
}
private void prepareStorage()
{
hitObjects ??= new List<ManiaHitObject>();
containedColumns ??= new HashSet<int>();
}
}
}