mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 13:37:51 +08:00
86 lines
2.6 KiB
C#
86 lines
2.6 KiB
C#
// 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 Newtonsoft.Json;
|
|
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>
|
|
{
|
|
protected override string ResourceAssembly => "osu.Game.Rulesets.Catch";
|
|
|
|
[TestCase("basic")]
|
|
[TestCase("spinner")]
|
|
[TestCase("spinner-and-circles")]
|
|
public new void Test(string name)
|
|
{
|
|
base.Test(name);
|
|
}
|
|
|
|
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
|
|
{
|
|
if (hitObject is JuiceStream stream)
|
|
{
|
|
foreach (var nested in stream.NestedHitObjects)
|
|
yield return new ConvertValue((CatchHitObject)nested);
|
|
}
|
|
else if (hitObject is BananaShower shower)
|
|
{
|
|
foreach (var nested in shower.NestedHitObjects)
|
|
yield return new ConvertValue((CatchHitObject)nested);
|
|
}
|
|
else
|
|
yield return new ConvertValue((CatchHitObject)hitObject);
|
|
}
|
|
|
|
protected override Ruleset CreateRuleset() => new CatchRuleset();
|
|
}
|
|
|
|
public struct ConvertValue : IEquatable<ConvertValue>
|
|
{
|
|
/// <summary>
|
|
/// A sane value to account for osu!stable using ints everwhere.
|
|
/// </summary>
|
|
private const float conversion_lenience = 2;
|
|
|
|
[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;
|
|
}
|
|
|
|
public bool Equals(ConvertValue other)
|
|
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
|
|
&& Precision.AlmostEquals(Position, other.Position, conversion_lenience);
|
|
}
|
|
}
|