1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

Add test coverage and refactor to better handle equality edge case

This commit is contained in:
Dean Herbert 2023-12-26 21:20:18 +09:00
parent 1f2f749db6
commit 03e2463b06
No known key found for this signature in database
3 changed files with 66 additions and 8 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Timing;
using osu.Game.Screens.Edit.Timing.RowAttributes;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Editing
@ -69,6 +70,48 @@ namespace osu.Game.Tests.Visual.Editing
AddUntilStep("Wait for rows to load", () => Child.ChildrenOfType<EffectRowAttribute>().Any());
}
[Test]
public void TestSelectedRetainedOverUndo()
{
AddStep("Select first timing point", () =>
{
InputManager.MoveMouseTo(Child.ChildrenOfType<TimingRowAttribute>().First());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 2170);
AddUntilStep("Ensure seeked to correct time", () => EditorClock.CurrentTimeAccurate == 2170);
AddStep("Adjust offset", () =>
{
InputManager.MoveMouseTo(timingScreen.ChildrenOfType<TimingAdjustButton>().First().ScreenSpaceDrawQuad.Centre + new Vector2(20, 0));
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for offset changed", () =>
{
return timingScreen.SelectedGroup.Value.ControlPoints.Any(c => c is TimingControlPoint) && timingScreen.SelectedGroup.Value.Time > 2170;
});
AddStep("simulate undo", () =>
{
var clone = editorBeatmap.ControlPointInfo.DeepClone();
editorBeatmap.ControlPointInfo.Clear();
foreach (var group in clone.Groups)
{
foreach (var cp in group.ControlPoints)
editorBeatmap.ControlPointInfo.Add(group.Time, cp);
}
});
AddUntilStep("selection retained", () =>
{
return timingScreen.SelectedGroup.Value.ControlPoints.Any(c => c is TimingControlPoint) && timingScreen.SelectedGroup.Value.Time > 2170;
});
}
[Test]
public void TestTrackingCurrentTimeWhileRunning()
{

View File

@ -58,7 +58,7 @@ namespace osu.Game.Screens.Edit
return -1;
}
protected bool SetSelectedRow(object? item)
protected virtual bool SetSelectedRow(object? item)
{
bool foundSelection = false;

View File

@ -46,7 +46,7 @@ namespace osu.Game.Screens.Edit.Timing
{
Action = () =>
{
selectedGroup.Value = group;
SetSelectedRow(group);
clock.SeekSmoothlyTo(group.Time);
}
});
@ -55,11 +55,16 @@ namespace osu.Game.Screens.Edit.Timing
Columns = createHeaders();
Content = value.Select(createContent).ToArray().ToRectangular();
if (!SetSelectedRow(selectedGroup.Value))
{
// Some operations completely obliterate references, so best-effort reselect based on index.
selectedGroup.Value = GetObjectAtIndex(selectedIndex) as ControlPointGroup;
}
// Attempt to retain selection.
if (SetSelectedRow(selectedGroup.Value))
return;
// Some operations completely obliterate references, so best-effort reselect based on index.
if (SetSelectedRow(GetObjectAtIndex(selectedIndex)))
return;
// Selection could not be retained.
selectedGroup.Value = null;
}
}
@ -67,7 +72,17 @@ namespace osu.Game.Screens.Edit.Timing
{
base.LoadComplete();
selectedGroup.BindValueChanged(_ => SetSelectedRow(selectedGroup.Value), true);
// Handle external selections.
selectedGroup.BindValueChanged(g => SetSelectedRow(g.NewValue), true);
}
protected override bool SetSelectedRow(object? item)
{
if (!base.SetSelectedRow(item))
return false;
selectedGroup.Value = item as ControlPointGroup;
return true;
}
private TableColumn[] createHeaders()