From cfb9649993cb86cd8b02c2382eb4fcea980cda64 Mon Sep 17 00:00:00 2001 From: Hivie Date: Mon, 11 Aug 2025 14:56:35 +0100 Subject: [PATCH] rework and improve `BeatmapVerifierContext` strtucture - uses ` VerifiedBeatmap` record for combining working and playable beatmaps - much better data access with all beatmapset diffs --- .../Rulesets/Edit/BeatmapVerifierContext.cs | 61 ++++++++----------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/osu.Game/Rulesets/Edit/BeatmapVerifierContext.cs b/osu.Game/Rulesets/Edit/BeatmapVerifierContext.cs index aa21276198..ab9cf1a35d 100644 --- a/osu.Game/Rulesets/Edit/BeatmapVerifierContext.cs +++ b/osu.Game/Rulesets/Edit/BeatmapVerifierContext.cs @@ -13,14 +13,9 @@ namespace osu.Game.Rulesets.Edit public class BeatmapVerifierContext { /// - /// The playable beatmap instance of the current beatmap. + /// A record containing the and playable versions of a beatmap. /// - public readonly IBeatmap Beatmap; - - /// - /// The working beatmap instance of the current beatmap. - /// - public readonly IWorkingBeatmap WorkingBeatmap; + public record VerifiedBeatmap(IWorkingBeatmap Working, IBeatmap Playable); /// /// The difficulty level which the current beatmap is considered to be. @@ -28,57 +23,51 @@ namespace osu.Game.Rulesets.Edit public DifficultyRating InterpretedDifficulty; /// - /// All playable beatmap difficulties in the same beatmapset, including the current beatmap. + /// The current beatmap being checked. /// - public readonly IReadOnlyList BeatmapsetDifficulties; + public readonly VerifiedBeatmap CurrentDifficulty; /// - /// The working beatmapset difficulties, including the current working beatmap. + /// Other beatmaps in the same beatmapset. /// - public readonly IReadOnlyList WorkingBeatmapsetDifficulties; + public readonly IReadOnlyList OtherDifficulties; - public BeatmapVerifierContext(IBeatmap beatmap, IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus, IReadOnlyList? beatmapsetDifficulties = null, IReadOnlyList? workingBeatmapsetDifficulties = null) + /// + /// All beatmaps in the same beatmapset. + /// + public IEnumerable AllDifficulties => [CurrentDifficulty, ..OtherDifficulties]; + + public BeatmapVerifierContext(VerifiedBeatmap currentDifficulty, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus, IReadOnlyList? otherDifficulties = null) { - Beatmap = beatmap; - WorkingBeatmap = workingBeatmap; + CurrentDifficulty = currentDifficulty; InterpretedDifficulty = difficultyRating; - BeatmapsetDifficulties = beatmapsetDifficulties ?? new List { beatmap }; - WorkingBeatmapsetDifficulties = workingBeatmapsetDifficulties ?? new List { workingBeatmap }; + OtherDifficulties = otherDifficulties ?? new List(); } 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(beatmap, workingBeatmap); - } + return new BeatmapVerifierContext(current, difficultyRating); - var difficulties = new List(); - var workingDifficulties = new List(); + var others = new List(); - foreach (var beatmapInfo in beatmapSet.Beatmaps) + foreach (var info in beatmapSet.Beatmaps) { - // Use the current beatmap if it matches this BeatmapInfo - if (beatmapInfo.Equals(beatmap.BeatmapInfo)) - { - difficulties.Add(beatmap); - workingDifficulties.Add(workingBeatmap); + if (info.Equals(beatmap.BeatmapInfo)) continue; - } - // Resolve other difficulties using BeatmapManager if available - var working = beatmapManager?.GetWorkingBeatmap(beatmapInfo); - if (working != null) - workingDifficulties.Add(working); + var otherWorking = beatmapManager?.GetWorkingBeatmap(info); + var otherPlayable = otherWorking?.GetPlayableBeatmap(info.Ruleset); - var playable = working?.GetPlayableBeatmap(beatmapInfo.Ruleset); - if (playable != null) - difficulties.Add(playable); + if (otherWorking != null && otherPlayable != null) + others.Add(new VerifiedBeatmap(otherWorking, otherPlayable)); } - return new BeatmapVerifierContext(beatmap, workingBeatmap, difficultyRating, difficulties, workingDifficulties); + return new BeatmapVerifierContext(current, difficultyRating); } } }