From 86540d1fb6b488ca11242e79ec2891d80650a672 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 4 Nov 2021 18:22:21 +0900 Subject: [PATCH] Update existing usages of `Author` as `string` to access `Username` directly --- .../Database/BeatmapImporterTests.cs | 5 ++- .../TestSceneExpandedPanelMiddleContent.cs | 7 +++-- .../Components/TournamentBeatmapPanel.cs | 2 +- osu.Game/Beatmaps/BeatmapManager.cs | 3 +- osu.Game/Beatmaps/BeatmapMetadata.cs | 31 +++++++------------ .../Beatmaps/BeatmapMetadataInfoExtensions.cs | 6 ++-- .../Graphics/Containers/LinkFlowContainer.cs | 6 ++-- .../API/Requests/Responses/APIBeatmapSet.cs | 18 +++-------- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 5 ++- .../Expanded/ExpandedPanelMiddleContent.cs | 2 +- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 2 +- .../Select/Carousel/CarouselBeatmapSet.cs | 2 +- .../Carousel/DrawableCarouselBeatmap.cs | 2 +- osu.Game/Stores/BeatmapImporter.cs | 6 +++- 14 files changed, 45 insertions(+), 52 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index a21f935f6b..e1fe1e224e 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -482,7 +482,10 @@ namespace osu.Game.Tests.Database var metadata = new RealmBeatmapMetadata { Artist = "SomeArtist", - Author = "SomeAuthor" + Author = + { + Username = "SomeAuthor" + } }; var ruleset = realmFactory.Context.All().First(); diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs b/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs index fee8985120..9983993d9c 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Linq; +using JetBrains.Annotations; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; @@ -57,7 +58,7 @@ namespace osu.Game.Tests.Visual.Ranking { AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo) { - BeatmapInfo = createTestBeatmap(null) + BeatmapInfo = createTestBeatmap(new APIUser()) })); AddAssert("mapped by text not present", () => @@ -74,7 +75,7 @@ namespace osu.Game.Tests.Visual.Ranking var ruleset = new OsuRuleset(); var mods = new Mod[] { ruleset.GetAutoplayMod() }; - var beatmap = createTestBeatmap(null); + var beatmap = createTestBeatmap(new APIUser()); showPanel(new TestScoreInfo(ruleset.RulesetInfo) { @@ -90,7 +91,7 @@ namespace osu.Game.Tests.Visual.Ranking private void showPanel(ScoreInfo score) => Child = new ExpandedPanelMiddleContentContainer(score); - private BeatmapInfo createTestBeatmap(APIUser author) + private BeatmapInfo createTestBeatmap([NotNull] APIUser author) { var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo; diff --git a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs index f3550f7465..364cccd076 100644 --- a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs +++ b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs @@ -93,7 +93,7 @@ namespace osu.Game.Tournament.Components }, new TournamentSpriteText { - Text = Beatmap.Metadata.Author, + Text = Beatmap.Metadata.Author.Username, Padding = new MarginPadding { Right = 20 }, Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) }, diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 680574cfc8..674d603d9a 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -262,7 +262,8 @@ namespace osu.Game.Beatmaps Artist = model.Metadata?.Artist ?? string.Empty, TitleUnicode = model.Metadata?.TitleUnicode ?? string.Empty, ArtistUnicode = model.Metadata?.ArtistUnicode ?? string.Empty, - Author = new APIUser { Username = model.Metadata?.Author }, + AuthorString = model.Metadata?.Author.Username ?? string.Empty, + AuthorID = model.Metadata?.Author.OnlineID ?? 1, } }, minimiseDownloadSize); } diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs index 60e3bcc98d..4ae212c411 100644 --- a/osu.Game/Beatmaps/BeatmapMetadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using osu.Framework.Testing; using osu.Game.Database; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; #nullable enable @@ -35,6 +36,12 @@ namespace osu.Game.Beatmaps [JsonIgnore] public List BeatmapSets { get; set; } = new List(); + /// + /// The author of the beatmaps in this set. + /// + [JsonIgnore] + public APIUser Author = new APIUser(); + /// /// Helper property to deserialize a username to . /// @@ -42,12 +49,8 @@ namespace osu.Game.Beatmaps [Column("AuthorID")] public int AuthorID { - get => Author?.Id ?? 1; - set - { - Author ??= new APIUser(); - Author.Id = value; - } + get => Author.Id; + set => Author.Id = value; } /// @@ -57,20 +60,10 @@ namespace osu.Game.Beatmaps [Column("Author")] public string AuthorString { - get => Author?.Username ?? string.Empty; - set - { - Author ??= new APIUser(); - Author.Username = value; - } + get => Author.Username; + set => Author.Username = value; } - /// - /// The author of the beatmaps in this set. - /// - [JsonIgnore] - public APIUser? Author; - public string Source { get; set; } = string.Empty; [JsonProperty(@"tags")] @@ -90,6 +83,6 @@ namespace osu.Game.Beatmaps public override string ToString() => this.GetDisplayTitle(); - string IBeatmapMetadataInfo.Author => AuthorString; + IUser IBeatmapMetadataInfo.Author => Author; } } diff --git a/osu.Game/Beatmaps/BeatmapMetadataInfoExtensions.cs b/osu.Game/Beatmaps/BeatmapMetadataInfoExtensions.cs index fcaad17059..27cd7f8d9a 100644 --- a/osu.Game/Beatmaps/BeatmapMetadataInfoExtensions.cs +++ b/osu.Game/Beatmaps/BeatmapMetadataInfoExtensions.cs @@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps /// public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo) => new[] { - metadataInfo.Author, + metadataInfo.Author.Username, metadataInfo.Artist, metadataInfo.ArtistUnicode, metadataInfo.Title, @@ -27,7 +27,7 @@ namespace osu.Game.Beatmaps /// public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo) { - string author = string.IsNullOrEmpty(metadataInfo.Author) ? string.Empty : $"({metadataInfo.Author})"; + string author = string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $"({metadataInfo.Author})"; return $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim(); } @@ -36,7 +36,7 @@ namespace osu.Game.Beatmaps /// public static RomanisableString GetDisplayTitleRomanisable(this IBeatmapMetadataInfo metadataInfo, bool includeCreator = true) { - string author = !includeCreator || string.IsNullOrEmpty(metadataInfo.Author) ? string.Empty : $"({metadataInfo.Author})"; + 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; diff --git a/osu.Game/Graphics/Containers/LinkFlowContainer.cs b/osu.Game/Graphics/Containers/LinkFlowContainer.cs index 48f6c36993..41b7df228e 100644 --- a/osu.Game/Graphics/Containers/LinkFlowContainer.cs +++ b/osu.Game/Graphics/Containers/LinkFlowContainer.cs @@ -11,7 +11,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; using osu.Framework.Platform; -using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; namespace osu.Game.Graphics.Containers { @@ -70,8 +70,8 @@ namespace osu.Game.Graphics.Containers createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText); } - public void AddUserLink(APIUser user, Action creationParameters = null) - => createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); + public void AddUserLink(IUser user, Action creationParameters = null) + => createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.OnlineID.ToString()), "view profile"); private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null) { diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index f8a0acf96e..1ff039a6b4 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -71,7 +71,7 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty("artist_unicode")] public string ArtistUnicode { get; set; } = string.Empty; - public APIUser? Author = new APIUser(); + public APIUser Author = new APIUser(); /// /// Helper property to deserialize a username to . @@ -79,12 +79,8 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"user_id")] public int AuthorID { - get => Author?.Id ?? 1; - set - { - Author ??= new APIUser(); - Author.Id = value; - } + get => Author.Id; + set => Author.Id = value; } /// @@ -93,12 +89,8 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"creator")] public string AuthorString { - get => Author?.Username ?? string.Empty; - set - { - Author ??= new APIUser(); - Author.Username = value; - } + get => Author.Username; + set => Author.Username = value; } [JsonProperty(@"availability")] diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index c22b9bd9aa..85cee46a29 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -20,7 +20,6 @@ using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; using osu.Game.Online.Rooms; using osu.Game.Overlays.BeatmapListing.Panels; @@ -119,10 +118,10 @@ namespace osu.Game.Screens.OnlinePlay authorText.Clear(); - if (!string.IsNullOrEmpty(Item.Beatmap.Value?.Metadata.Author)) + if (!string.IsNullOrEmpty(Item.Beatmap.Value?.Metadata.Author.Username)) { authorText.AddText("mapped by "); - authorText.AddUserLink(new APIUser { Username = Item.Beatmap.Value.Metadata.Author }); + authorText.AddUserLink(Item.Beatmap.Value.Metadata.Author); } bool hasExplicitContent = (Item.Beatmap.Value.BeatmapSet as IBeatmapSetOnlineInfo)?.HasExplicitContent == true; diff --git a/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs b/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs index c27d5227b5..29b9d6164e 100644 --- a/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs +++ b/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs @@ -62,7 +62,7 @@ namespace osu.Game.Screens.Ranking.Expanded { var beatmap = score.BeatmapInfo; var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata; - string creator = metadata.Author?.Username; + string creator = metadata.Author.Username; var topStatistics = new List { diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index 89eed14e6d..e344da4027 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -428,7 +428,7 @@ namespace osu.Game.Screens.Select private Drawable getMapper(BeatmapMetadata metadata) { - if (metadata.Author == null) + if (string.IsNullOrEmpty(metadata.Author.Username)) return Empty(); return new LinkFlowContainer(s => diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmapSet.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmapSet.cs index d41cb73a29..e465f423bc 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmapSet.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmapSet.cs @@ -69,7 +69,7 @@ namespace osu.Game.Screens.Select.Carousel return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.OrdinalIgnoreCase); case SortMode.Author: - return string.Compare(BeatmapSet.Metadata.Author?.Username, otherSet.BeatmapSet.Metadata.Author?.Username, StringComparison.OrdinalIgnoreCase); + return string.Compare(BeatmapSet.Metadata.Author.Username, otherSet.BeatmapSet.Metadata.Author.Username, StringComparison.OrdinalIgnoreCase); case SortMode.Source: return string.Compare(BeatmapSet.Metadata.Source, otherSet.BeatmapSet.Metadata.Source, StringComparison.OrdinalIgnoreCase); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index 8a5dde961f..5940911d4a 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -142,7 +142,7 @@ namespace osu.Game.Screens.Select.Carousel }, new OsuSpriteText { - Text = $"{(beatmapInfo.Metadata ?? beatmapInfo.BeatmapSet.Metadata).Author?.Username ?? string.Empty}", + Text = $"{(beatmapInfo.Metadata ?? beatmapInfo.BeatmapSet.Metadata).Author.Username}", Font = OsuFont.GetFont(italics: true), Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft diff --git a/osu.Game/Stores/BeatmapImporter.cs b/osu.Game/Stores/BeatmapImporter.cs index 787b1ddd60..5eb7b10d9b 100644 --- a/osu.Game/Stores/BeatmapImporter.cs +++ b/osu.Game/Stores/BeatmapImporter.cs @@ -238,7 +238,11 @@ namespace osu.Game.Stores TitleUnicode = decoded.Metadata.TitleUnicode, Artist = decoded.Metadata.Artist, ArtistUnicode = decoded.Metadata.ArtistUnicode, - Author = decoded.Metadata.AuthorString, + Author = + { + OnlineID = decoded.Metadata.AuthorID, + Username = decoded.Metadata.AuthorString + }, Source = decoded.Metadata.Source, Tags = decoded.Metadata.Tags, PreviewTime = decoded.Metadata.PreviewTime,