From 081d87fe6df7688e9831691831e4cc55fc6d7da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 9 Oct 2024 11:47:31 +0200 Subject: [PATCH 1/2] Revert 'Fix any and all migration attempts dying on MusicController' This reverts commit 310eec69fcb30fd89d00b46d6ecb9e99c94f4314. Way to try and "fix" stuff and screw stuff up even harder instead, me. Great job, well done. --- osu.Game/OsuGame.cs | 1 + osu.Game/OsuGameBase.cs | 4 ---- osu.Game/Overlays/MusicController.cs | 24 +++++++++++------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index a7f3cc8df150..dce24c6ee7e2 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -1137,6 +1137,7 @@ protected override void LoadComplete() loadComponentSingleFile(new MedalOverlay(), topMostOverlayContent.Add); loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add); + loadComponentSingleFile(new DetachedBeatmapStore(), Add, true); Add(difficultyRecommender); Add(externalLinkOpener = new ExternalLinkOpener()); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 96e5484d9303..d4704d1c72d4 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -377,10 +377,6 @@ private void load(ReadableKeyCombinationProvider keyCombinationProvider, Framewo dependencies.Cache(previewTrackManager = new PreviewTrackManager(BeatmapManager.BeatmapTrackStore)); base.Content.Add(previewTrackManager); - var detachedBeatmapStore = new DetachedBeatmapStore(); - base.Content.Add(detachedBeatmapStore); - dependencies.CacheAs(detachedBeatmapStore); - base.Content.Add(MusicController = new MusicController()); dependencies.CacheAs(MusicController); diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 261477414036..600c014a95af 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Threading; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Track; @@ -63,7 +62,8 @@ public partial class MusicController : CompositeDrawable public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000)); - private IBindableList detachedBeatmaps = null!; + [Resolved] + private RealmAccess realm { get; set; } = null!; private BindableNumber sampleVolume = null!; @@ -76,15 +76,13 @@ public partial class MusicController : CompositeDrawable private int randomHistoryDirection; [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager configManager, DetachedBeatmapStore detachedBeatmapStore, CancellationToken? cancellationToken) + private void load(AudioManager audio, OsuConfigManager configManager) { AddInternal(audioDuckFilter = new AudioFilter(audio.TrackMixer)); audio.Tracks.AddAdjustment(AdjustableProperty.Volume, audioDuckVolume); sampleVolume = audio.VolumeSample.GetBoundCopy(); configManager.BindWith(OsuSetting.RandomSelectAlgorithm, randomSelectAlgorithm); - - detachedBeatmaps = detachedBeatmapStore.GetDetachedBeatmaps(cancellationToken); } protected override void LoadComplete() @@ -257,8 +255,8 @@ private PreviousTrackResult prev(bool allowProtectedTracks) playableSet = getNextRandom(-1, allowProtectedTracks); else { - playableSet = getBeatmapSets().TakeWhile(i => !i.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Protected || allowProtectedTracks) - ?? getBeatmapSets().LastOrDefault(s => !s.Protected || allowProtectedTracks); + playableSet = getBeatmapSets().AsEnumerable().TakeWhile(i => !i.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Protected || allowProtectedTracks) + ?? getBeatmapSets().AsEnumerable().LastOrDefault(s => !s.Protected || allowProtectedTracks); } if (playableSet != null) @@ -353,10 +351,10 @@ private bool next(bool allowProtectedTracks) playableSet = getNextRandom(1, allowProtectedTracks); else { - playableSet = getBeatmapSets().SkipWhile(i => !i.Equals(current?.BeatmapSetInfo)) + playableSet = getBeatmapSets().AsEnumerable().SkipWhile(i => !i.Equals(current?.BeatmapSetInfo)) .Where(i => !i.Protected || allowProtectedTracks) .ElementAtOrDefault(1) - ?? getBeatmapSets().FirstOrDefault(i => !i.Protected || allowProtectedTracks); + ?? getBeatmapSets().AsEnumerable().FirstOrDefault(i => !i.Protected || allowProtectedTracks); } var playableBeatmap = playableSet?.Beatmaps.FirstOrDefault(); @@ -375,7 +373,7 @@ private bool next(bool allowProtectedTracks) { BeatmapSetInfo result; - var possibleSets = getBeatmapSets().Where(s => !s.Protected || allowProtectedTracks).ToArray(); + var possibleSets = getBeatmapSets().AsEnumerable().Where(s => !s.Protected || allowProtectedTracks).ToArray(); if (possibleSets.Length == 0) return null; @@ -434,7 +432,7 @@ private void restartTrack() private TrackChangeDirection? queuedDirection; - private IEnumerable getBeatmapSets() => detachedBeatmaps.Where(s => !s.DeletePending); + private IQueryable getBeatmapSets() => realm.Realm.All().Where(s => !s.DeletePending); private void changeBeatmap(WorkingBeatmap newWorking) { @@ -461,8 +459,8 @@ private void changeBeatmap(WorkingBeatmap newWorking) else { // figure out the best direction based on order in playlist. - int last = getBeatmapSets().TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count(); - int next = getBeatmapSets().TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count(); + int last = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count(); + int next = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count(); direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next; } From baa64d148627a09e55f0384ccb8ae0853f95b4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 9 Oct 2024 11:52:58 +0200 Subject: [PATCH 2/2] Migrate `MusicController` to `Live` to fix broken migrations instead --- osu.Game/Overlays/MusicController.cs | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 600c014a95af..971503ca8b66 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -72,7 +72,7 @@ public partial class MusicController : CompositeDrawable private AudioFilter audioDuckFilter = null!; private readonly Bindable randomSelectAlgorithm = new Bindable(); - private readonly List previousRandomSets = new List(); + private readonly List> previousRandomSets = new List>(); private int randomHistoryDirection; [BackgroundDependencyLoader] @@ -249,19 +249,19 @@ private PreviousTrackResult prev(bool allowProtectedTracks) queuedDirection = TrackChangeDirection.Prev; - BeatmapSetInfo? playableSet; + Live? playableSet; if (Shuffle.Value) playableSet = getNextRandom(-1, allowProtectedTracks); else { - playableSet = getBeatmapSets().AsEnumerable().TakeWhile(i => !i.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Protected || allowProtectedTracks) - ?? getBeatmapSets().AsEnumerable().LastOrDefault(s => !s.Protected || allowProtectedTracks); + playableSet = getBeatmapSets().TakeWhile(i => !i.Value.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Value.Protected || allowProtectedTracks) + ?? getBeatmapSets().LastOrDefault(s => !s.Value.Protected || allowProtectedTracks); } if (playableSet != null) { - changeBeatmap(beatmaps.GetWorkingBeatmap(playableSet.Beatmaps.First())); + changeBeatmap(beatmaps.GetWorkingBeatmap(playableSet.Value.Beatmaps.First())); restartTrack(); return PreviousTrackResult.Previous; } @@ -345,19 +345,19 @@ private bool next(bool allowProtectedTracks) queuedDirection = TrackChangeDirection.Next; - BeatmapSetInfo? playableSet; + Live? playableSet; if (Shuffle.Value) playableSet = getNextRandom(1, allowProtectedTracks); else { - playableSet = getBeatmapSets().AsEnumerable().SkipWhile(i => !i.Equals(current?.BeatmapSetInfo)) - .Where(i => !i.Protected || allowProtectedTracks) + playableSet = getBeatmapSets().SkipWhile(i => !i.Value.Equals(current?.BeatmapSetInfo)) + .Where(i => !i.Value.Protected || allowProtectedTracks) .ElementAtOrDefault(1) - ?? getBeatmapSets().AsEnumerable().FirstOrDefault(i => !i.Protected || allowProtectedTracks); + ?? getBeatmapSets().FirstOrDefault(i => !i.Value.Protected || allowProtectedTracks); } - var playableBeatmap = playableSet?.Beatmaps.FirstOrDefault(); + var playableBeatmap = playableSet?.Value.Beatmaps.FirstOrDefault(); if (playableBeatmap != null) { @@ -369,11 +369,11 @@ private bool next(bool allowProtectedTracks) return false; } - private BeatmapSetInfo? getNextRandom(int direction, bool allowProtectedTracks) + private Live? getNextRandom(int direction, bool allowProtectedTracks) { - BeatmapSetInfo result; + Live result; - var possibleSets = getBeatmapSets().AsEnumerable().Where(s => !s.Protected || allowProtectedTracks).ToArray(); + var possibleSets = getBeatmapSets().Where(s => !s.Value.Protected || allowProtectedTracks).ToArray(); if (possibleSets.Length == 0) return null; @@ -432,7 +432,9 @@ private void restartTrack() private TrackChangeDirection? queuedDirection; - private IQueryable getBeatmapSets() => realm.Realm.All().Where(s => !s.DeletePending); + private IEnumerable> getBeatmapSets() => realm.Realm.All().Where(s => !s.DeletePending) + .AsEnumerable() + .Select(s => new RealmLive(s, realm)); private void changeBeatmap(WorkingBeatmap newWorking) { @@ -459,8 +461,8 @@ private void changeBeatmap(WorkingBeatmap newWorking) else { // figure out the best direction based on order in playlist. - int last = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count(); - int next = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count(); + int last = getBeatmapSets().TakeWhile(b => !b.Value.Equals(current.BeatmapSetInfo)).Count(); + int next = getBeatmapSets().TakeWhile(b => !b.Value.Equals(newWorking.BeatmapSetInfo)).Count(); direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next; }