Allow song select to refresh the global `WorkingBeatmap` after an external update

This commit is contained in:
Dean Herbert 2022-06-20 19:48:46 +09:00
parent 6999933d33
commit 66a01d1ed2
4 changed files with 31 additions and 0 deletions

View File

@ -453,6 +453,12 @@ public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? beatmapInfo)
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);
void IWorkingBeatmapCache.Invalidate(BeatmapInfo beatmapInfo) => workingBeatmapCache.Invalidate(beatmapInfo);
public event Action<WorkingBeatmap>? OnInvalidated
{
add => workingBeatmapCache.OnInvalidated += value;
remove => workingBeatmapCache.OnInvalidated -= value;
}
public override bool IsAvailableLocally(BeatmapSetInfo model) => Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID));
#endregion

View File

@ -3,6 +3,8 @@
#nullable disable
using System;
namespace osu.Game.Beatmaps
{
public interface IWorkingBeatmapCache
@ -25,5 +27,7 @@ public interface IWorkingBeatmapCache
/// </summary>
/// <param name="beatmapInfo">The beatmap info to invalidate any cached entries for.</param>
void Invalidate(BeatmapInfo beatmapInfo);
event Action<WorkingBeatmap> OnInvalidated;
}
}

View File

@ -76,10 +76,13 @@ public void Invalidate(BeatmapInfo info)
{
Logger.Log($"Invalidating working beatmap cache for {info}");
workingCache.Remove(working);
OnInvalidated?.Invoke(working);
}
}
}
public event Action<WorkingBeatmap> OnInvalidated;
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
{
if (beatmapInfo?.BeatmapSet == null)

View File

@ -296,8 +296,24 @@ protected override void LoadComplete()
base.LoadComplete();
modSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(ModSelect);
beatmaps.OnInvalidated += workingBeatmapInvalidated;
}
private void workingBeatmapInvalidated(WorkingBeatmap working) => Scheduler.AddOnce(w =>
{
// The global beatmap may have already been updated (ie. by the editor).
// Only perform the actual switch if we still need to.
if (w == Beatmap.Value)
{
// Not sure if this refresh is required.
var beatmapInfo = beatmaps.QueryBeatmap(b => b.ID == w.BeatmapInfo.ID);
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
}
updateComponentFromBeatmap(Beatmap.Value);
}, working);
/// <summary>
/// Creates the buttons to be displayed in the footer.
/// </summary>
@ -700,6 +716,8 @@ protected override void Dispose(bool isDisposing)
music.TrackChanged -= ensureTrackLooping;
modSelectOverlayRegistration?.Dispose();
beatmaps.OnInvalidated -= workingBeatmapInvalidated;
}
/// <summary>