Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "Special" ManiaActions for center columns #29342

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions osu.Game.Rulesets.Mania.Tests/ManiaLegacyReplayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ManiaLegacyReplayTest
{
[TestCase(ManiaAction.Key1)]
[TestCase(ManiaAction.Key1, ManiaAction.Key2)]
[TestCase(ManiaAction.Special1)]
[TestCase(ManiaAction.Key8)]
[TestCase(ManiaAction.Key5)]
[TestCase(ManiaAction.Key9)]
public void TestEncodeDecodeSingleStage(params ManiaAction[] actions)
{
var beatmap = new ManiaBeatmap(new StageDefinition(9));
Expand All @@ -29,11 +29,11 @@ public void TestEncodeDecodeSingleStage(params ManiaAction[] actions)

[TestCase(ManiaAction.Key1)]
[TestCase(ManiaAction.Key1, ManiaAction.Key2)]
[TestCase(ManiaAction.Special1)]
[TestCase(ManiaAction.Special2)]
[TestCase(ManiaAction.Special1, ManiaAction.Special2)]
[TestCase(ManiaAction.Special1, ManiaAction.Key5)]
[TestCase(ManiaAction.Key3)]
[TestCase(ManiaAction.Key8)]
[TestCase(ManiaAction.Key3, ManiaAction.Key8)]
[TestCase(ManiaAction.Key3, ManiaAction.Key6)]
[TestCase(ManiaAction.Key10)]
public void TestEncodeDecodeDualStage(params ManiaAction[] actions)
{
var beatmap = new ManiaBeatmap(new StageDefinition(5));
Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Mania.Tests/Skinning/TestSceneStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ private void load()
{
SetContents(_ =>
{
ManiaAction normalAction = ManiaAction.Key1;
ManiaAction specialAction = ManiaAction.Special1;
ManiaAction action = ManiaAction.Key1;

return new ManiaInputManager(new ManiaRuleset().RulesetInfo, 4)
{
Child = new Stage(0, new StageDefinition(4), ref normalAction, ref specialAction)
Child = new Stage(0, new StageDefinition(4), ref action)
};
});
}
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Mania.Tests/TestSceneAutoGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void TestSingleNote()
Assert.AreEqual(generated.Frames.Count, frame_offset + 2, "Incorrect number of frames");
Assert.AreEqual(1000, generated.Frames[frame_offset].Time, "Incorrect hit time");
Assert.AreEqual(1000 + ManiaAutoGenerator.RELEASE_DELAY, generated.Frames[frame_offset + 1].Time, "Incorrect release time");
Assert.IsTrue(checkContains(generated.Frames[frame_offset], ManiaAction.Special1), "Special1 has not been pressed");
Assert.IsFalse(checkContains(generated.Frames[frame_offset + 1], ManiaAction.Special1), "Special1 has not been released");
Assert.IsTrue(checkContains(generated.Frames[frame_offset], ManiaAction.Key1), "Key1 has not been pressed");
Assert.IsFalse(checkContains(generated.Frames[frame_offset + 1], ManiaAction.Key1), "Key1 has not been released");
}

[Test]
Expand All @@ -57,8 +57,8 @@ public void TestSingleHoldNote()
Assert.AreEqual(generated.Frames.Count, frame_offset + 2, "Incorrect number of frames");
Assert.AreEqual(1000, generated.Frames[frame_offset].Time, "Incorrect hit time");
Assert.AreEqual(3000, generated.Frames[frame_offset + 1].Time, "Incorrect release time");
Assert.IsTrue(checkContains(generated.Frames[frame_offset], ManiaAction.Special1), "Special1 has not been pressed");
Assert.IsFalse(checkContains(generated.Frames[frame_offset + 1], ManiaAction.Special1), "Special1 has not been released");
Assert.IsTrue(checkContains(generated.Frames[frame_offset], ManiaAction.Key1), "Key1 has not been pressed");
Assert.IsFalse(checkContains(generated.Frames[frame_offset + 1], ManiaAction.Key1), "Key1 has not been released");
}

[Test]
Expand Down
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ private void createBarLine(bool major)

private ScrollingTestContainer createStage(ScrollingDirection direction, ManiaAction action)
{
var specialAction = ManiaAction.Special1;

var stage = new Stage(0, new StageDefinition(2), ref action, ref specialAction);
var stage = new Stage(0, new StageDefinition(2), ref action);
stages.Add(stage);

return new ScrollingTestContainer(direction)
Expand Down
9 changes: 3 additions & 6 deletions osu.Game.Rulesets.Mania/DualStageVariantGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ public IEnumerable<KeyBinding> GenerateMappings()
LeftKeys = stage1LeftKeys,
RightKeys = stage1RightKeys,
SpecialKey = InputKey.V,
SpecialAction = ManiaAction.Special1,
NormalActionStart = ManiaAction.Key1
}.GenerateKeyBindingsFor(singleStageVariant, out var nextNormal);
}.GenerateKeyBindingsFor(singleStageVariant);

