mirror of
https://github.com/ppy/osu.git
synced 2025-03-24 09:37:19 +08:00
Use extension method to compare online IDs
This commit is contained in:
parent
9f7e2750a5
commit
a4c11e8813
@ -1,11 +1,14 @@
|
||||
// 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;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public interface IHasOnlineID<out T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID (except in special cases where autoincrement is not used, like rulesets).
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Users;
|
||||
@ -57,5 +58,33 @@ namespace osu.Game.Extensions
|
||||
result ??= model?.ToString() ?? @"null";
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the online ID of two instances match.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to compare.</param>
|
||||
/// <param name="other">The other instance to compare against.</param>
|
||||
/// <returns>Whether online IDs match. If either instance is missing an online ID, this will return false.</returns>
|
||||
public static bool MatchesOnlineID(this IHasOnlineID<long> instance, IHasOnlineID<long> other)
|
||||
{
|
||||
if (instance.OnlineID < 0 || other.OnlineID < 0)
|
||||
return false;
|
||||
|
||||
return instance.OnlineID.Equals(other.OnlineID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the online ID of two instances match.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to compare.</param>
|
||||
/// <param name="other">The other instance to compare against.</param>
|
||||
/// <returns>Whether online IDs match. If either instance is missing an online ID, this will return false.</returns>
|
||||
public static bool MatchesOnlineID(this IHasOnlineID<int> instance, IHasOnlineID<int> other)
|
||||
{
|
||||
if (instance.OnlineID < 0 || other.OnlineID < 0)
|
||||
return false;
|
||||
|
||||
return instance.OnlineID.Equals(other.OnlineID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK;
|
||||
|
||||
@ -29,7 +30,7 @@ namespace osu.Game.Overlays.Music
|
||||
var items = (SearchContainer<RearrangeableListItem<BeatmapSetInfo>>)ListContainer;
|
||||
|
||||
foreach (var item in items.OfType<PlaylistItem>())
|
||||
item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.BeatmapSet.Equals(item.Model)) ?? true;
|
||||
item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.MatchesOnlineID(item.Model)) ?? true;
|
||||
|
||||
items.SearchTerm = criteria.SearchText;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user