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

Fix IntroScreen retrieving and iterating all realm beatmap sets

This commit is contained in:
Dean Herbert 2022-01-21 17:55:27 +09:00
parent 8f1dfa33a2
commit 2006620a2c

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,26 @@ 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 sets = 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 = sets.Count;
if (sets.Any())
{
var found = sets[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 +129,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;
@ -146,6 +145,7 @@ namespace osu.Game.Screens.Menu
return UsingThemedIntro = initialBeatmap != null; return UsingThemedIntro = initialBeatmap != null;
} }
} }
}
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
{ {