Fix MultiMod throwing exceptions when creating copies

This commit is contained in:
smoogipoo 2020-10-14 18:12:19 +09:00
parent 010f86ff34
commit f04aec538f
2 changed files with 21 additions and 1 deletions

View File

@ -95,6 +95,24 @@ public void TestModSettingsUnboundWhenCopied()
AddAssert("copy has original value", () => Precision.AlmostEquals(1.5, copy.SpeedChange.Value));
}
[Test]
public void TestMultiModSettingsUnboundWhenCopied()
{
MultiMod original = null;
MultiMod copy = null;
AddStep("create mods", () =>
{
original = new MultiMod(new OsuModDoubleTime());
copy = (MultiMod)original.CreateCopy();
});
AddStep("change property", () => ((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value = 2);
AddAssert("original has new value", () => Precision.AlmostEquals(2.0, ((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value));
AddAssert("copy has original value", () => Precision.AlmostEquals(1.5, ((OsuModDoubleTime)copy.Mods[0]).SpeedChange.Value));
}
private void createModSelect()
{
AddStep("create mod select", () =>

View File

@ -6,7 +6,7 @@
namespace osu.Game.Rulesets.Mods
{
public class MultiMod : Mod
public sealed class MultiMod : Mod
{
public override string Name => string.Empty;
public override string Acronym => string.Empty;
@ -20,6 +20,8 @@ public MultiMod(params Mod[] mods)
Mods = mods;
}
public override Mod CreateCopy() => new MultiMod(Mods.Select(m => m.CreateCopy()).ToArray());
public override Type[] IncompatibleMods => Mods.SelectMany(m => m.IncompatibleMods).ToArray();
}
}