Merge pull request #15466 from peppy/user-class-cleanup

Clean up `User` class
This commit is contained in:
Dan Balasescu
2021-11-08 13:27:26 +09:00
committed by GitHub
35 changed files with 206 additions and 148 deletions

View File

@ -112,7 +112,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual("Renatus", metadata.TitleUnicode); Assert.AreEqual("Renatus", metadata.TitleUnicode);
Assert.AreEqual("Soleily", metadata.Artist); Assert.AreEqual("Soleily", metadata.Artist);
Assert.AreEqual("Soleily", metadata.ArtistUnicode); Assert.AreEqual("Soleily", metadata.ArtistUnicode);
Assert.AreEqual("Gamu", metadata.AuthorString); Assert.AreEqual("Gamu", metadata.Author.Username);
Assert.AreEqual("Insane", beatmapInfo.Version); Assert.AreEqual("Insane", beatmapInfo.Version);
Assert.AreEqual(string.Empty, metadata.Source); Assert.AreEqual(string.Empty, metadata.Source);
Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", metadata.Tags); Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", metadata.Tags);
@ -547,7 +547,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream)); Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream));
Assert.IsNotNull(beatmap); Assert.IsNotNull(beatmap);
Assert.AreEqual("Beatmap with corrupted header", beatmap.Metadata.Title); Assert.AreEqual("Beatmap with corrupted header", beatmap.Metadata.Title);
Assert.AreEqual("Evil Hacker", beatmap.Metadata.AuthorString); Assert.AreEqual("Evil Hacker", beatmap.Metadata.Author.Username);
} }
} }
@ -565,7 +565,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream)); Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream));
Assert.IsNotNull(beatmap); Assert.IsNotNull(beatmap);
Assert.AreEqual("Beatmap with no header", beatmap.Metadata.Title); Assert.AreEqual("Beatmap with no header", beatmap.Metadata.Title);
Assert.AreEqual("Incredibly Evil Hacker", beatmap.Metadata.AuthorString); Assert.AreEqual("Incredibly Evil Hacker", beatmap.Metadata.Author.Username);
} }
} }
@ -583,7 +583,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream)); Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream));
Assert.IsNotNull(beatmap); Assert.IsNotNull(beatmap);
Assert.AreEqual("Empty lines at start", beatmap.Metadata.Title); Assert.AreEqual("Empty lines at start", beatmap.Metadata.Title);
Assert.AreEqual("Edge Case Hunter", beatmap.Metadata.AuthorString); Assert.AreEqual("Edge Case Hunter", beatmap.Metadata.Author.Username);
} }
} }
@ -601,7 +601,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream)); Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream));
Assert.IsNotNull(beatmap); Assert.IsNotNull(beatmap);
Assert.AreEqual("The dog ate the file header", beatmap.Metadata.Title); Assert.AreEqual("The dog ate the file header", beatmap.Metadata.Title);
Assert.AreEqual("Why does this keep happening", beatmap.Metadata.AuthorString); Assert.AreEqual("Why does this keep happening", beatmap.Metadata.Author.Username);
} }
} }
@ -619,7 +619,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream)); Assert.DoesNotThrow(() => beatmap = decoder.Decode(stream));
Assert.IsNotNull(beatmap); Assert.IsNotNull(beatmap);
Assert.AreEqual("No empty line delimiting header from contents", beatmap.Metadata.Title); Assert.AreEqual("No empty line delimiting header from contents", beatmap.Metadata.Title);
Assert.AreEqual("Edge Case Hunter", beatmap.Metadata.AuthorString); Assert.AreEqual("Edge Case Hunter", beatmap.Metadata.Author.Username);
} }
} }

View File

@ -35,7 +35,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
Assert.AreEqual("Gamu", meta.AuthorString); Assert.AreEqual("Gamu", meta.Author.Username);
Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile); Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile);
Assert.AreEqual(164471, meta.PreviewTime); Assert.AreEqual(164471, meta.PreviewTime);
Assert.AreEqual(string.Empty, meta.Source); Assert.AreEqual(string.Empty, meta.Source);

View File

