1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 14:12:55 +08:00

Add OnlinePlaySubScreenTestScene

This commit is contained in:
smoogipoo 2021-06-24 17:01:28 +09:00
parent 9287fae5f7
commit a7b5c3bed1
3 changed files with 68 additions and 2 deletions

View File

@ -20,10 +20,11 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestScenePlaylistsSongSelect : RoomTestScene
public class TestScenePlaylistsSongSelect : OnlinePlaySubScreenTestScene
{
[Resolved]
private BeatmapManager beatmapManager { get; set; }

View File

@ -19,12 +19,13 @@ using osu.Game.Screens.OnlinePlay;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Users;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Playlists
{
public class TestScenePlaylistsRoomSubScreen : RoomTestScene
public class TestScenePlaylistsRoomSubScreen : OnlinePlaySubScreenTestScene
{
[Cached(typeof(IRoomManager))]
private readonly TestRoomManager roomManager = new TestRoomManager();

View File

@ -0,0 +1,64 @@
// 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.
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
{
/// <summary>
/// The cached <see cref="Room"/>.
/// </summary>
protected Room Room { get; private set; }
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("create dependencies", () => LoadScreen(new DependenciesScreen(CreateScreenDependencies)));
}
/// <summary>
/// Creates dependencies for any <see cref="OsuScreen"/> pushed via <see cref="ScreenTestScene.LoadScreen"/>.
/// Invoked at the start of every test via <see cref="SetUpSteps"/>.
/// </summary>
/// <remarks>
/// This should be overridden to add any custom dependencies required by subclasses of <see cref="OnlinePlaySubScreen"/>.
/// </remarks>
/// <param name="parent">The parent dependency container.</param>
/// <returns>The resultant dependency container.</returns>
protected virtual IReadOnlyDependencyContainer CreateScreenDependencies(IReadOnlyDependencyContainer parent)
{
Room = new Room();
var dependencies = new DependencyContainer(
new CachedModelDependencyContainer<Room>(parent) { Model = { Value = Room } });
dependencies.Cache(new Bindable<Room>(Room));
return dependencies;
}
/// <summary>
/// A dummy screen used for injecting new dependencies into the hierarchy before any screen is pushed via <see cref="ScreenTestScene.LoadScreen"/>.
/// </summary>
private class DependenciesScreen : OsuScreen
{
private readonly Func<IReadOnlyDependencyContainer, IReadOnlyDependencyContainer> createDependenciesFunc;
public DependenciesScreen(Func<IReadOnlyDependencyContainer, IReadOnlyDependencyContainer> createDependenciesFunc)
{
this.createDependenciesFunc = createDependenciesFunc;
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> createDependenciesFunc(base.CreateChildDependencies(parent));
}
}
}