1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 18:23:00 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Objects/HoldNote.cs

110 lines
3.4 KiB
C#
Raw Normal View History

2017-05-29 14:35:50 +08: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 17:44:02 +08:00
using System.Collections.Generic;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2017-05-03 11:53:45 +08:00
using osu.Game.Rulesets.Objects.Types;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Mania.Objects
2016-09-02 17:44:02 +08:00
{
2017-05-09 19:55:20 +08:00
/// <summary>
/// Represents a hit object which requires pressing, holding, and releasing a key.
/// </summary>
public class HoldNote : ManiaHitObject, IHasEndTime
2016-09-02 17:44:02 +08:00
{
2017-05-03 11:53:45 +08: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-05-24 20:57:38 +08:00
/// <summary>
/// The head note of the hold.
/// </summary>
2017-05-26 15:28:39 +08:00
public readonly Note Head = new Note();
2017-05-24 20:57:38 +08:00
/// <summary>
/// The tail note of the hold.
/// </summary>
2017-05-26 15:28:39 +08:00
public readonly Note Tail = new TailNote();
2017-05-18 17:19:29 +08:00
2017-05-09 19:55:20 +08:00
/// <summary>
2017-05-24 20:57:38 +08:00
/// The time between ticks of this hold.
2017-05-09 19:55:20 +08:00
/// </summary>
private double tickSpacing = 50;
2017-05-24 20:24:33 +08: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 20:24:33 +08:00
}
2017-05-24 20:57:38 +08: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 11:53:45 +08:00
private List<HoldNoteTick> createTicks()
2017-05-03 11:53:45 +08:00
{
var ret = new List<HoldNoteTick>();
if (tickSpacing == 0)
return ret;
2017-05-26 15:28:39 +08:00
for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing)
{
ret.Add(new HoldNoteTick
{
StartTime = t
});
}
2017-05-03 11:53:45 +08:00
return ret;
2017-05-03 11:53:45 +08:00
}
2017-05-24 20:57:38 +08: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 17:44:02 +08:00
}
}