// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; using osu.Framework.Localisation; namespace osu.Game.Beatmaps { public static class BeatmapMetadataInfoExtensions { /// /// An array of all searchable terms provided in contained metadata. /// public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo) => new[] { metadataInfo.Author.Username, metadataInfo.Artist, metadataInfo.ArtistUnicode, metadataInfo.Title, metadataInfo.TitleUnicode, metadataInfo.Source, metadataInfo.Tags }.Where(s => !string.IsNullOrEmpty(s)).ToArray(); /// /// A user-presentable display title representing this metadata. /// public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo) { 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(); } /// /// A user-presentable display title representing this beatmap, with localisation handling for potentially romanisable fields. /// public static RomanisableString GetDisplayTitleRomanisable(this IBeatmapMetadataInfo metadataInfo, bool includeCreator = true) { string author = !includeCreator || string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $"({metadataInfo.Author})"; string artistUnicode = string.IsNullOrEmpty(metadataInfo.ArtistUnicode) ? metadataInfo.Artist : metadataInfo.ArtistUnicode; string titleUnicode = string.IsNullOrEmpty(metadataInfo.TitleUnicode) ? metadataInfo.Title : metadataInfo.TitleUnicode; return new RomanisableString($"{artistUnicode} - {titleUnicode} {author}".Trim(), $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim()); } } }