// 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 System.Linq; 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 { /// /// Collects the constituent parts of a beatmap being verified. /// /// /// Use this to access beatmap resources like its track, storyboard, waveform, or similar. /// /// /// The in its actual playable state after beatmap conversion. /// Use this to inspect the actual beatmap contents, like its hitobjects, timing points, breaks, etc. /// 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 => OtherDifficulties.Prepend(CurrentDifficulty); public BeatmapVerifierContext(VerifiedBeatmap currentDifficulty, IReadOnlyList otherDifficulties, DifficultyRating difficultyRating) { CurrentDifficulty = currentDifficulty; InterpretedDifficulty = difficultyRating; OtherDifficulties = otherDifficulties; } /// /// Backwards-compatible constructor that allows creating a context from a single playable and working beatmap. /// 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, others, difficultyRating); } } }