Implement IEquatable on ControlPoint

This commit is contained in:
Dan Balasescu
2022-06-20 14:56:04 +09:00
parent 468e5fcbed
commit 03ab6fc141
7 changed files with 109 additions and 22 deletions

View File

@ -1,18 +1,16 @@
// 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.
#nullable disable
using System;
using System.Linq;
using osu.Framework.Bindables;
namespace osu.Game.Beatmaps.ControlPoints
{
public class ControlPointGroup : IComparable<ControlPointGroup>
public class ControlPointGroup : IComparable<ControlPointGroup>, IEquatable<ControlPointGroup>
{
public event Action<ControlPoint> ItemAdded;
public event Action<ControlPoint> ItemRemoved;
public event Action<ControlPoint>? ItemAdded;
public event Action<ControlPoint>? ItemRemoved;
/// <summary>
/// The time at which the control point takes effect.
@ -48,5 +46,23 @@ namespace osu.Game.Beatmaps.ControlPoints
controlPoints.Remove(point);
ItemRemoved?.Invoke(point);
}
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();
}
}
}