1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 13:23:05 +08:00

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

View File

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