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

113 lines
3.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;
2020-12-04 01:21:54 +00:00
using osu.Framework.Graphics.Containers;
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.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;
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
private Catcher catcher => this.ChildrenOfType<Catcher>().First();
private float circleSize;
2020-07-16 18:12:32 +00:00
public TestSceneCatcherArea()
2018-04-13 09:19:50 +00:00
{
AddSliderStep<float>("circle size", 0, 8, 5, createCatcher);
AddToggleStep("hyper dash", t => this.ChildrenOfType<TestCatcherArea>().ForEach(area => area.ToggleHyperDash(t)));
AddStep("catch fruit", () => attemptCatch(new Fruit()));
AddStep("catch fruit last in combo", () => attemptCatch(new Fruit { LastInCombo = true }));
AddStep("catch kiai fruit", () => attemptCatch(new TestSceneCatcher.TestKiaiFruit()));
AddStep("miss last in combo", () => attemptCatch(new Fruit { X = 100, LastInCombo = true }));
2020-03-10 06:26:39 +00:00
}
private void attemptCatch(Fruit fruit)
2020-07-16 08:32:07 +00:00
{
fruit.X += catcher.X;
fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty
{
CircleSize = circleSize
});
foreach (var area in this.ChildrenOfType<CatcherArea>())
2020-03-10 06:26:39 +00:00
{
DrawableFruit drawable = new DrawableFruit(fruit);
area.Add(drawable);
Schedule(() =>
{
bool caught = area.AttemptCatch(fruit);
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement())
{
Type = caught ? HitResult.Great : HitResult.Miss
});
2020-03-10 06:26:39 +00:00
drawable.Expire();
});
}
2018-04-13 09:19:50 +00:00
}
private void createCatcher(float size)
{
circleSize = size;
2020-12-04 01:21:54 +00:00
SetContents(() =>
2018-04-13 09:19:50 +00:00
{
2020-12-04 01:21:54 +00:00
var droppedObjectContainer = new Container();
return new CatchInputManager(catchRuleset)
2018-04-13 09:19:50 +00:00
{
2020-12-04 01:21:54 +00:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
droppedObjectContainer,
new TestCatcherArea(droppedObjectContainer, new BeatmapDifficulty { CircleSize = size })
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
}
}
};
});
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);
}
private class TestCatcherArea : CatcherArea
{
2020-12-04 01:21:54 +00:00
public TestCatcherArea(Container droppedObjectContainer, BeatmapDifficulty beatmapDifficulty)
: base(droppedObjectContainer, beatmapDifficulty)
2018-04-13 09:19:50 +00:00
{
}
2018-06-03 06:31:51 +00:00
public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
2018-04-13 09:19:50 +00:00
}
}
}