2021-10-29 12:56:07 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-10-29 14:44:48 +08:00
using System ;
using System.Linq ;
using NUnit.Framework ;
2022-02-15 01:35:08 +08:00
using osu.Framework.Extensions ;
2021-10-29 14:44:48 +08:00
using osu.Framework.Testing ;
using osu.Game.Beatmaps ;
2021-11-19 13:46:53 +08:00
using osu.Game.Online.Multiplayer ;
2021-12-10 00:15:15 +08:00
using osu.Game.Screens.OnlinePlay ;
2021-10-29 14:44:48 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer ;
2021-12-12 15:11:48 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist ;
2021-10-29 14:44:48 +08:00
using osuTK.Input ;
2021-10-29 12:56:07 +08:00
2021-11-19 14:43:11 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
2021-10-29 12:56:07 +08:00
{
2021-10-29 15:45:30 +08:00
public class TestSceneHostOnlyQueueMode : QueueModeTestScene
2021-10-29 12:56:07 +08:00
{
2021-11-16 13:53:10 +08:00
protected override QueueMode Mode = > QueueMode . HostOnly ;
2021-10-29 14:44:48 +08:00
2021-11-01 17:55:42 +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 17:55:42 +08:00
}
2021-10-29 14:44:48 +08:00
[Test]
2021-10-29 15:44:39 +08:00
public void TestItemStillSelectedAfterChangeToSameBeatmap ( )
{
selectNewItem ( ( ) = > InitialBeatmap ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "playlist item still selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . ID ) ;
2021-10-29 15:44:39 +08:00
}
[Test]
public void TestItemStillSelectedAfterChangeToOtherBeatmap ( )
2021-10-29 14:44:48 +08:00
{
selectNewItem ( ( ) = > OtherBeatmap ) ;
2021-10-29 15:44:39 +08:00
2022-07-01 17:58:22 +08:00
AddUntilStep ( "playlist item still selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . ID ) ;
2021-10-29 14:44:48 +08:00
}
[Test]
public void TestNewItemCreatedAfterGameplayFinished ( )
{
RunGameplay ( ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist contains two items" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 2 ) ;
AddUntilStep ( "first playlist item expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 0 ] . Expired = = true ) ;
AddUntilStep ( "second playlist item not expired" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . Expired = = false ) ;
2022-07-01 17:58:22 +08:00
AddUntilStep ( "second playlist item selected" , ( ) = > MultiplayerClient . ClientRoom ? . Settings . PlaylistItemId = = MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . ID ) ;
2021-10-29 14:44:48 +08:00
}
[Test]
public void TestOnlyLastItemChangedAfterGameplayFinished ( )
{
RunGameplay ( ) ;
2021-11-05 14:57:32 +08:00
IBeatmapInfo firstBeatmap = null ;
2022-07-01 18:46:46 +08:00
AddStep ( "get first playlist item beatmap" , ( ) = > firstBeatmap = MultiplayerClient . ServerAPIRoom ? . Playlist [ 0 ] . Beatmap ) ;
2021-10-29 14:44:48 +08:00
selectNewItem ( ( ) = > OtherBeatmap ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "first playlist item hasn't changed" , ( ) = > MultiplayerClient . ServerAPIRoom ? . Playlist [ 0 ] . Beatmap = = firstBeatmap ) ;
AddUntilStep ( "second playlist item changed" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist [ 1 ] . Beatmap ! = firstBeatmap ) ;
2021-10-29 14:44:48 +08:00
}
2021-11-22 12:46:01 +08:00
[Test]
public void TestSettingsUpdatedWhenChangingQueueMode ( )
{
2022-02-16 08:43:28 +08:00
AddStep ( "change queue mode" , ( ) = > MultiplayerClient . ChangeSettings ( new MultiplayerRoomSettings
2021-11-22 12:46:01 +08:00
{
QueueMode = QueueMode . AllPlayers
2022-02-15 01:35:08 +08:00
} ) . WaitSafely ( ) ) ;
2021-11-22 12:46:01 +08:00
2022-07-01 17:04:29 +08:00
AddUntilStep ( "api room updated" , ( ) = > MultiplayerClient . ClientAPIRoom ? . QueueMode . Value = = QueueMode . AllPlayers ) ;
2021-11-22 12:46:01 +08:00
}
2021-12-10 00:15:15 +08:00
[Test]
public void TestAddItemsAsHost ( )
{
addItem ( ( ) = > OtherBeatmap ) ;
2022-07-01 18:46:46 +08:00
AddUntilStep ( "playlist contains two items" , ( ) = > MultiplayerClient . ClientAPIRoom ? . Playlist . Count = = 2 ) ;
2021-12-10 00:15:15 +08:00
}
2021-10-29 14:44:48 +08:00
private void selectNewItem ( Func < BeatmapInfo > beatmap )
{
2021-12-12 15:11:48 +08:00
AddUntilStep ( "wait for playlist panels to load" , ( ) = >
{
var queueList = this . ChildrenOfType < MultiplayerQueueList > ( ) . Single ( ) ;
return queueList . ChildrenOfType < DrawableRoomPlaylistItem > ( ) . Count ( ) = = queueList . Items . Count ;
} ) ;
2021-10-29 14:44:48 +08:00
AddStep ( "click edit button" , ( ) = >
{
2021-12-10 00:15:15 +08:00
InputManager . MoveMouseTo ( this . ChildrenOfType < DrawableRoomPlaylistItem . PlaylistEditButton > ( ) . First ( ) ) ;
2021-10-29 14:44:48 +08:00
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2021-11-25 20:11:13 +08:00
AddUntilStep ( "wait for song select" , ( ) = > CurrentSubScreen is Screens . Select . SongSelect select & & select . BeatmapSetsLoaded ) ;
2021-10-29 14:44:48 +08:00
2021-10-29 15:44:39 +08:00
BeatmapInfo otherBeatmap = null ;
2022-06-30 16:42:44 +08:00
AddUntilStep ( "wait for ongoing operation to complete" , ( ) = > ! ( CurrentScreen as OnlinePlayScreen ) . ChildrenOfType < OngoingOperationTracker > ( ) . Single ( ) . InProgress . Value ) ;
2021-10-29 15:44:39 +08:00
AddStep ( "select other beatmap" , ( ) = > ( ( Screens . Select . SongSelect ) CurrentSubScreen ) . FinaliseSelection ( otherBeatmap = beatmap ( ) ) ) ;
2021-10-29 14:44:48 +08:00
AddUntilStep ( "wait for return to match" , ( ) = > CurrentSubScreen is MultiplayerMatchSubScreen ) ;
2022-02-15 22:33:26 +08:00
AddUntilStep ( "selected item is new beatmap" , ( ) = > ( CurrentSubScreen as MultiplayerMatchSubScreen ) ? . SelectedItem . Value ? . Beatmap . OnlineID = = otherBeatmap . OnlineID ) ;
2021-10-29 14:44:48 +08:00
}
2021-12-10 00:15:15 +08:00
private void addItem ( Func < BeatmapInfo > beatmap )
{
AddStep ( "click add button" , ( ) = >
{
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerMatchSubScreen . AddItemButton > ( ) . Single ( ) ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
AddUntilStep ( "wait for song select" , ( ) = > CurrentSubScreen is Screens . Select . SongSelect select & & select . BeatmapSetsLoaded ) ;
2022-06-30 16:42:44 +08:00
AddUntilStep ( "wait for ongoing operation to complete" , ( ) = > ! ( CurrentScreen as OnlinePlayScreen ) . ChildrenOfType < OngoingOperationTracker > ( ) . Single ( ) . InProgress . Value ) ;
2021-12-10 00:15:15 +08:00
AddStep ( "select other beatmap" , ( ) = > ( ( Screens . Select . SongSelect ) CurrentSubScreen ) . FinaliseSelection ( beatmap ( ) ) ) ;
AddUntilStep ( "wait for return to match" , ( ) = > CurrentSubScreen is MultiplayerMatchSubScreen ) ;
}
2021-10-29 12:56:07 +08:00
}
}