2021-10-29 04:56:07 +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.
2022-06-17 07:37:17 +00:00
#nullable disable
2021-10-29 04:56:07 +00:00
using System.Linq ;
using NUnit.Framework ;
using osu.Framework.Allocation ;
using osu.Framework.Audio ;
2022-01-03 08:02:15 +00:00
using osu.Framework.Extensions ;
2021-10-29 04:56:07 +00:00
using osu.Framework.Platform ;
2021-10-29 06:44:48 +00:00
using osu.Framework.Screens ;
2021-10-29 04:56:07 +00:00
using osu.Framework.Testing ;
using osu.Game.Beatmaps ;
2021-10-29 06:44:48 +00:00
using osu.Game.Online.Multiplayer ;
2021-10-29 04:56:07 +00:00
using osu.Game.Online.Rooms ;
using osu.Game.Rulesets ;
using osu.Game.Rulesets.Osu ;
2023-01-28 21:24:05 +00:00
using osu.Game.Screens.OnlinePlay ;
2021-10-29 04:56:07 +00:00
using osu.Game.Screens.OnlinePlay.Lounge ;
using osu.Game.Screens.OnlinePlay.Multiplayer ;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match ;
2021-10-29 06:44:48 +00:00
using osu.Game.Screens.Play ;
using osu.Game.Tests.Resources ;
2021-10-29 04:56:07 +00:00
2021-11-19 06:43:11 +00:00
namespace osu.Game.Tests.Visual.Multiplayer
2021-10-29 04:56:07 +00:00
{
public abstract partial class QueueModeTestScene : ScreenTestScene
{
2021-11-16 05:53:10 +00:00
protected abstract QueueMode Mode { get ; }
2021-10-29 04:56:07 +00:00
2021-10-29 06:44:48 +00:00
protected BeatmapInfo InitialBeatmap { get ; private set ; }
protected BeatmapInfo OtherBeatmap { get ; private set ; }
2021-12-20 09:24:59 +00:00
protected IScreen CurrentScreen = > multiplayerComponents . CurrentScreen ;
protected IScreen CurrentSubScreen = > multiplayerComponents . MultiplayerScreen . CurrentSubScreen ;
2021-10-29 06:44:48 +00:00
2021-10-29 04:56:07 +00:00
private BeatmapManager beatmaps ;
2021-10-29 06:44:48 +00:00
private BeatmapSetInfo importedSet ;
2021-10-29 04:56:07 +00:00
2021-12-20 09:24:59 +00:00
private TestMultiplayerComponents multiplayerComponents ;
2021-10-29 04:56:07 +00:00
2022-02-16 00:43:28 +00:00
protected TestMultiplayerClient MultiplayerClient = > multiplayerComponents . MultiplayerClient ;
2021-10-29 04:56:07 +00:00
[BackgroundDependencyLoader]
private void load ( GameHost host , AudioManager audio )
{
2022-07-28 07:19:05 +00:00
Dependencies . Cache ( new RealmRulesetStore ( Realm ) ) ;
Dependencies . Cache ( beatmaps = new BeatmapManager ( LocalStorage , Realm , null , audio , Resources , host , Beatmap . Default ) ) ;
2022-01-25 03:58:15 +00:00
Dependencies . Cache ( Realm ) ;
2021-10-29 04:56:07 +00:00
}
public override void SetUpSteps ( )
{
base . SetUpSteps ( ) ;
AddStep ( "import beatmap" , ( ) = >
{
2022-01-03 08:02:15 +00:00
beatmaps . Import ( TestResources . GetQuickTestBeatmapForImport ( ) ) . WaitSafely ( ) ;
2021-12-17 09:26:12 +00:00
importedSet = beatmaps . GetAllUsableBeatmapSets ( ) . First ( ) ;
2022-01-27 06:19:48 +00:00
InitialBeatmap = importedSet . Beatmaps . First ( b = > b . Ruleset . OnlineID = = 0 ) ;
OtherBeatmap = importedSet . Beatmaps . Last ( b = > b . Ruleset . OnlineID = = 0 ) ;
2021-10-29 04:56:07 +00:00
} ) ;
2021-12-20 09:24:59 +00:00
AddStep ( "load multiplayer" , ( ) = > LoadScreen ( multiplayerComponents = new TestMultiplayerComponents ( ) ) ) ;
AddUntilStep ( "wait for multiplayer to load" , ( ) = > multiplayerComponents . IsLoaded ) ;
2021-10-29 04:56:07 +00:00
AddUntilStep ( "wait for lounge to load" , ( ) = > this . ChildrenOfType < MultiplayerLoungeSubScreen > ( ) . FirstOrDefault ( ) ? . IsLoaded = = true ) ;
2021-12-20 09:24:59 +00:00
AddUntilStep ( "wait for lounge" , ( ) = > multiplayerComponents . ChildrenOfType < LoungeSubScreen > ( ) . SingleOrDefault ( ) ? . IsLoaded = = true ) ;
AddStep ( "open room" , ( ) = > multiplayerComponents . ChildrenOfType < LoungeSubScreen > ( ) . Single ( ) . Open ( new Room
2021-10-29 04:56:07 +00:00
{
Name = { Value = "Test Room" } ,
QueueMode = { Value = Mode } ,
Playlist =
{
2022-02-15 14:33:26 +00:00
new PlaylistItem ( InitialBeatmap )
2021-10-29 04:56:07 +00:00
{
2022-02-15 07:01:14 +00:00
RulesetID = new OsuRuleset ( ) . RulesetInfo . OnlineID
2021-10-29 04:56:07 +00:00
}
}
} ) ) ;
AddUntilStep ( "wait for room open" , ( ) = > this . ChildrenOfType < MultiplayerMatchSubScreen > ( ) . FirstOrDefault ( ) ? . IsLoaded = = true ) ;
AddWaitStep ( "wait for transition" , 2 ) ;
2021-12-21 04:20:12 +00:00
ClickButtonWhenEnabled < MultiplayerMatchSettingsOverlay . CreateOrUpdateButton > ( ) ;
2021-10-29 04:56:07 +00:00
2022-02-16 00:43:28 +00:00
AddUntilStep ( "wait for join" , ( ) = > MultiplayerClient . RoomJoined ) ;
2023-01-28 21:24:05 +00:00
AddUntilStep ( "wait for ongoing operation to complete" , ( ) = > ! ( CurrentScreen as OnlinePlayScreen ) . ChildrenOfType < OngoingOperationTracker > ( ) . Single ( ) . InProgress . Value ) ;
2021-10-29 04:56:07 +00:00
}
[Test]
public void TestCreatedWithCorrectMode ( )
{
2022-07-01 10:46:46 +00:00
AddUntilStep ( "room created with correct mode" , ( ) = > MultiplayerClient . ClientAPIRoom ? . QueueMode . Value = = Mode ) ;
2021-10-29 06:44:48 +00:00
}
protected void RunGameplay ( )
{
2022-02-16 00:43:28 +00:00
AddUntilStep ( "wait for idle" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Idle ) ;
2021-12-21 04:20:12 +00:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
2021-10-29 06:44:48 +00:00
2022-02-16 00:43:28 +00:00
AddUntilStep ( "wait for ready" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Ready ) ;
2021-12-21 04:20:12 +00:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
2021-11-23 08:09:38 +00:00
2021-12-20 09:24:59 +00:00
AddUntilStep ( "wait for player" , ( ) = > multiplayerComponents . CurrentScreen is Player player & & player . IsLoaded ) ;
AddStep ( "exit player" , ( ) = > multiplayerComponents . MultiplayerScreen . MakeCurrent ( ) ) ;
2021-11-23 08:09:38 +00:00
}
2021-10-29 04:56:07 +00:00
}
}