mirror of
https://github.com/ppy/osu-tools.git
synced 2025-06-09 09:35:15 +09:00
Move to utility function
This commit is contained in:
parent
cca1f5e3c9
commit
664597edf7
2 changed files with 32 additions and 30 deletions
|
@ -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<Mod>();
|
||||
|
||||
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")]
|
||||
|
|
|
@ -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<Mod>();
|
||||
|
||||
var mods = new List<Mod>();
|
||||
|
||||
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<HitResult, int> GenerateHitResults(double accuracy, IBeatmap beatmap, int countMiss, int? countMeh, int? countGood);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue