mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 21:43:22 +08:00
Add more TestSceneCatcher tests
Some tests are moved from TestSceneCatcherArea
This commit is contained in:
parent
5a5c956ced
commit
1d669cf65e
@ -1,26 +1,192 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Catch.Objects;
|
||||
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneCatcher : CatchSkinnableTestScene
|
||||
public class TestSceneCatcher : OsuTestScene
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
[Resolved]
|
||||
private OsuConfigManager config { get; set; }
|
||||
|
||||
private Container droppedObjectContainer;
|
||||
|
||||
private TestCatcher catcher;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
SetContents(() => new Catcher(new Container(), new Container())
|
||||
var difficulty = new BeatmapDifficulty
|
||||
{
|
||||
CircleSize = 0,
|
||||
};
|
||||
|
||||
var trailContainer = new Container();
|
||||
droppedObjectContainer = new Container();
|
||||
catcher = new TestCatcher(trailContainer, droppedObjectContainer, difficulty);
|
||||
|
||||
Child = new Container
|
||||
{
|
||||
RelativePositionAxes = Axes.None,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
trailContainer,
|
||||
droppedObjectContainer,
|
||||
catcher
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestCatcherCatchWidth()
|
||||
{
|
||||
var halfWidth = Catcher.CalculateCatchWidth(new BeatmapDifficulty { CircleSize = 0 }) / 2;
|
||||
AddStep("catch fruit", () =>
|
||||
{
|
||||
attemptCatch(new Fruit { X = -halfWidth + 1 });
|
||||
attemptCatch(new Fruit { X = halfWidth - 1 });
|
||||
});
|
||||
checkPlate(2);
|
||||
AddStep("miss fruit", () =>
|
||||
{
|
||||
attemptCatch(new Fruit { X = -halfWidth - 1 });
|
||||
attemptCatch(new Fruit { X = halfWidth + 1 });
|
||||
});
|
||||
checkPlate(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCatcherStateFruit()
|
||||
{
|
||||
AddStep("miss fruit", () => attemptCatch(new Fruit { X = 100 }));
|
||||
checkState(CatcherAnimationState.Fail);
|
||||
AddStep("catch fruit", () => attemptCatch(new Fruit()));
|
||||
checkState(CatcherAnimationState.Idle);
|
||||
AddStep("catch kiai fruit", () => attemptCatch(new TestKiaiFruit()));
|
||||
checkState(CatcherAnimationState.Kiai);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCatcherStateTinyDroplet()
|
||||
{
|
||||
AddStep("catch hyper kiai fruit", () => attemptCatch(new TestKiaiFruit
|
||||
{
|
||||
HyperDashTarget = new Fruit { X = 100 }
|
||||
}));
|
||||
AddStep("catch tiny droplet", () => attemptCatch(new TinyDroplet()));
|
||||
AddStep("miss tiny droplet", () => attemptCatch(new TinyDroplet { X = 100 }));
|
||||
checkState(CatcherAnimationState.Kiai);
|
||||
checkHyperDash(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCatcherStateBanana()
|
||||
{
|
||||
AddStep("catch hyper kiai fruit", () => attemptCatch(new TestKiaiFruit
|
||||
{
|
||||
HyperDashTarget = new Fruit { X = 100 }
|
||||
}));
|
||||
AddStep("miss banana", () => attemptCatch(new Banana()));
|
||||
checkState(CatcherAnimationState.Idle);
|
||||
checkHyperDash(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCatcherStacking()
|
||||
{
|
||||
AddStep("catch fruit", () => attemptCatch(new Fruit()));
|
||||
checkPlate(1);
|
||||
AddStep("catch more fruits", () => attemptCatch(new Fruit(), 9));
|
||||
checkPlate(10);
|
||||
AddAssert("caught objects are stacked", () =>
|
||||
catcher.CaughtObjects.All(obj => obj.Y <= 0) &&
|
||||
catcher.CaughtObjects.Any(obj => obj.Y == 0) &&
|
||||
catcher.CaughtObjects.Any(obj => obj.Y < -20));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCatcherExplosionAndDropping()
|
||||
{
|
||||
AddStep("catch fruit", () => attemptCatch(new Fruit()));
|
||||
AddStep("catch tiny droplet", () => attemptCatch(new TinyDroplet()));
|
||||
AddAssert("tiny droplet is exploded", () => catcher.CaughtObjects.Count() == 1 && droppedObjectContainer.Count == 1);
|
||||
AddUntilStep("wait explosion", () => !droppedObjectContainer.Any());
|
||||
AddStep("catch more fruits", () => attemptCatch(new Fruit(), 9));
|
||||
AddStep("explode", () => catcher.Explode());
|
||||
AddAssert("fruits are exploded", () => !catcher.CaughtObjects.Any() && droppedObjectContainer.Count == 10);
|
||||
AddUntilStep("wait explosion", () => !droppedObjectContainer.Any());
|
||||
AddStep("catch fruits", () => attemptCatch(new Fruit(), 10));
|
||||
AddStep("drop", () => catcher.Drop());
|
||||
AddAssert("fruits are dropped", () => !catcher.CaughtObjects.Any() && droppedObjectContainer.Count == 10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHyperFruitHyperDash()
|
||||
{
|
||||
AddStep("catch hyper fruit", () => attemptCatch(new Fruit
|
||||
{
|
||||
HyperDashTarget = new Fruit { X = 100 }
|
||||
}));
|
||||
checkHyperDash(true);
|
||||
AddStep("catch normal fruit", () => attemptCatch(new Fruit()));
|
||||
checkHyperDash(false);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestHitLighting(bool enabled)
|
||||
{
|
||||
AddStep($"{(enabled ? "enable" : "disable")} hit lighting", () => config.Set(OsuSetting.HitLighting, enabled));
|
||||
AddStep("catch fruit", () => attemptCatch(new Fruit()));
|
||||
AddAssert("check hit lighting", () => catcher.ChildrenOfType<HitExplosion>().Any() == enabled);
|
||||
}
|
||||
|
||||
private void checkPlate(int count) => AddAssert($"{count} objects on the plate", () => catcher.CaughtObjects.Count() == count);
|
||||
|
||||
private void checkState(CatcherAnimationState state) => AddAssert($"catcher state is {state}", () => catcher.CurrentState == state);
|
||||
|
||||
private void checkHyperDash(bool state) => AddAssert($"catcher is {(state ? "" : "not ")}hyper dashing", () => catcher.HyperDashing == state);
|
||||
|
||||
private void attemptCatch(CatchHitObject hitObject, int count = 1)
|
||||
{
|
||||
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
catcher.AttemptCatch(hitObject);
|
||||
}
|
||||
|
||||
public class TestCatcher : Catcher
|
||||
{
|
||||
public IEnumerable<DrawablePalpableCatchHitObject> CaughtObjects => this.ChildrenOfType<DrawablePalpableCatchHitObject>();
|
||||
|
||||
public TestCatcher(Container trailsTarget, Container droppedObjectTarget, BeatmapDifficulty difficulty)
|
||||
: base(trailsTarget, droppedObjectTarget, difficulty)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class TestKiaiFruit : Fruit
|
||||
{
|
||||
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
||||
{
|
||||
controlPointInfo.Add(0, new EffectControlPoint { KiaiMode = true });
|
||||
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,73 +27,51 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
[Resolved]
|
||||
private OsuConfigManager config { get; set; }
|
||||
|
||||
private Catcher catcher => this.ChildrenOfType<CatcherArea>().First().MovableCatcher;
|
||||
private Catcher catcher => this.ChildrenOfType<Catcher>().First();
|
||||
|
||||
private float circleSize;
|
||||
|
||||
public TestSceneCatcherArea()
|
||||
{
|
||||
AddSliderStep<float>("CircleSize", 0, 8, 5, createCatcher);
|
||||
AddToggleStep("Hyperdash", t =>
|
||||
CreatedDrawables.OfType<CatchInputManager>().Select(i => i.Child)
|
||||
.OfType<TestCatcherArea>().ForEach(c => c.ToggleHyperDash(t)));
|
||||
AddSliderStep<float>("circle size", 0, 8, 5, createCatcher);
|
||||
AddToggleStep("hyper dash", t => this.ChildrenOfType<TestCatcherArea>().ForEach(area => area.ToggleHyperDash(t)));
|
||||
|
||||
AddRepeatStep("catch fruit", () => catchFruit(new TestFruit(false)
|
||||
{
|
||||
X = catcher.X
|
||||
}), 20);
|
||||
AddRepeatStep("catch fruit last in combo", () => catchFruit(new TestFruit(false)
|
||||
{
|
||||
X = catcher.X,
|
||||
LastInCombo = true,
|
||||
}), 20);
|
||||
AddRepeatStep("catch kiai fruit", () => catchFruit(new TestFruit(true)
|
||||
{
|
||||
X = catcher.X
|
||||
}), 20);
|
||||
AddRepeatStep("miss fruit", () => catchFruit(new Fruit
|
||||
{
|
||||
X = catcher.X + 100,
|
||||
LastInCombo = true,
|
||||
}, true), 20);
|
||||
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 }));
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestHitLighting(bool enable)
|
||||
private void attemptCatch(Fruit fruit)
|
||||
{
|
||||
AddStep("create catcher", () => createCatcher(5));
|
||||
|
||||
AddStep("toggle hit lighting", () => config.Set(OsuSetting.HitLighting, enable));
|
||||
AddStep("catch fruit", () => catchFruit(new TestFruit(false)
|
||||
fruit.X += catcher.X;
|
||||
fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty
|
||||
{
|
||||
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);
|
||||
}
|
||||
CircleSize = circleSize
|
||||
});
|
||||
|
||||
private void catchFruit(Fruit fruit, bool miss = false)
|
||||
{
|
||||
this.ChildrenOfType<CatcherArea>().ForEach(area =>
|
||||
foreach (var area in this.ChildrenOfType<CatcherArea>())
|
||||
{
|
||||
DrawableFruit drawable = new DrawableFruit(fruit);
|
||||
area.Add(drawable);
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
area.AttemptCatch(fruit);
|
||||
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement()) { Type = miss ? HitResult.Miss : HitResult.Great });
|
||||
bool caught = area.AttemptCatch(fruit);
|
||||
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement())
|
||||
{
|
||||
Type = caught ? HitResult.Great : HitResult.Miss
|
||||
});
|
||||
|
||||
drawable.Expire();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void createCatcher(float size)
|
||||
{
|
||||
circleSize = size;
|
||||
|
||||
SetContents(() => new CatchInputManager(catchRuleset)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -111,17 +89,6 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
catchRuleset = rulesets.GetRuleset(2);
|
||||
}
|
||||
|
||||
public class TestFruit : Fruit
|
||||
{
|
||||
public TestFruit(bool kiai)
|
||||
{
|
||||
var kiaiCpi = new ControlPointInfo();
|
||||
kiaiCpi.Add(0, new EffectControlPoint { KiaiMode = kiai });
|
||||
|
||||
ApplyDefaultsToSelf(kiaiCpi, new BeatmapDifficulty());
|
||||
}
|
||||
}
|
||||
|
||||
private class TestCatcherArea : CatcherArea
|
||||
{
|
||||
public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
|
||||
@ -129,8 +96,6 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
}
|
||||
|
||||
public new Catcher MovableCatcher => base.MovableCatcher;
|
||||
|
||||
public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user