mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Add IBeatmapSetInfo
equality support
This commit is contained in:
parent
a67e156883
commit
54cd1158a4
@ -66,6 +66,17 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public bool Protected { get; set; }
|
||||
|
||||
public bool Equals(IBeatmapSetInfo other)
|
||||
{
|
||||
if (other is BeatmapSetInfo b)
|
||||
return Equals(b);
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(BeatmapSetInfo other)
|
||||
{
|
||||
if (other == null)
|
||||
|
@ -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.
|
||||
|
@ -53,7 +53,16 @@ namespace osu.Game.Models
|
||||
/// <param name="filename">The name of the file to get the storage path of.</param>
|
||||
public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.StoragePath;
|
||||
|
||||
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
||||
public bool Equals(IBeatmapSetInfo? other)
|
||||
{
|
||||
if (other is RealmBeatmap b)
|
||||
return b.ID == ID;
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(RealmBeatmapSet? other)
|
||||
{
|
||||
@ -72,6 +81,8 @@ namespace osu.Game.Models
|
||||
return ReferenceEquals(this, other);
|
||||
}
|
||||
|
||||
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
||||
|
||||
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
|
||||
|
||||
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;
|
||||
|
@ -141,5 +141,17 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
double IBeatmapSetInfo.MaxBPM => BPM;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IEquatable<IBeatmapSetInfo>
|
||||
|
||||
public bool Equals(IBeatmapSetInfo? other)
|
||||
{
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user