1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 11:12:54 +08:00

Add start time tracking to EditorBeatmap

This commit is contained in:
smoogipoo 2019-10-03 14:23:48 +09:00
parent cbdf42cd7b
commit 897b3233af
2 changed files with 49 additions and 2 deletions

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
@ -27,10 +28,16 @@ namespace osu.Game.Rulesets.Objects
/// </summary>
private const double control_point_leniency = 1;
public readonly Bindable<double> StartTimeBindable = new Bindable<double>();
/// <summary>
/// The time at which the HitObject starts.
/// </summary>
public virtual double StartTime { get; set; }
public virtual double StartTime
{
get => StartTimeBindable.Value;
set => StartTimeBindable.Value = value;
}
private List<HitSampleInfo> samples;
@ -67,6 +74,17 @@ namespace osu.Game.Rulesets.Objects
[JsonIgnore]
public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects;
public HitObject()
{
StartTimeBindable.ValueChanged += time =>
{
double offset = time.NewValue - time.OldValue;
foreach (var nested in NestedHitObjects)
nested.StartTime += offset;
};
}
/// <summary>
/// Applies default values to this HitObject.
/// </summary>

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
@ -15,12 +16,17 @@ namespace osu.Game.Screens.Edit
{
public event Action<HitObject> HitObjectAdded;
public event Action<HitObject> HitObjectRemoved;
public event Action<HitObject> HitObjectChanged;
private readonly Dictionary<T, Bindable<double>> startTimeBindables = new Dictionary<T, Bindable<double>>();
private readonly Beatmap<T> beatmap;
public EditorBeatmap(Beatmap<T> beatmap)
{
this.beatmap = beatmap;
foreach (var obj in HitObjects)
trackStartTime(obj);
}
public BeatmapInfo BeatmapInfo
@ -37,7 +43,7 @@ namespace osu.Game.Screens.Edit
public double TotalBreakTime => beatmap.TotalBreakTime;
IReadOnlyList<T> IBeatmap<T>.HitObjects => beatmap.HitObjects;
public IReadOnlyList<T> HitObjects => beatmap.HitObjects;
IReadOnlyList<HitObject> IBeatmap.HitObjects => beatmap.HitObjects;
@ -51,6 +57,8 @@ namespace osu.Game.Screens.Edit
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
public void Add(T hitObject)
{
trackStartTime(hitObject);
// Preserve existing sorting order in the beatmap
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
beatmap.HitObjects.Insert(insertionIndex + 1, hitObject);
@ -65,7 +73,28 @@ namespace osu.Game.Screens.Edit
public void Remove(T hitObject)
{
if (beatmap.HitObjects.Remove(hitObject))
{
var bindable = startTimeBindables[hitObject];
bindable.UnbindAll();
startTimeBindables.Remove(hitObject);
HitObjectRemoved?.Invoke(hitObject);
}
}
private void trackStartTime(T hitObject)
{
startTimeBindables[hitObject] = hitObject.StartTimeBindable.GetBoundCopy();
startTimeBindables[hitObject].ValueChanged += _ =>
{
// For now we'll remove and re-add the hitobject. This is not optimal and can be improved if required.
beatmap.HitObjects.Remove(hitObject);
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
beatmap.HitObjects.Insert(insertionIndex + 1, hitObject);
HitObjectChanged?.Invoke(hitObject);
};
}
/// <summary>