Change CheckCompatibleSet to never deselect the current candidat when checking incompatibility

This commit is contained in:
Dean Herbert 2021-06-18 13:17:32 +09:00
parent d238c7ff9c
commit 5933e0d2d9
2 changed files with 31 additions and 2 deletions

View File

@ -21,6 +21,14 @@ namespace osu.Game.Tests.Mods
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object })); Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
} }
[Test]
public void TestModIsCompatibleByItselfWithIncompatibleInterface()
{
var mod = new Mock<CustomMod1>();
mod.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(IModCompatibilitySpecification) });
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
}
[Test] [Test]
public void TestIncompatibleThroughTopLevel() public void TestIncompatibleThroughTopLevel()
{ {
@ -34,6 +42,20 @@ namespace osu.Game.Tests.Mods
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
} }
[Test]
public void TestIncompatibleThroughInterface()
{
var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<CustomMod2>();
mod1.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(IModCompatibilitySpecification) });
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(IModCompatibilitySpecification) });
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
}
[Test] [Test]
public void TestMultiModIncompatibleWithTopLevel() public void TestMultiModIncompatibleWithTopLevel()
{ {
@ -149,11 +171,15 @@ namespace osu.Game.Tests.Mods
Assert.That(invalid.Select(t => t.GetType()), Is.EquivalentTo(expectedInvalid)); Assert.That(invalid.Select(t => t.GetType()), Is.EquivalentTo(expectedInvalid));
} }
public abstract class CustomMod1 : Mod public abstract class CustomMod1 : Mod, IModCompatibilitySpecification
{ {
} }
public abstract class CustomMod2 : Mod public abstract class CustomMod2 : Mod, IModCompatibilitySpecification
{
}
public interface IModCompatibilitySpecification
{ {
} }
} }

View File

@ -60,6 +60,9 @@ namespace osu.Game.Utils
{ {
foreach (var invalid in combination.Where(m => type.IsInstanceOfType(m))) foreach (var invalid in combination.Where(m => type.IsInstanceOfType(m)))
{ {
if (invalid == mod)
continue;
invalidMods ??= new List<Mod>(); invalidMods ??= new List<Mod>();
invalidMods.Add(invalid); invalidMods.Add(invalid);
} }