1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 12:02:57 +08:00
osu-lazer/osu.Game/Beatmaps/ControlPoints/ControlPointGroup.cs

69 lines
2.0 KiB
C#
Raw Normal View History

2019-10-25 18:48:01 +08:00
// 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.
using System;
using System.Linq;
using osu.Framework.Bindables;
2019-10-25 18:48:01 +08:00
namespace osu.Game.Beatmaps.ControlPoints
{
2022-06-20 13:56:04 +08:00
public class ControlPointGroup : IComparable<ControlPointGroup>, IEquatable<ControlPointGroup>
2019-10-25 18:48:01 +08:00
{
2022-06-20 13:56:04 +08:00
public event Action<ControlPoint>? ItemAdded;
public event Action<ControlPoint>? ItemRemoved;
2019-10-25 18:48:01 +08:00
/// <summary>
/// The time at which the control point takes effect.
/// </summary>
public double Time { get; }
public IBindableList<ControlPoint> ControlPoints => controlPoints;
2019-10-25 18:48:01 +08:00
private readonly BindableList<ControlPoint> controlPoints = new BindableList<ControlPoint>();
2019-10-25 18:48:01 +08:00
public ControlPointGroup(double time)
{
Time = time;
}
public int CompareTo(ControlPointGroup other) => Time.CompareTo(other.Time);
public void Add(ControlPoint point)
{
var existing = controlPoints.FirstOrDefault(p => p.GetType() == point.GetType());
2019-10-25 18:48:01 +08:00
if (existing != null)
2019-10-25 18:48:01 +08:00
Remove(existing);
point.AttachGroup(this);
2019-10-25 18:48:01 +08:00
controlPoints.Add(point);
ItemAdded?.Invoke(point);
}
public void Remove(ControlPoint point)
{
controlPoints.Remove(point);
ItemRemoved?.Invoke(point);
}
2022-06-20 13:56:04 +08:00
public sealed override bool Equals(object? obj)
=> obj is ControlPointGroup otherGroup
&& Equals(otherGroup);
public virtual bool Equals(ControlPointGroup? other)
=> other != null
&& Time == other.Time
&& ControlPoints.SequenceEqual(other.ControlPoints);
public override int GetHashCode()
{
HashCode hashCode = new HashCode();
hashCode.Add(Time);
foreach (var point in controlPoints)
hashCode.Add(point);
return hashCode.ToHashCode();
}
2019-10-25 18:48:01 +08:00
}
}