osu/osu.Game.Rulesets.Mania/Objects/HoldNote.cs

138 lines
3.7 KiB
C#
Raw Normal View History

// 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
2020-04-21 07:33:19 +00:00
using System.Collections.Generic;
using osu.Game.Audio;
2018-04-13 09:19:50 +00:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements;
2018-04-13 09:19:50 +00:00
using osu.Game.Rulesets.Objects.Types;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Scoring;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Mania.Objects
{
/// <summary>
/// Represents a hit object which requires pressing, holding, and releasing a key.
/// </summary>
public class HoldNote : ManiaHitObject, IHasEndTime
{
2020-02-05 08:12:26 +00:00
public double EndTime
{
get => StartTime + Duration;
set => Duration = value - StartTime;
}
2018-04-13 09:19:50 +00:00
private double duration;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public double Duration
{
get => duration;
2018-04-13 09:19:50 +00:00
set
{
duration = value;
2020-04-21 07:33:19 +00:00
if (Tail != null)
Tail.StartTime = EndTime;
2018-04-13 09:19:50 +00:00
}
}
public override double StartTime
{
get => base.StartTime;
2018-04-13 09:19:50 +00:00
set
{
base.StartTime = value;
2020-04-21 07:33:19 +00:00
if (Head != null)
Head.StartTime = value;
if (Tail != null)
Tail.StartTime = EndTime;
2018-04-13 09:19:50 +00:00
}
}
public override int Column
{
get => base.Column;
2018-04-13 09:19:50 +00:00
set
{
base.Column = value;
2020-04-21 07:33:19 +00:00
if (Head != null)
Head.Column = value;
if (Tail != null)
Tail.Column = value;
2018-04-13 09:19:50 +00:00
}
}
2020-04-21 07:33:19 +00:00
public List<IList<HitSampleInfo>> NodeSamples { get; set; }
2018-04-13 09:19:50 +00:00
/// <summary>
/// The head note of the hold.
/// </summary>
2020-04-21 07:33:19 +00:00
public Note Head { get; private set; }
2018-04-13 09:19:50 +00:00
/// <summary>
/// The tail note of the hold.
/// </summary>
2020-04-21 07:33:19 +00:00
public TailNote Tail { get; private set; }
2018-04-13 09:19:50 +00:00
/// <summary>
/// The time between ticks of this hold.
/// </summary>
private double tickSpacing = 50;
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate;
}
protected override void CreateNestedHitObjects()
{
base.CreateNestedHitObjects();
createTicks();
2020-04-21 07:33:19 +00:00
AddNested(Head = new Note
{
StartTime = StartTime,
Column = Column,
Samples = getNodeSamples(0),
});
AddNested(Tail = new TailNote
{
StartTime = EndTime,
Column = Column,
Samples = getNodeSamples((NodeSamples?.Count - 1) ?? 1),
2020-04-21 07:33:19 +00:00
});
2018-04-13 09:19:50 +00:00
}
private void createTicks()
{
if (tickSpacing == 0)
return;
for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing)
{
AddNested(new HoldNoteTick
{
StartTime = t,
Column = Column
});
}
}
public override Judgement CreateJudgement() => new IgnoreJudgement();
2019-10-09 10:08:31 +00:00
protected override HitWindows CreateHitWindows() => HitWindows.Empty;
2020-04-21 07:33:19 +00:00
private IList<HitSampleInfo> getNodeSamples(int nodeIndex) =>
nodeIndex < NodeSamples?.Count ? NodeSamples[nodeIndex] : Samples;
2018-04-13 09:19:50 +00:00
}
}