var stage2Bindings = new VariantMappingGenerator
{
LeftKeys = stage2LeftKeys,
RightKeys = stage2RightKeys,
SpecialKey = InputKey.B,
SpecialAction = ManiaAction.Special2,
NormalActionStart = nextNormal
}.GenerateKeyBindingsFor(singleStageVariant, out _);
ActionStart = (ManiaAction)singleStageVariant,
}.GenerateKeyBindingsFor(singleStageVariant);

return stage1Bindings.Concat(stage2Bindings);
}
Expand Down
10 changes: 1 addition & 9 deletions osu.Game.Rulesets.Mania/ManiaInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@ public ManiaInputManager(RulesetInfo ruleset, int variant)

public enum ManiaAction
{
[Description("Special 1")]
Special1 = 1,

[Description("Special 2")]
Special2,

// This offsets the start value of normal keys in-case we add more special keys
// above at a later time, without breaking replays/configs.
[Description("Key 1")]
Key1 = 10,
Key1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to make the enum match the key number, we could do this

Suggested change
Key1,
Key1 = 1,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied this via 952a73b (smoogi agrees to it).

Copy link
Member

@peppy peppy Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not, something relies on zero index somewhere who knows. Was hoping this would be agreed upon before committing to this.


[Description("Key 2")]
Key2,
Expand Down
23 changes: 2 additions & 21 deletions osu.Game.Rulesets.Mania/Replays/ManiaAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,9 @@ internal class ManiaAutoGenerator : AutoGenerator<ManiaReplayFrame>

public new ManiaBeatmap Beatmap => (ManiaBeatmap)base.Beatmap;

private readonly ManiaAction[] columnActions;

public ManiaAutoGenerator(ManiaBeatmap beatmap)
: base(beatmap)
{
columnActions = new ManiaAction[Beatmap.TotalColumns];

var normalAction = ManiaAction.Key1;
var specialAction = ManiaAction.Special1;
int totalCounter = 0;

foreach (var stage in Beatmap.Stages)
{
for (int i = 0; i < stage.Columns; i++)
{
if (stage.IsSpecialColumn(i))
columnActions[totalCounter] = specialAction++;
else
columnActions[totalCounter] = normalAction++;
totalCounter++;
}
}
}

protected override void GenerateFrames()
Expand All @@ -57,11 +38,11 @@ protected override void GenerateFrames()
switch (point)
{
case HitPoint:
actions.Add(columnActions[point.Column]);
actions.Add(ManiaAction.Key1 + point.Column);
break;

case ReleasePoint:
actions.Remove(columnActions[point.Column]);
actions.Remove(ManiaAction.Key1 + point.Column);
break;
}
}
Expand Down
101 changes: 4 additions & 97 deletions osu.Game.Rulesets.Mania/Replays/ManiaReplayFrame.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;

Expand All @@ -27,118 +25,27 @@ public ManiaReplayFrame(double time, params ManiaAction[] actions)

public void FromLegacy(LegacyReplayFrame legacyFrame, IBeatmap beatmap, ReplayFrame? lastFrame = null)
{
var maniaBeatmap = (ManiaBeatmap)beatmap;

var normalAction = ManiaAction.Key1;
var specialAction = ManiaAction.Special1;

var action = ManiaAction.Key1;
int activeColumns = (int)(legacyFrame.MouseX ?? 0);
int counter = 0;

while (activeColumns > 0)
{
bool isSpecial = isColumnAtIndexSpecial(maniaBeatmap, counter);

if ((activeColumns & 1) > 0)
Actions.Add(isSpecial ? specialAction : normalAction);

if (isSpecial)
specialAction++;
else
normalAction++;
Actions.Add(action);

counter++;
action++;
activeColumns >>= 1;
}
}

public LegacyReplayFrame ToLegacy(IBeatmap beatmap)
{
var maniaBeatmap = (ManiaBeatmap)beatmap;

int keys = 0;

foreach (var action in Actions)
{
switch (action)
{
case ManiaAction.Special1:
keys |= 1 << getSpecialColumnIndex(maniaBeatmap, 0);
break;

case ManiaAction.Special2:
keys |= 1 << getSpecialColumnIndex(maniaBeatmap, 1);
break;

default:
// the index in lazer, which doesn't include special keys.
int nonSpecialKeyIndex = action - ManiaAction.Key1;

// the index inclusive of special keys.
int overallIndex = 0;

// iterate to find the index including special keys.
for (; overallIndex < maniaBeatmap.TotalColumns; overallIndex++)
{
// skip over special columns.
if (isColumnAtIndexSpecial(maniaBeatmap, overallIndex))
continue;
// found a non-special column to use.
if (nonSpecialKeyIndex == 0)
break;
// found a non-special column but not ours.
nonSpecialKeyIndex--;
}

keys |= 1 << overallIndex;
break;
}
}
keys |= 1 << (int)action;

return new LegacyReplayFrame(Time, keys, null, ReplayButtonState.None);
}

