mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Add collection transfer logic to beatmap import-as-update flow
This commit is contained in:
@ -14,6 +14,7 @@ using osu.Framework.Logging;
|
|||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
using osu.Game.Collections;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
@ -71,6 +72,8 @@ namespace osu.Game.Beatmaps
|
|||||||
// Transfer local values which should be persisted across a beatmap update.
|
// Transfer local values which should be persisted across a beatmap update.
|
||||||
updated.DateAdded = original.DateAdded;
|
updated.DateAdded = original.DateAdded;
|
||||||
|
|
||||||
|
transferCollectionReferences(realm, original, updated);
|
||||||
|
|
||||||
foreach (var beatmap in original.Beatmaps.ToArray())
|
foreach (var beatmap in original.Beatmaps.ToArray())
|
||||||
{
|
{
|
||||||
var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash);
|
var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash);
|
||||||
@ -112,6 +115,40 @@ namespace osu.Game.Beatmaps
|
|||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void transferCollectionReferences(Realm realm, BeatmapSetInfo original, BeatmapSetInfo updated)
|
||||||
|
{
|
||||||
|
// First check if every beatmap in the original set is in any collections.
|
||||||
|
// In this case, we will assume they also want any newly added difficulties added to the collection.
|
||||||
|
foreach (var c in realm.All<BeatmapCollection>())
|
||||||
|
{
|
||||||
|
if (original.Beatmaps.Select(b => b.MD5Hash).All(c.BeatmapMD5Hashes.Contains))
|
||||||
|
{
|
||||||
|
foreach (var b in original.Beatmaps)
|
||||||
|
c.BeatmapMD5Hashes.Remove(b.MD5Hash);
|
||||||
|
|
||||||
|
foreach (var b in updated.Beatmaps)
|
||||||
|
c.BeatmapMD5Hashes.Add(b.MD5Hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
var collections = realm.All<BeatmapCollection>().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(originalBeatmap.MD5Hash));
|
||||||
|
|
||||||
|
foreach (var c in collections)
|
||||||
|
{
|
||||||
|
c.BeatmapMD5Hashes.Remove(originalBeatmap.MD5Hash);
|
||||||
|
c.BeatmapMD5Hashes.Add(updatedBeatmap.MD5Hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz";
|
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz";
|
||||||
|
|
||||||
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
||||||
|
Reference in New Issue
Block a user