osu/osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs

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

151 lines
5.3 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-06-08 05:28:27 +00:00
2019-04-10 08:54:57 +00:00
using System;
2018-06-11 06:43:15 +00:00
using System.Collections.Generic;
using System.Linq;
2018-06-08 05:28:27 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-06-11 06:43:15 +00:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2018-06-08 05:28:27 +00:00
using osu.Game.Rulesets.Mania.Beatmaps;
2018-06-11 06:43:15 +00:00
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
2018-06-08 05:28:27 +00:00
using osu.Game.Rulesets.Mania.UI;
2019-04-10 08:54:57 +00:00
using osu.Game.Rulesets.Mods;
2018-06-08 05:28:27 +00:00
using osu.Game.Rulesets.UI.Scrolling;
2018-11-06 06:46:36 +00:00
using osu.Game.Tests.Visual;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-06-08 05:28:27 +00:00
namespace osu.Game.Rulesets.Mania.Tests
{
[TestFixture]
public class TestSceneStage : ManiaInputTestScene
2018-06-08 05:28:27 +00:00
{
2018-06-11 06:43:15 +00:00
private const int columns = 4;
2019-04-10 08:54:57 +00:00
[Cached(typeof(IReadOnlyList<Mod>))]
private IReadOnlyList<Mod> mods { get; set; } = Array.Empty<Mod>();
2020-04-08 05:08:34 +00:00
private readonly List<Stage> stages = new List<Stage>();
2018-06-11 06:43:15 +00:00
private FillFlowContainer<ScrollingTestContainer> fill;
public TestSceneStage()
2018-06-11 06:43:15 +00:00
: base(columns)
2018-06-08 05:28:27 +00:00
{
}
[BackgroundDependencyLoader]
private void load()
{
Child = fill = new FillFlowContainer<ScrollingTestContainer>
2018-06-08 05:28:27 +00:00
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(20, 0),
Children = new[]
{
createStage(ScrollingDirection.Up, ManiaAction.Key1),
createStage(ScrollingDirection.Down, ManiaAction.Key3)
}
};
}
2018-06-11 06:43:15 +00:00
protected override void LoadComplete()
{
base.LoadComplete();
AddStep("note", createNote);
AddStep("hold note", createHoldNote);
2018-06-11 07:12:52 +00:00
AddStep("minor bar line", () => createBarLine(false));
AddStep("major bar line", () => createBarLine(true));
AddAssert("check note anchors", () => notesInStageAreAnchored(stages[0], Anchor.TopCentre));
AddAssert("check note anchors", () => notesInStageAreAnchored(stages[1], Anchor.BottomCentre));
AddAssert("check bar anchors", () => barsInStageAreAnchored(stages[0], Anchor.TopCentre));
AddAssert("check bar anchors", () => barsInStageAreAnchored(stages[1], Anchor.BottomCentre));
AddStep("flip direction", () =>
{
foreach (var c in fill.Children)
c.Flip();
});
AddAssert("check note anchors", () => notesInStageAreAnchored(stages[0], Anchor.BottomCentre));
AddAssert("check note anchors", () => notesInStageAreAnchored(stages[1], Anchor.TopCentre));
AddAssert("check bar anchors", () => barsInStageAreAnchored(stages[0], Anchor.BottomCentre));
AddAssert("check bar anchors", () => barsInStageAreAnchored(stages[1], Anchor.TopCentre));
2018-06-11 06:43:15 +00:00
}
2020-04-08 05:08:34 +00:00
private bool notesInStageAreAnchored(Stage stage, Anchor anchor) => stage.Columns.SelectMany(c => c.AllHitObjects).All(o => o.Anchor == anchor);
2020-04-08 05:08:34 +00:00
private bool barsInStageAreAnchored(Stage stage, Anchor anchor) => stage.AllHitObjects.Where(obj => obj is DrawableBarLine).All(o => o.Anchor == anchor);
2018-06-11 06:43:15 +00:00
private void createNote()
{
foreach (var stage in stages)
{
for (int i = 0; i < stage.Columns.Count; i++)
{
var obj = new Note { Column = i, StartTime = Time.Current + 2000 };
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
stage.Add(new DrawableNote(obj));
2018-06-11 06:43:15 +00:00
}
}
}
private void createHoldNote()
{
foreach (var stage in stages)
{
for (int i = 0; i < stage.Columns.Count; i++)
{
var obj = new HoldNote { Column = i, StartTime = Time.Current + 2000, Duration = 500 };
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
stage.Add(new DrawableHoldNote(obj));
2018-06-11 06:43:15 +00:00
}
}
}
2018-06-11 07:12:52 +00:00
private void createBarLine(bool major)
2018-06-11 06:43:15 +00:00
{
foreach (var stage in stages)
{
2018-06-11 07:12:52 +00:00
var obj = new BarLine
{
StartTime = Time.Current + 2000,
Major = major,
2018-06-11 07:12:52 +00:00
};
2018-06-11 06:43:15 +00:00
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
stage.Add(obj);
}
}
private ScrollingTestContainer createStage(ScrollingDirection direction, ManiaAction action)
2018-06-08 05:28:27 +00:00
{
var specialAction = ManiaAction.Special1;
2020-04-08 05:08:34 +00:00
var stage = new Stage(0, new StageDefinition { Columns = 2 }, ref action, ref specialAction);
2018-06-11 06:43:15 +00:00
stages.Add(stage);
return new ScrollingTestContainer(direction)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
TimeRange = 2000,
2018-06-11 06:43:15 +00:00
Child = stage
};
2018-06-08 05:28:27 +00:00
}
}
}