2019-10-25 18:58:42 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
2024-06-17 15:19:33 +08:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-08-31 14:05:10 +08:00
|
|
|
using Newtonsoft.Json;
|
2020-10-01 18:29:34 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-07-19 11:38:22 +08:00
|
|
|
using osu.Game.Utils;
|
2020-10-01 18:29:34 +08:00
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.ControlPoints
|
|
|
|
{
|
2024-06-17 15:19:33 +08:00
|
|
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
|
2022-10-18 15:01:04 +08:00
|
|
|
public abstract class ControlPoint : IComparable<ControlPoint>, IDeepCloneable<ControlPoint>, IEquatable<ControlPoint>, IControlPoint
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2024-06-11 15:14:46 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when any of this <see cref="ControlPoint"/>'s properties have changed.
|
|
|
|
/// </summary>
|
|
|
|
public event Action<ControlPoint>? Changed;
|
|
|
|
|
|
|
|
protected void RaiseChanged() => Changed?.Invoke(this);
|
|
|
|
|
|
|
|
private double time;
|
|
|
|
|
2021-08-31 14:05:10 +08:00
|
|
|
[JsonIgnore]
|
2024-06-11 15:14:46 +08:00
|
|
|
public double Time
|
|
|
|
{
|
|
|
|
get => time;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (time == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
time = value;
|
|
|
|
RaiseChanged();
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-09-10 13:35:53 +08:00
|
|
|
public void AttachGroup(ControlPointGroup pointGroup) => Time = pointGroup.Time;
|
2019-10-25 18:48:01 +08:00
|
|
|
|
2022-12-16 17:16:26 +08:00
|
|
|
public int CompareTo(ControlPoint? other) => Time.CompareTo(other?.Time);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-10-01 18:29:34 +08:00
|
|
|
public virtual Color4 GetRepresentingColour(OsuColour colours) => colours.Yellow;
|
|
|
|
|
2020-04-08 16:42:35 +08:00
|
|
|
/// <summary>
|
2020-04-17 16:06:12 +08:00
|
|
|
/// Determines whether this <see cref="ControlPoint"/> results in a meaningful change when placed alongside another.
|
2020-04-08 16:42:35 +08:00
|
|
|
/// </summary>
|
2020-04-10 00:34:40 +08:00
|
|
|
/// <param name="existing">An existing control point to compare with.</param>
|
2020-04-17 16:06:12 +08:00
|
|
|
/// <returns>Whether this <see cref="ControlPoint"/> is redundant when placed alongside <paramref name="existing"/>.</returns>
|
2022-06-20 15:52:01 +08:00
|
|
|
public abstract bool IsRedundant(ControlPoint? existing);
|
2021-01-04 15:37:07 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2021-01-07 18:06:10 +08:00
|
|
|
/// Create an unbound copy of this control point.
|
2021-01-04 15:37:07 +08:00
|
|
|
/// </summary>
|
2021-07-19 11:38:22 +08:00
|
|
|
public ControlPoint DeepClone()
|
2021-01-04 15:37:07 +08:00
|
|
|
{
|
2022-12-16 17:16:26 +08:00
|
|
|
var copy = (ControlPoint)Activator.CreateInstance(GetType())!;
|
2021-01-04 15:37:07 +08:00
|
|
|
|
|
|
|
copy.CopyFrom(this);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void CopyFrom(ControlPoint other)
|
|
|
|
{
|
2021-09-10 13:35:53 +08:00
|
|
|
Time = other.Time;
|
2021-01-04 15:37:07 +08:00
|
|
|
}
|
2022-06-20 13:56:04 +08:00
|
|
|
|
|
|
|
public sealed override bool Equals(object? obj)
|
|
|
|
=> obj is ControlPoint otherControlPoint
|
|
|
|
&& Equals(otherControlPoint);
|
|
|
|
|
|
|
|
public virtual bool Equals(ControlPoint? other)
|
2022-06-21 11:05:28 +08:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(other, null)) return false;
|
|
|
|
if (ReferenceEquals(other, this)) return true;
|
|
|
|
|
|
|
|
return Time == other.Time;
|
|
|
|
}
|
2022-06-20 13:56:04 +08:00
|
|
|
|
|
|
|
// ReSharper disable once NonReadonlyMemberInGetHashCode
|
|
|
|
public override int GetHashCode() => Time.GetHashCode();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|