Cache ruleset dependencies if the scene tests ruleset-specific components

This commit is contained in:
Salman Ahmed
2020-04-11 04:23:31 +03:00
parent 235d3046c6
commit 2b4208bebf
2 changed files with 32 additions and 1 deletions

View File

@ -20,6 +20,8 @@ using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Testing;
using osu.Game.Rulesets.UI;
using osu.Game.Screens;
using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps;
@ -36,6 +38,8 @@ namespace osu.Game.Tests.Visual
protected new OsuScreenDependencies Dependencies { get; private set; }
private DrawableRulesetDependencies rulesetDependencies;
private Lazy<Storage> localStorage;
protected Storage LocalStorage => localStorage.Value;
@ -64,7 +68,12 @@ namespace osu.Game.Tests.Visual
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
Dependencies = new OsuScreenDependencies(false, base.CreateChildDependencies(parent));
var baseDependencies = base.CreateChildDependencies(parent);
if (this is IRulesetTestScene rts)
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(rts.CreateRuleset(), baseDependencies);
Dependencies = new OsuScreenDependencies(false, baseDependencies);
Beatmap = Dependencies.Beatmap;
Beatmap.SetDefault();
@ -142,6 +151,8 @@ namespace osu.Game.Tests.Visual
{
base.Dispose(isDisposing);
rulesetDependencies?.Dispose();
if (Beatmap?.Value.TrackLoaded == true)
Beatmap.Value.Track.Stop();