1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 10:02:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneParticleSpewer.cs

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

131 lines
4.4 KiB
C#
Raw Normal View History

2021-09-10 06:02:37 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-09-10 06:02:37 +08:00
using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
2021-09-10 06:02:37 +08:00
using osu.Framework.Testing;
2021-09-19 21:35:03 +08:00
using osu.Framework.Timing;
2021-09-10 06:02:37 +08:00
using osu.Framework.Utils;
2021-09-13 06:35:13 +08:00
using osu.Game.Graphics;
2021-09-10 06:02:37 +08:00
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public class TestSceneParticleSpewer : OsuTestScene
{
private TestParticleSpewer spewer;
2021-09-10 06:02:37 +08:00
[Resolved]
private SkinManager skinManager { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Child = spewer = createSpewer();
AddToggleStep("toggle spawning", value => spewer.Active.Value = value);
AddSliderStep("particle gravity", 0f, 1f, 0f, value => spewer.Gravity = value);
AddSliderStep("particle velocity", 0f, 1f, 0.5f, value => spewer.MaxVelocity = value);
2021-09-19 04:54:12 +08:00
AddStep("move to new location", () =>
{
spewer.TransformTo(nameof(spewer.SpawnPosition), new Vector2(RNG.NextSingle(), RNG.NextSingle()), 1000, Easing.Out);
2021-09-19 04:54:12 +08:00
});
2021-09-10 06:02:37 +08:00
}
[SetUpSteps]
public void SetUpSteps()
{
2021-09-13 06:05:49 +08:00
AddStep("create spewer", () => Child = spewer = createSpewer());
2021-09-10 06:02:37 +08:00
}
[Test]
public void TestPresence()
{
2021-09-13 06:05:49 +08:00
AddStep("start spewer", () => spewer.Active.Value = true);
2021-09-10 06:02:37 +08:00
AddAssert("is present", () => spewer.IsPresent);
AddWaitStep("wait for some particles", 3);
2021-09-13 06:05:49 +08:00
AddStep("stop spewer", () => spewer.Active.Value = false);
2021-09-10 06:02:37 +08:00
AddWaitStep("wait for clean screen", 8);
AddAssert("is not present", () => !spewer.IsPresent);
}
2021-09-19 21:35:03 +08:00
[Test]
public void TestTimeJumps()
{
ManualClock testClock = new ManualClock();
AddStep("prepare clock", () =>
{
testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * -3;
spewer.Clock = new FramedClock(testClock);
});
AddStep("start spewer", () => spewer.Active.Value = true);
AddAssert("spawned first particle", () => spewer.TotalCreatedParticles == 1);
AddStep("move clock forward", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * 3);
AddAssert("spawned second particle", () => spewer.TotalCreatedParticles == 2);
AddStep("move clock backwards", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * -1);
AddAssert("spawned third particle", () => spewer.TotalCreatedParticles == 3);
}
private TestParticleSpewer createSpewer() =>
new TestParticleSpewer(skinManager.DefaultLegacySkin.GetTexture("star2"))
2021-09-10 06:02:37 +08:00
{
Origin = Anchor.Centre,
2021-09-19 04:54:12 +08:00
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Position = new Vector2(0.5f),
Size = new Vector2(0.5f),
2021-09-10 06:02:37 +08:00
};
private class TestParticleSpewer : ParticleSpewer
{
2021-09-19 21:35:03 +08:00
public const int MAX_DURATION = 1500;
private const int rate = 250;
2021-09-19 21:35:03 +08:00
public int TotalCreatedParticles { get; private set; }
public float Gravity;
public float MaxVelocity = 0.25f;
public Vector2 SpawnPosition { get; set; } = new Vector2(0.5f);
protected override float ParticleGravity => Gravity;
public TestParticleSpewer(Texture texture)
2021-09-19 21:35:03 +08:00
: base(texture, rate, MAX_DURATION)
2021-09-10 06:02:37 +08:00
{
}
2021-09-19 21:35:03 +08:00
protected override FallingParticle CreateParticle()
{
TotalCreatedParticles++;
return new FallingParticle
{
Velocity = new Vector2(
RNG.NextSingle(-MaxVelocity, MaxVelocity),
RNG.NextSingle(-MaxVelocity, MaxVelocity)
),
StartPosition = SpawnPosition,
2021-09-19 21:35:03 +08:00
Duration = RNG.NextSingle(MAX_DURATION),
StartAngle = RNG.NextSingle(MathF.PI * 2),
EndAngle = RNG.NextSingle(MathF.PI * 2),
EndScale = RNG.NextSingle(0.5f, 1.5f)
};
2021-09-19 21:35:03 +08:00
}
}
2021-09-10 06:02:37 +08:00
}
}