1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Add back interface equality but limit to only matching types

This commit is contained in:
Dean Herbert 2021-11-16 12:25:37 +09:00
parent 1988b263c6
commit 9207b87b76
8 changed files with 15 additions and 2 deletions

View File

@ -163,6 +163,8 @@ namespace osu.Game.Beatmaps
return false;
}
public bool Equals(IBeatmapInfo other) => other is BeatmapInfo b && Equals(b);
public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null &&
BeatmapSet.Hash == other.BeatmapSet.Hash &&
(Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile;

View File

@ -78,6 +78,8 @@ namespace osu.Game.Beatmaps
return false;
}
public bool Equals(IBeatmapSetInfo other) => other is BeatmapSetInfo b && Equals(b);
#region Implementation of IHasOnlineID
int IHasOnlineID<int>.OnlineID => OnlineID ?? -1;

View File

@ -1,6 +1,7 @@
// 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 osu.Game.Database;
using osu.Game.Rulesets;
@ -11,7 +12,7 @@ namespace osu.Game.Beatmaps
/// <summary>
/// A single beatmap difficulty.
/// </summary>
public interface IBeatmapInfo : IHasOnlineID<int>
public interface IBeatmapInfo : IHasOnlineID<int>, IEquatable<IBeatmapInfo>
{
/// <summary>
/// The user-specified name given to this beatmap.

View File

@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps
/// <summary>
/// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive.
/// </summary>
public interface IBeatmapSetInfo : IHasOnlineID<int>
public interface IBeatmapSetInfo : IHasOnlineID<int>, IEquatable<IBeatmapSetInfo>
{
/// <summary>
/// The date when this beatmap was imported.

View File

@ -106,6 +106,8 @@ namespace osu.Game.Models
return ID == other.ID;
}
public bool Equals(IBeatmapInfo? other) => other is RealmBeatmap b && Equals(b);
public bool AudioEquals(RealmBeatmap? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null

View File

@ -64,6 +64,8 @@ namespace osu.Game.Models
public override string ToString() => Metadata?.GetDisplayString() ?? base.ToString();
public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b);
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;

View File

@ -103,5 +103,7 @@ namespace osu.Game.Online.API.Requests.Responses
public string Hash => throw new NotImplementedException();
#endregion
public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && Equals(b);
}
}

View File

@ -141,5 +141,7 @@ namespace osu.Game.Online.API.Requests.Responses
double IBeatmapSetInfo.MaxBPM => BPM;
#endregion
public bool Equals(IBeatmapSetInfo? other) => other is APIBeatmapSet b && Equals(b);
}
}