// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Game.Online.Rooms; using osu.Game.Screens; using osu.Game.Screens.OnlinePlay; namespace osu.Game.Tests.Visual.OnlinePlay { public abstract class OnlinePlaySubScreenTestScene : ScreenTestScene { /// /// The cached . /// protected Room Room { get; private set; } public override void SetUpSteps() { base.SetUpSteps(); AddStep("create dependencies", () => LoadScreen(new DependenciesScreen(CreateScreenDependencies))); } /// /// Creates dependencies for any pushed via . /// Invoked at the start of every test via . /// /// /// This should be overridden to add any custom dependencies required by subclasses of . /// /// The parent dependency container. /// The resultant dependency container. protected virtual IReadOnlyDependencyContainer CreateScreenDependencies(IReadOnlyDependencyContainer parent) { Room = new Room(); var dependencies = new DependencyContainer( new CachedModelDependencyContainer(parent) { Model = { Value = Room } }); dependencies.Cache(new Bindable(Room)); return dependencies; } /// /// A dummy screen used for injecting new dependencies into the hierarchy before any screen is pushed via . /// private class DependenciesScreen : OsuScreen { private readonly Func createDependenciesFunc; public DependenciesScreen(Func createDependenciesFunc) { this.createDependenciesFunc = createDependenciesFunc; } protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => createDependenciesFunc(base.CreateChildDependencies(parent)); } } }