1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 19:12:59 +08:00

Merge pull request #28095 from cdwcgt/preset-td-autoplay

Do not attempt to preserve incompatible system mods when activating mod presets
This commit is contained in:
Bartłomiej Dach 2024-05-06 09:29:08 +02:00 committed by GitHub
commit 3e36412899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View File

@ -123,6 +123,43 @@ namespace osu.Game.Tests.Visual.UserInterface
assertSelectedModsEquivalentTo(new Mod[] { new OsuModTouchDevice(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.5 } } });
}
[Test]
public void TestSystemModsNotPreservedIfIncompatibleWithPresetMods()
{
ModPresetPanel? panel = null;
AddStep("create panel", () => Child = panel = new ModPresetPanel(new ModPreset
{
Name = "Autopilot included",
Description = "no way",
Mods = new Mod[]
{
new OsuModAutopilot()
},
Ruleset = new OsuRuleset().RulesetInfo
}.ToLiveUnmanaged())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f
});
AddStep("Add touch device to selected mods", () => SelectedMods.Value = new Mod[] { new OsuModTouchDevice() });
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
// touch device should be removed due to incompatibility with autopilot.
assertSelectedModsEquivalentTo(new Mod[] { new OsuModAutopilot() });
AddStep("deactivate panel", () => panel.AsNonNull().TriggerClick());
assertSelectedModsEquivalentTo(Array.Empty<Mod>());
// just for test purposes, can't/shouldn't happen in reality
AddStep("Add score v2 to selected mod", () => SelectedMods.Value = new Mod[] { new ModScoreV2() });
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
assertSelectedModsEquivalentTo(new Mod[] { new OsuModAutopilot(), new ModScoreV2() });
}
private void assertSelectedModsEquivalentTo(IEnumerable<Mod> mods)
=> AddAssert("selected mods changed correctly", () => new HashSet<Mod>(SelectedMods.Value).SetEquals(mods));

View File

@ -55,7 +55,12 @@ namespace osu.Game.Overlays.Mods
protected override void Select()
{
var selectedSystemMods = selectedMods.Value.Where(mod => mod.Type == ModType.System);
// this implicitly presumes that if a system mod declares incompatibility with a non-system mod,
// the non-system mod should take precedence.
// if this assumption is ever broken, this should be reconsidered.
var selectedSystemMods = selectedMods.Value.Where(mod => mod.Type == ModType.System &&
!mod.IncompatibleMods.Any(t => Preset.Value.Mods.Any(t.IsInstanceOfType)));
// will also have the side effect of activating the preset (see `updateActiveState()`).
selectedMods.Value = Preset.Value.Mods.Concat(selectedSystemMods).ToArray();
}