From 2408011c81882b71f49d5dda9d1ae98976d2058d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 29 Oct 2021 16:44:39 +0900 Subject: [PATCH] Don't replace identical playlist items --- .../TestSceneHostOnlyQueueingMode.cs | 18 +++++++++++++++--- .../Online/Multiplayer/MultiplayerClient.cs | 9 +++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneHostOnlyQueueingMode.cs b/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneHostOnlyQueueingMode.cs index ada04abc5a..59baccf181 100644 --- a/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneHostOnlyQueueingMode.cs +++ b/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneHostOnlyQueueingMode.cs @@ -17,9 +17,19 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes protected override QueueModes Mode => QueueModes.HostOnly; [Test] - public void TestItemStillSelectedAfterChange() + public void TestItemStillSelectedAfterChangeToSameBeatmap() + { + selectNewItem(() => InitialBeatmap); + + AddAssert("playlist item still selected", () => Client.CurrentMatchPlayingItem.Value == Client.APIRoom?.Playlist[0]); + } + + [Test] + public void TestItemStillSelectedAfterChangeToOtherBeatmap() { selectNewItem(() => OtherBeatmap); + + AddAssert("playlist item still selected", () => Client.CurrentMatchPlayingItem.Value == Client.APIRoom?.Playlist[0]); } [Test] @@ -57,9 +67,11 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes AddUntilStep("wait for song select", () => CurrentSubScreen is Screens.Select.SongSelect select && select.IsLoaded); - AddStep("select other beatmap", () => ((Screens.Select.SongSelect)CurrentSubScreen).FinaliseSelection(beatmap())); + BeatmapInfo otherBeatmap = null; + AddStep("select other beatmap", () => ((Screens.Select.SongSelect)CurrentSubScreen).FinaliseSelection(otherBeatmap = beatmap())); + AddUntilStep("wait for return to match", () => CurrentSubScreen is MultiplayerMatchSubScreen); - AddUntilStep("selected item is new beatmap", () => Client.CurrentMatchPlayingItem.Value?.Beatmap.Value?.OnlineID == OtherBeatmap.OnlineID); + AddUntilStep("selected item is new beatmap", () => Client.CurrentMatchPlayingItem.Value?.Beatmap.Value?.OnlineID == otherBeatmap.OnlineID); } } } diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs index cdf6684112..d3e1a7c91a 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -623,11 +623,16 @@ namespace osu.Game.Online.Multiplayer Debug.Assert(APIRoom != null); int index = APIRoom.Playlist.Select((i, index) => (i, index)).Single(kvp => kvp.i.ID == item.ID).index; + var oldItem = APIRoom.Playlist[index]; + if (oldItem.Equals(playlistItem)) + return; + + // Replace the item. APIRoom.Playlist.RemoveAt(index); APIRoom.Playlist.Insert(index, playlistItem); - // If the current item changed, update the selected playlist item. - if (item.ID == Room.Settings.PlaylistItemId) + // If the currently-selected item was the one that got replaced, update the selected item to the new one. + if (CurrentMatchPlayingItem.Value == oldItem) CurrentMatchPlayingItem.Value = APIRoom.Playlist[index]; }).ConfigureAwait(false); }