/// <summary>
/// Find the overall index (across all stages) for a specified special key.
/// </summary>
/// <param name="maniaBeatmap">The beatmap.</param>
/// <param name="specialOffset">The special key offset (0 is S1).</param>
/// <returns>The overall index for the special column.</returns>
private int getSpecialColumnIndex(ManiaBeatmap maniaBeatmap, int specialOffset)
{
for (int i = 0; i < maniaBeatmap.TotalColumns; i++)
{
if (isColumnAtIndexSpecial(maniaBeatmap, i))
{
if (specialOffset == 0)
return i;

specialOffset--;
}
}

throw new ArgumentException("Special key index is too high.", nameof(specialOffset));
}

/// <summary>
/// Check whether the column at an overall index (across all stages) is a special column.
/// </summary>
/// <param name="beatmap">The beatmap.</param>
/// <param name="index">The overall index to check.</param>
private bool isColumnAtIndexSpecial(ManiaBeatmap beatmap, int index)
{
foreach (var stage in beatmap.Stages)
{
if (index >= stage.Columns)
{
index -= stage.Columns;
continue;
}

return stage.IsSpecialColumn(index);
}

throw new ArgumentException("Column index is too high.", nameof(index));
}
}
}
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Mania/SingleStageVariantGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public SingleStageVariantGenerator(int variant)
LeftKeys = leftKeys,
RightKeys = rightKeys,
SpecialKey = InputKey.Space,
SpecialAction = ManiaAction.Special1,
NormalActionStart = ManiaAction.Key1,
}.GenerateKeyBindingsFor(variant, out _);
}.GenerateKeyBindingsFor(variant);
}
}
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ public ManiaPlayfield(List<StageDefinition> stageDefinitions)
Content = new[] { new Drawable[stageDefinitions.Count] }
});

var normalColumnAction = ManiaAction.Key1;
var specialColumnAction = ManiaAction.Special1;
var columnAction = ManiaAction.Key1;
int firstColumnIndex = 0;

for (int i = 0; i < stageDefinitions.Count; i++)
{
var newStage = new Stage(firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
var newStage = new Stage(firstColumnIndex, stageDefinitions[i], ref columnAction);

playfieldGrid.Content[0][i] = newStage;

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Mania/UI/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)

private ISkinSource currentSkin = null!;

public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction)
public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction columnStartAction)
{
this.firstColumnIndex = firstColumnIndex;
Definition = definition;
Expand Down Expand Up @@ -138,7 +138,7 @@ public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction n
{
RelativeSizeAxes = Axes.Both,
Width = 1,
Action = { Value = isSpecial ? specialColumnStartAction++ : normalColumnStartAction++ }
Action = { Value = columnStartAction++ }
};

topLevelContainer.Add(column.TopLevelContainer.CreateProxy());
Expand Down
21 changes: 7 additions & 14 deletions osu.Game.Rulesets.Mania/VariantMappingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,30 @@ public class VariantMappingGenerator
public InputKey SpecialKey;

/// <summary>
/// The <see cref="ManiaAction"/> at which the normal columns should begin.
/// The <see cref="ManiaAction"/> at which the columns should begin.
/// </summary>
public ManiaAction NormalActionStart;

/// <summary>
/// The <see cref="ManiaAction"/> for the special column.
/// </summary>
public ManiaAction SpecialAction;
public ManiaAction ActionStart;

/// <summary>
/// Generates a list of <see cref="KeyBinding"/>s for a specific number of columns.
/// </summary>
/// <param name="columns">The number of columns that need to be bound.</param>
/// <param name="nextNormalAction">The next <see cref="ManiaAction"/> to use for normal columns.</param>
/// <returns>The keybindings.</returns>
public IEnumerable<KeyBinding> GenerateKeyBindingsFor(int columns, out ManiaAction nextNormalAction)
public IEnumerable<KeyBinding> GenerateKeyBindingsFor(int columns)
{
ManiaAction currentNormalAction = NormalActionStart;
ManiaAction currentAction = ActionStart;

var bindings = new List<KeyBinding>();

for (int i = LeftKeys.Length - columns / 2; i < LeftKeys.Length; i++)
bindings.Add(new KeyBinding(LeftKeys[i], currentNormalAction++));
bindings.Add(new KeyBinding(LeftKeys[i], currentAction++));

if (columns % 2 == 1)
bindings.Add(new KeyBinding(SpecialKey, SpecialAction));
bindings.Add(new KeyBinding(SpecialKey, currentAction++));

for (int i = 0; i < columns / 2; i++)
bindings.Add(new KeyBinding(RightKeys[i], currentNormalAction++));
bindings.Add(new KeyBinding(RightKeys[i], currentAction++));

nextNormalAction = currentNormalAction;
return bindings;
}
}
Expand Down
Loading
Loading