Skip to content

Commit

Permalink
Merge pull request ppy#30763 from Darius-Wattimena/catch-convert-to-s…
Browse files Browse the repository at this point in the history
…tream

Add convert to stream functionality for juice streams
  • Loading branch information
bdach authored Dec 11, 2024
2 parents cc1f949 + 5a0b732 commit 99f9e28
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -10,10 +10,12 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Catch.Edit.Blueprints.Components;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit;
using osuTK;
using osuTK.Input;
@@ -54,6 +56,12 @@ public partial class JuiceStreamSelectionBlueprint : CatchSelectionBlueprint<Jui
[Resolved]
private EditorBeatmap? editorBeatmap { get; set; }

[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }

[Resolved]
private BindableBeatDivisor? beatDivisor { get; set; }

public JuiceStreamSelectionBlueprint(JuiceStream hitObject)
: base(hitObject)
{
@@ -119,6 +127,20 @@ protected override bool OnMouseDown(MouseDownEvent e)
return base.OnMouseDown(e);
}

protected override bool OnKeyDown(KeyDownEvent e)
{
if (!IsSelected)
return false;

if (e.Key == Key.F && e.ControlPressed && e.ShiftPressed)
{
convertToStream();
return true;
}

return false;
}

private void onDefaultsApplied(HitObject _)
{
computeObjectBounds();
@@ -168,6 +190,50 @@ private void updateHitObjectFromPath()
lastSliderPathVersion = HitObject.Path.Version.Value;
}

// duplicated in `SliderSelectionBlueprint.convertToStream()`
// consider extracting common helper when applying changes here
private void convertToStream()
{
if (editorBeatmap == null || beatDivisor == null)
return;

var timingPoint = editorBeatmap.ControlPointInfo.TimingPointAt(HitObject.StartTime);
double streamSpacing = timingPoint.BeatLength / beatDivisor.Value;

changeHandler?.BeginChange();

int i = 0;
double time = HitObject.StartTime;

while (!Precision.DefinitelyBigger(time, HitObject.GetEndTime(), 1))
{
// positionWithRepeats is a fractional number in the range of [0, HitObject.SpanCount()]
// and indicates how many fractional spans of a slider have passed up to time.
double positionWithRepeats = (time - HitObject.StartTime) / HitObject.Duration * HitObject.SpanCount();
double pathPosition = positionWithRepeats - (int)positionWithRepeats;
// every second span is in the reverse direction - need to reverse the path position.
if (positionWithRepeats % 2 >= 1)
pathPosition = 1 - pathPosition;

float fruitXValue = HitObject.OriginalX + HitObject.Path.PositionAt(pathPosition).X;

editorBeatmap.Add(new Fruit
{
StartTime = time,
OriginalX = fruitXValue,
NewCombo = i == 0 && HitObject.NewCombo,
Samples = HitObject.Samples.Select(s => s.With()).ToList()
});

i += 1;
time = HitObject.StartTime + i * streamSpacing;
}

editorBeatmap.Remove(HitObject);

changeHandler?.EndChange();
}

private IEnumerable<MenuItem> getContextMenuItems()
{
yield return new OsuMenuItem("Add vertex", MenuItemType.Standard, () =>
@@ -177,6 +243,11 @@ private IEnumerable<MenuItem> getContextMenuItems()
{
Hotkey = new Hotkey(new KeyCombination(InputKey.Control, InputKey.MouseLeft))
};

yield return new OsuMenuItem("Convert to stream", MenuItemType.Destructive, convertToStream)
{
Hotkey = new Hotkey(new KeyCombination(InputKey.Control, InputKey.Shift, InputKey.F))
};
}

protected override void Dispose(bool isDisposing)
Original file line number Diff line number Diff line change
@@ -551,6 +551,8 @@ private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt)
HitObject.Position += first;
}

// duplicated in `JuiceStreamSelectionBlueprint.convertToStream()`
// consider extracting common helper when applying changes here
private void convertToStream()
{
if (editorBeatmap == null || beatDivisor == null)

0 comments on commit 99f9e28

Please sign in to comment.