mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 13:33:03 +08:00
Fix beatmap carousel not maintaining selection if currently selected beatmap is updated
This commit is contained in:
parent
c30e8047ab
commit
8105d4854a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user