1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:18:22 +08:00

Cleanup handling of hitobject updates

This commit is contained in:
smoogipoo 2020-04-09 19:54:58 +09:00
parent 4bfc738f5b
commit ee6ea08cf8
5 changed files with 22 additions and 40 deletions

View File

@ -15,6 +15,7 @@ using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Compose;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
@ -34,6 +35,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private IPlacementHandler placementHandler { get; set; } private IPlacementHandler placementHandler { get; set; }
[Resolved(CanBeNull = true)]
private EditorBeatmap editorBeatmap { get; set; }
public SliderSelectionBlueprint(DrawableSlider slider) public SliderSelectionBlueprint(DrawableSlider slider)
: base(slider) : base(slider)
{ {
@ -162,7 +166,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void updatePath() private void updatePath()
{ {
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance; HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;
UpdateHitObject(); editorBeatmap?.UpdateHitObject(HitObject);
} }
public override MenuItem[] ContextMenuItems => new MenuItem[] public override MenuItem[] ContextMenuItems => new MenuItem[]

View File

@ -58,7 +58,7 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
hitCircle.StartTime = 1000; hitCircle.StartTime = 1000;
Assert.That(changedObject, Is.EqualTo(hitCircle)); Assert.That(changedObject, Is.EqualTo(hitCircle));
@ -74,7 +74,7 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap()); var editorBeatmap = new EditorBeatmap(new OsuBeatmap());
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
var hitCircle = new HitCircle(); var hitCircle = new HitCircle();
@ -95,7 +95,7 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
editorBeatmap.Remove(hitCircle); editorBeatmap.Remove(hitCircle);
Assert.That(changedObject, Is.Null); Assert.That(changedObject, Is.Null);

View File

@ -69,10 +69,6 @@ namespace osu.Game.Rulesets.Edit
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IFrameBasedClock framedClock) private void load(IFrameBasedClock framedClock)
{ {
EditorBeatmap.HitObjectAdded += addHitObject;
EditorBeatmap.HitObjectRemoved += removeHitObject;
EditorBeatmap.StartTimeChanged += UpdateHitObject;
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset); Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
try try
@ -236,10 +232,6 @@ namespace osu.Game.Rulesets.Edit
lastGridUpdateTime = EditorClock.CurrentTime; lastGridUpdateTime = EditorClock.CurrentTime;
} }
private void addHitObject(HitObject hitObject) => UpdateHitObject(hitObject);
private void removeHitObject(HitObject hitObject) => UpdateHitObject(null);
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects; public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position); public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
@ -302,19 +294,6 @@ namespace osu.Game.Rulesets.Edit
return DurationToDistance(referenceTime, snappedEndTime - referenceTime); return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
} }
public override void UpdateHitObject(HitObject hitObject) => EditorBeatmap.UpdateHitObject(hitObject);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (EditorBeatmap != null)
{
EditorBeatmap.HitObjectAdded -= addHitObject;
EditorBeatmap.HitObjectRemoved -= removeHitObject;
}
}
} }
[Cached(typeof(HitObjectComposer))] [Cached(typeof(HitObjectComposer))]
@ -344,12 +323,6 @@ namespace osu.Game.Rulesets.Edit
[CanBeNull] [CanBeNull]
protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null; protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null;
/// <summary>
/// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
public abstract void UpdateHitObject([CanBeNull] HitObject hitObject);
public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time); public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time);
public abstract float GetBeatSnapDistanceAt(double referenceTime); public abstract float GetBeatSnapDistanceAt(double referenceTime);

View File

@ -108,11 +108,6 @@ namespace osu.Game.Rulesets.Edit
public bool IsSelected => State == SelectionState.Selected; public bool IsSelected => State == SelectionState.Selected;
/// <summary>
/// Updates the <see cref="Objects.HitObject"/>, invoking <see cref="Objects.HitObject.ApplyDefaults"/> and re-processing the beatmap.
/// </summary>
protected void UpdateHitObject() => composer?.UpdateHitObject(HitObject);
/// <summary> /// <summary>
/// The <see cref="MenuItem"/>s to be displayed in the context menu for this <see cref="OverlaySelectionBlueprint"/>. /// The <see cref="MenuItem"/>s to be displayed in the context menu for this <see cref="OverlaySelectionBlueprint"/>.
/// </summary> /// </summary>

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -29,9 +30,9 @@ namespace osu.Game.Screens.Edit
public event Action<HitObject> HitObjectRemoved; public event Action<HitObject> HitObjectRemoved;
/// <summary> /// <summary>
/// Invoked when the start time of a <see cref="HitObject"/> in this <see cref="EditorBeatmap"/> was changed. /// Invoked when a <see cref="HitObject"/> is updated.
/// </summary> /// </summary>
public event Action<HitObject> StartTimeChanged; public event Action<HitObject> HitObjectUpdated;
/// <summary> /// <summary>
/// All currently selected <see cref="HitObject"/>s. /// All currently selected <see cref="HitObject"/>s.
@ -68,7 +69,9 @@ namespace osu.Game.Screens.Edit
/// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap. /// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to update.</param> /// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
public void UpdateHitObject(HitObject hitObject) public void UpdateHitObject([NotNull] HitObject hitObject) => updateHitObject(hitObject, false);
private void updateHitObject([CanBeNull] HitObject hitObject, bool silent)
{ {
scheduledUpdate?.Cancel(); scheduledUpdate?.Cancel();
scheduledUpdate = Scheduler.AddDelayed(() => scheduledUpdate = Scheduler.AddDelayed(() =>
@ -76,6 +79,9 @@ namespace osu.Game.Screens.Edit
beatmapProcessor?.PreProcess(); beatmapProcessor?.PreProcess();
hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty); hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
beatmapProcessor?.PostProcess(); beatmapProcessor?.PostProcess();
if (!silent)
HitObjectUpdated?.Invoke(hitObject);
}, 0); }, 0);
} }
@ -114,6 +120,8 @@ namespace osu.Game.Screens.Edit
mutableHitObjects.Insert(insertionIndex + 1, hitObject); mutableHitObjects.Insert(insertionIndex + 1, hitObject);
HitObjectAdded?.Invoke(hitObject); HitObjectAdded?.Invoke(hitObject);
updateHitObject(hitObject, true);
} }
/// <summary> /// <summary>
@ -132,6 +140,8 @@ namespace osu.Game.Screens.Edit
startTimeBindables.Remove(hitObject); startTimeBindables.Remove(hitObject);
HitObjectRemoved?.Invoke(hitObject); HitObjectRemoved?.Invoke(hitObject);
updateHitObject(null, true);
} }
private void trackStartTime(HitObject hitObject) private void trackStartTime(HitObject hitObject)
@ -145,7 +155,7 @@ namespace osu.Game.Screens.Edit
var insertionIndex = findInsertionIndex(PlayableBeatmap.HitObjects, hitObject.StartTime); var insertionIndex = findInsertionIndex(PlayableBeatmap.HitObjects, hitObject.StartTime);
mutableHitObjects.Insert(insertionIndex + 1, hitObject); mutableHitObjects.Insert(insertionIndex + 1, hitObject);
StartTimeChanged?.Invoke(hitObject); UpdateHitObject(hitObject);
}; };
} }