1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 05:32:54 +08:00

Add xmldoc and simplify calling

This commit is contained in:
Dean Herbert 2022-10-11 15:50:02 +09:00
parent e619c9c1e6
commit eba3d37a11
3 changed files with 13 additions and 10 deletions

View File

@ -141,12 +141,9 @@ namespace osu.Game.Beatmaps
// Handle collections using permissive difficulty name to track difficulties.
foreach (var originalBeatmap in original.Beatmaps)
{
var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName);
if (updatedBeatmap == null)
continue;
updatedBeatmap.TransferCollectionsFrom(realm, originalBeatmap.MD5Hash);
updated.Beatmaps
.FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName)?
.TransferCollectionReferences(realm, originalBeatmap.MD5Hash);
}
}

View File

@ -214,13 +214,19 @@ namespace osu.Game.Beatmaps
return fileHashX == fileHashY;
}
public void TransferCollectionsFrom(Realm realm, string oldMd5Hash)
/// <summary>
/// When updating a beatmap, its hashes will change. Collections currently track beatmaps by hash, so they need to be updated.
/// This method will handle updating
/// </summary>
/// <param name="realm">A realm instance in an active write transaction.</param>
/// <param name="previousMD5Hash">The previous MD5 hash of the beatmap before update.</param>
public void TransferCollectionReferences(Realm realm, string previousMD5Hash)
{
var collections = realm.All<BeatmapCollection>().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(oldMd5Hash));
var collections = realm.All<BeatmapCollection>().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(previousMD5Hash));
foreach (var c in collections)
{
c.BeatmapMD5Hashes.Remove(oldMd5Hash);
c.BeatmapMD5Hashes.Remove(previousMD5Hash);
c.BeatmapMD5Hashes.Add(MD5Hash);
}
}

View File

@ -330,7 +330,7 @@ namespace osu.Game.Beatmaps
setInfo.CopyChangesToRealm(liveBeatmapSet);
beatmapInfo.TransferCollectionsFrom(r, oldMd5Hash);
beatmapInfo.TransferCollectionReferences(r, oldMd5Hash);
ProcessBeatmap?.Invoke((liveBeatmapSet, false));
});