2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-01 23:07:02 +08:00
|
|
|
|
using System;
|
2018-03-02 01:02:09 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-10-16 19:35:24 +08:00
|
|
|
|
using System.Linq;
|
2018-03-01 23:07:02 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2018-03-01 23:07:02 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-01 23:07:02 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
2018-06-13 22:43:58 +08:00
|
|
|
|
[TestFixture]
|
|
|
|
|
public class OsuBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
|
2018-03-01 23:07:02 +08:00
|
|
|
|
{
|
|
|
|
|
protected override string ResourceAssembly => "osu.Game.Rulesets.Osu";
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-02 17:20:33 +08:00
|
|
|
|
[TestCase("basic")]
|
2018-03-02 17:30:31 +08:00
|
|
|
|
[TestCase("colinear-perfect-curve")]
|
2018-06-14 00:28:28 +08:00
|
|
|
|
[TestCase("slider-ticks")]
|
2023-09-07 17:20:07 +08:00
|
|
|
|
[TestCase("slider-ticks-edge-case")]
|
2023-09-19 00:02:20 +08:00
|
|
|
|
[TestCase("slider-paths-edge-case")]
|
2019-08-01 16:31:08 +08:00
|
|
|
|
[TestCase("repeat-slider")]
|
|
|
|
|
[TestCase("uneven-repeat-slider")]
|
2019-08-07 18:35:39 +08:00
|
|
|
|
[TestCase("old-stacking")]
|
2021-04-05 16:47:12 +08:00
|
|
|
|
[TestCase("multi-segment-slider")]
|
2023-07-09 05:02:41 +08:00
|
|
|
|
[TestCase("nan-slider")]
|
2019-08-05 15:50:43 +08:00
|
|
|
|
public void Test(string name) => base.Test(name);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-02 01:02:09 +08:00
|
|
|
|
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
|
2018-03-01 23:07:02 +08:00
|
|
|
|
{
|
2018-06-14 00:27:33 +08:00
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case Slider slider:
|
2023-10-16 19:35:24 +08:00
|
|
|
|
var objects = new List<ConvertValue>();
|
|
|
|
|
|
2018-06-14 00:27:33 +08:00
|
|
|
|
foreach (var nested in slider.NestedHitObjects)
|
2023-10-16 19:35:24 +08:00
|
|
|
|
objects.Add(createConvertValue((OsuHitObject)nested, slider));
|
|
|
|
|
|
2023-10-16 19:40:45 +08:00
|
|
|
|
// stable does slider tail leniency by offsetting the last tick 36ms back.
|
|
|
|
|
// based on player feedback, we're doing this a little different in lazer,
|
|
|
|
|
// and the lazer method does not require offsetting the last tick
|
|
|
|
|
// (see `DrawableSliderTail.CheckForResult()`).
|
|
|
|
|
// however, in conversion tests, just so the output matches, we're bringing
|
|
|
|
|
// the 36ms offset back locally.
|
|
|
|
|
// in particular, on some sliders, this may rearrange nested objects,
|
|
|
|
|
// so we sort them again by start time to prevent test failures.
|
2023-10-16 19:35:24 +08:00
|
|
|
|
foreach (var obj in objects.OrderBy(cv => cv.StartTime))
|
|
|
|
|
yield return obj;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-06-14 00:27:33 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-06-14 00:27:33 +08:00
|
|
|
|
default:
|
2019-08-07 18:33:16 +08:00
|
|
|
|
yield return createConvertValue((OsuHitObject)hitObject);
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-06-14 00:27:33 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-16 19:35:24 +08:00
|
|
|
|
static ConvertValue createConvertValue(OsuHitObject obj, OsuHitObject? parent = null)
|
2018-03-01 23:07:02 +08:00
|
|
|
|
{
|
2023-10-16 19:35:24 +08:00
|
|
|
|
double startTime = obj.StartTime;
|
|
|
|
|
double endTime = obj.GetEndTime();
|
|
|
|
|
|
2023-10-16 19:40:45 +08:00
|
|
|
|
// as stated in the inline comment above, 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 19:35:24 +08: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-03-01 23:07:02 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-05-16 12:09:48 +08:00
|
|
|
|
protected override Ruleset CreateRuleset() => new OsuRuleset();
|
2018-03-01 23:07:02 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 22:43:58 +08:00
|
|
|
|
public struct ConvertValue : IEquatable<ConvertValue>
|
2018-03-01 23:07:02 +08:00
|
|
|
|
{
|
2018-03-01 23:52:45 +08:00
|
|
|
|
/// <summary>
|
2018-07-05 10:32:09 +08:00
|
|
|
|
/// A sane value to account for osu!stable using <see cref="int"/>s everywhere.
|
2018-03-01 23:52:45 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private const double conversion_lenience = 2;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-01 23:07:02 +08:00
|
|
|
|
public double StartTime;
|
|
|
|
|
public double EndTime;
|
2018-06-14 00:27:33 +08:00
|
|
|
|
public float X;
|
|
|
|
|
public float Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-01 23:07:02 +08:00
|
|
|
|
public bool Equals(ConvertValue other)
|
2018-06-14 00:27:33 +08:00
|
|
|
|
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
|
2018-03-01 23:52:45 +08:00
|
|
|
|
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
|
2018-06-14 00:27:33 +08:00
|
|
|
|
&& Precision.AlmostEquals(X, other.X, conversion_lenience)
|
|
|
|
|
&& Precision.AlmostEquals(Y, other.Y, conversion_lenience);
|
2018-03-01 23:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|