osukey/osu.Game.Tests/Visual/Gameplay/TestSceneParticleSpewer.cs
Dean Herbert 2df4073946 SpawnParticle -> CreateParticle (and set time outside of virtual call)
Allows easier overriding (no need to call the `base.CreateParticle` call
and worry about overwriting the time value.
2021-09-16 16:52:46 +09:00

93 lines
2.9 KiB
C#

// 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;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public class TestSceneParticleSpewer : OsuTestScene
{
private TestParticleSpewer spewer;
[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, 250f, 0f, value => spewer.Gravity = value);
AddSliderStep("particle velocity", 0f, 500f, 250f, value => spewer.MaxVelocity = value);
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create spewer", () => Child = spewer = createSpewer());
}
[Test]
public void TestPresence()
{
AddStep("start spewer", () => spewer.Active.Value = true);
AddAssert("is present", () => spewer.IsPresent);
AddWaitStep("wait for some particles", 3);
AddStep("stop spewer", () => spewer.Active.Value = false);
AddWaitStep("wait for clean screen", 8);
AddAssert("is not present", () => !spewer.IsPresent);
}
private TestParticleSpewer createSpewer()
{
return new TestParticleSpewer(skinManager.DefaultLegacySkin.GetTexture("star2"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
private class TestParticleSpewer : ParticleSpewer
{
private const int lifetime = 1500;
private const int rate = 250;
public float Gravity;
public float MaxVelocity = 250;
protected override float ParticleGravity => Gravity;
public TestParticleSpewer(Texture texture)
: base(texture, rate, lifetime)
{
}
protected override FallingParticle CreateParticle() =>
new FallingParticle
{
Velocity = new Vector2(
RNG.NextSingle(-MaxVelocity, MaxVelocity),
RNG.NextSingle(-MaxVelocity, MaxVelocity)
),
Duration = RNG.NextSingle(lifetime),
StartAngle = RNG.NextSingle(MathF.PI * 2),
EndAngle = RNG.NextSingle(MathF.PI * 2),
EndScale = RNG.NextSingle(0.5f, 1.5f)
};
}
}
}