Tidy up comments, code, and multiple linq enumeration

This commit is contained in:
Dean Herbert 2020-12-22 14:12:02 +09:00
parent d229fbba6e
commit dff865f335
2 changed files with 8 additions and 12 deletions

View File

@ -364,25 +364,19 @@ namespace osu.Game
// we might even already be at the song
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash && (difficultyCriteria?.Invoke(Beatmap.Value.BeatmapInfo) ?? true))
{
return;
}
// Find beatmaps that match our predicate.
var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true);
var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true).ToList();
// Use all beatmaps if predicate matched nothing
if (!beatmaps.Any())
if (beatmaps.Count == 0)
beatmaps = databasedSet.Beatmaps;
// Try to select recommended beatmap
// This should give us a beatmap from current ruleset if there are any in our matched beatmaps
var selection = DifficultyRecommender.GetRecommendedBeatmap(beatmaps);
// Fallback if a difficulty can't be recommended, maybe we are offline
// First try to find a beatmap in current ruleset
selection ??= beatmaps.FirstOrDefault(b => b.Ruleset.Equals(Ruleset.Value));
// Otherwise use first beatmap
selection ??= beatmaps.First();
// 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();
Ruleset.Value = selection.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection);

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
@ -47,6 +48,7 @@ namespace osu.Game.Screens.Select
/// </remarks>
/// <param name="beatmaps">A collection of beatmaps to select a difficulty from.</param>
/// <returns>The recommended difficulty, or null if a recommendation could not be provided.</returns>
[CanBeNull]
public BeatmapInfo GetRecommendedBeatmap(IEnumerable<BeatmapInfo> beatmaps)
{
if (!recommendedStarDifficulty.Any())