1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 02:22:55 +08:00

Do not expose track directly in EditorClock

Intends to stop people from mutating it directly, and going through
`EditorClock` members like `AudioAdjustments` instead.
This commit is contained in:
Bartłomiej Dach 2025-01-07 11:37:06 +01:00
parent 275e8ce7b7
commit 98bb723438
No known key found for this signature in database
4 changed files with 59 additions and 28 deletions

View File

@ -3,8 +3,8 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osuTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -26,7 +26,8 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; } = null!;
protected readonly IBindable<Track> Track = new Bindable<Track>();
[Resolved]
private EditorClock editorClock { get; set; } = null!;
private readonly Container<T> content;
@ -35,22 +36,17 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
public TimelinePart(Container<T>? content = null)
{
AddInternal(this.content = content ?? new Container<T> { RelativeSizeAxes = Axes.Both });
beatmap.ValueChanged += _ =>
{
updateRelativeChildSize();
};
Track.ValueChanged += _ => updateRelativeChildSize();
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, EditorClock clock)
private void load(IBindable<WorkingBeatmap> beatmap)
{
this.beatmap.BindTo(beatmap);
LoadBeatmap(EditorBeatmap);
Track.BindTo(clock.Track);
this.beatmap.ValueChanged += _ => updateRelativeChildSize();
editorClock.TrackChanged += updateRelativeChildSize;
updateRelativeChildSize();
}
private void updateRelativeChildSize()
@ -68,5 +64,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
content.Clear();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (editorClock.IsNotNull())
editorClock.TrackChanged -= updateRelativeChildSize;
}
}
}

View File

@ -3,9 +3,9 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers;
@ -49,6 +49,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
[Resolved]
private EditorBeatmap editorBeatmap { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
/// <summary>
/// The timeline's scroll position in the last frame.
/// </summary>
@ -86,8 +89,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private double trackLengthForZoom;
private readonly IBindable<Track> track = new Bindable<Track>();
public Timeline(Drawable userContent)
{
this.userContent = userContent;
@ -101,7 +102,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OverlayColourProvider colourProvider, OsuConfigManager config)
private void load(OsuColour colours, OverlayColourProvider colourProvider, OsuConfigManager config)
{
CentreMarker centreMarker;
@ -150,16 +151,18 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
controlPointsVisible = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTimingChanges);
ticksVisible = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTicks);
track.BindTo(editorClock.Track);
track.BindValueChanged(_ =>
{
waveform.Waveform = beatmap.Value.Waveform;
Scheduler.AddOnce(applyVisualOffset, beatmap);
}, true);
editorClock.TrackChanged += updateWaveform;
updateWaveform();
Zoom = (float)(defaultTimelineZoom * editorBeatmap.TimelineZoom);
}
private void updateWaveform()
{
waveform.Waveform = beatmap.Value.Waveform;
Scheduler.AddOnce(applyVisualOffset, beatmap);
}
private void applyVisualOffset(IBindable<WorkingBeatmap> beatmap)
{
waveform.RelativePositionAxes = Axes.X;
@ -334,5 +337,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
double time = TimeAtPosition(Content.ToLocalSpace(screenSpacePosition).X);
return new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(time));
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (editorClock.IsNotNull())
editorClock.TrackChanged -= updateWaveform;
}
}
}

View File

@ -6,6 +6,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
@ -24,7 +25,8 @@ namespace osu.Game.Screens.Edit
/// </summary>
public partial class EditorClock : CompositeComponent, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock
{
public IBindable<Track> Track => track;
[CanBeNull]
public event Action TrackChanged;
private readonly Bindable<Track> track = new Bindable<Track>();
@ -59,6 +61,8 @@ namespace osu.Game.Screens.Edit
underlyingClock = new FramedBeatmapClock(applyOffsets: true, requireDecoupling: true);
AddInternal(underlyingClock);
track.BindValueChanged(_ => TrackChanged?.Invoke());
}
/// <summary>

View File

@ -4,8 +4,8 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers;
@ -305,7 +305,8 @@ namespace osu.Game.Screens.Edit.Timing
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
private readonly IBindable<Track> track = new Bindable<Track>();
[Resolved]
private EditorClock editorClock { get; set; } = null!;
public WaveformRow(bool isMainRow)
{
@ -313,7 +314,7 @@ namespace osu.Game.Screens.Edit.Timing
}
[BackgroundDependencyLoader]
private void load(EditorClock clock)
private void load()
{
InternalChildren = new Drawable[]
{
@ -343,13 +344,16 @@ namespace osu.Game.Screens.Edit.Timing
Colour = colourProvider.Content2
}
};
track.BindTo(clock.Track);
}
protected override void LoadComplete()
{
track.ValueChanged += _ => waveformGraph.Waveform = beatmap.Value.Waveform;
editorClock.TrackChanged += updateWaveform;
}
private void updateWaveform()
{
waveformGraph.Waveform = beatmap.Value.Waveform;
}
public int BeatIndex { set => beatIndexText.Text = value.ToString(); }
@ -363,6 +367,14 @@ namespace osu.Game.Screens.Edit.Timing
get => waveformGraph.X;
set => waveformGraph.X = value;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (editorClock.IsNotNull())
editorClock.TrackChanged -= updateWaveform;
}
}
}
}