@ -60,7 +60,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
Assert.AreEqual("Deif", meta.AuthorString); Assert.AreEqual("Deif", meta.Author.Username);
Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile); Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile);
Assert.AreEqual(164471, meta.PreviewTime); Assert.AreEqual(164471, meta.PreviewTime);
Assert.AreEqual(string.Empty, meta.Source); Assert.AreEqual(string.Empty, meta.Source);

View File

@ -482,7 +482,10 @@ namespace osu.Game.Tests.Database
var metadata = new RealmBeatmapMetadata var metadata = new RealmBeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
Author = "SomeAuthor" Author =
{
Username = "SomeAuthor"
}
}; };
var ruleset = realmFactory.Context.All<RealmRuleset>().First(); var ruleset = realmFactory.Context.All<RealmRuleset>().First();

View File

@ -82,7 +82,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
GlobalRank = 89000, GlobalRank = 89000,
PP = 12345, PP = 12345,
RankHistory = new APIUser.RankHistoryData RankHistory = new APIRankHistory
{ {
Data = data, Data = data,
} }
@ -95,7 +95,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
GlobalRank = 89000, GlobalRank = 89000,
PP = 12345, PP = 12345,
RankHistory = new APIUser.RankHistoryData RankHistory = new APIRankHistory
{ {
Data = dataWithZeros, Data = dataWithZeros,
} }
@ -108,7 +108,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
GlobalRank = 12000, GlobalRank = 12000,
PP = 12345, PP = 12345,
RankHistory = new APIUser.RankHistoryData RankHistory = new APIRankHistory
{ {
Data = smallData, Data = smallData,
} }
@ -121,7 +121,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
GlobalRank = 12000, GlobalRank = 12000,
PP = 12345, PP = 12345,
RankHistory = new APIUser.RankHistoryData RankHistory = new APIRankHistory
{ {
Data = edgyData, Data = edgyData,
} }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Tests.Visual.Online
Current = 727, Current = 727,
Progress = 69, Progress = 69,
}, },
RankHistory = new APIUser.RankHistoryData RankHistory = new APIRankHistory
{ {
Mode = @"osu", Mode = @"osu",
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray() Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online
}, },
Title = "osu!volunteer", Title = "osu!volunteer",
Colour = "ff0000", Colour = "ff0000",
Achievements = Array.Empty<APIUser.UserAchievement>(), Achievements = Array.Empty<APIUserAchievement>(),
}; };
public TestSceneUserProfileOverlay() public TestSceneUserProfileOverlay()

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; 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) AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
{ {
BeatmapInfo = createTestBeatmap(null) BeatmapInfo = createTestBeatmap(new APIUser())
})); }));
AddAssert("mapped by text not present", () => AddAssert("mapped by text not present", () =>
@ -74,7 +75,7 @@ namespace osu.Game.Tests.Visual.Ranking
var ruleset = new OsuRuleset(); var ruleset = new OsuRuleset();
var mods = new Mod[] { ruleset.GetAutoplayMod() }; var mods = new Mod[] { ruleset.GetAutoplayMod() };
var beatmap = createTestBeatmap(null); var beatmap = createTestBeatmap(new APIUser());
showPanel(new TestScoreInfo(ruleset.RulesetInfo) showPanel(new TestScoreInfo(ruleset.RulesetInfo)
{ {
@ -90,7 +91,7 @@ namespace osu.Game.Tests.Visual.Ranking
private void showPanel(ScoreInfo score) => private void showPanel(ScoreInfo score) =>
Child = new ExpandedPanelMiddleContentContainer(score); Child = new ExpandedPanelMiddleContentContainer(score);
private BeatmapInfo createTestBeatmap(APIUser author) private BeatmapInfo createTestBeatmap([NotNull] APIUser author)
{ {
var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo; var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo;

View File

@ -400,7 +400,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(); loadBeatmaps();
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false)); AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false));
AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.AuthorString == "zzzzz"); AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.Author.Username == "zzzzz");
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!", StringComparison.Ordinal)); AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!", StringComparison.Ordinal));
} }

View File

