From b6fe56f5e9a160e79e63742531d8577ca362b022 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 23:00:29 +0000 Subject: [PATCH 1/3] Bump difficalcy from `3f3b541` to `4343fda` Bumps [difficalcy](https://github.com/Syriiin/difficalcy) from `3f3b541` to `4343fda`. - [Release notes](https://github.com/Syriiin/difficalcy/releases) - [Commits](https://github.com/Syriiin/difficalcy/compare/3f3b541b117a30912ebc95bda569b88acb0a41b5...4343fda0ae2ecd2e39244a585e0b613c505313ae) --- updated-dependencies: - dependency-name: difficalcy dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- difficalcy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/difficalcy b/difficalcy index 3f3b541..4343fda 160000 --- a/difficalcy +++ b/difficalcy @@ -1 +1 @@ -Subproject commit 3f3b541b117a30912ebc95bda569b88acb0a41b5 +Subproject commit 4343fda0ae2ecd2e39244a585e0b613c505313ae From 8634dfdd3a21ea9f056ed0d1abcf697743b346dd Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Wed, 13 Nov 2024 23:26:35 +1100 Subject: [PATCH 2/3] Update to new mod format --- .../OsuCalculatorServiceTest.cs | 16 +++++++++++----- .../Services/OsuCalculatorService.cs | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Difficalcy.PerformancePlus.Tests/OsuCalculatorServiceTest.cs b/Difficalcy.PerformancePlus.Tests/OsuCalculatorServiceTest.cs index f4b6f84..00a1a8c 100644 --- a/Difficalcy.PerformancePlus.Tests/OsuCalculatorServiceTest.cs +++ b/Difficalcy.PerformancePlus.Tests/OsuCalculatorServiceTest.cs @@ -1,3 +1,4 @@ +using Difficalcy.Models; using Difficalcy.PerformancePlus.Models; using Difficalcy.PerformancePlus.Services; using Difficalcy.Services; @@ -20,10 +21,10 @@ public OsuCalculatorServiceTest() protected override CalculatorService CalculatorService { get; } [Theory] - [InlineData(6.578701261037768d, 288.6125590551904d, "diffcalc-test", 0)] - [InlineData(8.8180306947868328d, 722.9095478161727d, "diffcalc-test", 64)] - public void Test(double expectedDifficultyTotal, double expectedPerformanceTotal, string beatmapId, int mods) - => TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new OsuScore { BeatmapId = beatmapId, Mods = mods }); + [InlineData(6.578701261037768d, 288.6125590551904d, "diffcalc-test", new string[] { })] + [InlineData(8.8180306947868328d, 722.9095478161727d, "diffcalc-test", new string[] { "DT" })] + public void Test(double expectedDifficultyTotal, double expectedPerformanceTotal, string beatmapId, string[] mods) + => TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new OsuScore { BeatmapId = beatmapId, Mods = mods.Select(m => new Mod { Acronym = m }).ToArray() }); [Fact] public void TestAllParameters() @@ -31,7 +32,12 @@ public void TestAllParameters() var score = new OsuScore { BeatmapId = "diffcalc-test", - Mods = 1112, // HD, HR, DT, FL + Mods = [ + new Mod() { Acronym = "HD" }, + new Mod() { Acronym = "HR" }, + new Mod() { Acronym = "DT" }, + new Mod() { Acronym = "FL" }, + ], Combo = 200, Misses = 5, Mehs = 4, diff --git a/Difficalcy.PerformancePlus/Services/OsuCalculatorService.cs b/Difficalcy.PerformancePlus/Services/OsuCalculatorService.cs index e574792..bcb4544 100644 --- a/Difficalcy.PerformancePlus/Services/OsuCalculatorService.cs +++ b/Difficalcy.PerformancePlus/Services/OsuCalculatorService.cs @@ -8,11 +8,13 @@ using Difficalcy.Services; using Microsoft.Extensions.Configuration; using osu.Game.Beatmaps.Legacy; +using osu.Game.Online.API; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Difficulty; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; +using LazerMod = osu.Game.Rulesets.Mods.Mod; namespace Difficalcy.PerformancePlus.Services { @@ -52,13 +54,13 @@ protected override async Task EnsureBeatmap(string beatmapId) await beatmapProvider.EnsureBeatmap(beatmapId); } - protected override (object, string) CalculateDifficultyAttributes(string beatmapId, int bitMods) + protected override (object, string) CalculateDifficultyAttributes(string beatmapId, Mod[] mods) { var workingBeatmap = GetWorkingBeatmap(beatmapId); - var mods = OsuRuleset.ConvertFromLegacyMods((LegacyMods)bitMods).ToArray(); + var lazerMods = mods.Select(ModToLazerMod).ToArray(); var difficultyCalculator = OsuRuleset.CreateDifficultyCalculator(workingBeatmap); - var difficultyAttributes = difficultyCalculator.Calculate(mods) as OsuDifficultyAttributes; + var difficultyAttributes = difficultyCalculator.Calculate(lazerMods) as OsuDifficultyAttributes; // Serialising anonymous object with same names because Mods and Skills can't be serialised return (difficultyAttributes, JsonSerializer.Serialize(new @@ -89,7 +91,7 @@ protected override OsuCalculation CalculatePerformance(OsuScore score, object di var osuDifficultyAttributes = (OsuDifficultyAttributes)difficultyAttributes; var workingBeatmap = GetWorkingBeatmap(score.BeatmapId); - var mods = OsuRuleset.ConvertFromLegacyMods((LegacyMods)score.Mods).ToArray(); + var mods = score.Mods.Select(ModToLazerMod).ToArray(); var beatmap = workingBeatmap.GetPlayableBeatmap(OsuRuleset.RulesetInfo, mods); var combo = score.Combo ?? beatmap.HitObjects.Count + beatmap.HitObjects.OfType().Sum(s => s.NestedHitObjects.Count - 1); @@ -122,6 +124,15 @@ private CalculatorWorkingBeatmap GetWorkingBeatmap(string beatmapId) return new CalculatorWorkingBeatmap(OsuRuleset, beatmapStream); } + private LazerMod ModToLazerMod(Mod mod) + { + var apiMod = new APIMod { Acronym = mod.Acronym }; + foreach (var setting in mod.Settings) + apiMod.Settings.Add(setting.Key, setting.Value); + + return apiMod.ToMod(OsuRuleset); + } + private static Dictionary GetHitResults(int hitResultCount, int countMiss, int countMeh, int countOk) { var countGreat = hitResultCount - countOk - countMeh - countMiss; From 83fa06da82ffbad68d4466a40fe854803c1ae28f Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Wed, 13 Nov 2024 23:27:38 +1100 Subject: [PATCH 3/3] Update api reference --- docs/docs/difficalcy-performanceplus.json | 38 ++++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/docs/difficalcy-performanceplus.json b/docs/docs/difficalcy-performanceplus.json index 2c9da1b..b1c37c7 100644 --- a/docs/docs/difficalcy-performanceplus.json +++ b/docs/docs/difficalcy-performanceplus.json @@ -82,10 +82,10 @@ "name": "Mods", "in": "query", "schema": { - "maximum": 2147483647, - "minimum": 0, - "type": "integer", - "format": "int32" + "type": "array", + "items": { + "$ref": "#/components/schemas/Mod" + } } } ], @@ -166,6 +166,27 @@ }, "additionalProperties": false }, + "Mod": { + "required": [ + "acronym" + ], + "type": "object", + "properties": { + "acronym": { + "minLength": 1, + "type": "string" + }, + "settings": { + "type": "object", + "additionalProperties": { + "type": "string", + "nullable": true + }, + "nullable": true + } + }, + "additionalProperties": false + }, "OsuCalculation": { "type": "object", "properties": { @@ -273,10 +294,11 @@ "type": "string" }, "mods": { - "maximum": 2147483647, - "minimum": 0, - "type": "integer", - "format": "int32" + "type": "array", + "items": { + "$ref": "#/components/schemas/Mod" + }, + "nullable": true }, "combo": { "maximum": 2147483647,