osu/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs

136 lines
4.7 KiB
C#
Raw Normal View History

2020-12-21 09:42:31 +00:00
// 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.
2021-05-11 10:01:41 +00:00
using System.Linq;
using NUnit.Framework;
2021-03-03 12:54:34 +00:00
using osu.Framework.Allocation;
2021-05-11 10:01:41 +00:00
using osu.Framework.Audio;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
2021-03-03 12:54:34 +00:00
using osu.Game.Online.Multiplayer;
2021-05-11 10:01:41 +00:00
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.OnlinePlay.Components;
2021-05-11 10:01:41 +00:00
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Resources;
using osu.Game.Users;
using osuTK.Input;
2020-12-21 09:42:31 +00:00
namespace osu.Game.Tests.Visual.Multiplayer
2020-12-21 09:42:31 +00:00
{
2021-03-03 12:54:34 +00:00
public class TestSceneMultiplayer : ScreenTestScene
2020-12-21 09:42:31 +00:00
{
private TestMultiplayer multiplayerScreen;
2021-05-11 10:01:41 +00:00
private BeatmapManager beatmaps;
private RulesetStore rulesets;
private BeatmapSetInfo importedSet;
private TestMultiplayerClient client => multiplayerScreen.Client;
private Room room => client.APIRoom;
2020-12-25 04:38:11 +00:00
public TestSceneMultiplayer()
2021-05-11 10:01:41 +00:00
{
loadMultiplayer();
}
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
}
[Test]
public void TestMatchStartWhileSpectatingWithNoBeatmap()
{
loadMultiplayer();
AddStep("open room", () =>
{
multiplayerScreen.OpenNewRoom(new Room
{
Name = { Value = "Test Room" },
Playlist =
{
new PlaylistItem
{
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo },
}
}
});
});
AddStep("create room", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for join", () => client.Room != null);
AddStep("join other user (ready, host)", () =>
{
client.AddUser(new User { Id = MultiplayerTestScene.PLAYER_1_ID, Username = "Other" });
client.TransferHost(MultiplayerTestScene.PLAYER_1_ID);
client.ChangeUserState(MultiplayerTestScene.PLAYER_1_ID, MultiplayerUserState.Ready);
});
AddStep("change playlist", () =>
{
room.Playlist.Add(new PlaylistItem
{
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo },
});
});
AddStep("click spectate button", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerSpectateButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("start match externally", () => client.StartMatch());
AddAssert("screen not changed", () => multiplayerScreen.IsCurrentScreen());
}
private void loadMultiplayer()
2020-12-21 09:42:31 +00:00
{
AddStep("show", () =>
{
multiplayerScreen = new TestMultiplayer();
// Needs to be added at a higher level since the multiplayer screen becomes non-current.
Child = multiplayerScreen.Client;
LoadScreen(multiplayerScreen);
});
2020-12-21 09:42:31 +00:00
AddUntilStep("wait for loaded", () => multiplayerScreen.IsLoaded);
2020-12-21 09:42:31 +00:00
}
2021-03-03 12:54:34 +00:00
private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer
2020-12-23 20:00:47 +00:00
{
2021-03-03 12:54:34 +00:00
[Cached(typeof(StatefulMultiplayerClient))]
public readonly TestMultiplayerClient Client;
2020-12-23 20:00:47 +00:00
2021-03-03 12:54:34 +00:00
public TestMultiplayer()
{
Client = new TestMultiplayerClient((TestMultiplayerRoomManager)RoomManager);
2021-03-03 12:54:34 +00:00
}
2020-12-23 20:00:47 +00:00
2020-12-25 04:38:11 +00:00
protected override RoomManager CreateRoomManager() => new TestMultiplayerRoomManager();
2020-12-21 09:42:31 +00:00
}
}
}