2019-01-24 08:43:03 +00:00
|
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2023-11-06 09:16:04 +00:00
|
|
|
|
using System;
|
2021-01-15 08:13:52 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-01-01 10:55:24 +00:00
|
|
|
|
using System.Linq;
|
2018-03-02 06:34:31 +00:00
|
|
|
|
using NUnit.Framework;
|
2023-10-20 07:10:50 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-12-27 11:01:20 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-05-24 06:10:33 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2021-01-15 08:13:52 +00:00
|
|
|
|
using osu.Game.Audio;
|
2017-12-27 11:01:20 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-01-01 10:55:24 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2017-12-27 11:01:20 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2021-05-24 06:10:33 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2020-08-29 21:20:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-12-27 11:01:20 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
2018-03-02 06:34:31 +00:00
|
|
|
|
[TestFixture]
|
2020-07-29 06:24:14 +00:00
|
|
|
|
public partial class TestSceneSpinner : OsuSkinnableTestScene
|
2017-12-27 11:01:20 +00:00
|
|
|
|
{
|
|
|
|
|
private int depthIndex;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-08-05 09:44:34 +00:00
|
|
|
|
private TestDrawableSpinner drawableSpinner;
|
|
|
|
|
|
2023-10-20 07:10:50 +00:00
|
|
|
|
private readonly BindableDouble spinRate = new BindableDouble();
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
AddSliderStep("Spin rate", 0.5, 5, 1, val => spinRate.Value = val);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 09:16:31 +00:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Reset rate", () => spinRate.Value = 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 09:44:34 +00:00
|
|
|
|
[TestCase(true)]
|
2020-11-05 08:12:18 +00:00
|
|
|
|
[TestCase(false)]
|
2020-08-05 09:44:34 +00:00
|
|
|
|
public void TestVariousSpinners(bool autoplay)
|
2017-12-27 11:01:20 +00:00
|
|
|
|
{
|
2020-08-06 03:33:40 +00:00
|
|
|
|
string term = autoplay ? "Hit" : "Miss";
|
2021-06-02 07:04:53 +00:00
|
|
|
|
AddStep($"{term} Big", () => SetContents(_ => testSingle(2, autoplay)));
|
|
|
|
|
AddStep($"{term} Medium", () => SetContents(_ => testSingle(5, autoplay)));
|
|
|
|
|
AddStep($"{term} Small", () => SetContents(_ => testSingle(7, autoplay)));
|
2020-08-05 09:44:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 09:16:31 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinnerNoBonus()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Set high spin rate", () => spinRate.Value = 5);
|
|
|
|
|
|
|
|
|
|
Spinner spinner;
|
|
|
|
|
|
|
|
|
|
AddStep("add spinner", () => SetContents(_ =>
|
|
|
|
|
{
|
|
|
|
|
spinner = new Spinner
|
|
|
|
|
{
|
|
|
|
|
StartTime = Time.Current,
|
|
|
|
|
EndTime = Time.Current + 750,
|
|
|
|
|
Samples = new List<HitSampleInfo>
|
|
|
|
|
{
|
|
|
|
|
new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { OverallDifficulty = 0 });
|
|
|
|
|
|
|
|
|
|
return drawableSpinner = new TestDrawableSpinner(spinner, true, spinRate)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Depth = depthIndex++,
|
|
|
|
|
Scale = new Vector2(0.75f)
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 06:10:33 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinningSamplePitchShift()
|
|
|
|
|
{
|
2021-06-02 07:04:53 +00:00
|
|
|
|
AddStep("Add spinner", () => SetContents(_ => testSingle(5, true, 4000)));
|
2021-05-24 06:10:33 +00:00
|
|
|
|
AddUntilStep("Pitch starts low", () => getSpinningSample().Frequency.Value < 0.8);
|
|
|
|
|
AddUntilStep("Pitch increases", () => getSpinningSample().Frequency.Value > 0.8);
|
|
|
|
|
|
2023-09-26 09:11:27 +00:00
|
|
|
|
PausableSkinnableSound getSpinningSample() =>
|
|
|
|
|
drawableSpinner.ChildrenOfType<PausableSkinnableSound>().FirstOrDefault(s => s.Samples.Any(i => i.LookupNames.Any(l => l.Contains("spinnerspin"))));
|
2021-05-24 06:10:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 09:44:34 +00:00
|
|
|
|
[TestCase(false)]
|
|
|
|
|
[TestCase(true)]
|
|
|
|
|
public void TestLongSpinner(bool autoplay)
|
|
|
|
|
{
|
2021-06-02 07:04:53 +00:00
|
|
|
|
AddStep("Very long spinner", () => SetContents(_ => testSingle(5, autoplay, 4000)));
|
2020-08-05 09:44:34 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-06-02 07:04:53 +00:00
|
|
|
|
AddStep("Very short spinner", () => SetContents(_ => testSingle(5, autoplay, 200)));
|
2020-08-05 09:44:34 +00:00
|
|
|
|
AddUntilStep("Wait for completion", () => drawableSpinner.Result.HasResult);
|
|
|
|
|
AddUntilStep("Short spinner implicitly completes", () => drawableSpinner.Progress == 1);
|
2017-12-27 11:01:20 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-09-26 09:11:27 +00:00
|
|
|
|
[TestCase(0, 4, 6)]
|
|
|
|
|
[TestCase(5, 7, 10)]
|
|
|
|
|
[TestCase(10, 11, 8)]
|
|
|
|
|
public void TestSpinnerSpinRequirements(int od, int normalTicks, int bonusTicks)
|
|
|
|
|
{
|
|
|
|
|
Spinner spinner = null;
|
|
|
|
|
|
|
|
|
|
AddStep("add spinner", () => SetContents(_ =>
|
|
|
|
|
{
|
|
|
|
|
spinner = new Spinner
|
|
|
|
|
{
|
|
|
|
|
StartTime = Time.Current,
|
|
|
|
|
EndTime = Time.Current + 3000,
|
|
|
|
|
Samples = new List<HitSampleInfo>
|
|
|
|
|
{
|
|
|
|
|
new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { OverallDifficulty = od });
|
|
|
|
|
|
2023-10-20 07:10:50 +00:00
|
|
|
|
return drawableSpinner = new TestDrawableSpinner(spinner, true, spinRate)
|
2023-09-26 09:11:27 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Depth = depthIndex++,
|
|
|
|
|
Scale = new Vector2(0.75f)
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
AddAssert("number of normal ticks matches", () => spinner.SpinsRequired, () => Is.EqualTo(normalTicks));
|
|
|
|
|
AddAssert("number of bonus ticks matches", () => spinner.MaximumBonusSpins, () => Is.EqualTo(bonusTicks));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 09:44:34 +00:00
|
|
|
|
private Drawable testSingle(float circleSize, bool auto = false, double length = 3000)
|
2017-12-27 11:01:20 +00:00
|
|
|
|
{
|
2020-08-06 03:34:42 +00:00
|
|
|
|
const double delay = 2000;
|
|
|
|
|
|
|
|
|
|
var spinner = new Spinner
|
|
|
|
|
{
|
|
|
|
|
StartTime = Time.Current + delay,
|
2021-01-15 08:13:52 +00:00
|
|
|
|
EndTime = Time.Current + delay + length,
|
|
|
|
|
Samples = new List<HitSampleInfo>
|
|
|
|
|
{
|
2023-05-16 07:29:24 +00:00
|
|
|
|
new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
|
2021-01-15 08:13:52 +00:00
|
|
|
|
}
|
2020-08-06 03:34:42 +00:00
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-12-28 17:21:08 +00:00
|
|
|
|
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = circleSize });
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-10-20 07:10:50 +00:00
|
|
|
|
drawableSpinner = new TestDrawableSpinner(spinner, auto, spinRate)
|
2017-12-27 11:01:20 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2020-08-29 21:20:59 +00:00
|
|
|
|
Depth = depthIndex++,
|
|
|
|
|
Scale = new Vector2(0.75f)
|
2017-12-27 11:01:20 +00:00
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-06-16 09:46:29 +00:00
|
|
|
|
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
|
|
|
|
|
mod.ApplyToDrawableHitObject(drawableSpinner);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-08-05 09:44:34 +00:00
|
|
|
|
return drawableSpinner;
|
2017-12-27 11:01:20 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-01-01 10:55:24 +00:00
|
|
|
|
private partial class TestDrawableSpinner : DrawableSpinner
|
|
|
|
|
{
|
2020-07-29 06:24:14 +00:00
|
|
|
|
private readonly bool auto;
|
2023-10-20 07:10:50 +00:00
|
|
|
|
private readonly BindableDouble spinRate;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-10-20 07:10:50 +00:00
|
|
|
|
public TestDrawableSpinner(Spinner s, bool auto, BindableDouble spinRate)
|
2019-02-28 04:31:40 +00:00
|
|
|
|
: base(s)
|
2018-01-01 10:55:24 +00:00
|
|
|
|
{
|
|
|
|
|
this.auto = auto;
|
2023-10-20 07:10:50 +00:00
|
|
|
|
this.spinRate = spinRate;
|
2018-01-01 10:55:24 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-07-29 06:24:14 +00:00
|
|
|
|
protected override void Update()
|
2018-01-01 10:55:24 +00:00
|
|
|
|
{
|
2020-07-29 06:24:14 +00:00
|
|
|
|
base.Update();
|
|
|
|
|
if (auto)
|
2023-11-06 09:16:04 +00:00
|
|
|
|
RotationTracker.AddRotation((float)Math.Min(180, Clock.ElapsedFrameTime * spinRate.Value));
|
2018-01-01 10:55:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-27 11:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|