1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs

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

432 lines
17 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 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
2017-12-27 16:34:07 +08:00
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-01-01 18:55:24 +08:00
using osu.Game.Rulesets.Mods;
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Testing;
using osu.Game.Graphics;
2018-01-30 15:45:48 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
2018-01-30 15:45:48 +08:00
using osu.Game.Rulesets.Objects.Drawables;
2018-01-25 06:16:46 +08:00
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.Osu.Mods;
2018-04-13 17:19:50 +08:00
2017-12-27 16:34:07 +08:00
namespace osu.Game.Rulesets.Osu.Tests
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public partial class TestSceneSlider : OsuSkinnableTestScene
2017-12-27 16:34:07 +08:00
{
private int depthIndex;
2018-04-13 17:19:50 +08:00
2023-09-14 16:23:57 +08:00
private readonly BindableBool snakingIn = new BindableBool(true);
private readonly BindableBool snakingOut = new BindableBool(true);
private float progressToHit;
protected override void LoadComplete()
{
base.LoadComplete();
2023-09-14 16:23:57 +08:00
AddToggleStep("disable snaking", v =>
{
2023-09-14 16:23:57 +08:00
snakingIn.Value = !v;
snakingOut.Value = !v;
});
AddToggleStep("toggle hidden", hiddenActive => SelectedMods.Value = hiddenActive ? new[] { new OsuModHidden() } : Array.Empty<Mod>());
AddSliderStep("hit at", 0f, 1f, 0f, v =>
{
progressToHit = v;
});
}
[BackgroundDependencyLoader]
private void load()
{
var config = (OsuRulesetConfigManager)RulesetConfigs.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull();
config.BindWith(OsuRulesetSetting.SnakingInSliders, snakingIn);
config.BindWith(OsuRulesetSetting.SnakingOutSliders, snakingOut);
}
protected override void Update()
{
base.Update();
foreach (var slider in this.ChildrenOfType<DrawableSlider>())
{
double completionProgress = Math.Clamp((Time.Current - slider.HitObject.StartTime) / slider.HitObject.Duration, 0, 1);
if (completionProgress > progressToHit && !slider.IsHit)
slider.HeadCircle.HitArea.Hit();
}
}
[Test]
public void TestVariousSliders()
2017-12-27 16:34:07 +08:00
{
AddStep("Big Single", () => SetContents(_ => testSimpleBig()));
AddStep("Medium Single", () => SetContents(_ => testSimpleMedium()));
AddStep("Small Single", () => SetContents(_ => testSimpleSmall()));
AddStep("Big 1 Repeat", () => SetContents(_ => testSimpleBig(1)));
AddStep("Medium 1 Repeat", () => SetContents(_ => testSimpleMedium(1)));
AddStep("Small 1 Repeat", () => SetContents(_ => testSimpleSmall(1)));
AddStep("Big 2 Repeats", () => SetContents(_ => testSimpleBig(2)));
AddStep("Medium 2 Repeats", () => SetContents(_ => testSimpleMedium(2)));
AddStep("Small 2 Repeats", () => SetContents(_ => testSimpleSmall(2)));
2019-08-20 12:18:59 +08:00
AddStep("Slow Slider", () => SetContents(_ => testSlowSpeed())); // slow long sliders take ages already so no repeat steps
AddStep("Slow Short Slider", () => SetContents(_ => testShortSlowSpeed()));
AddStep("Slow Short Slider 1 Repeats", () => SetContents(_ => testShortSlowSpeed(1)));
AddStep("Slow Short Slider 2 Repeats", () => SetContents(_ => testShortSlowSpeed(2)));
2019-08-20 12:18:59 +08:00
AddStep("Fast Slider", () => SetContents(_ => testHighSpeed()));
AddStep("Fast Slider 1 Repeat", () => SetContents(_ => testHighSpeed(1)));
AddStep("Fast Slider 2 Repeats", () => SetContents(_ => testHighSpeed(2)));
AddStep("Fast Short Slider", () => SetContents(_ => testShortHighSpeed()));
AddStep("Fast Short Slider 1 Repeat", () => SetContents(_ => testShortHighSpeed(1)));
AddStep("Fast Short Slider 2 Repeats", () => SetContents(_ => testShortHighSpeed(2)));
AddStep("Fast Short Slider 6 Repeats", () => SetContents(_ => testShortHighSpeed(6)));
2019-08-20 12:18:59 +08:00
AddStep("Perfect Curve", () => SetContents(_ => testPerfect()));
AddStep("Perfect Curve 1 Repeat", () => SetContents(_ => testPerfect(1)));
AddStep("Perfect Curve 2 Repeats", () => SetContents(_ => testPerfect(2)));
2019-08-20 12:18:59 +08:00
AddStep("Linear Slider", () => SetContents(_ => testLinear()));
AddStep("Linear Slider 1 Repeat", () => SetContents(_ => testLinear(1)));
AddStep("Linear Slider 2 Repeats", () => SetContents(_ => testLinear(2)));
2019-08-20 12:18:59 +08:00
AddStep("Bezier Slider", () => SetContents(_ => testBezier()));
AddStep("Bezier Slider 1 Repeat", () => SetContents(_ => testBezier(1)));
AddStep("Bezier Slider 2 Repeats", () => SetContents(_ => testBezier(2)));
2019-08-20 12:18:59 +08:00
AddStep("Linear Overlapping", () => SetContents(_ => testLinearOverlapping()));
AddStep("Linear Overlapping 1 Repeat", () => SetContents(_ => testLinearOverlapping(1)));
AddStep("Linear Overlapping 2 Repeats", () => SetContents(_ => testLinearOverlapping(2)));
2019-08-20 12:18:59 +08:00
AddStep("Catmull Slider", () => SetContents(_ => testCatmull()));
AddStep("Catmull Slider 1 Repeat", () => SetContents(_ => testCatmull(1)));
AddStep("Catmull Slider 2 Repeats", () => SetContents(_ => testCatmull(2)));
2019-08-20 12:18:59 +08:00
AddStep("Big Single, Large StackOffset", () => SetContents(_ => testSimpleBigLargeStackOffset()));
AddStep("Big 1 Repeat, Large StackOffset", () => SetContents(_ => testSimpleBigLargeStackOffset(1)));
2019-08-20 12:18:59 +08:00
AddStep("Distance Overflow", () => SetContents(_ => testDistanceOverflow()));
AddStep("Distance Overflow 1 Repeat", () => SetContents(_ => testDistanceOverflow(1)));
2017-12-27 16:34:07 +08:00
}
2018-04-13 17:19:50 +08:00
[Test]
public void TestChangeStackHeight()
{
DrawableSlider slider = null;
AddStep("create slider", () =>
{
slider = (DrawableSlider)createSlider(repeats: 1);
Add(slider);
});
AddStep("change stack height", () => slider.HitObject.StackHeight = 10);
AddAssert("body positioned correctly", () => slider.Position == slider.HitObject.StackedPosition);
}
[Test]
public void TestChangeSamplesWithNoNodeSamples()
{
DrawableSlider slider = null;
AddStep("create slider", () =>
{
slider = (DrawableSlider)createSlider(repeats: 1);
Add(slider);
});
AddStep("change samples", () => slider.HitObject.Samples = new[]
{
2020-12-01 14:37:51 +08:00
new HitSampleInfo(HitSampleInfo.HIT_CLAP),
new HitSampleInfo(HitSampleInfo.HIT_WHISTLE),
});
2020-11-05 12:51:46 +08:00
AddAssert("head samples updated", () => assertSamples(slider.HitObject.HeadCircle));
AddAssert("tick samples not updated", () => slider.HitObject.NestedHitObjects.OfType<SliderTick>().All(assertTickSamples));
AddAssert("repeat samples updated", () => slider.HitObject.NestedHitObjects.OfType<SliderRepeat>().All(assertSamples));
AddAssert("tail has no samples", () => slider.HitObject.TailCircle.Samples.Count == 0);
2019-11-12 18:37:20 +08:00
static bool assertTickSamples(SliderTick tick) => tick.Samples.Single().Name == "slidertick";
2019-11-12 18:37:20 +08:00
static bool assertSamples(HitObject hitObject)
{
return hitObject.Samples.Any(s => s.Name == HitSampleInfo.HIT_CLAP)
&& hitObject.Samples.Any(s => s.Name == HitSampleInfo.HIT_WHISTLE);
}
}
[Test]
public void TestChangeSamplesWithNodeSamples()
{
DrawableSlider slider = null;
AddStep("create slider", () =>
{
slider = (DrawableSlider)createSlider(repeats: 1);
for (int i = 0; i < 2; i++)
2020-12-01 14:37:51 +08:00
slider.HitObject.NodeSamples.Add(new List<HitSampleInfo> { new HitSampleInfo(HitSampleInfo.HIT_FINISH) });
Add(slider);
});
AddStep("change samples", () => slider.HitObject.Samples = new[]
{
2020-12-01 14:37:51 +08:00
new HitSampleInfo(HitSampleInfo.HIT_CLAP),
new HitSampleInfo(HitSampleInfo.HIT_WHISTLE),
});
2020-11-05 12:51:46 +08:00
AddAssert("head samples not updated", () => assertSamples(slider.HitObject.HeadCircle));
AddAssert("tick samples not updated", () => slider.HitObject.NestedHitObjects.OfType<SliderTick>().All(assertTickSamples));
AddAssert("repeat samples not updated", () => slider.HitObject.NestedHitObjects.OfType<SliderRepeat>().All(assertSamples));
AddAssert("tail has no samples", () => slider.HitObject.TailCircle.Samples.Count == 0);
2019-11-12 18:37:20 +08:00
static bool assertTickSamples(SliderTick tick) => tick.Samples.Single().Name == "slidertick";
static bool assertSamples(HitObject hitObject) => hitObject.Samples.All(s => s.Name != HitSampleInfo.HIT_CLAP && s.Name != HitSampleInfo.HIT_WHISTLE);
}
private Drawable testSimpleBig(int repeats = 0) => createSlider(repeats: repeats);
2018-04-13 17:19:50 +08:00
private Drawable testSimpleBigLargeStackOffset(int repeats = 0) => createSlider(repeats: repeats, stackHeight: 10);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testDistanceOverflow(int repeats = 0)
{
var slider = new Slider
{
StartTime = Time.Current + time_offset,
Position = new Vector2(239, 176),
2023-11-13 15:24:09 +08:00
Path = new SliderPath(PathType.PERFECT_CURVE, new[]
{
Vector2.Zero,
new Vector2(154, 28),
new Vector2(52, -34)
}, 700),
RepeatCount = repeats,
StackHeight = 10
};
return createDrawable(slider, 2);
}
2019-08-20 12:18:59 +08:00
private Drawable testSimpleMedium(int repeats = 0) => createSlider(5, repeats: repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testSimpleSmall(int repeats = 0) => createSlider(7, repeats: repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testSlowSpeed() => createSlider(speedMultiplier: 0.5);
2018-04-13 17:19:50 +08:00
private Drawable testShortSlowSpeed(int repeats = 0) => createSlider(distance: max_length / 4, repeats: repeats, speedMultiplier: 0.5);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testHighSpeed(int repeats = 0) => createSlider(repeats: repeats, speedMultiplier: 15);
2018-04-13 17:19:50 +08:00
private Drawable testShortHighSpeed(int repeats = 0) => createSlider(distance: max_length / 4, repeats: repeats, speedMultiplier: 15);
2018-04-13 17:19:50 +08:00
private const double time_offset = 1500;
private const float max_length = 200;
private Drawable createSlider(float circleSize = 2, float distance = max_length, int repeats = 0, double speedMultiplier = 2, int stackHeight = 0)
2017-12-27 16:34:07 +08:00
{
var slider = new Slider
{
SliderVelocityMultiplier = speedMultiplier,
StartTime = Time.Current + time_offset,
Position = new Vector2(0, -(distance / 2)),
2023-11-13 15:24:09 +08:00
Path = new SliderPath(PathType.PERFECT_CURVE, new[]
2017-12-27 16:34:07 +08:00
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(0, distance),
}, distance),
2018-01-01 18:55:24 +08:00
RepeatCount = repeats,
StackHeight = stackHeight
2017-12-27 16:34:07 +08:00
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, circleSize);
2017-12-27 16:34:07 +08:00
}
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testPerfect(int repeats = 0)
2017-12-27 16:34:07 +08:00
{
var slider = new Slider
{
StartTime = Time.Current + time_offset,
Position = new Vector2(-max_length / 2, 0),
2023-11-13 15:24:09 +08:00
Path = new SliderPath(PathType.PERFECT_CURVE, new[]
2017-12-27 16:34:07 +08:00
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(max_length / 2, max_length / 2),
new Vector2(max_length, 0)
}, max_length * 1.5f),
2018-01-25 06:16:46 +08:00
RepeatCount = repeats,
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, 2);
2018-01-25 06:16:46 +08:00
}
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testLinear(int repeats = 0) => createLinear(repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable createLinear(int repeats)
2018-01-25 06:16:46 +08:00
{
var slider = new Slider
{
StartTime = Time.Current + time_offset,
Position = new Vector2(-max_length / 2, 0),
Path = new SliderPath(PathType.LINEAR, new[]
2018-01-25 06:16:46 +08:00
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(max_length * 0.375f, max_length * 0.18f),
new Vector2(max_length / 2, 0),
new Vector2(max_length * 0.75f, -max_length / 2),
new Vector2(max_length * 0.95f, 0),
new Vector2(max_length, 0)
}),
2018-01-25 06:16:46 +08:00
RepeatCount = repeats,
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, 2);
2018-01-25 06:16:46 +08:00
}
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testBezier(int repeats = 0) => createBezier(repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable createBezier(int repeats)
2018-01-25 06:16:46 +08:00
{
var slider = new Slider
{
StartTime = Time.Current + time_offset,
Position = new Vector2(-max_length / 2, 0),
Path = new SliderPath(PathType.BEZIER, new[]
2018-01-25 06:16:46 +08:00
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(max_length * 0.375f, max_length * 0.18f),
new Vector2(max_length / 2, max_length / 4),
new Vector2(max_length * 0.75f, -max_length / 2),
new Vector2(max_length, 0)
}),
2018-01-25 06:16:46 +08:00
RepeatCount = repeats,
2017-12-27 16:34:07 +08:00
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, 2);
}
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testLinearOverlapping(int repeats = 0) => createOverlapping(repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable createOverlapping(int repeats)
2018-01-25 06:16:46 +08:00
{
var slider = new Slider
{
StartTime = Time.Current + time_offset,
2018-01-25 06:16:46 +08:00
Position = new Vector2(0, 0),
Path = new SliderPath(PathType.LINEAR, new[]
2018-01-25 06:16:46 +08:00
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(-max_length / 2, 0),
2018-01-25 06:16:46 +08:00
new Vector2(0, 0),
new Vector2(0, -max_length / 2),
new Vector2(-max_length / 2, -max_length / 2),
new Vector2(0, -max_length / 2)
}),
2018-01-25 06:16:46 +08:00
RepeatCount = repeats,
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, 2);
2018-01-25 06:16:46 +08:00
}
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable testCatmull(int repeats = 0) => createCatmull(repeats);
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
private Drawable createCatmull(int repeats = 0)
{
2019-11-08 13:04:57 +08:00
var repeatSamples = new List<IList<HitSampleInfo>>();
for (int i = 0; i < repeats; i++)
2019-06-30 20:58:30 +08:00
repeatSamples.Add(new List<HitSampleInfo>());
2018-04-13 17:19:50 +08:00
var slider = new Slider
{
StartTime = Time.Current + time_offset,
Position = new Vector2(-max_length / 4, 0),
Path = new SliderPath(PathType.CATMULL, new[]
{
2018-02-23 20:03:45 +08:00
Vector2.Zero,
new Vector2(max_length * 0.125f, max_length * 0.125f),
new Vector2(max_length * 0.375f, max_length * 0.125f),
new Vector2(max_length / 2, 0)
}),
RepeatCount = repeats,
NodeSamples = repeatSamples
};
2018-04-13 17:19:50 +08:00
return createDrawable(slider, 3);
}
2018-04-13 17:19:50 +08:00
private Drawable createDrawable(Slider slider, float circleSize)
{
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty
{
CircleSize = circleSize,
SliderTickRate = 3
});
2018-04-13 17:19:50 +08:00
2019-09-26 16:39:26 +08:00
var drawable = CreateDrawableSlider(slider);
2018-04-13 17:19:50 +08:00
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObject(drawable);
2018-04-13 17:19:50 +08:00
drawable.OnNewResult += onNewResult;
2018-04-13 17:19:50 +08:00
2019-08-20 12:18:59 +08:00
return drawable;
2017-12-27 16:34:07 +08:00
}
2018-04-13 17:19:50 +08:00
2019-09-26 16:39:26 +08:00
protected virtual DrawableSlider CreateDrawableSlider(Slider slider) => new DrawableSlider(slider)
{
Anchor = Anchor.Centre,
Depth = depthIndex++
};
private float judgementOffsetDirection = 1;
2019-02-28 12:31:40 +08:00
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
2018-01-30 15:45:48 +08:00
{
if (!(judgedObject is DrawableOsuHitObject osuObject))
return;
OsuSpriteText text;
Add(text = new OsuSpriteText
2018-01-30 15:45:48 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = result.IsHit ? "Hit!" : "Miss!",
Colour = result.IsHit ? Color4.Green : Color4.Red,
Font = OsuFont.GetFont(size: 30),
Position = osuObject.HitObject.StackedEndPosition + judgementOffsetDirection * new Vector2(0, 45)
});
text.Delay(150)
.Then().FadeOut(200)
.Then().Expire();
judgementOffsetDirection *= -1;
2018-01-30 15:45:48 +08:00
}
2017-12-27 16:34:07 +08:00
}
}