1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 03:22:55 +08:00

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

@ -0,0 +1,20 @@
// 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.
namespace osu.Game.Rulesets.Testing
{
/// <summary>
/// An interface that can be assigned to test scenes to indicate
/// that the test scene is testing ruleset-specific components.
/// This is to cache required ruleset dependencies for the components.
/// </summary>
public interface IRulesetTestScene
{
/// <summary>
/// Retrieves the ruleset that is going
/// to be tested by this test scene.
/// </summary>
/// <returns>The <see cref="Ruleset"/>.</returns>
Ruleset CreateRuleset();
}
}

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();