Fix slider samples being overwritten by the last node

This commit is contained in:
smoogipoo 2020-10-09 20:50:09 +09:00
parent 07f19342d1
commit 696e3d53af
4 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,7 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -56,6 +57,7 @@ protected override void CreateNestedHitObjects(CancellationToken cancellationTok
Volume = s.Volume
}).ToList();
int nodeIndex = 0;
SliderEventDescriptor? lastEvent = null;
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken))
@ -105,7 +107,7 @@ protected override void CreateNestedHitObjects(CancellationToken cancellationTok
case SliderEventType.Repeat:
AddNested(new Fruit
{
Samples = Samples,
Samples = this.GetNodeSamples(nodeIndex++),
StartTime = e.Time,
X = X + Path.PositionAt(e.PathProgress).X,
});
@ -119,7 +121,7 @@ protected override void CreateNestedHitObjects(CancellationToken cancellationTok
public double Duration
{
get => this.SpanCount() * Path.Distance / Velocity;
set => throw new System.NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
set => throw new NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
}
public double EndTime => StartTime + Duration;

View File

@ -137,6 +137,10 @@ protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, B
Velocity = scoringDistance / timingPoint.BeatLength;
TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier;
// The samples should be attached to the slider tail, however this can only be done after LegacyLastTick is removed otherwise they would play earlier than they're intended to.
// For now, the samples are attached to and played by the slider itself at the correct end time.
Samples = this.GetNodeSamples(repeatCount + 1);
}
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
@ -230,15 +234,12 @@ private void updateNestedSamples()
tick.Samples = sampleList;
foreach (var repeat in NestedHitObjects.OfType<SliderRepeat>())
repeat.Samples = getNodeSamples(repeat.RepeatIndex + 1);
repeat.Samples = this.GetNodeSamples(repeat.RepeatIndex + 1);
if (HeadCircle != null)
HeadCircle.Samples = getNodeSamples(0);
HeadCircle.Samples = this.GetNodeSamples(0);
}
private IList<HitSampleInfo> getNodeSamples(int nodeIndex) =>
nodeIndex < NodeSamples.Count ? NodeSamples[nodeIndex] : Samples;
public override Judgement CreateJudgement() => new OsuIgnoreJudgement();
protected override HitWindows CreateHitWindows() => HitWindows.Empty;

View File

@ -184,9 +184,6 @@ public override HitObject Parse(string text)
nodeSamples.Add(convertSoundType(nodeSoundTypes[i], nodeBankInfos[i]));
result = CreateSlider(pos, combo, comboOffset, convertControlPoints(points, pathType), length, repeatCount, nodeSamples);
// The samples are played when the slider ends, which is the last node
result.Samples = nodeSamples[^1];
}
else if (type.HasFlag(LegacyHitObjectType.Spinner))
{

View File

@ -35,5 +35,15 @@ public static class HasRepeatsExtensions
/// </summary>
/// <param name="obj">The object that has repeats.</param>
public static int SpanCount(this IHasRepeats obj) => obj.RepeatCount + 1;
/// <summary>
/// Retrieves the samples at a particular node in a <see cref="IHasRepeats"/> object.
/// </summary>
/// <param name="obj">The <see cref="HitObject"/>.</param>
/// <param name="nodeIndex">The node to attempt to retrieve the samples at.</param>
/// <returns>The samples at the given node index, or <paramref name="obj"/>'s default samples if the given node doesn't exist.</returns>
public static IList<HitSampleInfo> GetNodeSamples<T>(this T obj, int nodeIndex)
where T : HitObject, IHasRepeats
=> nodeIndex < obj.NodeSamples.Count ? obj.NodeSamples[nodeIndex] : obj.Samples;
}
}