mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 05:53:10 +08:00
Allow song select to refresh the global WorkingBeatmap
after an external update
This commit is contained in:
parent
6999933d33
commit
66a01d1ed2
@ -453,6 +453,12 @@ namespace osu.Game.Beatmaps
|
||||
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
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public interface IWorkingBeatmapCache
|
||||
@ -25,5 +27,7 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
/// <param name="beatmapInfo">The beatmap info to invalidate any cached entries for.</param>
|
||||
void Invalidate(BeatmapInfo beatmapInfo);
|
||||
|
||||
event Action<WorkingBeatmap> OnInvalidated;
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,13 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
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)
|
||||
|
@ -296,8 +296,24 @@ namespace osu.Game.Screens.Select
|
||||
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 @@ namespace osu.Game.Screens.Select
|
||||
music.TrackChanged -= ensureTrackLooping;
|
||||
|
||||
modSelectOverlayRegistration?.Dispose();
|
||||
|
||||
beatmaps.OnInvalidated -= workingBeatmapInvalidated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user