@ -93,7 +93,7 @@ namespace osu.Game.Tournament.Components
}, },
new TournamentSpriteText new TournamentSpriteText
{ {
Text = Beatmap.Metadata.Author, Text = Beatmap.Metadata.Author.Username,
Padding = new MarginPadding { Right = 20 }, Padding = new MarginPadding { Right = 20 },
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
}, },

View File

@ -250,15 +250,11 @@ namespace osu.Game.Beatmaps
public IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> DownloadFailed => beatmapModelDownloader.DownloadFailed; public IBindable<WeakReference<ArchiveDownloadRequest<IBeatmapSetInfo>>> DownloadFailed => beatmapModelDownloader.DownloadFailed;
public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) =>
{ beatmapModelDownloader.Download(model, minimiseDownloadSize);
return beatmapModelDownloader.Download(model, minimiseDownloadSize);
}
public ArchiveDownloadRequest<IBeatmapSetInfo> GetExistingDownload(IBeatmapSetInfo model) public ArchiveDownloadRequest<IBeatmapSetInfo> GetExistingDownload(IBeatmapSetInfo model) =>
{ beatmapModelDownloader.GetExistingDownload(model);
return beatmapModelDownloader.GetExistingDownload(model);
}
#endregion #endregion

View File

@ -8,6 +8,7 @@ using Newtonsoft.Json;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Users;
#nullable enable #nullable enable
@ -35,6 +36,12 @@ namespace osu.Game.Beatmaps
[JsonIgnore] [JsonIgnore]
public List<BeatmapSetInfo> BeatmapSets { get; set; } = new List<BeatmapSetInfo>(); 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> /// <summary>
/// Helper property to deserialize a username to <see cref="APIUser"/>. /// Helper property to deserialize a username to <see cref="APIUser"/>.
/// </summary> /// </summary>
@ -42,12 +49,8 @@ namespace osu.Game.Beatmaps
[Column("AuthorID")] [Column("AuthorID")]
public int AuthorID public int AuthorID
{ {
get => Author?.Id ?? 1; get => Author.Id; // This should not be used, but is required to make EF work correctly.
set set => Author.Id = value;
{
Author ??= new APIUser();
Author.Id = value;
}
} }
/// <summary> /// <summary>
@ -57,20 +60,10 @@ namespace osu.Game.Beatmaps
[Column("Author")] [Column("Author")]
public string AuthorString public string AuthorString
{ {
get => Author?.Username ?? string.Empty; get => Author.Username; // This should not be used, but is required to make EF work correctly.
set set => Author.Username = value;
{
Author ??= new APIUser();
Author.Username = value;
}
} }
/// <summary>
/// The author of the beatmaps in this set.
/// </summary>
[JsonIgnore]
public APIUser? Author;
public string Source { get; set; } = string.Empty; public string Source { get; set; } = string.Empty;
[JsonProperty(@"tags")] [JsonProperty(@"tags")]
@ -90,6 +83,6 @@ namespace osu.Game.Beatmaps
public override string ToString() => this.GetDisplayTitle(); 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> /// </summary>
public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo) => new[] public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo) => new[]
{ {
metadataInfo.Author, metadataInfo.Author.Username,
metadataInfo.Artist, metadataInfo.Artist,
metadataInfo.ArtistUnicode, metadataInfo.ArtistUnicode,
metadataInfo.Title, metadataInfo.Title,
@ -27,7 +27,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo) 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(); return $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim();
} }
@ -36,7 +36,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public static RomanisableString GetDisplayTitleRomanisable(this IBeatmapMetadataInfo metadataInfo, bool includeCreator = true) 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 artistUnicode = string.IsNullOrEmpty(metadataInfo.ArtistUnicode) ? metadataInfo.Artist : metadataInfo.ArtistUnicode;
string titleUnicode = string.IsNullOrEmpty(metadataInfo.TitleUnicode) ? metadataInfo.Title : metadataInfo.TitleUnicode; string titleUnicode = string.IsNullOrEmpty(metadataInfo.TitleUnicode) ? metadataInfo.Title : metadataInfo.TitleUnicode;

View File

@ -129,7 +129,7 @@ namespace osu.Game.Beatmaps.Formats
if (!string.IsNullOrEmpty(beatmap.Metadata.TitleUnicode)) writer.WriteLine(FormattableString.Invariant($"TitleUnicode: {beatmap.Metadata.TitleUnicode}")); if (!string.IsNullOrEmpty(beatmap.Metadata.TitleUnicode)) writer.WriteLine(FormattableString.Invariant($"TitleUnicode: {beatmap.Metadata.TitleUnicode}"));
writer.WriteLine(FormattableString.Invariant($"Artist: {beatmap.Metadata.Artist}")); writer.WriteLine(FormattableString.Invariant($"Artist: {beatmap.Metadata.Artist}"));
if (!string.IsNullOrEmpty(beatmap.Metadata.ArtistUnicode)) writer.WriteLine(FormattableString.Invariant($"ArtistUnicode: {beatmap.Metadata.ArtistUnicode}")); if (!string.IsNullOrEmpty(beatmap.Metadata.ArtistUnicode)) writer.WriteLine(FormattableString.Invariant($"ArtistUnicode: {beatmap.Metadata.ArtistUnicode}"));
writer.WriteLine(FormattableString.Invariant($"Creator: {beatmap.Metadata.AuthorString}")); writer.WriteLine(FormattableString.Invariant($"Creator: {beatmap.Metadata.Author.Username}"));
writer.WriteLine(FormattableString.Invariant($"Version: {beatmap.BeatmapInfo.Version}")); writer.WriteLine(FormattableString.Invariant($"Version: {beatmap.BeatmapInfo.Version}"));
if (!string.IsNullOrEmpty(beatmap.Metadata.Source)) writer.WriteLine(FormattableString.Invariant($"Source: {beatmap.Metadata.Source}")); if (!string.IsNullOrEmpty(beatmap.Metadata.Source)) writer.WriteLine(FormattableString.Invariant($"Source: {beatmap.Metadata.Source}"));
if (!string.IsNullOrEmpty(beatmap.Metadata.Tags)) writer.WriteLine(FormattableString.Invariant($"Tags: {beatmap.Metadata.Tags}")); if (!string.IsNullOrEmpty(beatmap.Metadata.Tags)) writer.WriteLine(FormattableString.Invariant($"Tags: {beatmap.Metadata.Tags}"));

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Game.Users;
#nullable enable #nullable enable
@ -35,7 +36,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// The author of this beatmap. /// The author of this beatmap.
/// </summary> /// </summary>
string Author { get; } // eventually should be linked to a persisted User. IUser Author { get; }
/// <summary> /// <summary>
/// The source of this beatmap. /// The source of this beatmap.

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading; using System.Threading;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Development; using osu.Framework.Development;
@ -35,8 +36,9 @@ namespace osu.Game.Database
/// 6 First tracked version (~20211018) /// 6 First tracked version (~20211018)
/// 7 Changed OnlineID fields to non-nullable to add indexing support (20211018) /// 7 Changed OnlineID fields to non-nullable to add indexing support (20211018)
/// 8 Rebind scroll adjust keys to not have control modifier (20211029) /// 8 Rebind scroll adjust keys to not have control modifier (20211029)
/// 9 Converted BeatmapMetadata.Author from string to RealmUser (20211104)
/// </summary> /// </summary>
private const int schema_version = 8; private const int schema_version = 9;
/// <summary> /// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods. /// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
@ -151,50 +153,80 @@ namespace osu.Game.Database
private void onMigration(Migration migration, ulong lastSchemaVersion) private void onMigration(Migration migration, ulong lastSchemaVersion)
{ {
if (lastSchemaVersion < 8) for (ulong i = lastSchemaVersion; i <= schema_version; i++)
applyMigrationsForVersion(migration, i);
}
private void applyMigrationsForVersion(Migration migration, ulong version)
{
switch (version)
{ {
// Ctrl -/+ now adjusts UI scale so let's clear any bindings which overlap these combinations. case 7:
// New defaults will be populated by the key store afterwards. convertOnlineIDs<RealmBeatmap>();
var keyBindings = migration.NewRealm.All<RealmKeyBinding>(); convertOnlineIDs<RealmBeatmapSet>();
convertOnlineIDs<RealmRuleset>();
var increaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.IncreaseScrollSpeed); void convertOnlineIDs<T>() where T : RealmObject
if (increaseSpeedBinding != null && increaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Plus }))
migration.NewRealm.Remove(increaseSpeedBinding);
var decreaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.DecreaseScrollSpeed);
if (decreaseSpeedBinding != null && decreaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Minus }))
migration.NewRealm.Remove(decreaseSpeedBinding);
}
if (lastSchemaVersion < 7)
{
convertOnlineIDs<RealmBeatmap>();
convertOnlineIDs<RealmBeatmapSet>();
convertOnlineIDs<RealmRuleset>();
void convertOnlineIDs<T>() where T : RealmObject
{
string className = typeof(T).Name.Replace(@"Realm", string.Empty);
// version was not bumped when the beatmap/ruleset models were added
// therefore we must manually check for their presence to avoid throwing on the `DynamicApi` calls.
if (!migration.OldRealm.Schema.TryFindObjectSchema(className, out _))
return;
var oldItems = migration.OldRealm.DynamicApi.All(className);
var newItems = migration.NewRealm.DynamicApi.All(className);
int itemCount = newItems.Count();
for (int i = 0; i < itemCount; i++)
{ {
dynamic? oldItem = oldItems.ElementAt(i); string className = getMappedOrOriginalName(typeof(T));
dynamic? newItem = newItems.ElementAt(i);
long? nullableOnlineID = oldItem?.OnlineID; // version was not bumped when the beatmap/ruleset models were added
newItem.OnlineID = (int)(nullableOnlineID ?? -1); // therefore we must manually check for their presence to avoid throwing on the `DynamicApi` calls.
if (!migration.OldRealm.Schema.TryFindObjectSchema(className, out _))
return;
var oldItems = migration.OldRealm.DynamicApi.All(className);
var newItems = migration.NewRealm.DynamicApi.All(className);
int itemCount = newItems.Count();
for (int i = 0; i < itemCount; i++)
{
dynamic? oldItem = oldItems.ElementAt(i);
dynamic? newItem = newItems.ElementAt(i);
long? nullableOnlineID = oldItem?.OnlineID;
newItem.OnlineID = (int)(nullableOnlineID ?? -1);
}
} }
}
break;
case 8:
// Ctrl -/+ now adjusts UI scale so let's clear any bindings which overlap these combinations.
// New defaults will be populated by the key store afterwards.
var keyBindings = migration.NewRealm.All<RealmKeyBinding>();
var increaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.IncreaseScrollSpeed);
if (increaseSpeedBinding != null && increaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Plus }))
migration.NewRealm.Remove(increaseSpeedBinding);
var decreaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.DecreaseScrollSpeed);
if (decreaseSpeedBinding != null && decreaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Minus }))
migration.NewRealm.Remove(decreaseSpeedBinding);
break;
case 9:
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
var oldMetadata = migration.OldRealm.DynamicApi.All(getMappedOrOriginalName(typeof(RealmBeatmapMetadata)));
var newMetadata = migration.NewRealm.All<RealmBeatmapMetadata>();
int metadataCount = newMetadata.Count();
for (int i = 0; i < metadataCount; i++)
{
dynamic? oldItem = oldMetadata.ElementAt(i);
var newItem = newMetadata.ElementAt(i);
string username = oldItem.Author;
newItem.Author = new RealmUser
{
Username = username
};
}
break;
} }
} }
@ -252,6 +284,9 @@ namespace osu.Game.Database
}); });
} }
// https://github.com/realm/realm-dotnet/blob/32f4ebcc88b3e80a3b254412665340cd9f3bd6b5/Realm/Realm/Extensions/ReflectionExtensions.cs#L46
private static string getMappedOrOriginalName(MemberInfo member) => member.GetCustomAttribute<MapToAttribute>()?.Mapping ?? member.Name;
private bool isDisposed; private bool isDisposed;
public void Dispose() public void Dispose()

View File

@ -11,7 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Users;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
{ {
@ -70,8 +70,8 @@ namespace osu.Game.Graphics.Containers
createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText); createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText);
} }
public void AddUserLink(APIUser user, Action<SpriteText> creationParameters = null) public void AddUserLink(IUser user, Action<SpriteText> creationParameters = null)
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); => 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) private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
{ {

View File

@ -5,6 +5,7 @@ using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Users;
using Realms; using Realms;
#nullable enable #nullable enable
@ -26,7 +27,7 @@ namespace osu.Game.Models
[JsonProperty("artist_unicode")] [JsonProperty("artist_unicode")]
public string ArtistUnicode { get; set; } = string.Empty; public string ArtistUnicode { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty; // eventually should be linked to a persisted User. public RealmUser Author { get; set; } = new RealmUser();
public string Source { get; set; } = string.Empty; public string Source { get; set; } = string.Empty;
@ -41,5 +42,7 @@ namespace osu.Game.Models
public string AudioFile { get; set; } = string.Empty; public string AudioFile { get; set; } = string.Empty;
public string BackgroundFile { get; set; } = string.Empty; public string BackgroundFile { get; set; } = string.Empty;
IUser IBeatmapMetadataInfo.Author => Author;
} }
} }

View File

@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Users;
using Realms;
namespace osu.Game.Models
{
public class RealmUser : EmbeddedObject, IUser
{
public int OnlineID { get; set; } = 1;
public string Username { get; set; }
public bool IsBot => false;
}
}

