1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 14:52:55 +08:00

Make BeatmapSet.Metadata non-null

This commit is contained in:
Dean Herbert 2021-11-24 15:01:45 +09:00
parent 5b88e4d7b5
commit 3946a39b65
5 changed files with 11 additions and 11 deletions

View File

@ -29,9 +29,9 @@ namespace osu.Game.Tests.Models
{ {
var mock = new Mock<IBeatmapSetInfo>(); var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata!.Artist).Returns("artist"); mock.Setup(m => m.Metadata.Artist).Returns("artist");
mock.Setup(m => m.Metadata!.Title).Returns("title"); mock.Setup(m => m.Metadata.Title).Returns("title");
mock.Setup(m => m.Metadata!.Author.Username).Returns("author"); mock.Setup(m => m.Metadata.Author.Username).Returns("author");
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)")); Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
} }
@ -41,9 +41,9 @@ namespace osu.Game.Tests.Models
{ {
var mock = new Mock<IBeatmapSetInfo>(); var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata!.Artist).Returns("artist"); mock.Setup(m => m.Metadata.Artist).Returns("artist");
mock.Setup(m => m.Metadata!.Title).Returns("title"); mock.Setup(m => m.Metadata.Title).Returns("title");
mock.Setup(m => m.Metadata!.Author.Username).Returns(string.Empty); mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title")); Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
} }

View File

@ -89,7 +89,7 @@ namespace osu.Game.Beatmaps
#region Implementation of IBeatmapSetInfo #region Implementation of IBeatmapSetInfo
IBeatmapMetadataInfo IBeatmapSetInfo.Metadata => Metadata; IBeatmapMetadataInfo IBeatmapSetInfo.Metadata => Metadata ?? Beatmaps.FirstOrDefault()?.Metadata ?? new BeatmapMetadata();
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps; IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files; IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// The best-effort metadata representing this set. In the case metadata differs between contained beatmaps, one is arbitrarily chosen. /// The best-effort metadata representing this set. In the case metadata differs between contained beatmaps, one is arbitrarily chosen.
/// </summary> /// </summary>
IBeatmapMetadataInfo? Metadata { get; } IBeatmapMetadataInfo Metadata { get; }
/// <summary> /// <summary>
/// All beatmaps contained in this set. /// All beatmaps contained in this set.

View File

@ -42,7 +42,7 @@ namespace osu.Game.Extensions
switch (model) switch (model)
{ {
case IBeatmapSetInfo beatmapSetInfo: case IBeatmapSetInfo beatmapSetInfo:
result = beatmapSetInfo.Metadata?.GetDisplayTitle(); result = beatmapSetInfo.Metadata.GetDisplayTitle();
break; break;
case IBeatmapInfo beatmapInfo: case IBeatmapInfo beatmapInfo:

View File

@ -26,7 +26,7 @@ namespace osu.Game.Models
public DateTimeOffset DateAdded { get; set; } public DateTimeOffset DateAdded { get; set; }
public IBeatmapMetadataInfo? Metadata => Beatmaps.FirstOrDefault()?.Metadata; public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new RealmBeatmapMetadata();
public IList<RealmBeatmap> Beatmaps { get; } = null!; public IList<RealmBeatmap> Beatmaps { get; } = null!;
@ -62,7 +62,7 @@ namespace osu.Game.Models
return ID == other.ID; return ID == other.ID;
} }
public override string ToString() => Metadata?.GetDisplayString() ?? base.ToString(); public override string ToString() => Metadata.GetDisplayString();
public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b); public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b);