From 664597edf74ea47ed6daf04329797a5deecba972 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 23 Oct 2024 15:06:46 +0900 Subject: [PATCH] Move to utility function --- PerformanceCalculator/ProcessorCommand.cs | 31 +++++++++++++++++++ .../Simulate/SimulateCommand.cs | 31 +------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/PerformanceCalculator/ProcessorCommand.cs b/PerformanceCalculator/ProcessorCommand.cs index d99e501..67463a8 100644 --- a/PerformanceCalculator/ProcessorCommand.cs +++ b/PerformanceCalculator/ProcessorCommand.cs @@ -12,7 +12,9 @@ using JetBrains.Annotations; using McMaster.Extensions.CommandLineUtils; using Newtonsoft.Json; using osu.Game.Online.API; +using osu.Game.Rulesets; using osu.Game.Rulesets.Difficulty; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -131,6 +133,35 @@ namespace PerformanceCalculator { } + public static Mod[] ParseMods(Ruleset ruleset, string[] acronyms, string[] options) + { + acronyms ??= []; + options ??= []; + + if (acronyms.Length == 0) + return []; + + var mods = new List(); + + foreach (var acronym in acronyms) + { + APIMod mod = new APIMod { Acronym = acronym }; + + foreach (string modOption in options.Where(x => x.StartsWith($"{acronym}_", StringComparison.CurrentCultureIgnoreCase))) + { + string[] split = modOption[3..].Split('='); + if (split.Length != 2) + throw new ArgumentException($"Invalid mod-option format (key=value): {modOption[3..]}"); + + mod.Settings[split[0]] = split[1]; + } + + mods.Add(mod.ToMod(ruleset)); + } + + return mods.ToArray(); + } + private class Result { [JsonProperty("score")] diff --git a/PerformanceCalculator/Simulate/SimulateCommand.cs b/PerformanceCalculator/Simulate/SimulateCommand.cs index 9a63709..be3dcb5 100644 --- a/PerformanceCalculator/Simulate/SimulateCommand.cs +++ b/PerformanceCalculator/Simulate/SimulateCommand.cs @@ -4,13 +4,10 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; using JetBrains.Annotations; using McMaster.Extensions.CommandLineUtils; using osu.Game.Beatmaps; -using osu.Game.Online.API; using osu.Game.Rulesets; -using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -65,7 +62,7 @@ namespace PerformanceCalculator.Simulate var ruleset = Ruleset; var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(Beatmap); - var mods = GetMods(ruleset); + var mods = ParseMods(ruleset, Mods, ModOptions); var beatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods); var beatmapMaxCombo = GetMaxCombo(beatmap); @@ -86,32 +83,6 @@ namespace PerformanceCalculator.Simulate OutputPerformance(scoreInfo, performanceAttributes, difficultyAttributes); } - protected Mod[] GetMods(Ruleset ruleset) - { - if (Mods == null) - return Array.Empty(); - - var mods = new List(); - - foreach (var modString in Mods) - { - APIMod mod = new APIMod { Acronym = modString }; - - foreach (string modOption in ModOptions.Where(x => x.StartsWith($"{modString}_", StringComparison.CurrentCultureIgnoreCase))) - { - string[] split = modOption[3..].Split('='); - if (split.Length != 2) - throw new ArgumentException($"Invalid mod-option format (key=value): {modOption[3..]}"); - - mod.Settings[split[0]] = split[1]; - } - - mods.Add(mod.ToMod(ruleset)); - } - - return mods.ToArray(); - } - protected abstract int GetMaxCombo(IBeatmap beatmap); protected abstract Dictionary GenerateHitResults(double accuracy, IBeatmap beatmap, int countMiss, int? countMeh, int? countGood);