osu/osu.Game.Rulesets.Osu.Tests/OsuBeatmapConversionTest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
3.4 KiB
C#
Raw Permalink 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 09:19:50 +00:00
using System;
using System.Collections.Generic;
using NUnit.Framework;
2020-01-09 04:43:44 +00:00
using osu.Framework.Utils;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class OsuBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
{
protected override string ResourceAssembly => "osu.Game.Rulesets.Osu.Tests";
2018-04-13 09:19:50 +00:00
[TestCase("basic")]
2018-03-02 09:30:31 +00:00
[TestCase("colinear-perfect-curve")]
2018-06-13 16:28:28 +00:00
[TestCase("slider-ticks")]
[TestCase("slider-ticks-edge-case")]
2023-09-18 16:02:20 +00:00
[TestCase("slider-paths-edge-case")]
2019-08-01 08:31:08 +00:00
[TestCase("repeat-slider")]
[TestCase("uneven-repeat-slider")]
[TestCase("old-stacking")]
2021-04-05 08:47:12 +00:00
[TestCase("multi-segment-slider")]
[TestCase("nan-slider")]
[TestCase("1124896")]
public void Test(string name) => base.Test(name);
2018-04-13 09:19:50 +00:00
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
{
switch (hitObject)
{
case Slider slider:
foreach (var nested in slider.NestedHitObjects)
yield return createConvertValue((OsuHitObject)nested, slider);
2019-02-28 04:31:40 +00:00
break;
2019-04-01 03:44:46 +00:00
default:
yield return createConvertValue((OsuHitObject)hitObject);
2019-02-28 04:31:40 +00:00
break;
}
2018-04-13 09:19:50 +00:00
2023-10-16 11:35:24 +00:00
static ConvertValue createConvertValue(OsuHitObject obj, OsuHitObject? parent = null)
{
2023-10-16 11:35:24 +00:00
double startTime = obj.StartTime;
double endTime = obj.GetEndTime();
// this is locally bringing back the stable treatment of the "legacy last tick"
// just to make sure that the conversion output matches.
// compare: `SliderEventGenerator.Generate()`, and the calculation of `legacyLastTickTime`.
2023-10-16 11:35:24 +00:00
if (obj is SliderTailCircle && parent is Slider slider)
{
startTime = Math.Max(startTime + SliderEventGenerator.TAIL_LENIENCY, slider.StartTime + slider.Duration / 2);
endTime = Math.Max(endTime + SliderEventGenerator.TAIL_LENIENCY, slider.StartTime + slider.Duration / 2);
}
return new ConvertValue
{
StartTime = startTime,
EndTime = endTime,
X = obj.StackedPosition.X,
Y = obj.StackedPosition.Y
};
}
}
2018-04-13 09:19:50 +00:00
protected override Ruleset CreateRuleset() => new OsuRuleset();
}
2018-04-13 09:19:50 +00:00
public struct ConvertValue : IEquatable<ConvertValue>
{
2018-03-01 15:52:45 +00:00
/// <summary>
/// A sane value to account for osu!stable using <see cref="int"/>s everywhere.
2018-03-01 15:52:45 +00:00
/// </summary>
private const double conversion_lenience = 2;
2018-04-13 09:19:50 +00:00
public double StartTime;
public double EndTime;
public float X;
public float Y;
2018-04-13 09:19:50 +00:00
public bool Equals(ConvertValue other)
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
2018-03-01 15:52:45 +00:00
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
&& Precision.AlmostEquals(X, other.X, conversion_lenience)
&& Precision.AlmostEquals(Y, other.Y, conversion_lenience);
}
}