2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-03-01 16:51:04 +00:00
|
|
|
|
using System;
|
2018-03-01 17:02:09 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-03-01 16:51:04 +00:00
|
|
|
|
using NUnit.Framework;
|
2020-01-09 04:43:44 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2018-06-15 11:48:36 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
2018-03-01 16:51:04 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-01 16:51:04 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Tests
|
|
|
|
|
{
|
2018-06-13 14:43:58 +00:00
|
|
|
|
[TestFixture]
|
2018-06-15 11:48:36 +00:00
|
|
|
|
public class ManiaBeatmapConversionTest : BeatmapConversionTest<ManiaConvertMapping, ConvertValue>
|
2018-03-01 16:51:04 +00:00
|
|
|
|
{
|
2023-12-07 03:25:23 +00:00
|
|
|
|
protected override string ResourceAssembly => "osu.Game.Rulesets.Mania.Tests";
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-05-07 04:28:01 +00:00
|
|
|
|
[TestCase("basic")]
|
2020-09-07 08:18:40 +00:00
|
|
|
|
[TestCase("zero-length-slider")]
|
2023-12-07 03:25:23 +00:00
|
|
|
|
[TestCase("20544")]
|
|
|
|
|
[TestCase("100374")]
|
2023-12-09 06:39:54 +00:00
|
|
|
|
[TestCase("1450162")]
|
2019-08-05 08:02:28 +00:00
|
|
|
|
public void Test(string name) => base.Test(name);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-01 17:02:09 +00:00
|
|
|
|
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
|
2018-03-01 16:51:04 +00:00
|
|
|
|
{
|
2018-03-01 17:02:09 +00:00
|
|
|
|
yield return new ConvertValue
|
|
|
|
|
{
|
|
|
|
|
StartTime = hitObject.StartTime,
|
2019-11-25 10:01:24 +00:00
|
|
|
|
EndTime = hitObject.GetEndTime(),
|
2018-03-01 17:02:09 +00:00
|
|
|
|
Column = ((ManiaHitObject)hitObject).Column
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-31 10:48:50 +00:00
|
|
|
|
private readonly Dictionary<HitObject, RngSnapshot> rngSnapshots = new Dictionary<HitObject, RngSnapshot>();
|
|
|
|
|
|
|
|
|
|
protected override void OnConversionGenerated(HitObject original, IEnumerable<HitObject> result, IBeatmapConverter beatmapConverter)
|
|
|
|
|
{
|
|
|
|
|
base.OnConversionGenerated(original, result, beatmapConverter);
|
|
|
|
|
|
|
|
|
|
rngSnapshots[original] = new RngSnapshot(beatmapConverter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override ManiaConvertMapping CreateConvertMapping(HitObject source) => new ManiaConvertMapping(rngSnapshots[source]);
|
2018-06-15 11:48:36 +00:00
|
|
|
|
|
2018-05-16 04:09:48 +00:00
|
|
|
|
protected override Ruleset CreateRuleset() => new ManiaRuleset();
|
2018-03-01 16:51:04 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-31 10:48:50 +00:00
|
|
|
|
public class RngSnapshot
|
|
|
|
|
{
|
|
|
|
|
public readonly uint RandomW;
|
|
|
|
|
public readonly uint RandomX;
|
|
|
|
|
public readonly uint RandomY;
|
|
|
|
|
public readonly uint RandomZ;
|
|
|
|
|
|
|
|
|
|
public RngSnapshot(IBeatmapConverter converter)
|
|
|
|
|
{
|
|
|
|
|
var maniaConverter = (ManiaBeatmapConverter)converter;
|
|
|
|
|
RandomW = maniaConverter.Random.W;
|
|
|
|
|
RandomX = maniaConverter.Random.X;
|
|
|
|
|
RandomY = maniaConverter.Random.Y;
|
|
|
|
|
RandomZ = maniaConverter.Random.Z;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public class ManiaConvertMapping : ConvertMapping<ConvertValue>, IEquatable<ManiaConvertMapping>
|
|
|
|
|
{
|
|
|
|
|
public uint RandomW;
|
|
|
|
|
public uint RandomX;
|
|
|
|
|
public uint RandomY;
|
|
|
|
|
public uint RandomZ;
|
2018-06-15 11:48:36 +00:00
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public ManiaConvertMapping()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-06-15 11:48:36 +00:00
|
|
|
|
|
2019-07-31 10:48:50 +00:00
|
|
|
|
public ManiaConvertMapping(RngSnapshot snapshot)
|
2019-02-28 04:31:40 +00:00
|
|
|
|
{
|
2019-07-31 10:48:50 +00:00
|
|
|
|
RandomW = snapshot.RandomW;
|
|
|
|
|
RandomX = snapshot.RandomX;
|
|
|
|
|
RandomY = snapshot.RandomY;
|
|
|
|
|
RandomZ = snapshot.RandomZ;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
}
|
2018-06-15 11:48:36 +00:00
|
|
|
|
|
2020-10-09 11:12:17 +00:00
|
|
|
|
public override void PostProcess()
|
|
|
|
|
{
|
|
|
|
|
base.PostProcess();
|
|
|
|
|
Objects.Sort();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public bool Equals(ManiaConvertMapping other) => other != null && RandomW == other.RandomW && RandomX == other.RandomX && RandomY == other.RandomY && RandomZ == other.RandomZ;
|
|
|
|
|
public override bool Equals(ConvertMapping<ConvertValue> other) => base.Equals(other) && Equals(other as ManiaConvertMapping);
|
|
|
|
|
}
|
2018-06-15 11:48:36 +00:00
|
|
|
|
|
2020-10-09 11:12:17 +00:00
|
|
|
|
public struct ConvertValue : IEquatable<ConvertValue>, IComparable<ConvertValue>
|
2018-03-01 16:51:04 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A sane value to account for osu!stable using ints everwhere.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float conversion_lenience = 2;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-01 16:51:04 +00:00
|
|
|
|
public double StartTime;
|
|
|
|
|
public double EndTime;
|
|
|
|
|
public int Column;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-01 16:51:04 +00:00
|
|
|
|
public bool Equals(ConvertValue other)
|
2018-03-02 09:20:12 +00:00
|
|
|
|
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
|
2018-03-01 16:51:04 +00:00
|
|
|
|
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
|
|
|
|
|
&& Column == other.Column;
|
2020-10-09 11:12:17 +00:00
|
|
|
|
|
|
|
|
|
public int CompareTo(ConvertValue other)
|
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
int result = StartTime.CompareTo(other.StartTime);
|
2020-10-09 11:12:17 +00:00
|
|
|
|
|
|
|
|
|
if (result != 0)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
return Column.CompareTo(other.Column);
|
|
|
|
|
}
|
2018-03-01 16:51:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|