From 82f5024b6c5e9fe1ac73ab0faca35e000e023510 Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:03:43 +0100 Subject: [PATCH] adjust for structs --- .../Difficulty/DifficultyCommand.cs | 2 +- PerformanceCalculator/LegacyHelper.cs | 21 ------------------- .../Performance/ScorePerformanceCommand.cs | 10 ++++----- PerformanceCalculator/ProcessorCommand.cs | 6 +++--- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/PerformanceCalculator/Difficulty/DifficultyCommand.cs b/PerformanceCalculator/Difficulty/DifficultyCommand.cs index 8bdb8fd89..07577eee8 100644 --- a/PerformanceCalculator/Difficulty/DifficultyCommand.cs +++ b/PerformanceCalculator/Difficulty/DifficultyCommand.cs @@ -157,7 +157,7 @@ private class Result public List Mods { get; set; } [JsonProperty("attributes")] - public DifficultyAttributes Attributes { get; set; } + public IDifficultyAttributes Attributes { get; set; } } } } diff --git a/PerformanceCalculator/LegacyHelper.cs b/PerformanceCalculator/LegacyHelper.cs index 0449f0d93..f8e2f38c8 100644 --- a/PerformanceCalculator/LegacyHelper.cs +++ b/PerformanceCalculator/LegacyHelper.cs @@ -58,26 +58,5 @@ public static string GetRulesetShortNameFromId(int id) return "mania"; } } - - public static DifficultyAttributes CreateDifficultyAttributes(int legacyId) - { - switch (legacyId) - { - case 0: - return new OsuDifficultyAttributes(); - - case 1: - return new TaikoDifficultyAttributes(); - - case 2: - return new CatchDifficultyAttributes(); - - case 3: - return new ManiaDifficultyAttributes(); - - default: - throw new ArgumentException($"Invalid ruleset ID: {legacyId}", nameof(legacyId)); - } - } } } diff --git a/PerformanceCalculator/Performance/ScorePerformanceCommand.cs b/PerformanceCalculator/Performance/ScorePerformanceCommand.cs index 0bc18179b..44301b58e 100644 --- a/PerformanceCalculator/Performance/ScorePerformanceCommand.cs +++ b/PerformanceCalculator/Performance/ScorePerformanceCommand.cs @@ -43,7 +43,7 @@ public override void Execute() var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(apiScore.BeatmapID.ToString()); var score = CreateScore(apiScore, ruleset, apiBeatmap, workingBeatmap); - DifficultyAttributes attributes; + IDifficultyAttributes attributes; if (OnlineAttributes) { @@ -78,7 +78,7 @@ protected virtual ScoreInfo CreateScore(SoloScoreInfo apiScore, Ruleset ruleset, return score; } - private DifficultyAttributes queryApiAttributes(int beatmapId, int rulesetId, LegacyMods mods) + private IDifficultyAttributes queryApiAttributes(int beatmapId, int rulesetId, LegacyMods mods) { Dictionary parameters = new Dictionary { @@ -105,8 +105,8 @@ private DifficultyAttributes queryApiAttributes(int beatmapId, int rulesetId, Le throw new ArgumentOutOfRangeException(nameof(rulesetId)); } - DifficultyAttributes getMergedAttributes(APIBeatmap apiBeatmap) - where TAttributes : DifficultyAttributes, new() + IDifficultyAttributes getMergedAttributes(APIBeatmap apiBeatmap) + where TAttributes : IDifficultyAttributes, new() { // the osu-web endpoint queries osu-beatmap-difficulty-cache, which in turn does not return the full set of attributes - // it skips ones that are already present on `APIBeatmap` @@ -165,7 +165,7 @@ static LegacyMods maskRelevantMods(LegacyMods mods, bool isConvertedBeatmap, int [JsonObject(MemberSerialization.OptIn)] private class AttributesResponse - where T : DifficultyAttributes + where T : IDifficultyAttributes { [JsonProperty("attributes")] public T Attributes { get; set; } diff --git a/PerformanceCalculator/ProcessorCommand.cs b/PerformanceCalculator/ProcessorCommand.cs index 392631c00..ee4f0ba51 100644 --- a/PerformanceCalculator/ProcessorCommand.cs +++ b/PerformanceCalculator/ProcessorCommand.cs @@ -38,7 +38,7 @@ public virtual void OnExecute(CommandLineApplication app, IConsole console) Execute(); } - public void OutputPerformance(ScoreInfo score, PerformanceAttributes performanceAttributes, DifficultyAttributes difficultyAttributes) + public void OutputPerformance(ScoreInfo score, IPerformanceAttributes performanceAttributes, IDifficultyAttributes difficultyAttributes) { var result = new Result { @@ -170,10 +170,10 @@ private class Result public ScoreStatistics Score { get; set; } [JsonProperty("performance_attributes")] - public PerformanceAttributes PerformanceAttributes { get; set; } + public IPerformanceAttributes PerformanceAttributes { get; set; } [JsonProperty("difficulty_attributes")] - public DifficultyAttributes DifficultyAttributes { get; set; } + public IDifficultyAttributes DifficultyAttributes { get; set; } } ///