Skip to content

Commit

Permalink
Fix global mods being retained by rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Sep 4, 2020
1 parent ebed7d0 commit 4399f59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 22 additions & 0 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ public void TestNewItemHasNewModInstances()
AddAssert("item 2 has rate 2", () => Precision.AlmostEquals(2, ((OsuModDoubleTime)Room.Playlist.Last().RequiredMods[0]).SpeedChange.Value));
}

/// <summary>
/// Tests that the global mod instances are not retained by the rooms, as global mod instances are retained and re-used by the mod select overlay.
/// </summary>
[Test]
public void TestGlobalModInstancesNotRetained()
{
OsuModDoubleTime mod = null;

AddStep("set dt mod and store", () =>
{
SelectedMods.Value = new[] { new OsuModDoubleTime() };

// Mod select overlay replaces our mod.
mod = (OsuModDoubleTime)SelectedMods.Value[0];
});

AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem());

AddStep("change stored mod rate", () => mod.SpeedChange.Value = 2);
AddAssert("item has rate 1.5", () => Precision.AlmostEquals(1.5, ((OsuModDoubleTime)Room.Playlist.First().RequiredMods[0]).SpeedChange.Value));
}

private class TestMatchSongSelect : MatchSongSelect
{
public new MatchBeatmapDetailArea BeatmapDetails => (MatchBeatmapDetailArea)base.BeatmapDetails;
Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Screens/Select/MatchSongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ private void populateItemFromCurrent(PlaylistItem item)
item.Ruleset.Value = Ruleset.Value;

item.RequiredMods.Clear();
item.RequiredMods.AddRange(Mods.Value);

Mods.Value = Mods.Value.Select(m => m.CreateCopy()).ToArray();
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
}
}
}

0 comments on commit 4399f59

Please sign in to comment.