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

122 lines
3.7 KiB
C#
Raw Normal View History

2017-05-29 06:35:50 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-02 09:44:02 +00:00
using System.Collections.Generic;
2017-07-26 04:22:46 +00:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2017-05-03 03:53:45 +00:00
using osu.Game.Rulesets.Objects.Types;
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Mania.Objects
2016-09-02 09:44:02 +00:00
{
2017-05-09 11:55:20 +00:00
/// <summary>
/// Represents a hit object which requires pressing, holding, and releasing a key.
/// </summary>
public class HoldNote : ManiaHitObject, IHasEndTime
2016-09-02 09:44:02 +00:00
{
2017-05-03 03:53:45 +00:00
public double EndTime => StartTime + Duration;
private double duration;
public double Duration
{
get { return duration; }
set
{
duration = value;
Tail.StartTime = EndTime;
}
}
public override double StartTime
{
get { return base.StartTime; }
set
{
base.StartTime = value;
Head.StartTime = value;
Tail.StartTime = EndTime;
}
}
2017-09-11 04:44:39 +00:00
public override int Column
{
get { return base.Column; }
set
{
base.Column = value;
Head.Column = value;
Tail.Column = value;
}
}
2017-05-24 12:57:38 +00:00
/// <summary>
/// The head note of the hold.
/// </summary>
2017-05-26 07:28:39 +00:00
public readonly Note Head = new Note();
2017-05-24 12:57:38 +00:00
/// <summary>
/// The tail note of the hold.
/// </summary>
2017-05-26 07:28:39 +00:00
public readonly Note Tail = new TailNote();
2017-05-18 09:19:29 +00:00
2017-05-09 11:55:20 +00:00
/// <summary>
2017-05-24 12:57:38 +00:00
/// The time between ticks of this hold.
2017-05-09 11:55:20 +00:00
/// </summary>
private double tickSpacing = 50;
2017-05-24 12:24:33 +00:00
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaults(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate;
Head.ApplyDefaults(controlPointInfo, difficulty);
Tail.ApplyDefaults(controlPointInfo, difficulty);
2017-05-24 12:24:33 +00:00
}
2017-05-24 12:57:38 +00:00
/// <summary>
/// The scoring scoring ticks of the hold note.
/// </summary>
public IEnumerable<HoldNoteTick> Ticks => ticks ?? (ticks = createTicks());
private List<HoldNoteTick> ticks;
2017-05-03 03:53:45 +00:00
private List<HoldNoteTick> createTicks()
2017-05-03 03:53:45 +00:00
{
var ret = new List<HoldNoteTick>();
if (tickSpacing == 0)
return ret;
2017-05-26 07:28:39 +00:00
for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing)
{
ret.Add(new HoldNoteTick
{
StartTime = t,
Column = Column
});
}
2017-05-03 03:53:45 +00:00
return ret;
2017-05-03 03:53:45 +00:00
}
2017-05-24 12:57:38 +00:00
/// <summary>
/// The tail of the hold note.
/// </summary>
private class TailNote : Note
{
/// <summary>
/// Lenience of release hit windows. This is to make cases where the hold note release
/// is timed alongside presses of other hit objects less awkward.
/// </summary>
private const double release_window_lenience = 1.5;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaults(controlPointInfo, difficulty);
HitWindows *= release_window_lenience;
}
}
2016-09-02 09:44:02 +00:00
}
}