View File

@ -71,7 +71,7 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty("artist_unicode")] [JsonProperty("artist_unicode")]
public string ArtistUnicode { get; set; } = string.Empty; public string ArtistUnicode { get; set; } = string.Empty;
public APIUser? Author = new APIUser(); public APIUser Author = new APIUser();
/// <summary> /// <summary>
/// Helper property to deserialize a username to <see cref="APIUser"/>. /// Helper property to deserialize a username to <see cref="APIUser"/>.
@ -79,12 +79,8 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"user_id")] [JsonProperty(@"user_id")]
public int AuthorID public int AuthorID
{ {
get => Author?.Id ?? 1; get => Author.Id;
set set => Author.Id = value;
{
Author ??= new APIUser();
Author.Id = value;
}
} }
/// <summary> /// <summary>
@ -93,12 +89,8 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"creator")] [JsonProperty(@"creator")]
public string AuthorString public string AuthorString
{ {
get => Author?.Username ?? string.Empty; get => Author.Username;
set set => Author.Username = value;
{
Author ??= new APIUser();
Author.Username = value;
}
} }
[JsonProperty(@"availability")] [JsonProperty(@"availability")]

View File

@ -0,0 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIRankHistory
{
[JsonProperty(@"mode")]
public string Mode;
[JsonProperty(@"data")]
public int[] Data;
}
}

View File

@ -79,7 +79,7 @@ namespace osu.Game.Online.API.Requests.Responses
public bool IsBNG; public bool IsBNG;
[JsonProperty(@"is_bot")] [JsonProperty(@"is_bot")]
public bool IsBot; public bool IsBot { get; set; }
[JsonProperty(@"is_active")] [JsonProperty(@"is_active")]
public bool Active; public bool Active;
@ -200,34 +200,16 @@ namespace osu.Game.Online.API.Requests.Responses
} }
[JsonProperty(@"rank_history")] [JsonProperty(@"rank_history")]
private RankHistoryData rankHistory private APIRankHistory rankHistory
{ {
set => statistics.RankHistory = value; set => statistics.RankHistory = value;
} }
public class RankHistoryData
{
[JsonProperty(@"mode")]
public string Mode;
[JsonProperty(@"data")]
public int[] Data;
}
[JsonProperty("badges")] [JsonProperty("badges")]
public Badge[] Badges; public Badge[] Badges;
[JsonProperty("user_achievements")] [JsonProperty("user_achievements")]
public UserAchievement[] Achievements; public APIUserAchievement[] Achievements;
public class UserAchievement
{
[JsonProperty("achieved_at")]
public DateTimeOffset AchievedAt;
[JsonProperty("achievement_id")]
public int ID;
}
[JsonProperty("monthly_playcounts")] [JsonProperty("monthly_playcounts")]
public APIUserHistoryCount[] MonthlyPlaycounts; public APIUserHistoryCount[] MonthlyPlaycounts;

