1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 12:33:03 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneSmoke.cs

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

137 lines
4.0 KiB
C#
Raw Normal View History

2022-10-04 09:19:05 +08: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.
using System;
2022-10-06 10:09:34 +08:00
using System.Collections.Generic;
2022-10-04 09:19:05 +08:00
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
2022-10-06 10:09:34 +08:00
using osu.Framework.Logging;
2022-10-04 09:19:05 +08:00
using osu.Framework.Testing.Input;
using osu.Game.Rulesets.Osu.UI;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public partial class TestSceneSmoke : OsuSkinnableTestScene
{
[Test]
public void TestSmoking()
{
2022-10-06 10:09:34 +08:00
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)
{
var smokeContainers = new List<SmokeContainer>();
AddStep(stepName, () =>
2022-10-04 09:19:05 +08:00
{
2022-10-06 10:09:34 +08:00
smokeContainers.Clear();
SetContents(_ =>
2022-10-04 09:19:05 +08:00
{
2022-10-06 10:09:34 +08:00
smokeContainers.Add(new TestSmokeContainer
{
Duration = duration,
RelativeSizeAxes = Axes.Both
});
return new SmokingInputManager
{
Duration = duration,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.95f),
Child = smokeContainers[^1],
};
2022-10-04 09:19:05 +08:00
});
});
2022-10-06 10:09:34 +08:00
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;
});
}
2022-10-04 09:19:05 +08:00
private partial class SmokingInputManager : ManualInputManager
{
2022-10-06 10:09:34 +08:00
public double Duration { get; init; }
2022-10-04 09:19:05 +08:00
private double? startTime;
public SmokingInputManager()
{
UseParentInput = false;
}
protected override void LoadComplete()
{
base.LoadComplete();
MoveMouseTo(ToScreenSpace(DrawSize / 2));
}
protected override void Update()
{
base.Update();
2022-10-06 10:09:34 +08:00
const float spin_angle = 4 * MathF.PI;
2022-10-04 09:19:05 +08:00
startTime ??= Time.Current;
2022-10-06 10:09:34 +08:00
float fraction = (float)((Time.Current - startTime) / Duration);
2022-10-04 09:19:05 +08:00
float angle = fraction * spin_angle;
float radius = fraction * Math.Min(DrawSize.X, DrawSize.Y) / 2;
Vector2 pos = radius * new Vector2(MathF.Cos(angle), MathF.Sin(angle)) + DrawSize / 2;
MoveMouseTo(ToScreenSpace(pos));
}
}
private partial class TestSmokeContainer : SmokeContainer
{
2022-10-06 10:09:34 +08:00
public double Duration { get; init; }
2022-10-04 09:19:05 +08:00
private bool isPressing;
private bool isFinished;
2022-10-06 10:09:34 +08:00
private double? startTime;
2022-10-04 09:19:05 +08:00
protected override void Update()
{
base.Update();
2022-10-06 10:09:34 +08:00
startTime ??= Time.Current + 0.1;
2022-10-04 09:19:05 +08:00
2022-10-06 10:09:34 +08:00
if (!isPressing && !isFinished && Time.Current > startTime)
2022-10-04 09:19:05 +08:00
{
OnPressed(new KeyBindingPressEvent<OsuAction>(new InputState(), OsuAction.Smoke));
isPressing = true;
isFinished = false;
}
2022-10-06 10:09:34 +08:00
if (isPressing && Time.Current > startTime + Duration)
2022-10-04 09:19:05 +08:00
{
OnReleased(new KeyBindingReleaseEvent<OsuAction>(new InputState(), OsuAction.Smoke));
isPressing = false;
isFinished = true;
}
}
}
}
}