From c429c74d8984bc17001ad93d0521b0b662b4ff6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 23 Dec 2021 19:34:41 +0100 Subject: [PATCH] Expose and use test ruleset config cache in test scenes --- .../Editor/TestSceneEditor.cs | 4 ++-- .../TestSceneTimingBasedNoteColouring.cs | 6 +----- .../TestSceneSliderSnaking.cs | 4 ++-- osu.Game/Tests/Visual/OsuTestScene.cs | 12 +++++++++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneEditor.cs b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneEditor.cs index f186537875..5300747633 100644 --- a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneEditor.cs +++ b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneEditor.cs @@ -25,9 +25,9 @@ public TestSceneEditor() } [BackgroundDependencyLoader] - private void load(IRulesetConfigCache configCache) + private void load() { - var config = (ManiaRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); + var config = (ManiaRulesetConfigManager)RulesetConfigs.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); config.BindWith(ManiaRulesetSetting.ScrollDirection, direction); } } diff --git a/osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs b/osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs index 94b199c5d5..4c688520ef 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs @@ -4,7 +4,6 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; -using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -25,9 +24,6 @@ namespace osu.Game.Rulesets.Mania.Tests [TestFixture] public class TestSceneTimingBasedNoteColouring : OsuTestScene { - [Resolved] - private IRulesetConfigCache configCache { get; set; } - private Bindable configTimingBasedNoteColouring; private ManualClock clock; @@ -49,7 +45,7 @@ public void SetUpSteps() }); AddStep("retrieve config bindable", () => { - var config = (ManiaRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); + var config = (ManiaRulesetConfigManager)RulesetConfigs.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); configTimingBasedNoteColouring = config.GetBindable(ManiaRulesetSetting.TimingBasedNoteColouring); }); } diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneSliderSnaking.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneSliderSnaking.cs index 23d2d650bf..a3aa84d0e7 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestSceneSliderSnaking.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneSliderSnaking.cs @@ -47,9 +47,9 @@ protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storybo => new ClockBackedTestWorkingBeatmap(this.beatmap = beatmap, storyboard, new FramedClock(new ManualClock { Rate = 1 }), audioManager); [BackgroundDependencyLoader] - private void load(IRulesetConfigCache configCache) + private void load() { - var config = (OsuRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); + var config = (OsuRulesetConfigManager)RulesetConfigs.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull(); config.BindWith(OsuRulesetSetting.SnakingInSliders, snakingIn); config.BindWith(OsuRulesetSetting.SnakingOutSliders, snakingOut); } diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index df8c9f22db..6b029729ea 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -95,6 +95,16 @@ protected IAPIProvider API /// protected Storage LocalStorage => localStorage.Value; + /// + /// A cache for ruleset configurations to be used in this test scene. + /// + /// + /// This instance is provided to the children of this test scene via DI. + /// It is only exposed so that test scenes themselves can access the ruleset config cache in a safe manner + /// (s cannot use DI themselves, as they will end up accessing the real cached instance from ). + /// + protected IRulesetConfigCache RulesetConfigs { get; private set; } + private Lazy localStorage; private Storage headlessHostStorage; @@ -124,7 +134,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl // as well as problems due to the implementation details of the "real" implementation (the configs only being available at `LoadComplete()`), // cache a test implementation of the ruleset config cache over the "real" one. var isolatedBaseDependencies = new DependencyContainer(baseDependencies); - isolatedBaseDependencies.CacheAs(new TestRulesetConfigCache()); + isolatedBaseDependencies.CacheAs(RulesetConfigs = new TestRulesetConfigCache()); baseDependencies = isolatedBaseDependencies; var providedRuleset = CreateRuleset();