2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-09 11:50:09 +00:00
|
|
|
|
using System;
|
2017-10-10 07:34:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-05-15 09:07:41 +00:00
|
|
|
|
using System.Threading;
|
2021-06-22 08:33:32 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2017-10-10 07:34:01 +00:00
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2022-09-20 17:13:40 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
2020-02-23 04:01:30 +00:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2017-10-10 07:34:01 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-10-10 07:34:01 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Catch.Objects
|
|
|
|
|
{
|
2020-05-26 08:44:47 +00:00
|
|
|
|
public class JuiceStream : CatchHitObject, IHasPathWithRepeats
|
2017-10-10 07:34:01 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-10-12 13:27:22 +00:00
|
|
|
|
/// Positional distance that results in a duration of one second, before any speed adjustments.
|
2017-10-10 07:34:01 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private const float base_scoring_distance = 100;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-23 04:01:30 +00:00
|
|
|
|
public override Judgement CreateJudgement() => new IgnoreJudgement();
|
|
|
|
|
|
2018-01-23 04:37:25 +00:00
|
|
|
|
public int RepeatCount { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-06-22 08:33:32 +00:00
|
|
|
|
[JsonIgnore]
|
2022-05-08 12:32:05 +00:00
|
|
|
|
private double velocityFactor;
|
2021-06-22 08:33:32 +00:00
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2022-05-08 12:32:05 +00:00
|
|
|
|
private double tickDistanceFactor;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double Velocity => velocityFactor * DifficultyControlPoint.SliderVelocity;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double TickDistance => tickDistanceFactor * DifficultyControlPoint.SliderVelocity;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The length of one span of this <see cref="JuiceStream"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double SpanDuration => Duration / this.SpanCount();
|
|
|
|
|
|
2021-10-01 05:56:42 +00:00
|
|
|
|
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
|
2017-10-10 07:34:01 +00:00
|
|
|
|
{
|
2017-12-22 12:42:54 +00:00
|
|
|
|
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-10-10 07:34:01 +00:00
|
|
|
|
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-05-08 12:32:05 +00:00
|
|
|
|
velocityFactor = base_scoring_distance * difficulty.SliderMultiplier / timingPoint.BeatLength;
|
|
|
|
|
tickDistanceFactor = base_scoring_distance * difficulty.SliderMultiplier / difficulty.SliderTickRate;
|
2017-10-10 07:34:01 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-05-15 09:07:41 +00:00
|
|
|
|
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
|
2017-10-10 07:34:01 +00:00
|
|
|
|
{
|
2020-05-15 09:07:41 +00:00
|
|
|
|
base.CreateNestedHitObjects(cancellationToken);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-12-01 06:37:51 +00:00
|
|
|
|
var dropletSamples = Samples.Select(s => s.With(@"slidertick")).ToList();
|
2019-01-26 07:16:49 +00:00
|
|
|
|
|
2020-10-09 11:50:09 +00:00
|
|
|
|
int nodeIndex = 0;
|
2019-03-08 10:57:30 +00:00
|
|
|
|
SliderEventDescriptor? lastEvent = null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-05-15 09:17:39 +00:00
|
|
|
|
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken))
|
2017-12-22 12:42:54 +00:00
|
|
|
|
{
|
2019-03-08 10:57:30 +00:00
|
|
|
|
// generate tiny droplets since the last point
|
|
|
|
|
if (lastEvent != null)
|
2017-10-10 07:34:01 +00:00
|
|
|
|
{
|
2019-03-11 05:36:29 +00:00
|
|
|
|
double sinceLastTick = e.Time - lastEvent.Value.Time;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
if (sinceLastTick > 80)
|
2018-06-13 13:20:34 +00:00
|
|
|
|
{
|
2019-03-08 10:57:30 +00:00
|
|
|
|
double timeBetweenTiny = sinceLastTick;
|
|
|
|
|
while (timeBetweenTiny > 100)
|
|
|
|
|
timeBetweenTiny /= 2;
|
2018-06-13 13:20:34 +00:00
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
|
|
|
|
|
{
|
2020-05-15 09:17:39 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
AddNested(new TinyDroplet
|
|
|
|
|
{
|
2019-03-11 05:36:29 +00:00
|
|
|
|
StartTime = t + lastEvent.Value.Time,
|
2022-09-21 15:14:02 +00:00
|
|
|
|
X = ClampToPlayfield(EffectiveX + Path.PositionAt(
|
2022-09-20 17:13:40 +00:00
|
|
|
|
lastEvent.Value.PathProgress + (t / sinceLastTick) * (e.PathProgress - lastEvent.Value.PathProgress)).X),
|
2019-03-08 10:57:30 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-01-26 07:14:37 +00:00
|
|
|
|
}
|
2019-03-08 10:57:30 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-08 11:12:48 +00:00
|
|
|
|
// this also includes LegacyLastTick and this is used for TinyDroplet generation above.
|
|
|
|
|
// this means that the final segment of TinyDroplets are increasingly mistimed where LegacyLastTickOffset is being applied.
|
2019-03-08 10:57:30 +00:00
|
|
|
|
lastEvent = e;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
switch (e.Type)
|
|
|
|
|
{
|
|
|
|
|
case SliderEventType.Tick:
|
|
|
|
|
AddNested(new Droplet
|
2018-03-16 08:02:41 +00:00
|
|
|
|
{
|
2020-03-10 09:05:44 +00:00
|
|
|
|
Samples = dropletSamples,
|
2019-03-11 05:36:29 +00:00
|
|
|
|
StartTime = e.Time,
|
2022-09-21 15:14:02 +00:00
|
|
|
|
X = ClampToPlayfield(EffectiveX + Path.PositionAt(e.PathProgress).X),
|
2019-03-08 10:57:30 +00:00
|
|
|
|
});
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2019-03-08 10:57:30 +00:00
|
|
|
|
case SliderEventType.Head:
|
|
|
|
|
case SliderEventType.Tail:
|
|
|
|
|
case SliderEventType.Repeat:
|
|
|
|
|
AddNested(new Fruit
|
|
|
|
|
{
|
2020-10-09 11:50:09 +00:00
|
|
|
|
Samples = this.GetNodeSamples(nodeIndex++),
|
2019-03-11 05:36:29 +00:00
|
|
|
|
StartTime = e.Time,
|
2022-09-21 15:14:02 +00:00
|
|
|
|
X = ClampToPlayfield(EffectiveX + Path.PositionAt(e.PathProgress).X),
|
2018-03-16 08:02:41 +00:00
|
|
|
|
});
|
2019-01-21 08:53:00 +00:00
|
|
|
|
break;
|
2017-10-10 07:34:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-09-21 15:14:02 +00:00
|
|
|
|
public float EndX => ClampToPlayfield(EffectiveX + this.CurvePositionAt(1).X);
|
2022-09-20 17:13:40 +00:00
|
|
|
|
|
2022-09-21 15:14:02 +00:00
|
|
|
|
public float ClampToPlayfield(float value) => Math.Clamp(value, 0, CatchPlayfield.WIDTH);
|
2020-05-27 03:37:44 +00:00
|
|
|
|
|
2021-06-22 08:33:32 +00:00
|
|
|
|
[JsonIgnore]
|
2020-05-27 03:37:44 +00:00
|
|
|
|
public double Duration
|
2020-02-05 08:12:26 +00:00
|
|
|
|
{
|
2020-05-27 03:37:44 +00:00
|
|
|
|
get => this.SpanCount() * Path.Distance / Velocity;
|
2020-10-09 11:50:09 +00:00
|
|
|
|
set => throw new NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
|
2020-02-05 08:12:26 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-05-27 03:37:44 +00:00
|
|
|
|
public double EndTime => StartTime + Duration;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-12-09 08:48:27 +00:00
|
|
|
|
private readonly SliderPath path = new SliderPath();
|
2019-12-06 11:53:40 +00:00
|
|
|
|
|
|
|
|
|
public SliderPath Path
|
|
|
|
|
{
|
|
|
|
|
get => path;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
path.ControlPoints.Clear();
|
|
|
|
|
path.ExpectedDistance.Value = null;
|
|
|
|
|
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
2021-08-25 16:42:57 +00:00
|
|
|
|
path.ControlPoints.AddRange(value.ControlPoints.Select(c => new PathControlPoint(c.Position, c.Type)));
|
2019-12-06 11:53:40 +00:00
|
|
|
|
path.ExpectedDistance.Value = value.ExpectedDistance.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-12 05:07:48 +00:00
|
|
|
|
public double Distance => Path.Distance;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-23 08:59:07 +00:00
|
|
|
|
public IList<IList<HitSampleInfo>> NodeSamples { get; set; } = new List<IList<HitSampleInfo>>();
|
2018-06-13 13:20:34 +00:00
|
|
|
|
|
|
|
|
|
public double? LegacyLastTickOffset { get; set; }
|
2017-10-10 07:34:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|