2020-01-17 04:27:47 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-01-17 04:27:47 +00:00
|
|
|
using System.Collections.Generic;
|
2021-02-03 10:44:39 +00:00
|
|
|
using MessagePack;
|
2020-01-17 04:27:47 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
2022-08-10 20:09:11 +00:00
|
|
|
using osu.Framework.Localisation;
|
2020-01-17 04:27:47 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Online
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2021-02-03 10:44:39 +00:00
|
|
|
public class TestAPIModMessagePackSerialization
|
2020-01-17 04:27:47 +00:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestAcronymIsPreserved()
|
|
|
|
{
|
|
|
|
var apiMod = new APIMod(new TestMod());
|
|
|
|
|
2021-02-03 10:44:39 +00:00
|
|
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
2020-01-17 04:27:47 +00:00
|
|
|
|
|
|
|
Assert.That(deserialized.Acronym, Is.EqualTo(apiMod.Acronym));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRawSettingIsPreserved()
|
|
|
|
{
|
|
|
|
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
|
|
|
|
2021-02-03 10:44:39 +00:00
|
|
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
2020-01-17 04:27:47 +00:00
|
|
|
|
|
|
|
Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(2.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestConvertedModHasCorrectSetting()
|
|
|
|
{
|
|
|
|
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
|
|
|
|
2021-02-03 10:44:39 +00:00
|
|
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
2020-01-17 04:27:47 +00:00
|
|
|
var converted = (TestMod)deserialized.ToMod(new TestRuleset());
|
|
|
|
|
|
|
|
Assert.That(converted.TestSetting.Value, Is.EqualTo(2));
|
|
|
|
}
|
|
|
|
|
2020-06-26 14:21:44 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseTimeRampMod()
|
|
|
|
{
|
|
|
|
// Create the mod with values different from default.
|
|
|
|
var apiMod = new APIMod(new TestModTimeRamp
|
|
|
|
{
|
|
|
|
AdjustPitch = { Value = false },
|
|
|
|
InitialRate = { Value = 1.25 },
|
|
|
|
FinalRate = { Value = 0.25 }
|
|
|
|
});
|
|
|
|
|
2021-02-03 10:44:39 +00:00
|
|
|
var deserialised = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
2020-06-26 14:21:44 +00:00
|
|
|
var converted = (TestModTimeRamp)deserialised.ToMod(new TestRuleset());
|
|
|
|
|
|
|
|
Assert.That(converted.AdjustPitch.Value, Is.EqualTo(false));
|
|
|
|
Assert.That(converted.InitialRate.Value, Is.EqualTo(1.25));
|
|
|
|
Assert.That(converted.FinalRate.Value, Is.EqualTo(0.25));
|
|
|
|
}
|
|
|
|
|
2021-02-10 14:44:06 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseEnumMod()
|
|
|
|
{
|
|
|
|
var apiMod = new APIMod(new TestModEnum { TestSetting = { Value = TestEnum.Value2 } });
|
|
|
|
|
|
|
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
|
|
|
|
|
|
|
Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(1));
|
|
|
|
}
|
|
|
|
|
2020-01-17 04:27:47 +00:00
|
|
|
private class TestRuleset : Ruleset
|
|
|
|
{
|
2020-06-26 14:21:44 +00:00
|
|
|
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[]
|
|
|
|
{
|
|
|
|
new TestMod(),
|
|
|
|
new TestModTimeRamp(),
|
|
|
|
};
|
2020-01-17 04:27:47 +00:00
|
|
|
|
|
|
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new System.NotImplementedException();
|
|
|
|
|
|
|
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new System.NotImplementedException();
|
|
|
|
|
2021-11-15 09:19:23 +00:00
|
|
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new System.NotImplementedException();
|
2020-01-17 04:27:47 +00:00
|
|
|
|
2020-01-17 09:52:13 +00:00
|
|
|
public override string Description { get; } = string.Empty;
|
|
|
|
public override string ShortName { get; } = string.Empty;
|
2020-01-17 04:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestMod : Mod
|
|
|
|
{
|
|
|
|
public override string Name => "Test Mod";
|
|
|
|
public override string Acronym => "TM";
|
2022-08-10 20:09:11 +00:00
|
|
|
public override LocalisableString Description => "This is a test mod.";
|
2020-01-17 04:27:47 +00:00
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
[SettingSource("Test")]
|
|
|
|
public BindableNumber<double> TestSetting { get; } = new BindableDouble
|
|
|
|
{
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 10,
|
|
|
|
Default = 5,
|
|
|
|
Precision = 0.01,
|
|
|
|
};
|
|
|
|
}
|
2020-06-26 14:21:44 +00:00
|
|
|
|
|
|
|
private class TestModTimeRamp : ModTimeRamp
|
|
|
|
{
|
|
|
|
public override string Name => "Test Mod";
|
|
|
|
public override string Acronym => "TMTR";
|
2022-08-10 20:09:11 +00:00
|
|
|
public override LocalisableString Description => "This is a test mod.";
|
2020-06-26 14:21:44 +00:00
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
[SettingSource("Initial rate", "The starting speed of the track")]
|
2022-09-25 20:02:40 +00:00
|
|
|
public override BindableNumber<double> InitialRate { get; } = new BindableDouble(1.5)
|
2020-06-26 14:21:44 +00:00
|
|
|
{
|
|
|
|
MinValue = 1,
|
|
|
|
MaxValue = 2,
|
|
|
|
Precision = 0.01,
|
|
|
|
};
|
|
|
|
|
|
|
|
[SettingSource("Final rate", "The speed increase to ramp towards")]
|
2022-09-25 20:02:40 +00:00
|
|
|
public override BindableNumber<double> FinalRate { get; } = new BindableDouble(0.5)
|
2020-06-26 14:21:44 +00:00
|
|
|
{
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 1,
|
|
|
|
Precision = 0.01,
|
|
|
|
};
|
|
|
|
|
|
|
|
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
2022-09-25 20:02:40 +00:00
|
|
|
public override BindableBool AdjustPitch { get; } = new BindableBool(true);
|
2020-06-26 14:21:44 +00:00
|
|
|
}
|
2021-02-10 14:44:06 +00:00
|
|
|
|
|
|
|
private class TestModEnum : Mod
|
|
|
|
{
|
|
|
|
public override string Name => "Test Mod";
|
|
|
|
public override string Acronym => "TM";
|
2022-08-10 20:09:11 +00:00
|
|
|
public override LocalisableString Description => "This is a test mod.";
|
2021-02-10 14:44:06 +00:00
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
[SettingSource("Test")]
|
|
|
|
public Bindable<TestEnum> TestSetting { get; } = new Bindable<TestEnum>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum TestEnum
|
|
|
|
{
|
|
|
|
Value1 = 0,
|
|
|
|
Value2 = 1,
|
|
|
|
Value3 = 2
|
|
|
|
}
|
2020-01-17 04:27:47 +00:00
|
|
|
}
|
|
|
|
}
|