View File

@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using Newtonsoft.Json;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIUserAchievement
{
[JsonProperty("achievement_id")]
public int ID;
[JsonProperty("achieved_at")]
public DateTimeOffset AchievedAt;
}
}

View File

@ -46,7 +46,7 @@ namespace osu.Game.Screens.Edit.Setup
Empty(), Empty(),
creatorTextBox = createTextBox<LabelledTextBox>("Creator", metadata.AuthorString), creatorTextBox = createTextBox<LabelledTextBox>("Creator", metadata.Author.Username),
difficultyTextBox = createTextBox<LabelledTextBox>("Difficulty Name", Beatmap.BeatmapInfo.Version), difficultyTextBox = createTextBox<LabelledTextBox>("Difficulty Name", Beatmap.BeatmapInfo.Version),
sourceTextBox = createTextBox<LabelledTextBox>("Source", metadata.Source), sourceTextBox = createTextBox<LabelledTextBox>("Source", metadata.Source),
tagsTextBox = createTextBox<LabelledTextBox>("Tags", metadata.Tags) tagsTextBox = createTextBox<LabelledTextBox>("Tags", metadata.Tags)

View File

@ -20,7 +20,6 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays.BeatmapListing.Panels; using osu.Game.Overlays.BeatmapListing.Panels;
@ -119,10 +118,10 @@ namespace osu.Game.Screens.OnlinePlay
authorText.Clear(); authorText.Clear();
if (!string.IsNullOrEmpty(Item.Beatmap.Value?.Metadata.Author)) if (!string.IsNullOrEmpty(Item.Beatmap.Value?.Metadata.Author.Username))
{ {
authorText.AddText("mapped by "); 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; bool hasExplicitContent = (Item.Beatmap.Value.BeatmapSet as IBeatmapSetOnlineInfo)?.HasExplicitContent == true;

View File

@ -164,7 +164,7 @@ namespace osu.Game.Screens.Play
new Drawable[] new Drawable[]
{ {
new MetadataLineLabel("Mapper"), new MetadataLineLabel("Mapper"),
new MetadataLineInfo(metadata.AuthorString) new MetadataLineInfo(metadata.Author.Username)
} }
} }
}, },

View File

@ -62,7 +62,7 @@ namespace osu.Game.Screens.Ranking.Expanded
{ {
var beatmap = score.BeatmapInfo; var beatmap = score.BeatmapInfo;
var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata; var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata;
string creator = metadata.Author?.Username; string creator = metadata.Author.Username;
var topStatistics = new List<StatisticDisplay> var topStatistics = new List<StatisticDisplay>
{ {

View File

@ -428,7 +428,7 @@ namespace osu.Game.Screens.Select
private Drawable getMapper(BeatmapMetadata metadata) private Drawable getMapper(BeatmapMetadata metadata)
{ {
if (metadata.Author == null) if (string.IsNullOrEmpty(metadata.Author.Username))
return Empty(); return Empty();
return new LinkFlowContainer(s => return new LinkFlowContainer(s =>

View File

@ -49,7 +49,7 @@ namespace osu.Game.Screens.Select.Carousel
match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(BeatmapInfo.BeatDivisor); match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(BeatmapInfo.BeatDivisor);
match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(BeatmapInfo.Status); match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(BeatmapInfo.Status);
match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(BeatmapInfo.Metadata.AuthorString); match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(BeatmapInfo.Metadata.Author.Username);
match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(BeatmapInfo.Metadata.Artist) || match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(BeatmapInfo.Metadata.Artist) ||
criteria.Artist.Matches(BeatmapInfo.Metadata.ArtistUnicode); criteria.Artist.Matches(BeatmapInfo.Metadata.ArtistUnicode);

View File

@ -69,7 +69,7 @@ namespace osu.Game.Screens.Select.Carousel
return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.OrdinalIgnoreCase); return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.OrdinalIgnoreCase);
case SortMode.Author: 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: case SortMode.Source:
return string.Compare(BeatmapSet.Metadata.Source, otherSet.BeatmapSet.Metadata.Source, StringComparison.OrdinalIgnoreCase); 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 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), Font = OsuFont.GetFont(italics: true),
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft Origin = Anchor.BottomLeft

View File

@ -77,6 +77,6 @@ namespace osu.Game.Skinning
} }
private static SkinInfo createSkinInfo(BeatmapInfo beatmapInfo) => private static SkinInfo createSkinInfo(BeatmapInfo beatmapInfo) =>
new SkinInfo { Name = beatmapInfo.ToString(), Creator = beatmapInfo.Metadata?.AuthorString }; new SkinInfo { Name = beatmapInfo.ToString(), Creator = beatmapInfo.Metadata?.Author.Username };
} }
} }

