1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 21:17:33 +08:00
osu-lazer/osu.Game.Rulesets.Catch.Tests/CatchBeatmapConversionTest.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08: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;
2018-06-14 20:46:47 +08:00
using Newtonsoft.Json;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.MathUtils;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class CatchBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
2018-04-13 17:19:50 +08:00
{
protected override string ResourceAssembly => "osu.Game.Rulesets.Catch";
2018-06-13 21:23:19 +08:00
[TestCase("basic")]
[TestCase("spinner")]
2018-06-13 20:12:08 +08:00
[TestCase("spinner-and-circles")]
2018-04-13 17:19:50 +08:00
public new void Test(string name)
{
base.Test(name);
}
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
{
switch (hitObject)
2018-04-13 17:19:50 +08:00
{
case JuiceStream stream:
foreach (var nested in stream.NestedHitObjects)
yield return new ConvertValue((CatchHitObject)nested);
break;
case BananaShower shower:
foreach (var nested in shower.NestedHitObjects)
yield return new ConvertValue((CatchHitObject)nested);
break;
default:
yield return new ConvertValue((CatchHitObject)hitObject);
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>
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;
2018-06-14 20:46:47 +08:00
[JsonIgnore]
public readonly CatchHitObject HitObject;
public ConvertValue(CatchHitObject hitObject)
{
HitObject = hitObject;
startTime = 0;
position = 0;
}
private double startTime;
public double StartTime
{
get => HitObject?.StartTime ?? startTime;
set => startTime = value;
}
private float position;
public float Position
{
get => HitObject?.X * CatchPlayfield.BASE_WIDTH ?? position;
set => position = value;
}
2018-04-13 17:19:50 +08:00
public bool Equals(ConvertValue other)
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
&& Precision.AlmostEquals(Position, other.Position, conversion_lenience);
}
}