1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 15:33:21 +08:00

Replace local Equatable implementations with abstract EquivalentTo

This commit is contained in:
Dean Herbert 2019-10-25 17:00:56 +09:00
parent 5a70431263
commit e2f2638212
6 changed files with 28 additions and 28 deletions

View File

@ -5,7 +5,7 @@ using System;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public class ControlPoint : IComparable<ControlPoint>, IEquatable<ControlPoint> public abstract class ControlPoint : IComparable<ControlPoint>, IEquatable<ControlPoint>
{ {
/// <summary> /// <summary>
/// The time at which the control point takes effect. /// The time at which the control point takes effect.
@ -19,7 +19,13 @@ namespace osu.Game.Beatmaps.ControlPoints
public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time);
public bool Equals(ControlPoint other) /// <summary>
=> Time.Equals(other?.Time); /// Whether this control point is equivalent to another, ignoring time.
/// </summary>
/// <param name="other">Another control point to compare with.</param>
/// <returns>Whether equivalent.</returns>
public abstract bool EquivalentTo(ControlPoint other);
public bool Equals(ControlPoint other) => Time.Equals(other?.Time) && EquivalentTo(other);
} }
} }

View File

@ -1,12 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osuTK; using osuTK;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public class DifficultyControlPoint : ControlPoint, IEquatable<DifficultyControlPoint> public class DifficultyControlPoint : ControlPoint
{ {
/// <summary> /// <summary>
/// The speed multiplier at this control point. /// The speed multiplier at this control point.
@ -19,8 +18,7 @@ namespace osu.Game.Beatmaps.ControlPoints
private double speedMultiplier = 1; private double speedMultiplier = 1;
public bool Equals(DifficultyControlPoint other) public override bool EquivalentTo(ControlPoint other) =>
=> base.Equals(other) other is DifficultyControlPoint otherTyped && otherTyped.SpeedMultiplier.Equals(speedMultiplier);
&& SpeedMultiplier.Equals(other?.SpeedMultiplier);
} }
} }

View File

@ -1,11 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public class EffectControlPoint : ControlPoint, IEquatable<EffectControlPoint> public class EffectControlPoint : ControlPoint
{ {
/// <summary> /// <summary>
/// Whether this control point enables Kiai mode. /// Whether this control point enables Kiai mode.
@ -17,8 +15,8 @@ namespace osu.Game.Beatmaps.ControlPoints
/// </summary> /// </summary>
public bool OmitFirstBarLine; public bool OmitFirstBarLine;
public bool Equals(EffectControlPoint other) public override bool EquivalentTo(ControlPoint other) =>
=> base.Equals(other) other is EffectControlPoint otherTyped &&
&& KiaiMode == other?.KiaiMode && OmitFirstBarLine == other.OmitFirstBarLine; KiaiMode == otherTyped.KiaiMode && OmitFirstBarLine == otherTyped.OmitFirstBarLine;
} }
} }

View File

@ -1,12 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Audio; using osu.Game.Audio;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public class SampleControlPoint : ControlPoint, IEquatable<SampleControlPoint> public class SampleControlPoint : ControlPoint
{ {
public const string DEFAULT_BANK = "normal"; public const string DEFAULT_BANK = "normal";
@ -45,8 +44,8 @@ namespace osu.Game.Beatmaps.ControlPoints
return newSampleInfo; return newSampleInfo;
} }
public bool Equals(SampleControlPoint other) public override bool EquivalentTo(ControlPoint other) =>
=> base.Equals(other) other is SampleControlPoint otherTyped &&
&& string.Equals(SampleBank, other?.SampleBank) && SampleVolume == other?.SampleVolume; string.Equals(SampleBank, otherTyped?.SampleBank) && SampleVolume == otherTyped?.SampleVolume;
} }
} }

View File

@ -1,13 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osuTK; using osuTK;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public class TimingControlPoint : ControlPoint, IEquatable<TimingControlPoint> public class TimingControlPoint : ControlPoint
{ {
/// <summary> /// <summary>
/// The time signature at this control point. /// The time signature at this control point.
@ -27,8 +26,8 @@ namespace osu.Game.Beatmaps.ControlPoints
private double beatLength = DEFAULT_BEAT_LENGTH; private double beatLength = DEFAULT_BEAT_LENGTH;
public bool Equals(TimingControlPoint other) public override bool EquivalentTo(ControlPoint other) =>
=> base.Equals(other) other is TimingControlPoint otherTyped
&& TimeSignature == other?.TimeSignature && beatLength.Equals(other.beatLength); && TimeSignature == otherTyped?.TimeSignature && beatLength.Equals(otherTyped.beatLength);
} }
} }

View File

@ -189,7 +189,7 @@ namespace osu.Game.Beatmaps.Formats
Foreground = 3 Foreground = 3
} }
internal class LegacySampleControlPoint : SampleControlPoint, IEquatable<LegacySampleControlPoint> internal class LegacySampleControlPoint : SampleControlPoint
{ {
public int CustomSampleBank; public int CustomSampleBank;
@ -203,9 +203,9 @@ namespace osu.Game.Beatmaps.Formats
return baseInfo; return baseInfo;
} }
public bool Equals(LegacySampleControlPoint other) public override bool EquivalentTo(ControlPoint other) =>
=> base.Equals(other) base.EquivalentTo(other)
&& CustomSampleBank == other?.CustomSampleBank; && CustomSampleBank == ((LegacySampleControlPoint)other).CustomSampleBank;
} }
} }
} }