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.
|
|
|
|
|
|
2023-03-06 23:20:36 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-10-05 13:41:14 +08:00
|
|
|
|
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 BeatmapMetadataInfoExtensions
|
|
|
|
|
{
|
2023-12-05 13:53:47 +08:00
|
|
|
|
internal const int MAX_SEARCHABLE_TERM_COUNT = 7;
|
|
|
|
|
|
2021-10-05 13:41:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An array of all searchable terms provided in contained metadata.
|
|
|
|
|
/// </summary>
|
2023-03-06 23:20:36 +08:00
|
|
|
|
public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo)
|
2021-10-05 13:41:14 +08:00
|
|
|
|
{
|
2023-03-06 23:20:36 +08:00
|
|
|
|
var termsList = new List<string>(MAX_SEARCHABLE_TERM_COUNT);
|
|
|
|
|
CollectSearchableTerms(metadataInfo, termsList);
|
|
|
|
|
return termsList.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 17:20:27 +08:00
|
|
|
|
public static bool Match(IBeatmapMetadataInfo metadataInfo, FilterCriteria.OptionalTextFilter filter)
|
2023-12-05 13:53:47 +08:00
|
|
|
|
{
|
2023-12-05 17:20:27 +08:00
|
|
|
|
if (filter.Matches(metadataInfo.Author.Username)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.Artist)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.ArtistUnicode)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.Title)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.TitleUnicode)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.Source)) return true;
|
|
|
|
|
if (filter.Matches(metadataInfo.Tags)) return true;
|
2023-12-05 13:53:47 +08:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-06 23:20:36 +08:00
|
|
|
|
|
|
|
|
|
internal static void CollectSearchableTerms(IBeatmapMetadataInfo metadataInfo, IList<string> termsList)
|
|
|
|
|
{
|
|
|
|
|
addIfNotNull(metadataInfo.Author.Username);
|
|
|
|
|
addIfNotNull(metadataInfo.Artist);
|
|
|
|
|
addIfNotNull(metadataInfo.ArtistUnicode);
|
|
|
|
|
addIfNotNull(metadataInfo.Title);
|
|
|
|
|
addIfNotNull(metadataInfo.TitleUnicode);
|
|
|
|
|
addIfNotNull(metadataInfo.Source);
|
|
|
|
|
addIfNotNull(metadataInfo.Tags);
|
|
|
|
|
|
|
|
|
|
void addIfNotNull(string s)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(s))
|
|
|
|
|
termsList.Add(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-05 13:41:14 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A user-presentable display title representing this metadata.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo)
|
|
|
|
|
{
|
2021-11-10 17:27:23 +08:00
|
|
|
|
string author = string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $" ({metadataInfo.Author.Username})";
|
|
|
|
|
|
|
|
|
|
string artist = string.IsNullOrEmpty(metadataInfo.Artist) ? "unknown artist" : metadataInfo.Artist;
|
|
|
|
|
string title = string.IsNullOrEmpty(metadataInfo.Title) ? "unknown title" : metadataInfo.Title;
|
|
|
|
|
|
|
|
|
|
return $"{artist} - {title}{author}".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 IBeatmapMetadataInfo metadataInfo, bool includeCreator = true)
|
2021-10-05 13:41:14 +08:00
|
|
|
|
{
|
2022-01-15 22:26:41 +08:00
|
|
|
|
string author = !includeCreator || string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $"({metadataInfo.Author.Username})";
|
2021-10-27 12:04:41 +08:00
|
|
|
|
string artistUnicode = string.IsNullOrEmpty(metadataInfo.ArtistUnicode) ? metadataInfo.Artist : metadataInfo.ArtistUnicode;
|
|
|
|
|
string titleUnicode = string.IsNullOrEmpty(metadataInfo.TitleUnicode) ? metadataInfo.Title : metadataInfo.TitleUnicode;
|
2021-10-05 13:41:14 +08:00
|
|
|
|
|
|
|
|
|
return new RomanisableString($"{artistUnicode} - {titleUnicode} {author}".Trim(), $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|