1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Update existing usages of Author as string to access Username directly

This commit is contained in:
Dean Herbert 2021-11-04 18:22:21 +09:00
parent 7547810979
commit 86540d1fb6
14 changed files with 45 additions and 52 deletions

View File

@ -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<RealmRuleset>().First();

View File

@ -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;

View File

@ -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)
},

View File

@ -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);
}

View File

@ -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<BeatmapSetInfo> BeatmapSets { get; set; } = new List<BeatmapSetInfo>();
/// <summary>
/// The author of the beatmaps in this set.
/// </summary>
[JsonIgnore]
public APIUser Author = new APIUser();
/// <summary>
/// Helper property to deserialize a username to <see cref="APIUser"/>.
/// </summary>
@ -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;
}
/// <summary>
@ -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;
}
/// <summary>
/// The author of the beatmaps in this set.
/// </summary>
[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;
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps
/// </summary>
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
/// </summary>
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
/// </summary>
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;

View File

@ -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<SpriteText> creationParameters = null)
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile");
public void AddUserLink(IUser user, Action<SpriteText> 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)
{

View File

@ -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();
/// <summary>
/// Helper property to deserialize a username to <see cref="APIUser"/>.
@ -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;
}
/// <summary>
@ -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")]

View File

@ -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;

View File

@ -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<StatisticDisplay>
{

View File

@ -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 =>

View File

@ -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);

View File

@ -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

View File

@ -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,