1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Add failing test cases

This commit is contained in:
Bartłomiej Dach 2020-07-14 22:51:30 +02:00
parent e0df75d735
commit bbc7d69524
2 changed files with 83 additions and 40 deletions

View File

@ -4,24 +4,62 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Pooling;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Tests namespace osu.Game.Rulesets.Osu.Tests
{ {
public class TestSceneDrawableJudgement : OsuSkinnableTestScene public class TestSceneDrawableJudgement : OsuSkinnableTestScene
{ {
[Resolved]
private OsuConfigManager config { get; set; }
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools;
public TestSceneDrawableJudgement() public TestSceneDrawableJudgement()
{ {
var pools = new List<DrawablePool<DrawableOsuJudgement>>(); pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1)) foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
showResult(result);
}
[Test]
public void TestHitLightingDisabled()
{
AddStep("hit lighting disabled", () => config.Set(OsuSetting.HitLighting, false));
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddAssert("hit lighting hidden",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha == 0));
}
[Test]
public void TestHitLightingEnabled()
{
AddStep("hit lighting enabled", () => config.Set(OsuSetting.HitLighting, true));
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddAssert("hit lighting shown",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha > 0));
}
private void showResult(HitResult result)
{ {
AddStep("Show " + result.GetDescription(), () => AddStep("Show " + result.GetDescription(), () =>
{ {
@ -29,10 +67,10 @@ namespace osu.Game.Rulesets.Osu.Tests
SetContents(() => SetContents(() =>
{ {
DrawablePool<DrawableOsuJudgement> pool; DrawablePool<TestDrawableOsuJudgement> pool;
if (poolIndex >= pools.Count) if (poolIndex >= pools.Count)
pools.Add(pool = new DrawablePool<DrawableOsuJudgement>(1)); pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
else else
{ {
pool = pools[poolIndex]; pool = pools[poolIndex];
@ -60,6 +98,10 @@ namespace osu.Game.Rulesets.Osu.Tests
}); });
}); });
} }
private class TestDrawableOsuJudgement : DrawableOsuJudgement
{
public new SkinnableSprite Lighting => base.Lighting;
} }
} }
} }

View File

@ -16,7 +16,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
public class DrawableOsuJudgement : DrawableJudgement public class DrawableOsuJudgement : DrawableJudgement
{ {
private SkinnableSprite lighting; protected SkinnableSprite Lighting;
private Bindable<Color4> lightingColour; private Bindable<Color4> lightingColour;
public DrawableOsuJudgement(JudgementResult result, DrawableHitObject judgedObject) public DrawableOsuJudgement(JudgementResult result, DrawableHitObject judgedObject)
@ -33,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
if (config.Get<bool>(OsuSetting.HitLighting)) if (config.Get<bool>(OsuSetting.HitLighting))
{ {
AddInternal(lighting = new SkinnableSprite("lighting") AddInternal(Lighting = new SkinnableSprite("lighting")
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -60,32 +61,32 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
lightingColour?.UnbindAll(); lightingColour?.UnbindAll();
if (lighting != null) if (Lighting != null)
{ {
lighting.ResetAnimation(); Lighting.ResetAnimation();
if (JudgedObject != null) if (JudgedObject != null)
{ {
lightingColour = JudgedObject.AccentColour.GetBoundCopy(); lightingColour = JudgedObject.AccentColour.GetBoundCopy();
lightingColour.BindValueChanged(colour => lighting.Colour = Result.Type == HitResult.Miss ? Color4.Transparent : colour.NewValue, true); lightingColour.BindValueChanged(colour => Lighting.Colour = Result.Type == HitResult.Miss ? Color4.Transparent : colour.NewValue, true);
} }
else else
{ {
lighting.Colour = Color4.White; Lighting.Colour = Color4.White;
} }
} }
} }
protected override double FadeOutDelay => lighting == null ? base.FadeOutDelay : 1400; protected override double FadeOutDelay => Lighting == null ? base.FadeOutDelay : 1400;
protected override void ApplyHitAnimations() protected override void ApplyHitAnimations()
{ {
if (lighting != null) if (Lighting != null)
{ {
JudgementBody.FadeIn().Delay(FadeInDuration).FadeOut(400); JudgementBody.FadeIn().Delay(FadeInDuration).FadeOut(400);
lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out); Lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
lighting.FadeIn(200).Then().Delay(200).FadeOut(1000); Lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
} }
JudgementText?.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); JudgementText?.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);