2022-05-11 04:07:24 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
2023-02-24 22:11:22 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Configuration;
|
2022-05-11 04:07:24 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Mods
|
|
|
|
{
|
|
|
|
public class ModSettingsTest
|
|
|
|
{
|
|
|
|
[Test]
|
2023-03-10 03:14:58 +08:00
|
|
|
public void TestModSettingsUnboundWhenCloned()
|
2022-05-11 04:07:24 +08:00
|
|
|
{
|
|
|
|
var original = new OsuModDoubleTime();
|
|
|
|
var copy = (OsuModDoubleTime)original.DeepClone();
|
|
|
|
|
|
|
|
original.SpeedChange.Value = 2;
|
|
|
|
|
|
|
|
Assert.That(original.SpeedChange.Value, Is.EqualTo(2.0));
|
|
|
|
Assert.That(copy.SpeedChange.Value, Is.EqualTo(1.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-10 03:14:58 +08:00
|
|
|
public void TestMultiModSettingsUnboundWhenCloned()
|
2022-05-11 04:07:24 +08:00
|
|
|
{
|
|
|
|
var original = new MultiMod(new OsuModDoubleTime());
|
|
|
|
var copy = (MultiMod)original.DeepClone();
|
|
|
|
|
|
|
|
((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value = 2;
|
|
|
|
|
|
|
|
Assert.That(((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value, Is.EqualTo(2.0));
|
|
|
|
Assert.That(((OsuModDoubleTime)copy.Mods[0]).SpeedChange.Value, Is.EqualTo(1.5));
|
|
|
|
}
|
2023-02-24 22:11:22 +08:00
|
|
|
|
|
|
|
[Test]
|
2023-03-08 03:38:33 +08:00
|
|
|
public void TestDifferentTypeSettingsKeptWhenCopied()
|
2023-02-24 22:11:22 +08:00
|
|
|
{
|
2023-03-08 03:38:33 +08:00
|
|
|
const double setting_change = 50.4;
|
2023-02-24 22:11:22 +08:00
|
|
|
|
2023-03-12 06:29:36 +08:00
|
|
|
var modDouble = new TestNonMatchingSettingTypeModDouble { TestSetting = { Value = setting_change } };
|
|
|
|
var modBool = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = false, Value = true } };
|
2023-04-26 03:05:40 +08:00
|
|
|
var modInt = new TestNonMatchingSettingTypeModInt { TestSetting = { Value = (int)setting_change / 2 } };
|
2023-02-24 22:11:22 +08:00
|
|
|
|
2023-05-05 00:15:12 +08:00
|
|
|
modDouble.CopyCommonSettingsFrom(modBool);
|
|
|
|
modDouble.CopyCommonSettingsFrom(modInt);
|
|
|
|
modBool.CopyCommonSettingsFrom(modDouble);
|
|
|
|
modBool.CopyCommonSettingsFrom(modInt);
|
|
|
|
modInt.CopyCommonSettingsFrom(modDouble);
|
|
|
|
modInt.CopyCommonSettingsFrom(modBool);
|
2023-02-24 22:11:22 +08:00
|
|
|
|
2023-03-08 03:38:33 +08:00
|
|
|
Assert.That(modDouble.TestSetting.Value, Is.EqualTo(setting_change));
|
2023-05-05 01:14:20 +08:00
|
|
|
Assert.That(modBool.TestSetting.Value, Is.EqualTo(true));
|
2023-04-26 03:05:40 +08:00
|
|
|
Assert.That(modInt.TestSetting.Value, Is.EqualTo((int)setting_change / 2));
|
2023-02-24 22:11:22 +08:00
|
|
|
}
|
|
|
|
|
2023-03-10 03:14:58 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDefaultValueKeptWhenCopied()
|
|
|
|
{
|
|
|
|
var modBoolTrue = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = true, Value = false } };
|
|
|
|
var modBoolFalse = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = false, Value = true } };
|
|
|
|
|
2023-05-05 00:15:12 +08:00
|
|
|
modBoolFalse.CopyCommonSettingsFrom(modBoolTrue);
|
2023-03-10 03:14:58 +08:00
|
|
|
|
|
|
|
Assert.That(modBoolFalse.TestSetting.Default, Is.EqualTo(false));
|
|
|
|
Assert.That(modBoolFalse.TestSetting.Value, Is.EqualTo(modBoolTrue.TestSetting.Value));
|
|
|
|
}
|
|
|
|
|
2023-03-08 03:38:33 +08:00
|
|
|
private class TestNonMatchingSettingTypeModDouble : TestNonMatchingSettingTypeMod
|
|
|
|
{
|
|
|
|
public override string Acronym => "NMD";
|
|
|
|
public override BindableNumber<double> TestSetting { get; } = new BindableDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestNonMatchingSettingTypeModInt : TestNonMatchingSettingTypeMod
|
2023-02-24 22:11:22 +08:00
|
|
|
{
|
2023-03-08 03:38:33 +08:00
|
|
|
public override string Acronym => "NMI";
|
|
|
|
public override BindableNumber<int> TestSetting { get; } = new BindableInt();
|
2023-02-24 22:11:22 +08:00
|
|
|
}
|
|
|
|
|
2023-03-08 03:38:33 +08:00
|
|
|
private class TestNonMatchingSettingTypeModBool : TestNonMatchingSettingTypeMod
|
2023-02-24 22:11:22 +08:00
|
|
|
{
|
2023-03-08 03:38:33 +08:00
|
|
|
public override string Acronym => "NMB";
|
|
|
|
public override Bindable<bool> TestSetting { get; } = new BindableBool();
|
2023-02-24 22:11:22 +08:00
|
|
|
}
|
|
|
|
|
2023-03-08 03:38:33 +08:00
|
|
|
private abstract class TestNonMatchingSettingTypeMod : Mod
|
2023-02-24 22:11:22 +08:00
|
|
|
{
|
|
|
|
public override string Name => "Non-matching setting type mod";
|
|
|
|
public override LocalisableString Description => "Description";
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
public override ModType Type => ModType.Conversion;
|
|
|
|
|
|
|
|
[SettingSource("Test setting")]
|
|
|
|
public abstract IBindable TestSetting { get; }
|
|
|
|
}
|
2022-05-11 04:07:24 +08:00
|
|
|
}
|
|
|
|
}
|