1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 14:42:57 +08:00
osu-lazer/osu.Game.Rulesets.Catch.Tests/CatchBeatmapConversionTest.cs

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

108 lines
3.3 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
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Collections.Generic;
2018-06-14 20:46:47 +08:00
using Newtonsoft.Json;
using NUnit.Framework;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2019-08-01 13:58:17 +08:00
using osu.Game.Rulesets.Catch.Mods;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class CatchBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
{
protected override string ResourceAssembly => "osu.Game.Rulesets.Catch";
2018-04-13 17:19:50 +08:00
2018-06-13 21:23:19 +08:00
[TestCase("basic")]
[TestCase("spinner")]
2018-06-13 20:12:08 +08:00
[TestCase("spinner-and-circles")]
2019-01-25 17:13:14 +08:00
[TestCase("slider")]
2019-08-01 13:58:17 +08:00
[TestCase("hardrock-stream", new[] { typeof(CatchModHardRock) })]
[TestCase("hardrock-repeat-slider", new[] { typeof(CatchModHardRock) })]
2019-08-01 16:58:20 +08:00
[TestCase("hardrock-spinner", new[] { typeof(CatchModHardRock) })]
[TestCase("right-bound-hr-offset", new[] { typeof(CatchModHardRock) })]
[TestCase("basic-hyperdash")]
public new void Test(string name, params Type[] mods) => base.Test(name, mods);
2018-04-13 17:19:50 +08:00
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
{
switch (hitObject)
{
case JuiceStream stream:
foreach (var nested in stream.NestedHitObjects)
yield return new ConvertValue((CatchHitObject)nested);
2019-02-28 12:31:40 +08:00
break;
2019-04-01 11:44:46 +08:00
case BananaShower shower:
foreach (var nested in shower.NestedHitObjects)
yield return new ConvertValue((CatchHitObject)nested);
2019-02-28 12:31:40 +08:00
break;
2019-04-01 11:44:46 +08:00
default:
yield return new ConvertValue((CatchHitObject)hitObject);
2019-02-28 12:31:40 +08:00
break;
}
}
2018-04-13 17:19:50 +08:00
protected override Ruleset CreateRuleset() => new CatchRuleset();
}
2018-04-13 17:19:50 +08:00
public struct ConvertValue : IEquatable<ConvertValue>
{
/// <summary>
/// A sane value to account for osu!stable using ints everwhere.
/// </summary>
private const float conversion_lenience = 2;
2018-04-13 17:19:50 +08:00
2018-06-14 20:46:47 +08:00
[JsonIgnore]
public readonly CatchHitObject HitObject;
public ConvertValue(CatchHitObject hitObject)
{
HitObject = hitObject;
startTime = 0;
position = 0;
hyperDash = false;
2018-06-14 20:46:47 +08:00
}
private double startTime;
public double StartTime
{
get => HitObject?.StartTime ?? startTime;
set => startTime = value;
}
private float position;
public float Position
{
get => HitObject?.EffectiveX ?? position;
2018-06-14 20:46:47 +08:00
set => position = value;
}
2018-04-13 17:19:50 +08:00
private bool hyperDash;
public bool HyperDash
{
get => (HitObject as PalpableCatchHitObject)?.HyperDash ?? hyperDash;
set => hyperDash = value;
}
public bool Equals(ConvertValue other)
2018-03-02 17:20:12 +08:00
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
&& Precision.AlmostEquals(Position, other.Position, conversion_lenience)
&& HyperDash == other.HyperDash;
}
}