1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

187 lines
7.9 KiB
C#
Raw Normal View History

2021-08-02 17:31:56 +08: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.
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions;
2021-08-02 17:31:56 +08:00
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
2021-11-11 15:39:59 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
2021-08-02 17:31:56 +08:00
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
2021-08-05 19:52:40 +08:00
using osu.Game.Screens.OnlinePlay.Lounge;
2021-08-02 17:31:56 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
2021-08-02 17:31:56 +08:00
using osu.Game.Tests.Resources;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneTeamVersus : ScreenTestScene
{
2024-11-13 15:55:18 +08:00
private BeatmapManager beatmaps = null!;
private BeatmapSetInfo importedSet = null!;
2021-08-02 17:31:56 +08:00
2024-11-13 15:55:18 +08:00
private TestMultiplayerComponents multiplayerComponents = null!;
private TestMultiplayerClient multiplayerClient => multiplayerComponents.MultiplayerClient;
2021-08-02 17:31:56 +08:00
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(new RealmRulesetStore(Realm));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(Realm);
2021-08-02 17:31:56 +08:00
}
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("import beatmap", () =>
{
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
2021-12-17 17:26:12 +08:00
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
2021-08-02 17:31:56 +08:00
});
AddStep("load multiplayer", () => LoadScreen(multiplayerComponents = new TestMultiplayerComponents()));
AddUntilStep("wait for multiplayer to load", () => multiplayerComponents.IsLoaded);
2021-08-02 17:31:56 +08:00
AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true);
}
[Test]
public void TestCreateWithType()
{
createRoom(() => new Room
{
2024-11-13 15:55:18 +08:00
Name = "Test Room",
2024-11-13 17:36:47 +08:00
Type = MatchType.TeamVersus,
Playlist =
2024-11-14 16:57:32 +08:00
[
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
}
2024-11-14 16:57:32 +08:00
]
});
AddUntilStep("room type is team vs", () => multiplayerClient.ClientRoom?.Settings.MatchType == MatchType.TeamVersus);
AddUntilStep("user state arrived", () => multiplayerClient.ClientRoom?.Users.FirstOrDefault()?.MatchState is TeamVersusUserState);
}
[Test]
public void TestChangeTeamsViaButton()
{
createRoom(() => new Room
{
2024-11-13 15:55:18 +08:00
Name = "Test Room",
2024-11-13 17:36:47 +08:00
Type = MatchType.TeamVersus,
Playlist =
2024-11-14 16:57:32 +08:00
[
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
}
2024-11-14 16:57:32 +08:00
]
});
AddUntilStep("user on team 0", () => (multiplayerClient.ClientRoom?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
AddStep("add another user", () => multiplayerClient.AddUser(new APIUser { Username = "otheruser", Id = 44 }));
2021-11-11 15:39:59 +08:00
AddStep("press own button", () =>
{
InputManager.MoveMouseTo(multiplayerComponents.ChildrenOfType<TeamDisplay>().First());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("user on team 1", () => (multiplayerClient.ClientRoom?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 1);
2021-11-11 15:39:59 +08:00
AddStep("press own button again", () => InputManager.Click(MouseButton.Left));
AddUntilStep("user on team 0", () => (multiplayerClient.ClientRoom?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
2021-11-11 15:39:59 +08:00
AddStep("press other user's button", () =>
{
InputManager.MoveMouseTo(multiplayerComponents.ChildrenOfType<TeamDisplay>().ElementAt(1));
2021-11-11 15:39:59 +08:00
InputManager.Click(MouseButton.Left);
});
AddUntilStep("user still on team 0", () => (multiplayerClient.ClientRoom?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
}
[Test]
public void TestSettingsUpdatedWhenChangingMatchType()
{
createRoom(() => new Room
{
2024-11-13 15:55:18 +08:00
Name = "Test Room",
2024-11-13 17:36:47 +08:00
Type = MatchType.HeadToHead,
Playlist =
2024-11-14 16:57:32 +08:00
[
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
}
2024-11-14 16:57:32 +08:00
]
});
2024-11-13 17:36:47 +08:00
AddUntilStep("match type head to head", () => multiplayerClient.ClientAPIRoom?.Type == MatchType.HeadToHead);
AddStep("change match type", () => multiplayerClient.ChangeSettings(new MultiplayerRoomSettings
{
MatchType = MatchType.TeamVersus
}).WaitSafely());
2024-11-13 17:36:47 +08:00
AddUntilStep("api room updated to team versus", () => multiplayerClient.ClientAPIRoom?.Type == MatchType.TeamVersus);
}
2021-08-02 17:31:56 +08:00
[Test]
public void TestChangeTypeViaMatchSettings()
{
createRoom(() => new Room
{
2024-11-13 15:55:18 +08:00
Name = "Test Room",
2021-08-02 17:31:56 +08:00
Playlist =
2024-11-14 16:57:32 +08:00
[
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
2021-08-02 17:31:56 +08:00
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
2021-08-02 17:31:56 +08:00
}
2024-11-14 16:57:32 +08:00
]
2021-08-02 17:31:56 +08:00
});
AddUntilStep("room type is head to head", () => multiplayerClient.ClientRoom?.Settings.MatchType == MatchType.HeadToHead);
2021-08-02 17:31:56 +08:00
AddUntilStep("team displays are not displaying teams", () => multiplayerComponents.ChildrenOfType<TeamDisplay>().All(d => d.DisplayedTeam == null));
AddStep("change to team vs", () => multiplayerClient.ChangeSettings(matchType: MatchType.TeamVersus));
2021-08-02 17:31:56 +08:00
AddUntilStep("room type is team vs", () => multiplayerClient.ClientRoom?.Settings.MatchType == MatchType.TeamVersus);
AddUntilStep("team displays are displaying teams", () => multiplayerComponents.ChildrenOfType<TeamDisplay>().All(d => d.DisplayedTeam != null));
2021-08-02 17:31:56 +08:00
}
private void createRoom(Func<Room> room)
{
AddStep("open room", () => multiplayerComponents.ChildrenOfType<LoungeSubScreen>().Single().Open(room()));
2021-08-02 17:31:56 +08:00
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddWaitStep("wait for transition", 2);
AddUntilStep("create room button enabled", () => this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single().Enabled.Value);
2021-08-02 17:31:56 +08:00
AddStep("create room", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for join", () => multiplayerClient.RoomJoined);
2021-08-02 17:31:56 +08:00
}
}
}