View File

@ -238,7 +238,11 @@ namespace osu.Game.Stores
TitleUnicode = decoded.Metadata.TitleUnicode, TitleUnicode = decoded.Metadata.TitleUnicode,
Artist = decoded.Metadata.Artist, Artist = decoded.Metadata.Artist,
ArtistUnicode = decoded.Metadata.ArtistUnicode, ArtistUnicode = decoded.Metadata.ArtistUnicode,
Author = decoded.Metadata.AuthorString, Author =
{
OnlineID = decoded.Metadata.Author.Id,
Username = decoded.Metadata.Author.Username
},
Source = decoded.Metadata.Source, Source = decoded.Metadata.Source,
Tags = decoded.Metadata.Tags, Tags = decoded.Metadata.Tags,
PreviewTime = decoded.Metadata.PreviewTime, PreviewTime = decoded.Metadata.PreviewTime,

View File

@ -216,8 +216,6 @@ namespace osu.Game.Tests.Visual
Artist = beatmap.BeatmapSet.Metadata.Artist, Artist = beatmap.BeatmapSet.Metadata.Artist,
ArtistUnicode = beatmap.BeatmapSet.Metadata.ArtistUnicode, ArtistUnicode = beatmap.BeatmapSet.Metadata.ArtistUnicode,
Author = beatmap.BeatmapSet.Metadata.Author, Author = beatmap.BeatmapSet.Metadata.Author,
AuthorID = beatmap.BeatmapSet.Metadata.AuthorID,
AuthorString = beatmap.BeatmapSet.Metadata.AuthorString,
Source = beatmap.BeatmapSet.Metadata.Source, Source = beatmap.BeatmapSet.Metadata.Source,
Tags = beatmap.BeatmapSet.Metadata.Tags, Tags = beatmap.BeatmapSet.Metadata.Tags,
Beatmaps = new[] Beatmaps = new[]
@ -228,7 +226,7 @@ namespace osu.Game.Tests.Visual
OnlineBeatmapSetID = beatmap.BeatmapSet.OnlineID, OnlineBeatmapSetID = beatmap.BeatmapSet.OnlineID,
Status = beatmap.Status, Status = beatmap.Status,
Checksum = beatmap.MD5Hash, Checksum = beatmap.MD5Hash,
AuthorID = beatmap.Metadata.AuthorID, AuthorID = beatmap.Metadata.Author.OnlineID,
RulesetID = beatmap.RulesetID, RulesetID = beatmap.RulesetID,
StarRating = beatmap.StarDifficulty, StarRating = beatmap.StarDifficulty,
DifficultyName = beatmap.Version, DifficultyName = beatmap.Version,

View File

@ -7,6 +7,8 @@ namespace osu.Game.Users
{ {
public interface IUser : IHasOnlineID<int> public interface IUser : IHasOnlineID<int>
{ {
string Username { get; set; } string Username { get; }
bool IsBot { get; }
} }
} }

View File

@ -7,7 +7,6 @@ using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Utils; using osu.Game.Utils;
using static osu.Game.Online.API.Requests.Responses.APIUser;
namespace osu.Game.Users namespace osu.Game.Users
{ {
@ -35,7 +34,7 @@ namespace osu.Game.Users
public int? CountryRank; public int? CountryRank;
// populated via User model, as that's where the data currently lives. // populated via User model, as that's where the data currently lives.
public RankHistoryData RankHistory; public APIRankHistory RankHistory;
[JsonProperty(@"pp")] [JsonProperty(@"pp")]
public decimal? PP; public decimal? PP;