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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
4.6 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
2022-06-17 07:37:17 +00:00
#nullable disable
using System.Linq;
2017-09-18 13:32:49 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
2017-09-18 13:32:49 +00:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Framework.Utils;
2017-11-28 10:43:26 +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;
2017-09-18 13:32:49 +00:00
using osu.Game.Rulesets.Catch.UI;
2020-03-10 06:26:39 +00:00
using osu.Game.Rulesets.Scoring;
2018-04-13 09:19:50 +00:00
2017-09-18 13:32:49 +00:00
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class TestSceneCatcherArea : CatchSkinnableTestScene
2017-09-18 13:32:49 +00:00
{
2017-11-28 10:43:26 +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
private ScheduledDelegate addManyFruit;
private IBeatmapDifficultyInfo beatmapDifficulty;
public TestSceneCatcherArea()
2017-11-28 10:43:26 +00:00
{
AddSliderStep<float>("circle size", 0, 8, 5, createCatcher);
AddToggleStep("hyper dash", t => this.ChildrenOfType<TestCatcherArea>().ForEach(area => area.ToggleHyperDash(t)));
AddToggleStep("toggle hit lighting", lighting => config.SetValue(OsuSetting.HitLighting, lighting));
AddStep("catch centered fruit", () => attemptCatch(new Fruit()));
AddStep("catch many random fruit", () =>
{
int count = 50;
addManyFruit?.Cancel();
addManyFruit = Scheduler.AddDelayed(() =>
{
attemptCatch(new Fruit
{
X = (RNG.NextSingle() - 0.5f) * Catcher.CalculateCatchWidth(beatmapDifficulty) * 0.6f,
});
if (count-- == 0)
addManyFruit?.Cancel();
}, 50, true);
});
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 = fruit.OriginalX + catcher.X;
fruit.ApplyDefaults(new ControlPointInfo(), beatmapDifficulty);
foreach (var area in this.ChildrenOfType<CatcherArea>())
2020-03-10 06:26:39 +00:00
{
DrawableFruit drawable = new DrawableFruit(fruit);
area.Add(drawable);
Schedule(() =>
{
2020-12-08 08:04:26 +00:00
area.OnNewResult(drawable, new CatchJudgementResult(fruit, new CatchJudgement())
{
Type = area.Catcher.CanCatch(fruit) ? HitResult.Great : HitResult.Miss
});
2020-03-10 06:26:39 +00:00
drawable.Expire();
});
}
2017-11-28 10:43:26 +00:00
}
2018-04-13 09:19:50 +00:00
2017-11-28 12:30:03 +00:00
private void createCatcher(float size)
2017-09-18 13:32:49 +00:00
{
circleSize = size;
beatmapDifficulty = new BeatmapDifficulty
{
CircleSize = circleSize
};
SetContents(_ =>
2017-09-18 13:32:49 +00:00
{
2020-12-04 01:21:54 +00:00
return new CatchInputManager(catchRuleset)
2017-09-18 13:32:49 +00:00
{
2020-12-04 01:21:54 +00:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new TestCatcherArea(beatmapDifficulty)
2020-12-04 01:21:54 +00:00
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
}
}
};
});
2017-09-18 13:32:49 +00:00
}
2018-04-13 09:19:50 +00:00
2017-11-28 10:43:26 +00:00
[BackgroundDependencyLoader]
2020-07-16 18:08:48 +00:00
private void load(RulesetStore rulesets)
2017-11-28 10:43:26 +00:00
{
catchRuleset = rulesets.GetRuleset(2);
}
2018-04-13 09:19:50 +00:00
private class TestCatcherArea : CatcherArea
{
public TestCatcherArea(IBeatmapDifficultyInfo beatmapDifficulty)
{
var droppedObjectContainer = new DroppedObjectContainer();
Add(droppedObjectContainer);
Catcher = new Catcher(droppedObjectContainer, beatmapDifficulty)
2021-07-19 10:44:40 +00:00
{
X = CatchPlayfield.CENTER_X
};
}
2018-06-03 06:31:51 +00:00
public void ToggleHyperDash(bool status) => Catcher.SetHyperDashState(status ? 2 : 1);
}
2017-09-18 13:32:49 +00:00
}
}