Cache StageDefinition for consumption (and remove ColumnType)

This commit is contained in:
Dean Herbert 2022-10-04 18:24:49 +09:00
parent df3ad618e1
commit 7796a4c109
12 changed files with 61 additions and 85 deletions

View File

@ -10,7 +10,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -35,7 +34,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
{ {
scrollingInfo = ((ScrollingTestContainer)HitObjectContainer).ScrollingInfo; scrollingInfo = ((ScrollingTestContainer)HitObjectContainer).ScrollingInfo;
Add(column = new Column(0, ColumnType.Even) Add(column = new Column(0, false)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -10,43 +10,43 @@ using NUnit.Framework;
namespace osu.Game.Rulesets.Mania.Tests namespace osu.Game.Rulesets.Mania.Tests
{ {
[TestFixture] [TestFixture]
public class ManiaColumnTypeTest public class ManiaSpecialColumnTest
{ {
[TestCase(new[] [TestCase(new[]
{ {
ColumnType.Special true
}, 1)] }, 1)]
[TestCase(new[] [TestCase(new[]
{ {
ColumnType.Odd, false,
ColumnType.Even, false,
ColumnType.Even, false,
ColumnType.Odd false
}, 4)] }, 4)]
[TestCase(new[] [TestCase(new[]
{ {
ColumnType.Odd, false,
ColumnType.Even, false,
ColumnType.Odd, false,
ColumnType.Special, true,
ColumnType.Odd, false,
ColumnType.Even, false,
ColumnType.Odd false
}, 7)] }, 7)]
public void Test(IEnumerable<ColumnType> expected, int columns) public void Test(IEnumerable<bool> special, int columns)
{ {
var definition = new StageDefinition var definition = new StageDefinition
{ {
Columns = columns Columns = columns
}; };
var results = getResults(definition); var results = getResults(definition);
Assert.AreEqual(expected, results); Assert.AreEqual(special, results);
} }
private IEnumerable<ColumnType> getResults(StageDefinition definition) private IEnumerable<bool> getResults(StageDefinition definition)
{ {
for (int i = 0; i < definition.Columns; i++) for (int i = 0; i < definition.Columns; i++)
yield return definition.GetTypeOfColumn(i); yield return definition.IsSpecialColumn(i);
} }
} }
} }

View File

@ -24,11 +24,14 @@ namespace osu.Game.Rulesets.Mania.Tests.Skinning
[Cached] [Cached]
private readonly Column column; private readonly Column column;
[Cached]
private readonly StageDefinition stageDefinition = new StageDefinition { Columns = 1 };
public ColumnTestContainer(int column, ManiaAction action, bool showColumn = false) public ColumnTestContainer(int column, ManiaAction action, bool showColumn = false)
{ {
InternalChildren = new[] InternalChildren = new[]
{ {
this.column = new Column(column, column % 2 == 0 ? ColumnType.Even : ColumnType.Odd) this.column = new Column(column, false)
{ {
Action = { Value = action }, Action = { Value = action },
AccentColour = Color4.Orange, AccentColour = Color4.Orange,

View File

@ -11,7 +11,6 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
@ -85,7 +84,7 @@ namespace osu.Game.Rulesets.Mania.Tests
private Drawable createColumn(ScrollingDirection direction, ManiaAction action, int index) private Drawable createColumn(ScrollingDirection direction, ManiaAction action, int index)
{ {
var column = new Column(index, ColumnType.Even) var column = new Column(index, false)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -9,7 +9,6 @@ using osu.Framework.Input.Events;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
@ -36,7 +35,7 @@ namespace osu.Game.Rulesets.Mania.Tests
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
TimeRange = 2000, TimeRange = 2000,
Clock = new FramedClock(clock), Clock = new FramedClock(clock),
Child = column = new Column(0, ColumnType.Even) Child = column = new Column(0, false)
{ {
Action = { Value = ManiaAction.Key1 }, Action = { Value = ManiaAction.Key1 },
Height = 0.85f, Height = 0.85f,

View File

@ -1,12 +0,0 @@
// 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.
namespace osu.Game.Rulesets.Mania.Beatmaps
{
public enum ColumnType
{
Even,
Odd,
Special
}
}

View File

@ -3,7 +3,6 @@
#nullable disable #nullable disable
using System;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps
@ -11,7 +10,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <summary> /// <summary>
/// Defines properties for each stage in a <see cref="ManiaPlayfield"/>. /// Defines properties for each stage in a <see cref="ManiaPlayfield"/>.
/// </summary> /// </summary>
public struct StageDefinition public class StageDefinition
{ {
/// <summary> /// <summary>
/// The number of <see cref="Column"/>s which this stage contains. /// The number of <see cref="Column"/>s which this stage contains.
@ -23,20 +22,6 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// </summary> /// </summary>
/// <param name="column">The 0-based column index.</param> /// <param name="column">The 0-based column index.</param>
/// <returns>Whether the column is a special column.</returns> /// <returns>Whether the column is a special column.</returns>
public readonly bool IsSpecialColumn(int column) => Columns % 2 == 1 && column == Columns / 2; public bool IsSpecialColumn(int column) => Columns % 2 == 1 && column == Columns / 2;
/// <summary>
/// Get the type of column given a column index.
/// </summary>
/// <param name="column">The 0-based column index.</param>
/// <returns>The type of the column.</returns>
public readonly ColumnType GetTypeOfColumn(int column)
{
if (IsSpecialColumn(column))
return ColumnType.Special;
int distanceToEdge = Math.Min(column, (Columns - 1) - column);
return distanceToEdge % 2 == 0 ? ColumnType.Odd : ColumnType.Even;
}
} }
} }

View File

@ -15,14 +15,14 @@ namespace osu.Game.Rulesets.Mania
/// The intended <see cref="StageDefinition"/> for this component. /// The intended <see cref="StageDefinition"/> for this component.
/// May be null if the component is not a direct member of a <see cref="Stage"/>. /// May be null if the component is not a direct member of a <see cref="Stage"/>.
/// </summary> /// </summary>
public readonly StageDefinition? StageDefinition; public readonly StageDefinition StageDefinition;
/// <summary> /// <summary>
/// Creates a new <see cref="ManiaSkinComponent"/>. /// Creates a new <see cref="ManiaSkinComponent"/>.
/// </summary> /// </summary>
/// <param name="component">The component.</param> /// <param name="component">The component.</param>
/// <param name="stageDefinition">The intended <see cref="StageDefinition"/> for this component. May be null if the component is not a direct member of a <see cref="Stage"/>.</param> /// <param name="stageDefinition">The intended <see cref="StageDefinition"/> for this component. May be null if the component is not a direct member of a <see cref="Stage"/>.</param>
public ManiaSkinComponent(ManiaSkinComponents component, StageDefinition? stageDefinition = null) public ManiaSkinComponent(ManiaSkinComponents component, StageDefinition stageDefinition = null)
: base(component) : base(component)
{ {
StageDefinition = stageDefinition; StageDefinition = stageDefinition;

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -20,6 +21,9 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
[Resolved] [Resolved]
protected Column Column { get; private set; } protected Column Column { get; private set; }
[Resolved]
private StageDefinition stage { get; set; }
/// <summary> /// <summary>
/// The column type identifier to use for texture lookups, in the case of no user-provided configuration. /// The column type identifier to use for texture lookups, in the case of no user-provided configuration.
/// </summary> /// </summary>
@ -28,19 +32,12 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
switch (Column.ColumnType) if (Column.IsSpecial)
FallbackColumnIndex = "S";
else
{ {
case ColumnType.Special: int distanceToEdge = Math.Min(Column.Index, (stage.Columns - 1) - Column.Index);
FallbackColumnIndex = "S"; FallbackColumnIndex = distanceToEdge % 2 == 0 ? "1" : "2";
break;
case ColumnType.Odd:
FallbackColumnIndex = "1";
break;
case ColumnType.Even:
FallbackColumnIndex = "2";
break;
} }
} }

View File

@ -114,7 +114,7 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
case ManiaSkinComponents.StageBackground: case ManiaSkinComponents.StageBackground:
Debug.Assert(maniaComponent.StageDefinition != null); Debug.Assert(maniaComponent.StageDefinition != null);
return new LegacyStageBackground(maniaComponent.StageDefinition.Value); return new LegacyStageBackground(maniaComponent.StageDefinition);
case ManiaSkinComponents.StageForeground: case ManiaSkinComponents.StageForeground:
return new LegacyStageForeground(); return new LegacyStageForeground();

View File

@ -6,7 +6,6 @@
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -18,7 +17,6 @@ using osu.Game.Rulesets.Mania.UI.Components;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
@ -26,7 +24,7 @@ using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Mania.UI namespace osu.Game.Rulesets.Mania.UI
{ {
[Cached] [Cached]
public class Column : ScrollingPlayfield, IKeyBindingHandler<ManiaAction>, IHasAccentColour public class Column : ScrollingPlayfield, IKeyBindingHandler<ManiaAction>
{ {
public const float COLUMN_WIDTH = 80; public const float COLUMN_WIDTH = 80;
public const float SPECIAL_COLUMN_WIDTH = 70; public const float SPECIAL_COLUMN_WIDTH = 70;
@ -46,14 +44,17 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly GameplaySampleTriggerSource sampleTriggerSource; private readonly GameplaySampleTriggerSource sampleTriggerSource;
public readonly ColumnType ColumnType; /// <summary>
/// Whether this is a special (ie. scratch) column.
/// </summary>
public readonly bool IsSpecial;
public Color4 AccentColour { get; set; } public Color4 AccentColour { get; set; }
public Column(int index, ColumnType columnType) public Column(int index, bool isSpecial)
{ {
Index = index; Index = index;
ColumnType = columnType; IsSpecial = isSpecial;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Width = COLUMN_WIDTH; Width = COLUMN_WIDTH;

View File

@ -5,6 +5,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Pooling;
@ -19,7 +20,6 @@ using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.UI namespace osu.Game.Rulesets.Mania.UI
{ {
@ -28,6 +28,9 @@ namespace osu.Game.Rulesets.Mania.UI
/// </summary> /// </summary>
public class Stage : ScrollingPlayfield public class Stage : ScrollingPlayfield
{ {
[Cached]
public readonly StageDefinition Definition;
public const float COLUMN_SPACING = 1; public const float COLUMN_SPACING = 1;
public const float HIT_TARGET_POSITION = 110; public const float HIT_TARGET_POSITION = 110;
@ -40,12 +43,12 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly Drawable barLineContainer; private readonly Drawable barLineContainer;
private readonly Dictionary<ColumnType, Color4> columnColours = new Dictionary<ColumnType, Color4> // private readonly Dictionary<ColumnType, Color4> columnColours = new Dictionary<ColumnType, Color4>
{ // {
{ ColumnType.Even, new Color4(6, 84, 0, 255) }, // { ColumnType.Even, new Color4(6, 84, 0, 255) },
{ ColumnType.Odd, new Color4(94, 0, 57, 255) }, // { ColumnType.Odd, new Color4(94, 0, 57, 255) },
{ ColumnType.Special, new Color4(0, 48, 63, 255) } // { ColumnType.Special, new Color4(0, 48, 63, 255) }
}; // };
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos)); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos));
@ -54,6 +57,7 @@ namespace osu.Game.Rulesets.Mania.UI
public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction) public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction)
{ {
this.firstColumnIndex = firstColumnIndex; this.firstColumnIndex = firstColumnIndex;
Definition = definition;
Name = "Stage"; Name = "Stage";
@ -118,14 +122,15 @@ namespace osu.Game.Rulesets.Mania.UI
for (int i = 0; i < definition.Columns; i++) for (int i = 0; i < definition.Columns; i++)
{ {
var columnType = definition.GetTypeOfColumn(i); bool isSpecial = definition.IsSpecialColumn(i);
var column = new Column(firstColumnIndex + i, columnType) var column = new Column(firstColumnIndex + i, isSpecial)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
AccentColour = columnColours[columnType],
Action = { Value = columnType == ColumnType.Special ? specialColumnStartAction++ : normalColumnStartAction++ }
Width = 1, Width = 1,
// TODO: reimplement this somewhere.
//AccentColour = columnColours[isSpecial],
Action = { Value = isSpecial ? specialColumnStartAction++ : normalColumnStartAction++ }
}; };
topLevelContainer.Add(column.TopLevelContainer.CreateProxy()); topLevelContainer.Add(column.TopLevelContainer.CreateProxy());