osu/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs

141 lines
4.8 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.
2018-04-13 09:19:50 +00:00
using System.Linq;
2018-04-13 09:19:50 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
2018-04-13 09:19:50 +00:00
using osu.Game.Beatmaps;
2020-03-10 06:26:39 +00:00
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration;
2020-03-10 06:26:39 +00:00
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables;
2018-04-13 09:19:50 +00:00
using osu.Game.Rulesets.Catch.UI;
2020-03-10 06:26:39 +00:00
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class TestSceneCatcherArea : CatchSkinnableTestScene
2018-04-13 09:19:50 +00:00
{
private RulesetInfo catchRuleset;
2020-07-16 18:08:48 +00:00
[Resolved]
private OsuConfigManager config { get; set; }
2018-04-13 09:19:50 +00:00
2020-07-16 18:12:32 +00:00
private Catcher catcher => this.ChildrenOfType<CatcherArea>().First().MovableCatcher;
public TestSceneCatcherArea()
2018-04-13 09:19:50 +00:00
{
AddSliderStep<float>("CircleSize", 0, 8, 5, createCatcher);
AddToggleStep("Hyperdash", t =>
CreatedDrawables.OfType<CatchInputManager>().Select(i => i.Child)
.OfType<TestCatcherArea>().ForEach(c => c.ToggleHyperDash(t)));
2020-03-10 06:26:39 +00:00
AddRepeatStep("catch fruit", () => catchFruit(new TestFruit(false)
{
2020-07-16 18:12:32 +00:00
X = catcher.X
2020-03-10 06:26:39 +00:00
}), 20);
AddRepeatStep("catch fruit last in combo", () => catchFruit(new TestFruit(false)
{
2020-07-16 18:12:32 +00:00
X = catcher.X,
2020-03-10 06:26:39 +00:00
LastInCombo = true,
}), 20);
AddRepeatStep("catch kiai fruit", () => catchFruit(new TestFruit(true)
{
2020-07-16 18:12:32 +00:00
X = catcher.X
2020-03-10 06:26:39 +00:00
}), 20);
AddRepeatStep("miss fruit", () => catchFruit(new Fruit
{
2020-07-16 18:12:32 +00:00
X = catcher.X + 100,
2020-03-10 06:26:39 +00:00
LastInCombo = true,
}, true), 20);
}
[TestCase(true)]
[TestCase(false)]
2020-07-16 08:32:07 +00:00
public void TestHitLighting(bool enable)
{
AddStep("create catcher", () => createCatcher(5));
AddStep("toggle hit lighting", () => config.Set(OsuSetting.HitLighting, enable));
AddStep("catch fruit", () => catchFruit(new TestFruit(false)
{
X = catcher.X
}));
AddStep("catch fruit last in combo", () => catchFruit(new TestFruit(false)
{
X = catcher.X,
LastInCombo = true
}));
AddAssert("check hit explosion", () => catcher.ChildrenOfType<HitExplosion>().Any() == enable);
}
2020-03-10 06:26:39 +00:00
private void catchFruit(Fruit fruit, bool miss = false)
{
this.ChildrenOfType<CatcherArea>().ForEach(area =>
{
DrawableFruit drawable = new DrawableFruit(fruit);
area.Add(drawable);
Schedule(() =>
{
area.AttemptCatch(fruit);
2020-09-12 20:39:06 +00:00
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement()) { Type = miss ? HitResult.Miss : HitResult.Great });
2020-03-10 06:26:39 +00:00
drawable.Expire();
});
});
2018-04-13 09:19:50 +00:00
}
private void createCatcher(float size)
{
SetContents(() => new CatchInputManager(catchRuleset)
2018-04-13 09:19:50 +00:00
{
RelativeSizeAxes = Axes.Both,
Child = new TestCatcherArea(new BeatmapDifficulty { CircleSize = size })
2018-04-13 09:19:50 +00:00
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
2020-03-10 06:26:39 +00:00
CreateDrawableRepresentation = ((DrawableRuleset<CatchHitObject>)catchRuleset.CreateInstance().CreateDrawableRulesetWith(new CatchBeatmap())).CreateDrawableRepresentation
2018-04-13 09:19:50 +00:00
},
});
2018-04-13 09:19:50 +00:00
}
[BackgroundDependencyLoader]
2020-07-16 18:08:48 +00:00
private void load(RulesetStore rulesets)
2018-04-13 09:19:50 +00:00
{
catchRuleset = rulesets.GetRuleset(2);
}
2020-03-10 06:26:39 +00:00
public class TestFruit : Fruit
{
public TestFruit(bool kiai)
{
var kiaiCpi = new ControlPointInfo();
kiaiCpi.Add(0, new EffectControlPoint { KiaiMode = kiai });
ApplyDefaultsToSelf(kiaiCpi, new BeatmapDifficulty());
}
}
2018-04-13 09:19:50 +00:00
private class TestCatcherArea : CatcherArea
{
public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
: base(beatmapDifficulty)
{
}
2018-06-03 06:31:51 +00:00
public new Catcher MovableCatcher => base.MovableCatcher;
public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
2018-04-13 09:19:50 +00:00
}
}
}