1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneSpinner.cs

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

115 lines
4.0 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.Collections.Generic;
2018-01-01 18:55:24 +08:00
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-12-27 19:01:20 +08:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Audio;
2017-12-27 19:01:20 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2018-01-01 18:55:24 +08:00
using osu.Game.Rulesets.Mods;
2017-12-27 19:01:20 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-12-27 19:01:20 +08:00
namespace osu.Game.Rulesets.Osu.Tests
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public class TestSceneSpinner : OsuSkinnableTestScene
2017-12-27 19:01:20 +08:00
{
private int depthIndex;
2018-04-13 17:19:50 +08:00
private TestDrawableSpinner drawableSpinner;
[TestCase(true)]
[TestCase(false)]
public void TestVariousSpinners(bool autoplay)
2017-12-27 19:01:20 +08:00
{
2020-08-06 11:33:40 +08:00
string term = autoplay ? "Hit" : "Miss";
AddStep($"{term} Big", () => SetContents(_ => testSingle(2, autoplay)));
AddStep($"{term} Medium", () => SetContents(_ => testSingle(5, autoplay)));
AddStep($"{term} Small", () => SetContents(_ => testSingle(7, autoplay)));
}
[Test]
public void TestSpinningSamplePitchShift()
{
AddStep("Add spinner", () => SetContents(_ => testSingle(5, true, 4000)));
AddUntilStep("Pitch starts low", () => getSpinningSample().Frequency.Value < 0.8);
AddUntilStep("Pitch increases", () => getSpinningSample().Frequency.Value > 0.8);
PausableSkinnableSound getSpinningSample() => drawableSpinner.ChildrenOfType<PausableSkinnableSound>().FirstOrDefault(s => s.Samples.Any(i => i.LookupNames.Any(l => l.Contains("spinnerspin"))));
}
[TestCase(false)]
[TestCase(true)]
public void TestLongSpinner(bool autoplay)
{
AddStep("Very long spinner", () => SetContents(_ => testSingle(5, autoplay, 4000)));
AddUntilStep("Wait for completion", () => drawableSpinner.Result.HasResult);
AddUntilStep("Check correct progress", () => drawableSpinner.Progress == (autoplay ? 1 : 0));
}
[TestCase(false)]
[TestCase(true)]
public void TestSuperShortSpinner(bool autoplay)
{
AddStep("Very short spinner", () => SetContents(_ => testSingle(5, autoplay, 200)));
AddUntilStep("Wait for completion", () => drawableSpinner.Result.HasResult);
AddUntilStep("Short spinner implicitly completes", () => drawableSpinner.Progress == 1);
2017-12-27 19:01:20 +08:00
}
2018-04-13 17:19:50 +08:00
private Drawable testSingle(float circleSize, bool auto = false, double length = 3000)
2017-12-27 19:01:20 +08:00
{
2020-08-06 11:34:42 +08:00
const double delay = 2000;
var spinner = new Spinner
{
StartTime = Time.Current + delay,
EndTime = Time.Current + delay + length,
Samples = new List<HitSampleInfo>
{
new HitSampleInfo("hitnormal")
}
2020-08-06 11:34:42 +08:00
};
2018-04-13 17:19:50 +08:00
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = circleSize });
2018-04-13 17:19:50 +08:00
drawableSpinner = new TestDrawableSpinner(spinner, auto)
2017-12-27 19:01:20 +08:00
{
Anchor = Anchor.Centre,
Depth = depthIndex++,
Scale = new Vector2(0.75f)
2017-12-27 19:01:20 +08:00
};
2018-04-13 17:19:50 +08:00
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObject(drawableSpinner);
2018-04-13 17:19:50 +08:00
return drawableSpinner;
2017-12-27 19:01:20 +08:00
}
2018-04-13 17:19:50 +08:00
2018-01-01 18:55:24 +08:00
private class TestDrawableSpinner : DrawableSpinner
{
private readonly bool auto;
2018-04-13 17:19:50 +08:00
2019-02-28 12:31:40 +08:00
public TestDrawableSpinner(Spinner s, bool auto)
: base(s)
2018-01-01 18:55:24 +08:00
{
this.auto = auto;
}
2018-04-13 17:19:50 +08:00
protected override void Update()
2018-01-01 18:55:24 +08:00
{
base.Update();
if (auto)
RotationTracker.AddRotation((float)(Clock.ElapsedFrameTime * 2));
2018-01-01 18:55:24 +08:00
}
}
2017-12-27 19:01:20 +08:00
}
}