2021-07-02 14:09:37 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-02 14:09:37 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Catch.Skinning;
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using Direction = osu.Game.Rulesets.Catch.UI.Direction;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Tests
|
|
|
|
{
|
|
|
|
public partial class TestSceneCatchSkinConfiguration : OsuTestScene
|
|
|
|
{
|
|
|
|
private Catcher catcher;
|
|
|
|
|
|
|
|
private readonly Container container;
|
|
|
|
|
|
|
|
public TestSceneCatchSkinConfiguration()
|
|
|
|
{
|
|
|
|
Add(container = new Container { RelativeSizeAxes = Axes.Both });
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(false)]
|
|
|
|
[TestCase(true)]
|
|
|
|
public void TestCatcherPlateFlipping(bool flip)
|
|
|
|
{
|
|
|
|
AddStep("setup catcher", () =>
|
|
|
|
{
|
|
|
|
var skin = new TestSkin { FlipCatcherPlate = flip };
|
|
|
|
container.Child = new SkinProvidingContainer(skin)
|
|
|
|
{
|
2021-07-27 09:59:55 +00:00
|
|
|
Child = catcher = new Catcher(new DroppedObjectContainer())
|
2021-07-02 14:09:37 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
Fruit fruit = new Fruit();
|
|
|
|
|
|
|
|
AddStep("catch fruit", () => catchFruit(fruit, 20));
|
|
|
|
|
|
|
|
float position = 0;
|
|
|
|
|
|
|
|
AddStep("record fruit position", () => position = getCaughtObjectPosition(fruit));
|
|
|
|
|
|
|
|
AddStep("face left", () => catcher.VisualDirection = Direction.Left);
|
|
|
|
|
|
|
|
if (flip)
|
|
|
|
AddAssert("fruit position changed", () => !Precision.AlmostEquals(getCaughtObjectPosition(fruit), position));
|
|
|
|
else
|
|
|
|
AddAssert("fruit position unchanged", () => Precision.AlmostEquals(getCaughtObjectPosition(fruit), position));
|
|
|
|
|
|
|
|
AddStep("face right", () => catcher.VisualDirection = Direction.Right);
|
|
|
|
|
|
|
|
AddAssert("fruit position restored", () => Precision.AlmostEquals(getCaughtObjectPosition(fruit), position));
|
|
|
|
}
|
|
|
|
|
|
|
|
private float getCaughtObjectPosition(Fruit fruit)
|
|
|
|
{
|
|
|
|
var caughtObject = catcher.ChildrenOfType<CaughtObject>().Single(c => c.HitObject == fruit);
|
2023-10-17 08:40:44 +00:00
|
|
|
return caughtObject.Parent!.ToSpaceOfOtherDrawable(caughtObject.Position, catcher).X;
|
2021-07-02 14:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void catchFruit(Fruit fruit, float x)
|
|
|
|
{
|
|
|
|
fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
var drawableFruit = new DrawableFruit(fruit) { X = x };
|
|
|
|
var judgement = fruit.CreateJudgement();
|
|
|
|
catcher.OnNewResult(drawableFruit, new CatchJudgementResult(fruit, judgement)
|
|
|
|
{
|
|
|
|
Type = judgement.MaxResult
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-17 15:14:49 +00:00
|
|
|
private class TestSkin : TrianglesSkin
|
2021-07-02 14:09:37 +00:00
|
|
|
{
|
|
|
|
public bool FlipCatcherPlate { get; set; }
|
|
|
|
|
|
|
|
public TestSkin()
|
2022-11-09 07:45:06 +00:00
|
|
|
: base(null!)
|
2021-07-02 14:09:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
|
|
|
{
|
|
|
|
if (lookup is CatchSkinConfiguration config)
|
|
|
|
{
|
|
|
|
if (config == CatchSkinConfiguration.FlipCatcherPlate)
|
|
|
|
return SkinUtils.As<TValue>(new Bindable<bool>(FlipCatcherPlate));
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.GetConfig<TLookup, TValue>(lookup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|