From 58e122a7cb1c0b47365e1fe28c16f24d85ce0681 Mon Sep 17 00:00:00 2001 From: Endrik Tombak Date: Tue, 14 Apr 2020 19:56:41 +0300 Subject: [PATCH] Better fallback logic --- osu.Game/OsuGame.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index e64ca3ad87..fea89155f5 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -322,8 +322,6 @@ namespace osu.Game /// public void PresentBeatmap(BeatmapSetInfo beatmap, Predicate difficultyCriteria = null) { - difficultyCriteria ??= _ => true; - var databasedSet = beatmap.OnlineBeatmapSetID != null ? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID) : BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash); @@ -347,14 +345,20 @@ namespace osu.Game } // Find beatmaps that match our predicate. - var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria(b)); + var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true); if (!beatmaps.Any()) beatmaps = databasedSet.Beatmaps; - var selection = DifficultyRecommender.GetRecommendedBeatmap(beatmaps) ?? ( - // fallback if a difficulty can't be recommended, maybe we are offline - databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First() - ); + var selection = DifficultyRecommender.GetRecommendedBeatmap(beatmaps); + + // fallback if a difficulty can't be recommended, maybe we are offline + if (selection == null) + { + if (difficultyCriteria != null) + selection = beatmaps.First(); + else + selection = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First(); + } Ruleset.Value = selection.Ruleset; Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection);