1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 06:37:50 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/Editor/Checks/CheckOffscreenObjectsTest.cs

251 lines
7.8 KiB
C#
Raw Normal View History

2021-04-13 07:22:36 +08: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.
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
2021-04-13 07:22:36 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Checks;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Tests.Beatmaps;
2021-04-13 07:22:36 +08:00
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
{
[TestFixture]
public class CheckOffscreenObjectsTest
{
private static readonly Vector2 playfield_centre = OsuPlayfield.BASE_SIZE * 0.5f;
2021-04-13 07:22:36 +08:00
private CheckOffscreenObjects check;
[SetUp]
public void Setup()
{
check = new CheckOffscreenObjects();
}
[Test]
public void TestCircleInCenter()
{
assertOk(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new HitCircle
{
StartTime = 3000,
Position = playfield_centre
2021-04-13 07:22:36 +08:00
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestCircleNearEdge()
{
assertOk(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new HitCircle
{
StartTime = 3000,
Position = new Vector2(5, 5)
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestCircleNearEdgeStackedOffscreen()
{
assertOffscreenCircle(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new HitCircle
{
StartTime = 3000,
Position = new Vector2(5, 5),
StackHeight = 5
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestCircleOffscreen()
{
assertOffscreenCircle(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new HitCircle
{
StartTime = 3000,
Position = new Vector2(0, 0)
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderInCenter()
{
assertOk(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = new Vector2(420, 240),
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
new PathControlPoint(new Vector2(-100, 0))
}),
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderNearEdge()
{
assertOk(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = playfield_centre,
2021-04-13 07:22:36 +08:00
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
new PathControlPoint(new Vector2(0, -playfield_centre.Y + 5))
2021-04-13 07:22:36 +08:00
}),
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderNearEdgeStackedOffscreen()
{
2021-04-20 19:21:57 +08:00
assertOffscreenSlider(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = playfield_centre,
2021-04-13 07:22:36 +08:00
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
new PathControlPoint(new Vector2(0, -playfield_centre.Y + 5))
2021-04-13 07:22:36 +08:00
}),
StackHeight = 5
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderOffscreenStart()
{
assertOffscreenSlider(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = new Vector2(0, 0),
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
new PathControlPoint(playfield_centre)
2021-04-13 07:22:36 +08:00
}),
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderOffscreenEnd()
{
assertOffscreenSlider(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = playfield_centre,
2021-04-13 07:22:36 +08:00
Path = new SliderPath(new[]
{
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
new PathControlPoint(-playfield_centre)
2021-04-13 07:22:36 +08:00
}),
}
}
});
2021-04-13 07:22:36 +08:00
}
[Test]
public void TestSliderOffscreenPath()
{
assertOffscreenSlider(new Beatmap<HitObject>
2021-04-13 07:22:36 +08:00
{
HitObjects = new List<HitObject>
{
new Slider
{
StartTime = 3000,
Position = playfield_centre,
2021-04-13 07:22:36 +08:00
Path = new SliderPath(new[]
{
// Circular arc shoots over the top of the screen.
new PathControlPoint(new Vector2(0, 0), PathType.PerfectCurve),
new PathControlPoint(new Vector2(-100, -200)),
new PathControlPoint(new Vector2(100, -200))
}),
}
}
});
}
2021-04-13 07:22:36 +08:00
private void assertOk(IBeatmap beatmap)
{
2021-05-13 17:24:22 +08:00
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
Assert.That(check.Run(context), Is.Empty);
2021-04-13 07:22:36 +08:00
}
private void assertOffscreenCircle(IBeatmap beatmap)
2021-04-13 07:22:36 +08:00
{
2021-05-13 17:24:22 +08:00
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
2021-04-13 07:22:36 +08:00
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenCircle);
2021-04-13 07:22:36 +08:00
}
private void assertOffscreenSlider(IBeatmap beatmap)
{
2021-05-13 17:24:22 +08:00
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
2021-04-13 07:22:36 +08:00
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenSlider);
}
2021-04-13 07:22:36 +08:00
}
}