From 001f7c36f36fe8151d422d45de86d7328acfaa72 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 17:15:26 +0900 Subject: [PATCH 1/3] Use `Equals` in carousel tests for better realm compatibility --- .../SongSelect/TestSceneBeatmapCarousel.cs | 25 ++++++++++--------- .../SongSelect/TestScenePlaySongSelect.cs | 8 +++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs index 534442c8b6..5c40a3dd94 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs @@ -78,9 +78,9 @@ namespace osu.Game.Tests.Visual.SongSelect { AddStep("store selection", () => selection = carousel.SelectedBeatmapInfo); if (isIterating) - AddUntilStep("selection changed", () => carousel.SelectedBeatmapInfo != selection); + AddUntilStep("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(selection)); else - AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo == selection); + AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo.Equals(selection)); } } } @@ -412,7 +412,8 @@ namespace osu.Game.Tests.Visual.SongSelect for (int i = 0; i < 20; i++) { - var set = createTestBeatmapSet(i); + // index + 1 because we are using OnlineID which should never be zero. + var set = createTestBeatmapSet(i + 1); set.Metadata.Artist = "same artist"; set.Metadata.Title = "same title"; sets.Add(set); @@ -421,10 +422,10 @@ namespace osu.Game.Tests.Visual.SongSelect loadBeatmaps(sets); AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); - AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.ID == index).All(b => b)); + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + 1).All(b => b)); AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false)); - AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.ID == index).All(b => b)); + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + 1).All(b => b)); } [Test] @@ -443,12 +444,12 @@ namespace osu.Game.Tests.Visual.SongSelect loadBeatmaps(sets); AddStep("Filter to normal", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Normal" }, false)); - AddAssert("Check first set at end", () => carousel.BeatmapSets.First() == sets.Last()); - AddAssert("Check last set at start", () => carousel.BeatmapSets.Last() == sets.First()); + AddAssert("Check first set at end", () => carousel.BeatmapSets.First().Equals(sets.Last())); + AddAssert("Check last set at start", () => carousel.BeatmapSets.Last().Equals(sets.First())); AddStep("Filter to insane", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Insane" }, false)); - AddAssert("Check first set at start", () => carousel.BeatmapSets.First() == sets.First()); - AddAssert("Check last set at end", () => carousel.BeatmapSets.Last() == sets.Last()); + AddAssert("Check first set at start", () => carousel.BeatmapSets.First().Equals(sets.First())); + AddAssert("Check last set at end", () => carousel.BeatmapSets.Last().Equals(sets.Last())); } [Test] @@ -662,7 +663,7 @@ namespace osu.Game.Tests.Visual.SongSelect eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID); }); - AddAssert("selection changed", () => carousel.SelectedBeatmapInfo != manySets.First().Beatmaps.First()); + AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First())); } AddAssert("Selection was random", () => eagerSelectedIDs.Count > 2); @@ -759,13 +760,13 @@ namespace osu.Game.Tests.Visual.SongSelect } private void ensureRandomFetchSuccess() => - AddAssert("ensure prev random fetch worked", () => selectedSets.Peek() == carousel.SelectedBeatmapSet); + AddAssert("ensure prev random fetch worked", () => selectedSets.Peek().Equals(carousel.SelectedBeatmapSet)); private void waitForSelection(int set, int? diff = null) => AddUntilStep($"selected is set{set}{(diff.HasValue ? $" diff{diff.Value}" : "")}", () => { if (diff != null) - return carousel.SelectedBeatmapInfo == carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First(); + return carousel.SelectedBeatmapInfo.Equals(carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First()); return carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Contains(carousel.SelectedBeatmapInfo); }); diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 0437c1b25b..f09dc38378 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -148,7 +148,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select next and enter", () => { InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType() - .First(b => ((CarouselBeatmap)b.Item).BeatmapInfo != songSelect.Carousel.SelectedBeatmapInfo)); + .First(b => !((CarouselBeatmap)b.Item).BeatmapInfo.Equals(songSelect.Carousel.SelectedBeatmapInfo))); InputManager.Click(MouseButton.Left); @@ -175,7 +175,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select next and enter", () => { InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType() - .First(b => ((CarouselBeatmap)b.Item).BeatmapInfo != songSelect.Carousel.SelectedBeatmapInfo)); + .First(b => !((CarouselBeatmap)b.Item).BeatmapInfo.Equals(songSelect.Carousel.SelectedBeatmapInfo))); InputManager.PressButton(MouseButton.Left); @@ -644,7 +644,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.Click(MouseButton.Left); }); - AddAssert("Selected beatmap correct", () => songSelect.Carousel.SelectedBeatmapInfo == filteredBeatmap); + AddAssert("Selected beatmap correct", () => songSelect.Carousel.SelectedBeatmapInfo.Equals(filteredBeatmap)); } [Test] @@ -858,7 +858,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddUntilStep("wait for difficulty panels visible", () => songSelect.Carousel.ChildrenOfType().Any()); } - private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.FindIndex(b => b == info); + private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.IndexOf(info); private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmapInfo); From f1926c6d275c082f2f0fa8df20aa6e6090982f75 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 17:40:43 +0900 Subject: [PATCH 2/3] Store preferred ruleset to configuration using `ShortName` instead of `ID` --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/OsuGame.cs | 64 +++++++++++----------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 1beef89b51..84da3f666d 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -26,7 +26,7 @@ namespace osu.Game.Configuration protected override void InitialiseDefaults() { // UI/selection defaults - SetDefault(OsuSetting.Ruleset, 0, 0, int.MaxValue); + SetDefault(OsuSetting.Ruleset, string.Empty); SetDefault(OsuSetting.Skin, 0, -1, int.MaxValue); SetDefault(OsuSetting.BeatmapDetailTab, PlayBeatmapDetailArea.TabType.Details); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 1274d8d867..574a5e5393 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -4,59 +4,58 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using osu.Framework.Configuration; -using osu.Framework.Screens; -using osu.Game.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Overlays; -using osu.Framework.Logging; -using osu.Framework.Allocation; -using osu.Game.Overlays.Toolbar; -using osu.Game.Screens; -using osu.Game.Screens.Menu; using System.Linq; using System.Threading; using System.Threading.Tasks; using Humanizer; using JetBrains.Annotations; +using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Bindables; +using osu.Framework.Configuration; using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; +using osu.Framework.Logging; +using osu.Framework.Screens; using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Collections; +using osu.Game.Configuration; +using osu.Game.Database; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Input; -using osu.Game.Overlays.Notifications; using osu.Game.Input.Bindings; -using osu.Game.Online.Chat; -using osu.Game.Overlays.Music; -using osu.Game.Skinning; -using osuTK.Graphics; -using osu.Game.Overlays.Volume; -using osu.Game.Rulesets.Mods; -using osu.Game.Scoring; -using osu.Game.Screens.Play; -using osu.Game.Screens.Ranking; -using osu.Game.Screens.Select; -using osu.Game.Updater; -using osu.Game.Utils; -using LogLevel = osu.Framework.Logging.LogLevel; -using osu.Game.Database; -using osu.Game.Extensions; using osu.Game.IO; using osu.Game.Localisation; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Chat; +using osu.Game.Overlays; +using osu.Game.Overlays.Music; +using osu.Game.Overlays.Notifications; +using osu.Game.Overlays.Toolbar; +using osu.Game.Overlays.Volume; using osu.Game.Performance; +using osu.Game.Rulesets.Mods; +using osu.Game.Scoring; +using osu.Game.Screens; +using osu.Game.Screens.Menu; +using osu.Game.Screens.Play; +using osu.Game.Screens.Ranking; +using osu.Game.Screens.Select; +using osu.Game.Skinning; using osu.Game.Skinning.Editor; +using osu.Game.Updater; using osu.Game.Users; +using osu.Game.Utils; +using osuTK.Graphics; namespace osu.Game { @@ -158,7 +157,7 @@ namespace osu.Game [CanBeNull] private IntroScreen introScreen; - private Bindable configRuleset; + private Bindable configRuleset; private Bindable uiScale; @@ -222,10 +221,13 @@ namespace osu.Game dependencies.Cache(osuLogo = new OsuLogo { Alpha = 0 }); // bind config int to database RulesetInfo - configRuleset = LocalConfig.GetBindable(OsuSetting.Ruleset); + configRuleset = LocalConfig.GetBindable(OsuSetting.Ruleset); uiScale = LocalConfig.GetBindable(OsuSetting.UIScale); - var preferredRuleset = RulesetStore.GetRuleset(configRuleset.Value); + var preferredRuleset = int.TryParse(configRuleset.Value, out int rulesetId) + // int parsing can be removed 20220522 + ? RulesetStore.GetRuleset(rulesetId) + : RulesetStore.GetRuleset(configRuleset.Value); try { @@ -238,7 +240,7 @@ namespace osu.Game Ruleset.Value = RulesetStore.AvailableRulesets.First(); } - Ruleset.ValueChanged += r => configRuleset.Value = r.NewValue.ID ?? 0; + Ruleset.ValueChanged += r => configRuleset.Value = r.NewValue.ShortName; // bind config int to database SkinInfo configSkin = LocalConfig.GetBindable(OsuSetting.Skin); From 361cb7888071da026f7cacdc0486d88e05708598 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 18:37:28 +0900 Subject: [PATCH 3/3] Fix realm applying migrations from one version too early --- osu.Game/Database/RealmContextFactory.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index 42ae986921..0bb46a379a 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -153,13 +153,13 @@ namespace osu.Game.Database private void onMigration(Migration migration, ulong lastSchemaVersion) { - for (ulong i = lastSchemaVersion; i <= schema_version; i++) + for (ulong i = lastSchemaVersion + 1; i <= schema_version; i++) applyMigrationsForVersion(migration, i); } - private void applyMigrationsForVersion(Migration migration, ulong version) + private void applyMigrationsForVersion(Migration migration, ulong targetVersion) { - switch (version) + switch (targetVersion) { case 7: convertOnlineIDs();