1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Refactor gameplay cursor test scene and add visual coverage

This commit is contained in:
Salman Ahmed 2021-04-14 06:36:31 +03:00
parent bf5ed12b75
commit df991bc0af

View File

@ -4,13 +4,22 @@
using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.Testing.Input;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Skinning;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
@ -21,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Tests
[Cached]
private GameplayBeatmap gameplayBeatmap;
private ClickingCursorContainer lastContainer;
private OsuCursorContainer lastContainer;
[Resolved]
private OsuConfigManager config { get; set; }
@ -48,12 +57,10 @@ namespace osu.Game.Rulesets.Osu.Tests
{
config.SetValue(OsuSetting.AutoCursorSize, true);
gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = val;
Scheduler.AddOnce(recreate);
Scheduler.AddOnce(() => loadContent(false));
});
AddStep("test cursor container", recreate);
void recreate() => SetContents(() => new OsuInputManager(new OsuRuleset().RulesetInfo) { Child = new OsuCursorContainer() });
AddStep("test cursor container", () => loadContent(false));
}
[TestCase(1, 1)]
@ -68,7 +75,7 @@ namespace osu.Game.Rulesets.Osu.Tests
AddStep($"adjust cs to {circleSize}", () => gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = circleSize);
AddStep("turn on autosizing", () => config.SetValue(OsuSetting.AutoCursorSize, true));
AddStep("load content", loadContent);
AddStep("load content", () => loadContent());
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == OsuCursorContainer.GetScaleForCircleSize(circleSize) * userScale);
@ -82,18 +89,47 @@ namespace osu.Game.Rulesets.Osu.Tests
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == userScale);
}
private void loadContent()
[Test]
public void TestTopLeftOrigin()
{
SetContents(() => new MovingCursorInputManager
{
Child = lastContainer = new ClickingCursorContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
AddStep("load content", () => loadContent(false, () => new SkinProvidingContainer(new TopLeftCursorSkin())));
AddAssert("cursor top left", () => lastContainer.ActiveCursor.Origin == Anchor.TopLeft);
}
private void loadContent(bool automated = true, Func<SkinProvidingContainer> skinProvider = null)
{
SetContents(() =>
{
var inputManager = automated ? (InputManager)new MovingCursorInputManager() : new OsuInputManager(new OsuRuleset().RulesetInfo);
var skinContainer = skinProvider?.Invoke() ?? new SkinProvidingContainer(null);
lastContainer = automated ? new ClickingCursorContainer() : new OsuCursorContainer();
return inputManager.WithChild(skinContainer.WithChild(lastContainer));
});
}
private class TopLeftCursorSkin : ISkin
{
public Drawable GetDrawableComponent(ISkinComponent component) => null;
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null;
public ISample GetSample(ISampleInfo sampleInfo) => null;
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
{
case OsuSkinConfiguration osuLookup:
if (osuLookup == OsuSkinConfiguration.CursorCentre)
return SkinUtils.As<TValue>(new BindableBool(false));
break;
}
return null;
}
}
private class ClickingCursorContainer : OsuCursorContainer
{
private bool pressed;