2018-04-13 09:19:50 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-06-27 03:18:00 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
2018-06-13 14:43:58 +00:00
|
|
|
|
[TestFixture]
|
|
|
|
|
public class OsuBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
protected override string ResourceAssembly => "osu.Game.Rulesets.Osu";
|
|
|
|
|
|
|
|
|
|
[TestCase("basic")]
|
|
|
|
|
[TestCase("colinear-perfect-curve")]
|
2018-06-13 16:28:28 +00:00
|
|
|
|
[TestCase("slider-ticks")]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public new void Test(string name)
|
|
|
|
|
{
|
|
|
|
|
base.Test(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
|
|
|
|
|
{
|
2018-06-13 16:27:33 +00:00
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case Slider slider:
|
|
|
|
|
foreach (var nested in slider.NestedHitObjects)
|
|
|
|
|
yield return createConvertValue(nested);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
yield return createConvertValue(hitObject);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-06-13 16:27:33 +00:00
|
|
|
|
ConvertValue createConvertValue(HitObject obj) => new ConvertValue
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-13 16:27:33 +00:00
|
|
|
|
StartTime = obj.StartTime,
|
|
|
|
|
EndTime = (obj as IHasEndTime)?.EndTime ?? obj.StartTime,
|
2018-06-27 03:18:00 +00:00
|
|
|
|
X = (obj as IHasPosition)?.X ?? OsuPlayfield.BASE_SIZE.X / 2,
|
|
|
|
|
Y = (obj as IHasPosition)?.Y ?? OsuPlayfield.BASE_SIZE.Y / 2,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 04:09:48 +00:00
|
|
|
|
protected override Ruleset CreateRuleset() => new OsuRuleset();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 14:43:58 +00:00
|
|
|
|
public struct ConvertValue : IEquatable<ConvertValue>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A sane value to account for osu!stable using ints everwhere.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double conversion_lenience = 2;
|
|
|
|
|
|
|
|
|
|
public double StartTime;
|
|
|
|
|
public double EndTime;
|
2018-06-13 16:27:33 +00:00
|
|
|
|
public float X;
|
|
|
|
|
public float Y;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public bool Equals(ConvertValue other)
|
2018-06-13 16:27:33 +00:00
|
|
|
|
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
|
2018-06-13 16:27:33 +00:00
|
|
|
|
&& Precision.AlmostEquals(X, other.X, conversion_lenience)
|
|
|
|
|
&& Precision.AlmostEquals(Y, other.Y, conversion_lenience);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|