From 1d536fd0bc6bed1575503f7a5f7636cbc0079bc7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Dec 2021 15:03:06 +0900 Subject: [PATCH] Start introducing `ILive` --- osu.Game/Beatmaps/BeatmapManager.cs | 4 +- osu.Game/Beatmaps/BeatmapModelManager.cs | 4 +- osu.Game/OsuGame.cs | 45 ++++++++++--------- osu.Game/Overlays/MusicController.cs | 1 - .../Sections/Maintenance/GeneralSettings.cs | 3 +- osu.Game/Screens/Menu/IntroScreen.cs | 7 +-- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 1d39873016..7fb0729967 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -173,14 +173,14 @@ public virtual void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin? beatm /// /// The query. /// Results from the provided query. - public ILive> QueryBeatmapSets(Expression> query) => beatmapModelManager.QueryBeatmapSets(query).ToLive(contextFactory); + public List> QueryBeatmapSets(Expression> query) => beatmapModelManager.QueryBeatmapSets(query).ToLive(); /// /// Perform a lookup query on available s. /// /// The query. /// The first result for the provided query, or null if no results were found. - public BeatmapSetInfo? QueryBeatmapSet(Expression> query) => beatmapModelManager.QueryBeatmapSet(query); + public ILive? QueryBeatmapSet(Expression> query) => beatmapModelManager.QueryBeatmapSet(query); /// /// Perform a lookup query on available s. diff --git a/osu.Game/Beatmaps/BeatmapModelManager.cs b/osu.Game/Beatmaps/BeatmapModelManager.cs index 1d1aa20a5b..839d3df159 100644 --- a/osu.Game/Beatmaps/BeatmapModelManager.cs +++ b/osu.Game/Beatmaps/BeatmapModelManager.cs @@ -104,10 +104,10 @@ public virtual void Save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin /// /// The query. /// The first result for the provided query, or null if no results were found. - public BeatmapSetInfo? QueryBeatmapSet(Expression> query) + public ILive? QueryBeatmapSet(Expression> query) { using (var context = ContextFactory.CreateContext()) - return context.All().FirstOrDefault(query); // TODO: ?.ToLive(); + return context.All().FirstOrDefault(query)?.ToLive(); } /// diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 49893a6d36..8d1eccb7c1 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -437,7 +437,7 @@ public void ShowChannel(string channel) => waitForReady(() => channelManager, _ /// public void PresentBeatmap(IBeatmapSetInfo beatmap, Predicate difficultyCriteria = null) { - BeatmapSetInfo databasedSet = null; + ILive databasedSet = null; if (beatmap.OnlineID > 0) databasedSet = BeatmapManager.QueryBeatmapSet(s => s.OnlineID == beatmap.OnlineID); @@ -453,27 +453,30 @@ public void PresentBeatmap(IBeatmapSetInfo beatmap, Predicate diffi PerformFromScreen(screen => { - // Find beatmaps that match our predicate. - var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true).ToList(); - - // Use all beatmaps if predicate matched nothing - if (beatmaps.Count == 0) - beatmaps = databasedSet.Beatmaps.ToList(); - - // Prefer recommended beatmap if recommendations are available, else fallback to a sane selection. - var selection = difficultyRecommender.GetRecommendedBeatmap(beatmaps) - ?? beatmaps.FirstOrDefault(b => b.Ruleset.Equals(Ruleset.Value)) - ?? beatmaps.First(); - - if (screen is IHandlePresentBeatmap presentableScreen) + databasedSet.PerformRead(set => { - presentableScreen.PresentBeatmap(BeatmapManager.GetWorkingBeatmap(selection), selection.Ruleset); - } - else - { - Ruleset.Value = selection.Ruleset; - Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection); - } + // Find beatmaps that match our predicate. + var beatmaps = set.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true).ToList(); + + // Use all beatmaps if predicate matched nothing + if (beatmaps.Count == 0) + beatmaps = set.Beatmaps.ToList(); + + // Prefer recommended beatmap if recommendations are available, else fallback to a sane selection. + var selection = difficultyRecommender.GetRecommendedBeatmap(beatmaps) + ?? beatmaps.FirstOrDefault(b => b.Ruleset.Equals(Ruleset.Value)) + ?? beatmaps.First(); + + if (screen is IHandlePresentBeatmap presentableScreen) + { + presentableScreen.PresentBeatmap(BeatmapManager.GetWorkingBeatmap(selection), selection.Ruleset); + } + else + { + Ruleset.Value = selection.Ruleset; + Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection); + } + }); }, validScreens: new[] { typeof(SongSelect), typeof(IHandlePresentBeatmap) }); } diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 58707c3321..8c115c2c94 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -88,7 +88,6 @@ private void beatmapsChanged(IRealmCollection sender, ChangeSet if (changes == null) { beatmapSets.AddRange(sender); - return; } // beatmaps.ItemUpdated += set => Schedule(() => diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 51e4d61d2e..93884812fe 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -160,7 +160,8 @@ private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skin Action = () => { undeleteButton.Enabled.Value = false; - Task.Run(() => beatmaps.Undelete(beatmaps.QueryBeatmapSets(b => b.DeletePending).ToList())).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true)); + // TODO: reimplement similar to SkinManager? + // Task.Run(() => beatmaps.Undelete(beatmaps.QueryBeatmapSets(b => b.DeletePending).ToList())).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true)); } }, }); diff --git a/osu.Game/Screens/Menu/IntroScreen.cs b/osu.Game/Screens/Menu/IntroScreen.cs index aa3fe9fd88..bb8ddb8cd6 100644 --- a/osu.Game/Screens/Menu/IntroScreen.cs +++ b/osu.Game/Screens/Menu/IntroScreen.cs @@ -15,6 +15,7 @@ using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.IO.Archives; using osu.Game.Overlays; using osu.Game.Screens.Backgrounds; @@ -90,7 +91,7 @@ private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManag MenuMusic = config.GetBindable(OsuSetting.MenuMusic); seeya = audio.Samples.Get(SeeyaSampleName); - BeatmapSetInfo setInfo = null; + ILive setInfo = null; // if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection. if (!MenuMusic.Value) @@ -100,7 +101,7 @@ private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManag if (sets.Count > 0) { setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID); - initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo?.Beatmaps[0]); + initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo?.PerformRead(s => s.Beatmaps[0].ToLive())); } } @@ -130,7 +131,7 @@ bool loadThemedIntro() if (setInfo == null) return false; - initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); + initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.PerformRead(s => s.Beatmaps[0].ToLive())); return UsingThemedIntro = initialBeatmap != null; }