1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 00:03:21 +08:00

Merge pull request #16545 from peppy/fix-intro-realm-usage

Fix `IntroScreen` retrieving and iterating all realm beatmap sets
This commit is contained in:
Bartłomiej Dach 2022-01-23 15:38:03 +01:00 committed by GitHub
commit 00a6d4e51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ using osu.Game.Overlays;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using Realms;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -93,28 +94,27 @@ namespace osu.Game.Screens.Menu
MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic); MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
seeya = audio.Samples.Get(SeeyaSampleName); seeya = audio.Samples.Get(SeeyaSampleName);
ILive<BeatmapSetInfo> setInfo = null;
// if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection. // if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
if (!MenuMusic.Value) if (!MenuMusic.Value)
{ {
var sets = beatmaps.GetAllUsableBeatmapSets(); realmContextFactory.Run(realm =>
if (sets.Count > 0)
{ {
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID); var usableBeatmapSets = realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();
setInfo?.PerformRead(s =>
{
if (s.Beatmaps.Count == 0)
return;
initialBeatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps[0]); int setCount = usableBeatmapSets.Count;
});
} if (setCount > 0)
{
var found = usableBeatmapSets[RNG.Next(0, setCount - 1)].Beatmaps.FirstOrDefault();
if (found != null)
initialBeatmap = beatmaps.GetWorkingBeatmap(found);
}
});
} }
// we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available. // we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
if (setInfo == null) if (initialBeatmap == null)
{ {
if (!loadThemedIntro()) if (!loadThemedIntro())
{ {
@ -130,7 +130,7 @@ namespace osu.Game.Screens.Menu
bool loadThemedIntro() bool loadThemedIntro()
{ {
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash); var setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
if (setInfo == null) if (setInfo == null)
return false; return false;