Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Mar 28, 2024
1 parent a9cbabf commit 2f786ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
21 changes: 10 additions & 11 deletions osu.Game.Rulesets.Catch/Edit/CatchSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ public override bool HandleFlip(Direction direction, bool flipOverOrigin)
public override bool HandleReverse()
{
var hitObjects = EditorBeatmap.SelectedHitObjects
.OfType<CatchHitObject>()
.OrderBy(obj => obj.StartTime)
.ToList();
.OfType<CatchHitObject>()
.OrderBy(obj => obj.StartTime)
.ToList();

double selectionStartTime = SelectedItems.Min(h => h.StartTime);
double selectionEndTime = SelectedItems.Max(h => h.GetEndTime());

// the expectation is that even if the objects themselves are reversed temporally,
// the position of new combos in the selection should remain the same.
// preserve it for later before doing the reversal.
var newComboOrder = hitObjects.Select(obj => obj.NewCombo).ToList();

foreach (var h in hitObjects)
Expand All @@ -99,15 +102,11 @@ public override bool HandleReverse()
}
}

// re-order objects again after flipping their times
hitObjects = [.. hitObjects.OrderBy(obj => obj.StartTime)];
// re-order objects by start time again after reversing, and restore new combo flag positioning
hitObjects = hitObjects.OrderBy(obj => obj.StartTime).ToList();

int i = 0;
foreach (bool newCombo in newComboOrder)
{
hitObjects[i].NewCombo = newCombo;
i++;
}
for (int i = 0; i < hitObjects.Count; ++i)
hitObjects[i].NewCombo = newComboOrder[i];

return true;
}
Expand Down
21 changes: 10 additions & 11 deletions osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
public override bool HandleReverse()
{
var hitObjects = EditorBeatmap.SelectedHitObjects
.OfType<OsuHitObject>()
.OrderBy(obj => obj.StartTime)
.ToList();
.OfType<OsuHitObject>()
.OrderBy(obj => obj.StartTime)
.ToList();

double endTime = hitObjects.Max(h => h.GetEndTime());
double startTime = hitObjects.Min(h => h.StartTime);

bool moreThanOneObject = hitObjects.Count > 1;

// the expectation is that even if the objects themselves are reversed temporally,
// the position of new combos in the selection should remain the same.
// preserve it for later before doing the reversal.
var newComboOrder = hitObjects.Select(obj => obj.NewCombo).ToList();

foreach (var h in hitObjects)
Expand All @@ -102,15 +105,11 @@ public override bool HandleReverse()
}
}

// re-order objects again after flipping their times
hitObjects = [.. hitObjects.OrderBy(obj => obj.StartTime)];
// re-order objects by start time again after reversing, and restore new combo flag positioning
hitObjects = hitObjects.OrderBy(obj => obj.StartTime).ToList();

int i = 0;
foreach (bool newCombo in newComboOrder)
{
hitObjects[i].NewCombo = newCombo;
i++;
}
for (int i = 0; i < hitObjects.Count; ++i)
hitObjects[i].NewCombo = newComboOrder[i];

return true;
}
Expand Down

0 comments on commit 2f786ff

Please sign in to comment.