Ensure locally executed methods are always loaded before propagation

This commit is contained in:
Dean Herbert 2020-08-21 18:43:58 +09:00
parent 1edafc39ba
commit 308d9f5967
1 changed files with 16 additions and 11 deletions

View File

@ -231,9 +231,7 @@ private PreviousTrackResult prev()
if (playable != null) if (playable != null)
{ {
if (beatmap is Bindable<WorkingBeatmap> working) changeBeatmap(beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value));
working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
restartTrack(); restartTrack();
return PreviousTrackResult.Previous; return PreviousTrackResult.Previous;
} }
@ -257,9 +255,7 @@ private bool next()
if (playable != null) if (playable != null)
{ {
if (beatmap is Bindable<WorkingBeatmap> working) changeBeatmap(beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value));
working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
restartTrack(); restartTrack();
return true; return true;
} }
@ -278,11 +274,15 @@ private void restartTrack()
private TrackChangeDirection? queuedDirection; private TrackChangeDirection? queuedDirection;
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap) private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap) => changeBeatmap(beatmap.NewValue);
private void changeBeatmap(WorkingBeatmap newWorking)
{ {
var lastWorking = current;
TrackChangeDirection direction = TrackChangeDirection.None; TrackChangeDirection direction = TrackChangeDirection.None;
bool audioEquals = beatmap.NewValue?.BeatmapInfo?.AudioEquals(current?.BeatmapInfo) ?? false; bool audioEquals = newWorking?.BeatmapInfo?.AudioEquals(current?.BeatmapInfo) ?? false;
if (current != null) if (current != null)
{ {
@ -297,13 +297,13 @@ private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)
{ {
// figure out the best direction based on order in playlist. // figure out the best direction based on order in playlist.
var last = BeatmapSets.TakeWhile(b => b.ID != current.BeatmapSetInfo?.ID).Count(); var last = BeatmapSets.TakeWhile(b => b.ID != current.BeatmapSetInfo?.ID).Count();
var next = beatmap.NewValue == null ? -1 : BeatmapSets.TakeWhile(b => b.ID != beatmap.NewValue.BeatmapSetInfo?.ID).Count(); var next = newWorking == null ? -1 : BeatmapSets.TakeWhile(b => b.ID != newWorking.BeatmapSetInfo?.ID).Count();
direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next; direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next;
} }
} }
current = beatmap.NewValue; current = newWorking;
if (!audioEquals || CurrentTrack.IsDummyDevice) if (!audioEquals || CurrentTrack.IsDummyDevice)
{ {
@ -312,7 +312,7 @@ private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)
else else
{ {
// transfer still valid track to new working beatmap // transfer still valid track to new working beatmap
current.TransferTrack(beatmap.OldValue.Track); current.TransferTrack(lastWorking.Track);
} }
TrackChanged?.Invoke(current, direction); TrackChanged?.Invoke(current, direction);
@ -320,6 +320,11 @@ private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)
ResetTrackAdjustments(); ResetTrackAdjustments();
queuedDirection = null; queuedDirection = null;
// this will be a noop if coming from the beatmapChanged event.
// the exception is local operations like next/prev, where we want to complete loading the track before sending out a change.
if (beatmap.Value != current && beatmap is Bindable<WorkingBeatmap> working)
working.Value = current;
} }
private void changeTrack() private void changeTrack()