1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Add fallback for cases where beatmap has no author/title/artist specified

This commit is contained in:
Dean Herbert 2021-11-10 18:27:23 +09:00
parent 03a315b9f5
commit f4ef841972
2 changed files with 28 additions and 2 deletions

View File

@ -17,6 +17,8 @@ namespace osu.Game.Tests.Models
{
private static readonly object[][] test_cases =
{
new object[] { makeNoMetadataMockBeatmapSet(), "unknown artist - unknown title" },
new object[] { makeNoAuthorMockBeatmapSet(), "artist - title" },
new object[] { makeMockBeatmapSet(), "artist - title (author)" },
new object[] { makeMockBeatmap(), "artist - title (author) [difficulty]" },
new object[] { makeMockMetadata(), "artist - title (author)" },
@ -29,6 +31,26 @@ namespace osu.Game.Tests.Models
[TestCaseSource(nameof(test_cases))]
public void TestDisplayString(object model, string expected) => Assert.That(model.GetDisplayString(), Is.EqualTo(expected));
private static IBeatmapSetInfo makeNoAuthorMockBeatmapSet()
{
var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata.Artist).Returns("artist");
mock.Setup(m => m.Metadata.Title).Returns("title");
mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
return mock.Object;
}
private static IBeatmapSetInfo makeNoMetadataMockBeatmapSet()
{
var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
return mock.Object;
}
private static IBeatmapSetInfo makeMockBeatmapSet()
{
var mock = new Mock<IBeatmapSetInfo>();

View File

@ -28,7 +28,11 @@ namespace osu.Game.Beatmaps
public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo)
{
string author = string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $" ({metadataInfo.Author.Username})";
return $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim();
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();
}
/// <summary>