2021-11-01 17:52:57 +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.
2021-11-01 18:25:47 +08:00
using System ;
2022-01-08 21:46:41 +08:00
using System.Collections.Generic ;
2021-11-01 18:25:47 +08:00
using System.Linq ;
using NUnit.Framework ;
2022-01-08 21:46:41 +08:00
using osu.Framework.Extensions.ObjectExtensions ;
2022-01-08 21:16:05 +08:00
using osu.Framework.Screens ;
2021-11-01 18:25:47 +08:00
using osu.Framework.Testing ;
using osu.Game.Beatmaps ;
2021-11-19 13:46:53 +08:00
using osu.Game.Online.Multiplayer ;
2022-01-08 21:16:05 +08:00
using osu.Game.Rulesets ;
using osu.Game.Rulesets.Catch ;
2022-01-08 21:46:41 +08:00
using osu.Game.Rulesets.Mods ;
2022-01-08 21:16:05 +08:00
using osu.Game.Rulesets.Osu ;
2022-01-08 21:46:41 +08:00
using osu.Game.Rulesets.Osu.Mods ;
2022-06-30 16:42:44 +08:00
using osu.Game.Screens.OnlinePlay ;
2021-11-01 18:25:47 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer ;
2022-01-08 21:16:05 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer.Match ;
using osu.Game.Screens.Play ;
2021-11-01 18:25:47 +08:00
using osuTK.Input ;
2021-11-01 17:52:57 +08:00
2021-11-19 14:43:11 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
2021-11-01 17:52:57 +08:00
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneAllPlayersQueueMode : QueueModeTestScene
2021-11-01 17:52:57 +08:00
{
2021-11-19 17:28:43 +08:00
protected override QueueMode Mode = > QueueMode . AllPlayers ;
2021-11-01 18:25:47 +08:00
[Test]
public void TestFirstItemSelectedByDefault ( )
{
2022-07-01 17:58:22 +08:00
AddUntilStep ( "first item selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . ID ) ;
2021-11-01 18:25:47 +08:00
}
[Test]
public void TestItemAddedToTheEndOfQueue ( )
{
addItem ( ( ) = > OtherBeatmap ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist has 2 items" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 2 ) ;
2021-11-01 18:25:47 +08:00
addItem ( ( ) = > InitialBeatmap ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist has 3 items" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 3 ) ;
2021-11-01 18:25:47 +08:00
2022-07-01 17:58:22 +08:00
AddUntilStep ( "first item still selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . ID ) ;
2021-11-01 18:25:47 +08:00
}
[Test]
public void TestSingleItemExpiredAfterGameplay ( )
{
RunGameplay ( ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist has only one item" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 1 ) ;
AddUntilStep ( "playlist item is expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . Expired = = true ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "last item selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . ID ) ;
2021-11-01 18:25:47 +08:00
}
[Test]
public void TestNextItemSelectedAfterGameplayFinish ( )
{
addItem ( ( ) = > OtherBeatmap ) ;
addItem ( ( ) = > InitialBeatmap ) ;
RunGameplay ( ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "first item expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . Expired = = true ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "next item selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . ID ) ;
2021-11-01 18:25:47 +08:00
RunGameplay ( ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "second item expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . Expired = = true ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "next item selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 2 ] . ID ) ;
2021-11-01 18:25:47 +08:00
}
[Test]
2021-11-22 10:20:18 +08:00
public void TestItemsNotClearedWhenSwitchToHostOnlyMode ( )
2021-11-01 18:25:47 +08:00
{
addItem ( ( ) = > OtherBeatmap ) ;
addItem ( ( ) = > InitialBeatmap ) ;
// Move to the "other" beatmap.
RunGameplay ( ) ;
2022-02-16 08:43:28 +08:00
AddStep ( "change queue mode" , ( ) = > MultiplayerClient . ChangeSettings ( queueMode : QueueMode . HostOnly ) ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist has 3 items" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 3 ) ;
AddUntilStep ( "item 2 is not expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . Expired = = false ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "current item is the other beatmap" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = 2 ) ;
2021-11-01 18:25:47 +08:00
}
2021-11-24 18:53:21 +08:00
[Test]
public void TestCorrectItemSelectedAfterNewItemAdded ( )
{
addItem ( ( ) = > OtherBeatmap ) ;
2021-12-11 21:52:06 +08:00
AddUntilStep ( "selected beatmap is initial beatmap" , ( ) = > Beatmap . Value . BeatmapInfo . OnlineID = = InitialBeatmap . OnlineID ) ;
2021-11-24 18:53:21 +08:00
}
2022-01-08 21:16:05 +08:00
[Test]
public void TestCorrectRulesetSelectedAfterNewItemAdded ( )
{
addItem ( ( ) = > OtherBeatmap , new CatchRuleset ( ) . RulesetInfo ) ;
AddUntilStep ( "selected beatmap is initial beatmap" , ( ) = > Beatmap . Value . BeatmapInfo . OnlineID = = InitialBeatmap . OnlineID ) ;
2022-02-16 08:43:28 +08:00
AddUntilStep ( "wait for idle" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Idle ) ;
2022-01-08 21:16:05 +08:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
2022-02-16 08:43:28 +08:00
AddUntilStep ( "wait for ready" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Ready ) ;
2022-01-08 21:16:05 +08:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
AddUntilStep ( "wait for player" , ( ) = > CurrentScreen is Player player & & player . IsLoaded ) ;
AddAssert ( "ruleset is correct" , ( ) = > ( ( Player ) CurrentScreen ) . Ruleset . Value . Equals ( new OsuRuleset ( ) . RulesetInfo ) ) ;
AddStep ( "exit player" , ( ) = > CurrentScreen . Exit ( ) ) ;
}
2022-01-08 21:46:41 +08:00
[Test]
public void TestCorrectModsSelectedAfterNewItemAdded ( )
2021-11-01 18:25:47 +08:00
{
2022-01-08 21:46:41 +08:00
addItem ( ( ) = > OtherBeatmap , mods : new Mod [ ] { new OsuModDoubleTime ( ) } ) ;
AddUntilStep ( "selected beatmap is initial beatmap" , ( ) = > Beatmap . Value . BeatmapInfo . OnlineID = = InitialBeatmap . OnlineID ) ;
2022-02-16 08:43:28 +08:00
AddUntilStep ( "wait for idle" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Idle ) ;
2022-01-08 21:46:41 +08:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
2022-02-16 08:43:28 +08:00
AddUntilStep ( "wait for ready" , ( ) = > MultiplayerClient . LocalUser ? . State = = MultiplayerUserState . Ready ) ;
2022-01-08 21:46:41 +08:00
ClickButtonWhenEnabled < MultiplayerReadyButton > ( ) ;
AddUntilStep ( "wait for player" , ( ) = > CurrentScreen is Player player & & player . IsLoaded ) ;
AddAssert ( "mods are correct" , ( ) = > ! ( ( Player ) CurrentScreen ) . Mods . Value . Any ( ) ) ;
AddStep ( "exit player" , ( ) = > CurrentScreen . Exit ( ) ) ;
}
private void addItem ( Func < BeatmapInfo > beatmap , RulesetInfo ? ruleset = null , IReadOnlyList < Mod > ? mods = null )
{
Screens . Select . SongSelect ? songSelect = null ;
2021-12-10 00:15:15 +08:00
AddStep ( "click add button" , ( ) = >
2021-11-01 18:25:47 +08:00
{
2021-12-10 00:15:15 +08:00
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerMatchSubScreen . AddItemButton > ( ) . Single ( ) ) ;
2021-11-01 18:25:47 +08:00
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2022-01-08 21:46:41 +08:00
AddUntilStep ( "wait for song select" , ( ) = > ( songSelect = CurrentSubScreen as Screens . Select . SongSelect ) ! = null ) ;
AddUntilStep ( "wait for loaded" , ( ) = > songSelect . AsNonNull ( ) . BeatmapSetsLoaded ) ;
2022-06-30 16:58:43 +08:00
AddUntilStep ( "wait for ongoing operation to complete" , ( ) = > ! ( CurrentScreen as OnlinePlayScreen ) . ChildrenOfType < OngoingOperationTracker > ( ) . Single ( ) . InProgress . Value ) ;
2022-01-08 21:16:05 +08:00
if ( ruleset ! = null )
2022-01-08 21:46:41 +08:00
AddStep ( $"set {ruleset.Name} ruleset" , ( ) = > songSelect . AsNonNull ( ) . Ruleset . Value = ruleset ) ;
if ( mods ! = null )
AddStep ( $"set mods to {string.Join(" , ", mods.Select(m => m.Acronym))}" , ( ) = > songSelect . AsNonNull ( ) . Mods . Value = mods ) ;
2022-01-08 21:16:05 +08:00
2022-01-08 21:46:41 +08:00
AddStep ( "select other beatmap" , ( ) = > songSelect . AsNonNull ( ) . FinaliseSelection ( beatmap ( ) ) ) ;
2021-11-01 18:25:47 +08:00
AddUntilStep ( "wait for return to match" , ( ) = > CurrentSubScreen is MultiplayerMatchSubScreen ) ;
}
2021-11-01 17:52:57 +08:00
}
}