// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. 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 { /// /// A record containing the and playable versions of a beatmap. /// public record VerifiedBeatmap(IWorkingBeatmap Working, IBeatmap Playable); /// /// The difficulty level which the current beatmap is considered to be. /// public DifficultyRating InterpretedDifficulty; /// /// The current beatmap being checked. /// public readonly VerifiedBeatmap CurrentDifficulty; /// /// Other beatmaps in the same beatmapset. /// public readonly IReadOnlyList OtherDifficulties; /// /// All beatmaps in the same beatmapset. /// public IEnumerable AllDifficulties => [CurrentDifficulty, ..OtherDifficulties]; public BeatmapVerifierContext(VerifiedBeatmap currentDifficulty, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus, IReadOnlyList? otherDifficulties = null) { CurrentDifficulty = currentDifficulty; InterpretedDifficulty = difficultyRating; OtherDifficulties = otherDifficulties ?? new List(); } public BeatmapVerifierContext(IBeatmap beatmap, IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus) : this(new VerifiedBeatmap(workingBeatmap, beatmap), difficultyRating) { } public static BeatmapVerifierContext Create(IBeatmap beatmap, IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus, BeatmapManager? beatmapManager = null) { var beatmapSet = beatmap.BeatmapInfo.BeatmapSet; var current = new VerifiedBeatmap(workingBeatmap, beatmap); if (beatmapSet?.Beatmaps == null || beatmapSet.Beatmaps.Count == 1) return new BeatmapVerifierContext(current, difficultyRating); var others = new List(); foreach (var info in beatmapSet.Beatmaps) { if (info.Equals(beatmap.BeatmapInfo)) continue; var otherWorking = beatmapManager?.GetWorkingBeatmap(info); var otherPlayable = otherWorking?.GetPlayableBeatmap(info.Ruleset); if (otherWorking != null && otherPlayable != null) others.Add(new VerifiedBeatmap(otherWorking, otherPlayable)); } return new BeatmapVerifierContext(current, difficultyRating); } } }