2020-04-05 13:54:15 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2020-03-29 14:00:26 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
using System;
|
2020-03-29 14:00:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-04-04 12:10:54 +00:00
|
|
|
|
using Humanizer;
|
2020-03-29 14:00:26 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Configuration;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2020-12-04 11:21:53 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2020-03-29 14:00:26 +00:00
|
|
|
|
using osu.Game.Storyboards;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestSceneSliderSnaking : TestSceneOsuPlayer
|
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private AudioManager audioManager { get; set; }
|
|
|
|
|
|
2020-03-29 14:43:18 +00:00
|
|
|
|
protected override bool Autoplay => autoplay;
|
|
|
|
|
private bool autoplay;
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
2020-04-04 12:35:35 +00:00
|
|
|
|
private readonly BindableBool snakingIn = new BindableBool();
|
|
|
|
|
private readonly BindableBool snakingOut = new BindableBool();
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
2020-04-04 12:10:54 +00:00
|
|
|
|
private const double duration_of_span = 3605;
|
|
|
|
|
private const double fade_in_modifier = -1200;
|
|
|
|
|
|
2020-03-29 14:00:26 +00:00
|
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
2020-08-04 12:53:00 +00:00
|
|
|
|
=> new ClockBackedTestWorkingBeatmap(beatmap, storyboard, new FramedClock(new ManualClock { Rate = 1 }), audioManager);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(RulesetConfigCache configCache)
|
|
|
|
|
{
|
|
|
|
|
var config = (OsuRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance());
|
|
|
|
|
config.BindWith(OsuRulesetSetting.SnakingInSliders, snakingIn);
|
|
|
|
|
config.BindWith(OsuRulesetSetting.SnakingOutSliders, snakingOut);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 14:03:44 +00:00
|
|
|
|
private DrawableSlider drawableSlider;
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
|
|
|
|
[SetUpSteps]
|
2020-06-09 14:38:54 +00:00
|
|
|
|
public override void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
2020-04-05 08:22:52 +00:00
|
|
|
|
[TestCase(0)]
|
|
|
|
|
[TestCase(1)]
|
|
|
|
|
[TestCase(2)]
|
2020-04-05 13:26:32 +00:00
|
|
|
|
public void TestSnakingEnabled(int sliderIndex)
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 13:26:32 +00:00
|
|
|
|
AddStep("enable autoplay", () => autoplay = true);
|
2020-03-29 14:43:18 +00:00
|
|
|
|
base.SetUpSteps();
|
2020-08-26 15:21:50 +00:00
|
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
2020-03-29 14:43:18 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
double startTime = hitObjects[sliderIndex].StartTime;
|
2020-11-13 14:03:44 +00:00
|
|
|
|
addSeekStep(startTime);
|
|
|
|
|
retrieveDrawableSlider((Slider)hitObjects[sliderIndex]);
|
2020-04-05 13:26:32 +00:00
|
|
|
|
setSnaking(true);
|
|
|
|
|
|
|
|
|
|
ensureSnakingIn(startTime + fade_in_modifier);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sliderIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
// non-final repeats should not snake out
|
|
|
|
|
ensureNoSnakingOut(startTime, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// final repeat should snake out
|
|
|
|
|
ensureSnakingOut(startTime, sliderIndex);
|
2020-04-05 08:22:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(0)]
|
|
|
|
|
[TestCase(1)]
|
|
|
|
|
[TestCase(2)]
|
2020-04-05 13:26:32 +00:00
|
|
|
|
public void TestSnakingDisabled(int sliderIndex)
|
2020-04-05 08:22:52 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("have autoplay", () => autoplay = true);
|
|
|
|
|
base.SetUpSteps();
|
2020-08-26 15:21:50 +00:00
|
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
2020-04-05 08:22:52 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
double startTime = hitObjects[sliderIndex].StartTime;
|
2020-11-13 14:03:44 +00:00
|
|
|
|
addSeekStep(startTime);
|
|
|
|
|
retrieveDrawableSlider((Slider)hitObjects[sliderIndex]);
|
2020-04-05 13:26:32 +00:00
|
|
|
|
setSnaking(false);
|
|
|
|
|
|
|
|
|
|
ensureNoSnakingIn(startTime + fade_in_modifier);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <= sliderIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
// no snaking out ever, including final repeat
|
|
|
|
|
ensureNoSnakingOut(startTime, i);
|
|
|
|
|
}
|
2020-03-29 14:43:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 13:37:31 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRepeatArrowDoesNotMoveWhenHit()
|
2020-03-29 14:43:18 +00:00
|
|
|
|
{
|
2020-04-05 13:37:31 +00:00
|
|
|
|
AddStep("enable autoplay", () => autoplay = true);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
setSnaking(true);
|
2020-03-29 14:43:18 +00:00
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
2020-04-05 13:53:56 +00:00
|
|
|
|
// repeat might have a chance to update its position depending on where in the frame its hit,
|
|
|
|
|
// so some leniency is allowed here instead of checking strict equality
|
2020-04-05 13:37:31 +00:00
|
|
|
|
checkPositionChange(16600, sliderRepeat, positionAlmostSame);
|
|
|
|
|
}
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-04-05 13:37:31 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRepeatArrowMovesWhenNotHit()
|
|
|
|
|
{
|
|
|
|
|
AddStep("disable autoplay", () => autoplay = false);
|
|
|
|
|
setSnaking(true);
|
|
|
|
|
base.SetUpSteps();
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-04-05 13:37:31 +00:00
|
|
|
|
checkPositionChange(16600, sliderRepeat, positionDecreased);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 14:03:44 +00:00
|
|
|
|
private void retrieveDrawableSlider(Slider slider) => AddUntilStep($"retrieve slider @ {slider.StartTime}", () =>
|
|
|
|
|
(drawableSlider = (DrawableSlider)Player.DrawableRuleset.Playfield.AllHitObjects.SingleOrDefault(d => d.HitObject == slider)) != null);
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private void ensureSnakingIn(double startTime) => checkPositionChange(startTime, sliderEnd, positionIncreased);
|
|
|
|
|
private void ensureNoSnakingIn(double startTime) => checkPositionChange(startTime, sliderEnd, positionRemainsSame);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private void ensureSnakingOut(double startTime, int repeatIndex)
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 13:26:32 +00:00
|
|
|
|
var repeatTime = timeAtRepeat(startTime, repeatIndex);
|
|
|
|
|
|
|
|
|
|
if (repeatIndex % 2 == 0)
|
|
|
|
|
checkPositionChange(repeatTime, sliderStart, positionIncreased);
|
|
|
|
|
else
|
|
|
|
|
checkPositionChange(repeatTime, sliderEnd, positionDecreased);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private void ensureNoSnakingOut(double startTime, int repeatIndex) =>
|
|
|
|
|
checkPositionChange(timeAtRepeat(startTime, repeatIndex), positionAtRepeat(repeatIndex), positionRemainsSame);
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private double timeAtRepeat(double startTime, int repeatIndex) => startTime + 100 + duration_of_span * repeatIndex;
|
|
|
|
|
private Func<Vector2> positionAtRepeat(int repeatIndex) => repeatIndex % 2 == 0 ? (Func<Vector2>)sliderStart : sliderEnd;
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-11-13 14:03:44 +00:00
|
|
|
|
private List<Vector2> sliderCurve => ((PlaySliderBody)drawableSlider.Body.Drawable).CurrentCurve;
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private Vector2 sliderStart() => sliderCurve.First();
|
|
|
|
|
private Vector2 sliderEnd() => sliderCurve.Last();
|
2020-04-05 13:39:32 +00:00
|
|
|
|
|
2020-04-05 13:37:31 +00:00
|
|
|
|
private Vector2 sliderRepeat()
|
|
|
|
|
{
|
2020-11-13 14:03:44 +00:00
|
|
|
|
var drawable = Player.DrawableRuleset.Playfield.AllHitObjects.SingleOrDefault(d => d.HitObject == hitObjects[1]);
|
2020-04-05 13:37:31 +00:00
|
|
|
|
var repeat = drawable.ChildrenOfType<Container<DrawableSliderRepeat>>().First().Children.First();
|
|
|
|
|
return repeat.Position;
|
|
|
|
|
}
|
2020-04-04 12:35:35 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private bool positionRemainsSame(Vector2 previous, Vector2 current) => previous == current;
|
|
|
|
|
private bool positionIncreased(Vector2 previous, Vector2 current) => current.X > previous.X && current.Y > previous.Y;
|
|
|
|
|
private bool positionDecreased(Vector2 previous, Vector2 current) => current.X < previous.X && current.Y < previous.Y;
|
2020-04-05 13:37:31 +00:00
|
|
|
|
private bool positionAlmostSame(Vector2 previous, Vector2 current) => Precision.AlmostEquals(previous, current, 1);
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
2020-04-05 13:26:32 +00:00
|
|
|
|
private void checkPositionChange(double startTime, Func<Vector2> positionToCheck, Func<Vector2, Vector2, bool> positionAssertion)
|
2020-04-04 12:10:54 +00:00
|
|
|
|
{
|
2020-04-05 13:26:32 +00:00
|
|
|
|
Vector2 previousPosition = Vector2.Zero;
|
|
|
|
|
|
|
|
|
|
string positionDescription = positionToCheck.Method.Name.Humanize(LetterCasing.LowerCase);
|
|
|
|
|
string assertionDescription = positionAssertion.Method.Name.Humanize(LetterCasing.LowerCase);
|
|
|
|
|
|
|
|
|
|
addSeekStep(startTime);
|
|
|
|
|
AddStep($"save {positionDescription} position", () => previousPosition = positionToCheck.Invoke());
|
|
|
|
|
addSeekStep(startTime + 100);
|
|
|
|
|
AddAssert($"{positionDescription} {assertionDescription}", () =>
|
|
|
|
|
{
|
|
|
|
|
var currentPosition = positionToCheck.Invoke();
|
|
|
|
|
return positionAssertion.Invoke(previousPosition, currentPosition);
|
|
|
|
|
});
|
2020-04-04 12:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 14:00:26 +00:00
|
|
|
|
private void setSnaking(bool value)
|
|
|
|
|
{
|
2020-04-05 13:39:32 +00:00
|
|
|
|
AddStep($"{(value ? "enable" : "disable")} snaking", () =>
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
|
|
|
|
snakingIn.Value = value;
|
|
|
|
|
snakingOut.Value = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addSeekStep(double time)
|
|
|
|
|
{
|
2020-08-04 12:53:00 +00:00
|
|
|
|
AddStep($"seek to {time}", () => MusicController.SeekTo(time));
|
2020-03-29 14:00:26 +00:00
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, Player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new Beatmap
|
|
|
|
|
{
|
2020-04-05 11:50:27 +00:00
|
|
|
|
HitObjects = hitObjects
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly List<HitObject> hitObjects = new List<HitObject>
|
|
|
|
|
{
|
|
|
|
|
new Slider
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 11:50:27 +00:00
|
|
|
|
StartTime = 3000,
|
|
|
|
|
Position = new Vector2(100, 100),
|
|
|
|
|
Path = new SliderPath(PathType.PerfectCurve, new[]
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 11:50:27 +00:00
|
|
|
|
Vector2.Zero,
|
|
|
|
|
new Vector2(300, 200)
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
new Slider
|
|
|
|
|
{
|
|
|
|
|
StartTime = 13000,
|
|
|
|
|
Position = new Vector2(100, 100),
|
|
|
|
|
Path = new SliderPath(PathType.PerfectCurve, new[]
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 11:50:27 +00:00
|
|
|
|
Vector2.Zero,
|
|
|
|
|
new Vector2(300, 200)
|
|
|
|
|
}),
|
|
|
|
|
RepeatCount = 1,
|
|
|
|
|
},
|
|
|
|
|
new Slider
|
|
|
|
|
{
|
|
|
|
|
StartTime = 23000,
|
|
|
|
|
Position = new Vector2(100, 100),
|
|
|
|
|
Path = new SliderPath(PathType.PerfectCurve, new[]
|
2020-03-29 14:00:26 +00:00
|
|
|
|
{
|
2020-04-05 11:50:27 +00:00
|
|
|
|
Vector2.Zero,
|
|
|
|
|
new Vector2(300, 200)
|
|
|
|
|
}),
|
|
|
|
|
RepeatCount = 2,
|
|
|
|
|
},
|
|
|
|
|
new HitCircle
|
|
|
|
|
{
|
|
|
|
|
StartTime = 199999,
|
2020-03-29 14:00:26 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|