mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Add more smoke tests
This commit is contained in:
@ -2,10 +2,12 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Testing.Input;
|
using osu.Framework.Testing.Input;
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -17,22 +19,57 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestSmoking()
|
public void TestSmoking()
|
||||||
{
|
{
|
||||||
AddStep("Create smoke", () =>
|
addStep("Create short smoke", 2_000);
|
||||||
|
addStep("Create medium smoke", 5_000);
|
||||||
|
addStep("Create long smoke", 10_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStep(string stepName, double duration)
|
||||||
{
|
{
|
||||||
SetContents(_ => new SmokingInputManager
|
var smokeContainers = new List<SmokeContainer>();
|
||||||
|
|
||||||
|
AddStep(stepName, () =>
|
||||||
{
|
{
|
||||||
|
smokeContainers.Clear();
|
||||||
|
SetContents(_ =>
|
||||||
|
{
|
||||||
|
smokeContainers.Add(new TestSmokeContainer
|
||||||
|
{
|
||||||
|
Duration = duration,
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
});
|
||||||
|
|
||||||
|
return new SmokingInputManager
|
||||||
|
{
|
||||||
|
Duration = duration,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Size = new Vector2(0.95f),
|
Size = new Vector2(0.95f),
|
||||||
Child = new TestSmokeContainer { RelativeSizeAxes = Axes.Both },
|
Child = smokeContainers[^1],
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddUntilStep("Until skinnable expires", () =>
|
||||||
|
{
|
||||||
|
if (smokeContainers.Count == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Logger.Log("How many: " + smokeContainers.Count);
|
||||||
|
|
||||||
|
foreach (var smokeContainer in smokeContainers)
|
||||||
|
{
|
||||||
|
if (smokeContainer.Children.Count != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private const double spin_duration = 5_000;
|
|
||||||
private const float spin_angle = 4 * MathF.PI;
|
|
||||||
|
|
||||||
private class SmokingInputManager : ManualInputManager
|
private class SmokingInputManager : ManualInputManager
|
||||||
{
|
{
|
||||||
|
public double Duration { get; init; }
|
||||||
|
|
||||||
private double? startTime;
|
private double? startTime;
|
||||||
|
|
||||||
public SmokingInputManager()
|
public SmokingInputManager()
|
||||||
@ -51,9 +88,11 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
const float spin_angle = 4 * MathF.PI;
|
||||||
|
|
||||||
startTime ??= Time.Current;
|
startTime ??= Time.Current;
|
||||||
|
|
||||||
float fraction = (float)((Time.Current - startTime) / spin_duration);
|
float fraction = (float)((Time.Current - startTime) / Duration);
|
||||||
|
|
||||||
float angle = fraction * spin_angle;
|
float angle = fraction * spin_angle;
|
||||||
float radius = fraction * Math.Min(DrawSize.X, DrawSize.Y) / 2;
|
float radius = fraction * Math.Min(DrawSize.X, DrawSize.Y) / 2;
|
||||||
@ -65,24 +104,27 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
|
|
||||||
private class TestSmokeContainer : SmokeContainer
|
private class TestSmokeContainer : SmokeContainer
|
||||||
{
|
{
|
||||||
private double? startTime;
|
public double Duration { get; init; }
|
||||||
|
|
||||||
private bool isPressing;
|
private bool isPressing;
|
||||||
private bool isFinished;
|
private bool isFinished;
|
||||||
|
|
||||||
|
private double? startTime;
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
startTime ??= Time.Current;
|
startTime ??= Time.Current + 0.1;
|
||||||
|
|
||||||
if (!isPressing && !isFinished && Time.Current > startTime + 0.1)
|
if (!isPressing && !isFinished && Time.Current > startTime)
|
||||||
{
|
{
|
||||||
OnPressed(new KeyBindingPressEvent<OsuAction>(new InputState(), OsuAction.Smoke));
|
OnPressed(new KeyBindingPressEvent<OsuAction>(new InputState(), OsuAction.Smoke));
|
||||||
isPressing = true;
|
isPressing = true;
|
||||||
isFinished = false;
|
isFinished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPressing && Time.Current > startTime + spin_duration)
|
if (isPressing && Time.Current > startTime + Duration)
|
||||||
{
|
{
|
||||||
OnReleased(new KeyBindingReleaseEvent<OsuAction>(new InputState(), OsuAction.Smoke));
|
OnReleased(new KeyBindingReleaseEvent<OsuAction>(new InputState(), OsuAction.Smoke));
|
||||||
isPressing = false;
|
isPressing = false;
|
||||||
|
Reference in New Issue
Block a user