1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

Add IBeatmapInfo equality support

This commit is contained in:
Dean Herbert 2021-11-12 18:09:45 +09:00
parent 7323f6a50c
commit a67e156883
4 changed files with 40 additions and 1 deletions

View File

@ -151,6 +151,17 @@ namespace osu.Game.Beatmaps
public override string ToString() => this.GetDisplayTitle();
public bool Equals(IBeatmapInfo other)
{
if (other is BeatmapInfo b)
return Equals(b);
if (OnlineID > 0 && other?.OnlineID > 0)
return other.OnlineID == OnlineID;
return false;
}
public bool Equals(BeatmapInfo other)
{
if (ID == 0 || other?.ID == 0)

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

@ -98,6 +98,21 @@ namespace osu.Game.Models
#endregion
#region Implementation of IEquatable<IBeatmapInfo>
public bool Equals(IBeatmapInfo? other)
{
if (other is RealmBeatmap b)
return b.ID == ID;
if (OnlineID > 0 && other?.OnlineID > 0)
return other.OnlineID == OnlineID;
return false;
}
#endregion
public bool AudioEquals(RealmBeatmap? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null

View File

@ -103,5 +103,17 @@ namespace osu.Game.Online.API.Requests.Responses
public string Hash => throw new NotImplementedException();
#endregion
#region Implementation of IEquatable<IBeatmapInfo>
public bool Equals(IBeatmapInfo? other)
{
if (OnlineID > 0 && other?.OnlineID > 0)
return other.OnlineID == OnlineID;
return false;
}
#endregion
}
}