osu/osu.Game.Rulesets.Osu.Tests/TestSceneDrawableJudgement.cs

115 lines
4.3 KiB
C#
Raw Normal View History

// 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;
2020-07-13 11:55:55 +00:00
using System.Collections.Generic;
2019-08-20 08:47:24 +00:00
using System.Linq;
2020-07-14 20:51:30 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
2020-07-13 11:55:55 +00:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
2020-07-14 20:51:30 +00:00
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
2020-07-14 20:51:30 +00:00
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Tests
{
2022-11-24 05:32:20 +00:00
public partial class TestSceneDrawableJudgement : OsuSkinnableTestScene
{
2020-07-14 20:51:30 +00:00
[Resolved]
2023-06-22 16:37:25 +00:00
private OsuConfigManager config { get; set; } = null!;
2020-07-14 20:51:30 +00:00
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
2020-07-14 20:51:30 +00:00
[TestCaseSource(nameof(validResults))]
public void Test(HitResult result)
{
showResult(result);
2020-07-14 20:51:30 +00:00
}
private static IEnumerable<HitResult> validResults => Enum.GetValues<HitResult>().Skip(1);
2020-07-14 20:51:30 +00:00
[Test]
public void TestHitLightingDisabled()
{
AddStep("hit lighting disabled", () => config.SetValue(OsuSetting.HitLighting, false));
2020-07-14 20:51:30 +00:00
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddAssert("hit lighting has no transforms", () => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => !judgement.Lighting.Transforms.Any()));
AddAssert("hit lighting hidden", () => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha == 0));
2020-07-14 20:51:30 +00:00
}
[Test]
public void TestHitLightingEnabled()
{
AddStep("hit lighting enabled", () => config.SetValue(OsuSetting.HitLighting, true));
2020-07-14 20:51:30 +00:00
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddUntilStep("hit lighting shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any(judgement => judgement.Lighting.Alpha > 0));
2020-07-14 20:51:30 +00:00
}
private void showResult(HitResult result)
{
AddStep("Show " + result.GetDescription(), () =>
2019-11-11 11:53:22 +00:00
{
2020-07-14 20:51:30 +00:00
int poolIndex = 0;
SetContents(_ =>
2020-07-13 11:55:55 +00:00
{
2020-07-14 20:51:30 +00:00
DrawablePool<TestDrawableOsuJudgement> pool;
2020-07-13 11:55:55 +00:00
2020-07-14 20:51:30 +00:00
if (poolIndex >= pools.Count)
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
else
2019-08-20 08:47:24 +00:00
{
2020-07-14 20:51:30 +00:00
// We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent.
pool = pools[poolIndex];
((Container)pool.Parent!).Clear(false);
2020-07-14 20:51:30 +00:00
}
2020-07-13 11:55:55 +00:00
2020-07-14 20:51:30 +00:00
var container = new Container
{
RelativeSizeAxes = Axes.Both,
Child = pool,
2020-07-14 20:51:30 +00:00
};
// Must be scheduled so the pool is loaded before we try and retrieve from it.
Schedule(() =>
{
container.Add(pool.Get(j => j.Apply(new JudgementResult(new HitObject
{
StartTime = Time.Current
}, new Judgement())
{
Type = result,
}, null)).With(j =>
{
j.Anchor = Anchor.Centre;
j.Origin = Anchor.Centre;
}));
});
2020-07-14 20:51:30 +00:00
poolIndex++;
return container;
2020-07-13 11:55:55 +00:00
});
2020-07-14 20:51:30 +00:00
});
}
2022-11-24 05:32:20 +00:00
private partial class TestDrawableOsuJudgement : DrawableOsuJudgement
2020-07-14 20:51:30 +00:00
{
public new SkinnableSprite Lighting => base.Lighting;
public new SkinnableDrawable JudgementBody => base.JudgementBody;
}
}
}