mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 14:12:55 +08:00
Re-query beatmap info on database changes
This commit is contained in:
parent
ca5f2bcd4c
commit
445a4bd01c
@ -9,6 +9,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Humanizer;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
|
@ -2,8 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -41,38 +39,20 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
||||
}
|
||||
|
||||
private void updateSelectedItem(PlaylistItem item)
|
||||
{
|
||||
hasBeatmap = findBeatmap(expr => beatmaps.QueryBeatmap(expr));
|
||||
}
|
||||
private void updateSelectedItem(PlaylistItem _) => updateBeatmapState();
|
||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => updateBeatmapState();
|
||||
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => updateBeatmapState();
|
||||
|
||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
|
||||
{
|
||||
if (weakSet.NewValue.TryGetTarget(out var set))
|
||||
{
|
||||
if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
|
||||
Schedule(() => hasBeatmap = true);
|
||||
}
|
||||
}
|
||||
|
||||
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
|
||||
{
|
||||
if (weakSet.NewValue.TryGetTarget(out var set))
|
||||
{
|
||||
if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
|
||||
Schedule(() => hasBeatmap = false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool findBeatmap(Func<Expression<Func<BeatmapInfo, bool>>, BeatmapInfo> expression)
|
||||
private void updateBeatmapState()
|
||||
{
|
||||
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
||||
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
|
||||
|
||||
if (beatmapId == null || checksum == null)
|
||||
return false;
|
||||
return;
|
||||
|
||||
return expression(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum) != null;
|
||||
var databasedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
||||
hasBeatmap = databasedBeatmap != null && !databasedBeatmap.BeatmapSet.DeletePending;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
Loading…
Reference in New Issue
Block a user