From ff13a980770b8ac162eb6663b80556e07c2679e6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 15:23:16 +0900 Subject: [PATCH 01/10] Reformat realm migrations list for legibility --- osu.Game/Database/RealmContextFactory.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index 42ae986921..e235effc64 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -33,10 +33,10 @@ namespace osu.Game.Database /// /// Version history: - /// 6 First tracked version (~20211018) - /// 7 Changed OnlineID fields to non-nullable to add indexing support (20211018) - /// 8 Rebind scroll adjust keys to not have control modifier (20211029) - /// 9 Converted BeatmapMetadata.Author from string to RealmUser (20211104) + /// 6 ~2021-10-18 First tracked version. + /// 7 2021-10-18 Changed OnlineID fields to non-nullable to add indexing support. + /// 8 2021-10-29 Rebind scroll adjust keys to not have control modifier. + /// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser. /// private const int schema_version = 9; From 1cdfa6d9a098fd2db3725227c43bc64395fb1689 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 15:30:11 +0900 Subject: [PATCH 02/10] Add helper property to access a realm beatmap's beatmap file --- .../Database/BeatmapImporterTests.cs | 18 ++++++++++++++++++ osu.Game/Models/RealmBeatmap.cs | 3 +++ 2 files changed, 21 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 75eb4a043a..71e5e9081c 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -74,6 +74,24 @@ namespace osu.Game.Tests.Database }); } + [Test] + public void TestAccessFileAfterImport() + { + RunTestWithRealmAsync(async (realmFactory, storage) => + { + using var importer = new BeatmapImporter(realmFactory, storage); + using var store = new RealmRulesetStore(realmFactory, storage); + + var imported = await LoadOszIntoStore(importer, realmFactory.Context); + + var beatmap = imported.Beatmaps.First(); + var file = beatmap.File; + + Assert.NotNull(file); + Assert.AreEqual(beatmap.Hash, file!.File.Hash); + }); + } + [Test] public void TestImportThenDelete() { diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index 1a25d55d04..d190eb0c3b 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using JetBrains.Annotations; using Newtonsoft.Json; using osu.Framework.Testing; @@ -35,6 +36,8 @@ namespace osu.Game.Models public RealmBeatmapSet? BeatmapSet { get; set; } + public RealmNamedFileUsage? File => BeatmapSet?.Files.First(f => f.File.Hash == Hash); + public BeatmapSetOnlineStatus Status { get => (BeatmapSetOnlineStatus)StatusInt; From b9923e53969e3a2ebd267de46086f5c1a7cada7a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 16:39:17 +0900 Subject: [PATCH 03/10] Remove subclassing of `RulesetInfo` --- .../Gameplay/TestSceneReplayRecorder.cs | 4 +- .../Gameplay/TestSceneReplayRecording.cs | 4 +- .../Gameplay/TestSceneSpectatorPlayback.cs | 4 +- .../UserInterface/TestSceneModSettings.cs | 48 +++++++--------- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 57 +++++++++---------- 5 files changed, 52 insertions(+), 65 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs index 159d583fc0..dcc193669b 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs @@ -55,7 +55,7 @@ namespace osu.Game.Tests.Visual.Gameplay { new Drawable[] { - recordingManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Recorder = recorder = new TestReplayRecorder(new Score { @@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Gameplay }, new Drawable[] { - playbackManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { ReplayInputHandler = new TestFramedReplayInputHandler(replay) { diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecording.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecording.cs index 1d4245308d..3f7155f1e2 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecording.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecording.cs @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Gameplay { new Drawable[] { - recordingManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Recorder = new TestReplayRecorder(new Score { @@ -80,7 +80,7 @@ namespace osu.Game.Tests.Visual.Gameplay }, new Drawable[] { - playbackManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { ReplayInputHandler = new TestFramedReplayInputHandler(replay) { diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs index ef870a32a9..5fbccd54c8 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs @@ -109,7 +109,7 @@ namespace osu.Game.Tests.Visual.Gameplay { new Drawable[] { - recordingManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Recorder = recorder = new TestReplayRecorder { @@ -139,7 +139,7 @@ namespace osu.Game.Tests.Visual.Gameplay }, new Drawable[] { - playbackManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Clock = new FramedClock(manualClock), ReplayInputHandler = replayHandler = new TestFramedReplayInputHandler(replay) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs index 4bb5e29589..9a3083e8db 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs @@ -35,7 +35,7 @@ namespace osu.Game.Tests.Visual.UserInterface public void SetUp() => Schedule(() => { SelectedMods.Value = Array.Empty(); - Ruleset.Value = new TestRulesetInfo(); + Ruleset.Value = CreateTestRulesetInfo(); }); [Test] @@ -170,40 +170,32 @@ namespace osu.Game.Tests.Visual.UserInterface ModSettingsContainer.Parent.Width = newWidth; } - public class TestRulesetInfo : RulesetInfo + public static RulesetInfo CreateTestRulesetInfo() => new TestCustomisableModRuleset().RulesetInfo; + + public class TestCustomisableModRuleset : Ruleset { - public override Ruleset CreateInstance() => new TestCustomisableModRuleset(); - - public TestRulesetInfo() + public override IEnumerable GetModsFor(ModType type) { - Available = true; - } - - public class TestCustomisableModRuleset : Ruleset - { - public override IEnumerable GetModsFor(ModType type) + if (type == ModType.Conversion) { - if (type == ModType.Conversion) + return new Mod[] { - return new Mod[] - { - new TestModCustomisable1(), - new TestModCustomisable2() - }; - } - - return Array.Empty(); + new TestModCustomisable1(), + new TestModCustomisable2() + }; } - public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) => throw new NotImplementedException(); - - public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException(); - - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); - - public override string Description { get; } = "test"; - public override string ShortName { get; } = "tst"; + return Array.Empty(); } + + public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) => throw new NotImplementedException(); + + public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException(); + + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); + + public override string Description { get; } = "test"; + public override string ShortName { get; } = "tst"; } private class TestModCustomisable1 : TestModCustomisable diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index fcb44c462d..9ea8517764 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -38,7 +38,7 @@ namespace osu.Game.Beatmaps CircleSize = 0, OverallDifficulty = 0, }, - Ruleset = new DummyRulesetInfo() + Ruleset = new DummyRuleset().RulesetInfo }, audio) { this.textures = textures; @@ -54,42 +54,37 @@ namespace osu.Game.Beatmaps public override Stream GetStream(string storagePath) => null; - private class DummyRulesetInfo : RulesetInfo + private class DummyRuleset : Ruleset { - public override Ruleset CreateInstance() => new DummyRuleset(); + public override IEnumerable GetModsFor(ModType type) => Array.Empty(); - private class DummyRuleset : Ruleset + public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) { - public override IEnumerable GetModsFor(ModType type) => Array.Empty(); + throw new NotImplementedException(); + } - public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) + public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new DummyBeatmapConverter { Beatmap = beatmap }; + + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null; + + public override string Description => "dummy"; + + public override string ShortName => "dummy"; + + private class DummyBeatmapConverter : IBeatmapConverter + { + public event Action> ObjectConverted; + + public IBeatmap Beatmap { get; set; } + + public bool CanConvert() => true; + + public IBeatmap Convert(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + foreach (var obj in Beatmap.HitObjects) + ObjectConverted?.Invoke(obj, obj.Yield()); - public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new DummyBeatmapConverter { Beatmap = beatmap }; - - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null; - - public override string Description => "dummy"; - - public override string ShortName => "dummy"; - - private class DummyBeatmapConverter : IBeatmapConverter - { - public event Action> ObjectConverted; - - public IBeatmap Beatmap { get; set; } - - public bool CanConvert() => true; - - public IBeatmap Convert(CancellationToken cancellationToken = default) - { - foreach (var obj in Beatmap.HitObjects) - ObjectConverted?.Invoke(obj, obj.Yield()); - - return Beatmap; - } + return Beatmap; } } } From cb5b6911e6d3263e01f11f49258214cf256f705b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 16:39:26 +0900 Subject: [PATCH 04/10] Seal `RulesetInfo` and remove `virtual` methods --- osu.Game/Rulesets/RulesetInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 8083041a3b..ccb614fe91 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -10,7 +10,7 @@ using osu.Framework.Testing; namespace osu.Game.Rulesets { [ExcludeFromDynamicCompile] - public class RulesetInfo : IEquatable, IRulesetInfo + public sealed class RulesetInfo : IEquatable, IRulesetInfo { public int? ID { get; set; } @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets public bool Available { get; set; } // TODO: this should probably be moved to RulesetStore. - public virtual Ruleset CreateInstance() + public Ruleset CreateInstance() { if (!Available) return null; From a8bc1ab052dbc75aa9461cf65545d228b8706a95 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 16:45:55 +0900 Subject: [PATCH 05/10] Attempt to fix fody issues by ignoring new property --- osu.Game/Models/RealmBeatmap.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index d190eb0c3b..4e3f96ee5f 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -36,6 +36,7 @@ namespace osu.Game.Models public RealmBeatmapSet? BeatmapSet { get; set; } + [Ignored] public RealmNamedFileUsage? File => BeatmapSet?.Files.First(f => f.File.Hash == Hash); public BeatmapSetOnlineStatus Status From 377ba2673aa1f6869e7bca74de95df2e99717365 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 16:52:54 +0900 Subject: [PATCH 06/10] Use `Ruleset`'s `ShortName` for mod caching purposes --- osu.Game/Rulesets/Ruleset.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index ade763eed8..a252bd4786 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -39,7 +39,7 @@ namespace osu.Game.Rulesets { public RulesetInfo RulesetInfo { get; internal set; } - private static readonly ConcurrentDictionary mod_reference_cache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary mod_reference_cache = new ConcurrentDictionary(); /// /// A queryable source containing all available mods. @@ -49,11 +49,8 @@ namespace osu.Game.Rulesets { get { - if (!(RulesetInfo.ID is int id)) - return CreateAllMods(); - - if (!mod_reference_cache.TryGetValue(id, out var mods)) - mod_reference_cache[id] = mods = CreateAllMods().Cast().ToArray(); + if (!mod_reference_cache.TryGetValue(ShortName, out var mods)) + mod_reference_cache[ShortName] = mods = CreateAllMods().Cast().ToArray(); return mods; } From 001f7c36f36fe8151d422d45de86d7328acfaa72 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 17:15:26 +0900 Subject: [PATCH 07/10] 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 08/10] 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 6c36770eb388fe80f079b6001e7f4899bc1f20c9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 21:41:09 +0900 Subject: [PATCH 09/10] Add back allowance for tests scenes using empty `ShortName` --- osu.Game/Rulesets/Ruleset.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index a252bd4786..31ebcfd600 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -49,6 +49,10 @@ namespace osu.Game.Rulesets { get { + // Is the case for many test usages. + if (string.IsNullOrEmpty(ShortName)) + return CreateAllMods(); + if (!mod_reference_cache.TryGetValue(ShortName, out var mods)) mod_reference_cache[ShortName] = mods = CreateAllMods().Cast().ToArray(); From feb983d5bdb876ef9f0ac61a7985ab38f2b1b4ce Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Nov 2021 13:09:41 +0900 Subject: [PATCH 10/10] Rename `Debug` namespace to avoid collisions --- osu.Game/Overlays/Settings/Sections/DebugSection.cs | 2 +- .../Sections/{Debug => DebugSettings}/GeneralSettings.cs | 2 +- .../Sections/{Debug => DebugSettings}/MemorySettings.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename osu.Game/Overlays/Settings/Sections/{Debug => DebugSettings}/GeneralSettings.cs (96%) rename osu.Game/Overlays/Settings/Sections/{Debug => DebugSettings}/MemorySettings.cs (93%) diff --git a/osu.Game/Overlays/Settings/Sections/DebugSection.cs b/osu.Game/Overlays/Settings/Sections/DebugSection.cs index aa85ec920c..2e23d8a22a 100644 --- a/osu.Game/Overlays/Settings/Sections/DebugSection.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSection.cs @@ -5,7 +5,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; using osu.Game.Localisation; -using osu.Game.Overlays.Settings.Sections.Debug; +using osu.Game.Overlays.Settings.Sections.DebugSettings; namespace osu.Game.Overlays.Settings.Sections { diff --git a/osu.Game/Overlays/Settings/Sections/Debug/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs similarity index 96% rename from osu.Game/Overlays/Settings/Sections/Debug/GeneralSettings.cs rename to osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs index 25e20911b8..60540a089e 100644 --- a/osu.Game/Overlays/Settings/Sections/Debug/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs @@ -9,7 +9,7 @@ using osu.Framework.Screens; using osu.Game.Localisation; using osu.Game.Screens.Import; -namespace osu.Game.Overlays.Settings.Sections.Debug +namespace osu.Game.Overlays.Settings.Sections.DebugSettings { public class GeneralSettings : SettingsSubsection { diff --git a/osu.Game/Overlays/Settings/Sections/Debug/MemorySettings.cs b/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs similarity index 93% rename from osu.Game/Overlays/Settings/Sections/Debug/MemorySettings.cs rename to osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs index 07fb0aca5a..6f48768dcd 100644 --- a/osu.Game/Overlays/Settings/Sections/Debug/MemorySettings.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs @@ -8,7 +8,7 @@ using osu.Framework.Localisation; using osu.Framework.Platform; using osu.Game.Localisation; -namespace osu.Game.Overlays.Settings.Sections.Debug +namespace osu.Game.Overlays.Settings.Sections.DebugSettings { public class MemorySettings : SettingsSubsection {