2021-10-05 13:41:14 +08:00
|
|
|
// 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 osu.Framework.Localisation;
|
2023-12-05 13:53:47 +08:00
|
|
|
using osu.Game.Screens.Select;
|
2021-10-05 13:41:14 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
{
|
|
|
|
public static class BeatmapInfoExtensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A user-presentable display title representing this beatmap.
|
|
|
|
/// </summary>
|
2021-11-09 20:51:18 +08:00
|
|
|
public static string GetDisplayTitle(this IBeatmapInfo beatmapInfo) => $"{beatmapInfo.Metadata.GetDisplayTitle()} {getVersionString(beatmapInfo)}".Trim();
|
2021-10-05 13:41:14 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A user-presentable display title representing this beatmap, with localisation handling for potentially romanisable fields.
|
|
|
|
/// </summary>
|
2021-11-01 13:33:24 +08:00
|
|
|
public static RomanisableString GetDisplayTitleRomanisable(this IBeatmapInfo beatmapInfo, bool includeDifficultyName = true, bool includeCreator = true)
|
2021-10-05 13:41:14 +08:00
|
|
|
{
|
2021-11-04 13:25:30 +08:00
|
|
|
var metadata = beatmapInfo.Metadata.GetDisplayTitleRomanisable(includeCreator);
|
2021-10-05 13:41:14 +08:00
|
|
|
|
2021-10-20 17:43:48 +08:00
|
|
|
if (includeDifficultyName)
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
string versionString = getVersionString(beatmapInfo);
|
2021-10-20 17:43:48 +08:00
|
|
|
return new RomanisableString($"{metadata.GetPreferred(true)} {versionString}".Trim(), $"{metadata.GetPreferred(false)} {versionString}".Trim());
|
|
|
|
}
|
|
|
|
|
|
|
|
return new RomanisableString($"{metadata.GetPreferred(true)}".Trim(), $"{metadata.GetPreferred(false)}".Trim());
|
2021-10-05 13:41:14 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 13:53:47 +08:00
|
|
|
public static bool Match(this IBeatmapInfo beatmapInfo, params FilterCriteria.OptionalTextFilter[] filters)
|
2021-10-05 13:41:14 +08:00
|
|
|
{
|
2023-12-05 13:53:47 +08:00
|
|
|
foreach (var filter in filters)
|
2023-03-04 22:42:35 +08:00
|
|
|
{
|
2023-12-05 13:53:47 +08:00
|
|
|
if (filter.Matches(beatmapInfo.DifficultyName))
|
2023-12-05 17:20:27 +08:00
|
|
|
continue;
|
2023-12-05 13:53:47 +08:00
|
|
|
|
2023-12-05 17:20:27 +08:00
|
|
|
if (BeatmapMetadataInfoExtensions.Match(beatmapInfo.Metadata, filter))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// failed to match a single filter at all - fail the whole match.
|
|
|
|
return false;
|
2023-03-04 22:42:35 +08:00
|
|
|
}
|
2023-12-05 13:53:47 +08:00
|
|
|
|
2023-12-05 17:20:27 +08:00
|
|
|
// got through all filters without failing any - pass the whole match.
|
|
|
|
return true;
|
2023-03-04 02:21:50 +08:00
|
|
|
}
|
2021-10-05 13:41:14 +08:00
|
|
|
|
|
|
|
private static string getVersionString(IBeatmapInfo beatmapInfo) => string.IsNullOrEmpty(beatmapInfo.DifficultyName) ? string.Empty : $"[{beatmapInfo.DifficultyName}]";
|
|
|
|
}
|
|
|
|
}
|