1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 04:27:34 +08:00
osu-lazer/osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs

139 lines
4.6 KiB
C#
Raw Normal View History

2018-06-08 13:28:27 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-06-11 14:43:15 +08:00
using System.Collections.Generic;
using System.Linq;
2018-06-08 13:28:27 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-06-11 14:43:15 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2018-06-08 13:28:27 +08:00
using osu.Game.Rulesets.Mania.Beatmaps;
2018-06-11 14:43:15 +08:00
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
2018-06-08 13:28:27 +08:00
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI.Scrolling;
using OpenTK;
namespace osu.Game.Rulesets.Mania.Tests
{
[TestFixture]
public class TestCaseStage : ManiaInputTestCase
{
2018-06-11 14:43:15 +08:00
private const int columns = 4;
private readonly List<ManiaStage> stages = new List<ManiaStage>();
private FillFlowContainer<ScrollingTestContainer> fill;
2018-06-08 13:28:27 +08:00
public TestCaseStage()
2018-06-11 14:43:15 +08:00
: base(columns)
2018-06-08 13:28:27 +08:00
{
}
[BackgroundDependencyLoader]
private void load()
{
Child = fill = new FillFlowContainer<ScrollingTestContainer>
2018-06-08 13:28:27 +08: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 14:43:15 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
AddStep("note", createNote);
AddStep("hold note", createHoldNote);
2018-06-11 15:12:52 +08: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));
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));
2018-06-11 14:43:15 +08:00
}
private bool notesInStageAreAnchored(ManiaStage stage, Anchor anchor) => stage.Columns.SelectMany(c => c.AllHitObjects).All(o => o.Anchor == anchor);
2018-06-11 14:43:15 +08: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 14:43:15 +08: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 14:43:15 +08:00
}
}
}
2018-06-11 15:12:52 +08:00
private void createBarLine(bool major)
2018-06-11 14:43:15 +08:00
{
foreach (var stage in stages)
{
2018-06-11 15:12:52 +08:00
var obj = new BarLine
{
StartTime = Time.Current + 2000,
ControlPoint = new TimingControlPoint(),
BeatIndex = major ? 0 : 1
};
2018-06-11 14:43:15 +08:00
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
stage.Add(obj);
}
}
private ScrollingTestContainer createStage(ScrollingDirection direction, ManiaAction action)
2018-06-08 13:28:27 +08:00
{
var specialAction = ManiaAction.Special1;
var stage = new ManiaStage(0, new StageDefinition { Columns = 2 }, ref action, ref specialAction) { VisibleTimeRange = { Value = 2000 } };
2018-06-11 14:43:15 +08:00
stages.Add(stage);
return new ScrollingTestContainer(direction)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
2018-06-11 14:43:15 +08:00
Child = stage
};
2018-06-08 13:28:27 +08:00
}
}
}