// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using osu.Game.Beatmaps; namespace osu.Game.Rulesets.Edit { /// /// Represents the context provided by the beatmap verifier to the checks it runs. /// Contains information about what is being checked and how it should be checked. /// public class BeatmapVerifierContext { /// /// The playable beatmap instance of the current beatmap. /// public readonly IBeatmap Beatmap; /// /// The working beatmap instance of the current beatmap. /// public readonly IWorkingBeatmap WorkingBeatmap; /// /// The difficulty level which the current beatmap is considered to be. /// public DifficultyRating InterpretedDifficulty; /// /// All beatmap difficulties in the same beatmapset, including the current beatmap. /// public readonly IReadOnlyList BeatmapsetDifficulties; // TODO: Refactor this to have a simple constructor that only stores data and move the beatmap resolution logic to a static factory method. public BeatmapVerifierContext(IBeatmap beatmap, IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus, Func? beatmapResolver = null) { Beatmap = beatmap; WorkingBeatmap = workingBeatmap; InterpretedDifficulty = difficultyRating; var beatmapSet = beatmap.BeatmapInfo.BeatmapSet; if (beatmapSet?.Beatmaps == null) { BeatmapsetDifficulties = new[] { beatmap }; return; } var difficulties = new List(); foreach (var beatmapInfo in beatmapSet.Beatmaps) { // Use the current beatmap if it matches this BeatmapInfo if (beatmapInfo.Equals(beatmap.BeatmapInfo)) { difficulties.Add(beatmap); continue; } // Try to resolve other difficulties using the provided resolver var resolvedBeatmap = beatmapResolver?.Invoke(beatmapInfo); if (resolvedBeatmap != null) difficulties.Add(resolvedBeatmap); } BeatmapsetDifficulties = difficulties; } } }