osu/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.5 KiB
C#
Raw Normal View History

2021-09-09 22:02:37 +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.
2022-06-17 07:37:17 +00:00
#nullable disable
2021-09-09 22:02:37 +00:00
using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
2021-09-09 22:02:37 +00:00
using osu.Framework.Testing;
2021-09-19 13:35:03 +00:00
using osu.Framework.Timing;
2021-09-09 22:02:37 +00:00
using osu.Framework.Utils;
2021-09-12 22:35:13 +00:00
using osu.Game.Graphics;
2021-09-09 22:02:37 +00:00
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public partial class TestSceneParticleSpewer : OsuTestScene
{
private TestParticleSpewer spewer;
2021-09-09 22:02:37 +00: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-18 20:54:12 +00:00
AddStep("move to new location", () =>
{
spewer.TransformTo(nameof(spewer.SpawnPosition), new Vector2(RNG.NextSingle(), RNG.NextSingle()), 1000, Easing.Out);
2021-09-18 20:54:12 +00:00
});
2021-09-09 22:02:37 +00:00
}
[SetUpSteps]
public void SetUpSteps()
{
2021-09-12 22:05:49 +00:00
AddStep("create spewer", () => Child = spewer = createSpewer());
2021-09-09 22:02:37 +00:00
}
[Test]
public void TestPresence()
{
2021-09-12 22:05:49 +00:00
AddStep("start spewer", () => spewer.Active.Value = true);
2021-09-09 22:02:37 +00:00
AddAssert("is present", () => spewer.IsPresent);
AddWaitStep("wait for some particles", 3);
2021-09-12 22:05:49 +00:00
AddStep("stop spewer", () => spewer.Active.Value = false);
2021-09-09 22:02:37 +00:00
AddWaitStep("wait for clean screen", 8);
AddAssert("is not present", () => !spewer.IsPresent);
}
2021-09-19 13:35:03 +00: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, () => Is.EqualTo(1));
2021-09-19 13:35:03 +00:00
AddStep("move clock forward", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * 3);
AddAssert("spawned second particle", () => spewer.TotalCreatedParticles, () => Is.EqualTo(2));
2021-09-19 13:35:03 +00:00
AddStep("move clock backwards", () => testClock.CurrentTime = TestParticleSpewer.MAX_DURATION * -1);
AddAssert("spawned third particle", () => spewer.TotalCreatedParticles, () => Is.EqualTo(3));
2021-09-19 13:35:03 +00:00
}
private TestParticleSpewer createSpewer() =>
2022-09-18 09:18:10 +00:00
new TestParticleSpewer(skinManager.DefaultClassicSkin.GetTexture("star2"))
2021-09-09 22:02:37 +00:00
{
Origin = Anchor.Centre,
2021-09-18 20:54:12 +00:00
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Position = new Vector2(0.5f),
Size = new Vector2(0.5f),
2021-09-09 22:02:37 +00:00
};
private partial class TestParticleSpewer : ParticleSpewer
{
2021-09-19 13:35:03 +00:00
public const int MAX_DURATION = 1500;
private const int rate = 250;
2021-09-19 13:35:03 +00: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 13:35:03 +00:00
: base(texture, rate, MAX_DURATION)
2021-09-09 22:02:37 +00:00
{
}
2021-09-19 13:35:03 +00: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 13:35:03 +00: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 13:35:03 +00:00
}
}
2021-09-09 22:02:37 +00:00
}
}