From f719b9bef58da1e82dce0d702c8f498446dd5865 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 7 Aug 2018 12:20:24 +0900 Subject: [PATCH 1/4] Fix mania scroll direction not being read from database --- osu.Game.Rulesets.Mania/UI/ManiaScrollingInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaScrollingInfo.cs b/osu.Game.Rulesets.Mania/UI/ManiaScrollingInfo.cs index a1cc7cfbc7..624ea13e1b 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaScrollingInfo.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaScrollingInfo.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mania.UI public ManiaScrollingInfo(ManiaConfigManager config) { config.BindWith(ManiaSetting.ScrollDirection, configDirection); - configDirection.BindValueChanged(v => Direction.Value = (ScrollingDirection)v); + configDirection.BindValueChanged(v => Direction.Value = (ScrollingDirection)v, true); } } } From 6379c70a68ae4369483f64b3cb3275a9b85d48c4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 8 Aug 2018 11:28:44 +0900 Subject: [PATCH 2/4] Add some ticks --- osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs index fdc8f362f7..30318464de 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs @@ -71,7 +71,7 @@ namespace osu.Game.Rulesets.Mania.Tests private Drawable createHoldNoteDisplay(ScrollingDirection direction) { - var note = new HoldNote { StartTime = 999999999, Duration = 1000 }; + var note = new HoldNote { StartTime = 999999999, Duration = 5000 }; note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); return new ScrollingTestContainer(direction) From 31146fbc014f24630438ff1d5b0d96c3ab592bb5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 8 Aug 2018 11:28:55 +0900 Subject: [PATCH 3/4] Add anchor/origin tests --- .../TestCaseNotes.cs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs index 30318464de..a8b2b20fda 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs @@ -46,15 +46,20 @@ namespace osu.Game.Rulesets.Mania.Tests Spacing = new Vector2(20), Children = new[] { - createNoteDisplay(ScrollingDirection.Down), - createNoteDisplay(ScrollingDirection.Up), - createHoldNoteDisplay(ScrollingDirection.Down), - createHoldNoteDisplay(ScrollingDirection.Up), + createNoteDisplay(ScrollingDirection.Down, 1, out var note1), + createNoteDisplay(ScrollingDirection.Up, 2, out var note2), + createHoldNoteDisplay(ScrollingDirection.Down, 1, out var holdNote1), + createHoldNoteDisplay(ScrollingDirection.Up, 2, out var holdNote2), } }; + + AddAssert("note 1 facing downwards", () => verifyAnchors(note1, Anchor.y2)); + AddAssert("note 2 facing upwards", () => verifyAnchors(note2, Anchor.y0)); + AddAssert("hold note 1 facing downwards", () => verifyAnchors(holdNote1, Anchor.y2)); + AddAssert("hold note 2 facing upwards", () => verifyAnchors(holdNote2, Anchor.y0)); } - private Drawable createNoteDisplay(ScrollingDirection direction) + private Drawable createNoteDisplay(ScrollingDirection direction, int identifier, out DrawableNote hitObject) { var note = new Note { StartTime = 999999999 }; note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); @@ -62,14 +67,14 @@ namespace osu.Game.Rulesets.Mania.Tests return new ScrollingTestContainer(direction) { AutoSizeAxes = Axes.Both, - Child = new NoteContainer(direction, $"note, scrolling {direction.ToString().ToLowerInvariant()}") + Child = new NoteContainer(direction, $"note {identifier}, scrolling {direction.ToString().ToLowerInvariant()}") { - Child = new DrawableNote(note) { AccentColour = Color4.OrangeRed } + Child = hitObject = new DrawableNote(note) { AccentColour = Color4.OrangeRed } } }; } - private Drawable createHoldNoteDisplay(ScrollingDirection direction) + private Drawable createHoldNoteDisplay(ScrollingDirection direction, int identifier, out DrawableHoldNote hitObject) { var note = new HoldNote { StartTime = 999999999, Duration = 5000 }; note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); @@ -77,9 +82,9 @@ namespace osu.Game.Rulesets.Mania.Tests return new ScrollingTestContainer(direction) { AutoSizeAxes = Axes.Both, - Child = new NoteContainer(direction, $"hold note, scrolling {direction.ToString().ToLowerInvariant()}") + Child = new NoteContainer(direction, $"hold note {identifier}, scrolling {direction.ToString().ToLowerInvariant()}") { - Child = new DrawableHoldNote(note) + Child = hitObject = new DrawableHoldNote(note) { RelativeSizeAxes = Axes.Both, AccentColour = Color4.OrangeRed, @@ -88,6 +93,12 @@ namespace osu.Game.Rulesets.Mania.Tests }; } + private bool verifyAnchors(DrawableHitObject hitObject, Anchor expectedAnchor) + => hitObject.Anchor.HasFlag(expectedAnchor) && hitObject.Origin.HasFlag(expectedAnchor); + + private bool verifyAnchors(DrawableHoldNote holdNote, Anchor expectedAnchor) + => verifyAnchors((DrawableHitObject)holdNote, expectedAnchor) && holdNote.NestedHitObjects.All(n => verifyAnchors(n, expectedAnchor)); + private class NoteContainer : Container { private readonly Container content; From dc7804983938cf6e721f4f1823576df8f968036a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 8 Aug 2018 12:21:44 +0900 Subject: [PATCH 4/4] Add test for propagation of direction through mania stack --- .../ScrollingTestContainer.cs | 22 ++++++++----------- .../TestCaseStage.cs | 21 ++++++++++++++++-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/ScrollingTestContainer.cs b/osu.Game.Rulesets.Mania.Tests/ScrollingTestContainer.cs index 5a93efb0dc..29663c2093 100644 --- a/osu.Game.Rulesets.Mania.Tests/ScrollingTestContainer.cs +++ b/osu.Game.Rulesets.Mania.Tests/ScrollingTestContainer.cs @@ -14,24 +14,20 @@ namespace osu.Game.Rulesets.Mania.Tests /// public class ScrollingTestContainer : Container { - private readonly ScrollingDirection direction; + [Cached(Type = typeof(IScrollingInfo))] + private readonly TestScrollingInfo scrollingInfo = new TestScrollingInfo(); public ScrollingTestContainer(ScrollingDirection direction) { - this.direction = direction; + scrollingInfo.Direction.Value = direction; } - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - dependencies.CacheAs(new ScrollingInfo { Direction = { Value = direction }}); - return dependencies; - } + public void Flip() => scrollingInfo.Direction.Value = scrollingInfo.Direction.Value == ScrollingDirection.Up ? ScrollingDirection.Down : ScrollingDirection.Up; + } - private class ScrollingInfo : IScrollingInfo - { - public readonly Bindable Direction = new Bindable(); - IBindable IScrollingInfo.Direction => Direction; - } + public class TestScrollingInfo : IScrollingInfo + { + public readonly Bindable Direction = new Bindable(); + IBindable IScrollingInfo.Direction => Direction; } } diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs index b1bb7f5187..5c5d955168 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -24,6 +25,8 @@ namespace osu.Game.Rulesets.Mania.Tests private readonly List stages = new List(); + private FillFlowContainer fill; + public TestCaseStage() : base(columns) { @@ -32,7 +35,7 @@ namespace osu.Game.Rulesets.Mania.Tests [BackgroundDependencyLoader] private void load() { - Child = new FillFlowContainer + Child = fill = new FillFlowContainer { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, @@ -54,8 +57,22 @@ namespace osu.Game.Rulesets.Mania.Tests AddStep("hold note", createHoldNote); 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)); } + private bool notesInStageAreAnchored(ManiaStage stage, Anchor anchor) => stage.Columns.SelectMany(c => c.AllHitObjects).All(o => o.Anchor == anchor); + private void createNote() { foreach (var stage in stages) @@ -101,7 +118,7 @@ namespace osu.Game.Rulesets.Mania.Tests } } - private Drawable createStage(ScrollingDirection direction, ManiaAction action) + private ScrollingTestContainer createStage(ScrollingDirection direction, ManiaAction action) { var specialAction = ManiaAction.Special1;