// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Linq; using osu.Framework.Localisation; #nullable enable namespace osu.Game.Beatmaps { /// /// Metadata representing a beatmap. May be shared between multiple beatmap difficulties. /// public interface IBeatmapMetadataInfo : IEquatable { /// /// The romanised title of this beatmap. /// string Title { get; } /// /// The unicode title of this beatmap. /// string TitleUnicode { get; } /// /// The romanised artist of this beatmap. /// string Artist { get; } /// /// The unicode artist of this beatmap. /// string ArtistUnicode { get; } /// /// The author of this beatmap. /// string Author { get; } // eventually should be linked to a persisted User. /// /// The source of this beatmap. /// string Source { get; } /// /// The tags of this beatmap. /// string Tags { get; } /// /// The time in milliseconds to begin playing the track for preview purposes. /// If -1, the track should begin playing at 40% of its length. /// int PreviewTime { get; } /// /// The filename of the audio file consumed by this beatmap. /// string AudioFile { get; } /// /// The filename of the background image file consumed by this beatmap. /// string BackgroundFile { get; } /// /// A user-presentable display title representing this metadata. /// string DisplayTitle { get { string author = string.IsNullOrEmpty(Author) ? string.Empty : $"({Author})"; return $"{Artist} - {Title} {author}".Trim(); } } /// /// A user-presentable display title representing this metadata, with localisation handling for potentially romanisable fields. /// RomanisableString DisplayTitleRomanisable { get { string author = string.IsNullOrEmpty(Author) ? string.Empty : $"({Author})"; var artistUnicode = string.IsNullOrEmpty(ArtistUnicode) ? Artist : ArtistUnicode; var titleUnicode = string.IsNullOrEmpty(TitleUnicode) ? Title : TitleUnicode; return new RomanisableString($"{artistUnicode} - {titleUnicode} {author}".Trim(), $"{Artist} - {Title} {author}".Trim()); } } /// /// An array of all searchable terms provided in contained metadata. /// string[] SearchableTerms => new[] { Author, Artist, ArtistUnicode, Title, TitleUnicode, Source, Tags }.Where(s => !string.IsNullOrEmpty(s)).ToArray(); bool IEquatable.Equals(IBeatmapMetadataInfo? other) { if (other == null) return false; return Title == other.Title && TitleUnicode == other.TitleUnicode && Artist == other.Artist && ArtistUnicode == other.ArtistUnicode && Author == other.Author && Source == other.Source && Tags == other.Tags && PreviewTime == other.PreviewTime && AudioFile == other.AudioFile && BackgroundFile == other.BackgroundFile; } } }