1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 14:07:25 +08:00

Fix beatmap carousel not maintaining selection if currently selected beatmap is updated

This commit is contained in:
Dean Herbert 2022-07-27 13:30:38 +09:00
parent c30e8047ab
commit 8105d4854a

View File

@ -265,6 +265,38 @@ namespace osu.Game.Screens.Select
foreach (int i in changes.InsertedIndices)
UpdateBeatmapSet(sender[i].Detach());
if (changes.DeletedIndices.Length > 0)
{
// To handle the beatmap update flow, attempt to track selection changes across delete-insert transactions.
// When an update occurs, the previous beatmap set is either soft or hard deleted.
// Check if the current selection was potentially deleted by re-querying its validity.
bool selectedSetMarkedDeleted = realm.Run(r => r.Find<BeatmapSetInfo>(SelectedBeatmapSet.ID))?.DeletePending != false;
if (selectedSetMarkedDeleted)
{
// If it is no longer valid, make the bold assumption that an updated version will be available in the modified indices.
// This relies on the full update operation being in a single transaction, so please don't change that.
foreach (int i in changes.NewModifiedIndices)
{
var beatmapSetInfo = sender[i];
foreach (var beatmapInfo in beatmapSetInfo.Beatmaps)
{
// Best effort matching. We can't use ID because in the update flow a new version will get its own GUID.
bool selectionMatches =
((IBeatmapMetadataInfo)beatmapInfo.Metadata).Equals(SelectedBeatmapInfo.Metadata)
&& beatmapInfo.DifficultyName == SelectedBeatmapInfo.DifficultyName;
if (selectionMatches)
{
SelectBeatmap(beatmapInfo);
break;
}
}
}
}
}
}
private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error)