1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 22:07:27 +08:00
osu-lazer/osu.Game/Rulesets/Objects/HitObject.cs

103 lines
3.6 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
2017-12-07 13:42:36 +08:00
using Newtonsoft.Json;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Audio;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Types;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Objects
{
/// <summary>
/// A HitObject describes an object in a Beatmap.
/// <para>
/// HitObjects may contain more properties for which you should be checking through the IHas* types.
/// </para>
/// </summary>
public class HitObject
{
/// <summary>
/// The time at which the HitObject starts.
/// </summary>
public virtual double StartTime { get; set; }
2017-12-25 15:41:18 +08:00
private List<SampleInfo> samples;
/// <summary>
/// The samples to be played when this hit object is hit.
/// <para>
2017-04-21 19:42:13 +08:00
/// In the case of <see cref="IHasRepeats"/> types, this is the sample of the curve body
/// and can be treated as the default samples for the hit object.
/// </para>
/// </summary>
2017-12-25 15:41:18 +08:00
public List<SampleInfo> Samples
{
get => samples ?? (samples = new List<SampleInfo>());
set => samples = value;
}
2017-03-16 15:55:08 +08:00
[JsonIgnore]
public SampleControlPoint SampleControlPoint;
2017-09-12 09:01:07 +08:00
/// <summary>
/// Whether this <see cref="HitObject"/> is in Kiai time.
/// </summary>
2017-12-07 13:42:36 +08:00
[JsonIgnore]
2017-09-12 09:01:07 +08:00
public bool Kiai { get; private set; }
2018-02-02 17:47:10 +08:00
private float overallDifficulty = BeatmapDifficulty.DEFAULT_DIFFICULTY;
private HitWindows hitWindows;
/// <summary>
2018-02-08 16:38:46 +08:00
/// The hit windows for this <see cref="HitObject"/>.
2018-02-02 17:47:10 +08:00
/// </summary>
public HitWindows HitWindows
{
get => hitWindows ?? (hitWindows = new HitWindows(overallDifficulty));
protected set => hitWindows = value;
}
2018-02-02 17:47:10 +08:00
private readonly SortedList<HitObject> nestedHitObjects = new SortedList<HitObject>((h1, h2) => h1.StartTime.CompareTo(h2.StartTime));
[JsonIgnore]
public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects;
2017-03-16 15:55:08 +08:00
/// <summary>
/// Applies default values to this HitObject.
/// </summary>
/// <param name="controlPointInfo">The control points.</param>
/// <param name="difficulty">The difficulty settings to use.</param>
public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
ApplyDefaultsToSelf(controlPointInfo, difficulty);
nestedHitObjects.Clear();
CreateNestedHitObjects();
nestedHitObjects.ForEach(h => h.ApplyDefaults(controlPointInfo, difficulty));
}
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
SampleControlPoint samplePoint = controlPointInfo.SamplePointAt(StartTime);
2017-09-12 09:01:07 +08:00
EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime);
2017-12-07 13:42:36 +08:00
Kiai = effectPoint.KiaiMode;
SampleControlPoint = samplePoint;
2018-02-02 17:47:10 +08:00
overallDifficulty = difficulty.OverallDifficulty;
hitWindows = null;
}
protected virtual void CreateNestedHitObjects()
{
}
protected void AddNested(HitObject hitObject) => nestedHitObjects.Add(hitObject);
}
}