1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 08:22:56 +08:00
osu-lazer/osu.Game.Rulesets.Mania.Tests/ManiaBeatmapConversionTest.cs

123 lines
4.1 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using System;
using System.Collections.Generic;
using NUnit.Framework;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Rulesets.Mania.Tests
{
[TestFixture]
2020-09-07 16:18:54 +08:00
[Timeout(10000)]
public class ManiaBeatmapConversionTest : BeatmapConversionTest<ManiaConvertMapping, ConvertValue>
2018-04-13 17:19:50 +08:00
{
protected override string ResourceAssembly => "osu.Game.Rulesets.Mania";
2018-05-07 12:28:01 +08:00
[TestCase("basic")]
2020-09-07 16:18:40 +08:00
[TestCase("zero-length-slider")]
2019-08-05 16:02:28 +08:00
public void Test(string name) => base.Test(name);
2018-04-13 17:19:50 +08:00
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
{
yield return new ConvertValue
{
StartTime = hitObject.StartTime,
EndTime = hitObject.GetEndTime(),
2018-04-13 17:19:50 +08:00
Column = ((ManiaHitObject)hitObject).Column
};
}
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]);
protected override Ruleset CreateRuleset() => new ManiaRuleset();
2018-04-13 17:19:50 +08: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 12:31:40 +08:00
public class ManiaConvertMapping : ConvertMapping<ConvertValue>, IEquatable<ManiaConvertMapping>
{
public uint RandomW;
public uint RandomX;
public uint RandomY;
public uint RandomZ;
2019-02-28 12:31:40 +08:00
public ManiaConvertMapping()
{
}
public ManiaConvertMapping(RngSnapshot snapshot)
2019-02-28 12:31:40 +08:00
{
RandomW = snapshot.RandomW;
RandomX = snapshot.RandomX;
RandomY = snapshot.RandomY;
RandomZ = snapshot.RandomZ;
2019-02-28 12:31:40 +08:00
}
public override void PostProcess()
{
base.PostProcess();
Objects.Sort();
}
2019-02-28 12:31:40 +08: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);
}
public struct ConvertValue : IEquatable<ConvertValue>, IComparable<ConvertValue>
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// A sane value to account for osu!stable using ints everwhere.
/// </summary>
private const float conversion_lenience = 2;
public double StartTime;
public double EndTime;
public int Column;
public bool Equals(ConvertValue other)
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
&& Column == other.Column;
public int CompareTo(ConvertValue other)
{
int result = StartTime.CompareTo(other.StartTime);
if (result != 0)
return result;
return Column.CompareTo(other.Column);
}
2018-04-13 17:19:50 +08:00
}
}