From 0cfd6fdf0455224de5d8a98be1aaae954e0f82c0 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 15 Nov 2021 16:06:46 +0900 Subject: [PATCH] Add to/from database mapping functions to difficulty attributes --- .../Difficulty/CatchDifficultyAttributes.cs | 21 +++++++++++ .../Difficulty/ManiaDifficultyAttributes.cs | 21 +++++++++++ .../Difficulty/OsuDifficultyAttributes.cs | 37 +++++++++++++++++++ .../Difficulty/TaikoDifficultyAttributes.cs | 20 ++++++++++ .../Difficulty/DifficultyAttributes.cs | 8 ++++ 5 files changed, 107 insertions(+) diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyAttributes.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyAttributes.cs index 57305ce62b..3f03fc102b 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyAttributes.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyAttributes.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Rulesets.Difficulty; @@ -10,5 +11,25 @@ namespace osu.Game.Rulesets.Catch.Difficulty { [JsonProperty("approach_rate")] public double ApproachRate { get; set; } + + public override IEnumerable<(int attributeId, object value)> ToDatabase() + { + foreach (var v in base.ToDatabase()) + yield return v; + + // Todo: Catch should not output star rating in the 'aim' attribute. + yield return (1, StarRating); + yield return (7, ApproachRate); + yield return (9, MaxCombo); + } + + public override void FromDatabase(IReadOnlyDictionary values, int hitCircleCount, int spinnerCount) + { + base.FromDatabase(values, hitCircleCount, spinnerCount); + + StarRating = values[1]; + ApproachRate = values[7]; + MaxCombo = (int)values[9]; + } } } diff --git a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyAttributes.cs b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyAttributes.cs index dd966ca859..d1cb48f728 100644 --- a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyAttributes.cs +++ b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyAttributes.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Rulesets.Difficulty; @@ -13,5 +14,25 @@ namespace osu.Game.Rulesets.Mania.Difficulty [JsonProperty("score_multiplier")] public double ScoreMultiplier { get; set; } + + public override IEnumerable<(int attributeId, object value)> ToDatabase() + { + foreach (var v in base.ToDatabase()) + yield return v; + + // Todo: Mania doesn't output MaxCombo attribute for some reason. + yield return (11, StarRating); + yield return (13, GreatHitWindow); + yield return (15, ScoreMultiplier); + } + + public override void FromDatabase(IReadOnlyDictionary values, int hitCircleCount, int spinnerCount) + { + base.FromDatabase(values, hitCircleCount, spinnerCount); + + StarRating = values[11]; + GreatHitWindow = values[13]; + ScoreMultiplier = values[15]; + } } } diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyAttributes.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyAttributes.cs index 323cda76d4..75d1eed1ab 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyAttributes.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyAttributes.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using osu.Game.Rulesets.Difficulty; +using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Difficulty { @@ -37,5 +40,39 @@ namespace osu.Game.Rulesets.Osu.Difficulty [JsonProperty("spinner_count")] public int SpinnerCount { get; set; } + + public override IEnumerable<(int attributeId, object value)> ToDatabase() + { + foreach (var v in base.ToDatabase()) + yield return v; + + yield return (1, AimStrain); + yield return (3, SpeedStrain); + yield return (5, OverallDifficulty); + yield return (7, ApproachRate); + yield return (9, MaxCombo); + yield return (11, StarRating); + + if (Mods.Any(m => m is ModFlashlight)) + yield return (17, FlashlightRating); + + yield return (19, SliderFactor); + } + + public override void FromDatabase(IReadOnlyDictionary values, int hitCircleCount, int spinnerCount) + { + base.FromDatabase(values, hitCircleCount, spinnerCount); + + AimStrain = values[1]; + SpeedStrain = values[3]; + OverallDifficulty = values[5]; + ApproachRate = values[7]; + MaxCombo = (int)values[9]; + StarRating = values[11]; + FlashlightRating = values.GetValueOrDefault(17); + SliderFactor = values[19]; + HitCircleCount = hitCircleCount; + SpinnerCount = spinnerCount; + } } } diff --git a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyAttributes.cs b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyAttributes.cs index 171ac89e6f..b2208ea617 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyAttributes.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyAttributes.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Rulesets.Difficulty; @@ -22,5 +23,24 @@ namespace osu.Game.Rulesets.Taiko.Difficulty [JsonProperty("great_hit_window")] public double GreatHitWindow { get; set; } + + public override IEnumerable<(int attributeId, object value)> ToDatabase() + { + foreach (var v in base.ToDatabase()) + yield return v; + + yield return (9, MaxCombo); + yield return (11, StarRating); + yield return (13, GreatHitWindow); + } + + public override void FromDatabase(IReadOnlyDictionary values, int hitCircleCount, int spinnerCount) + { + base.FromDatabase(values, hitCircleCount, spinnerCount); + + MaxCombo = (int)values[9]; + StarRating = values[11]; + GreatHitWindow = values[13]; + } } } diff --git a/osu.Game/Rulesets/Difficulty/DifficultyAttributes.cs b/osu.Game/Rulesets/Difficulty/DifficultyAttributes.cs index fb67396718..96d52833e0 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyAttributes.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyAttributes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; @@ -31,5 +33,11 @@ namespace osu.Game.Rulesets.Difficulty Skills = skills; StarRating = starRating; } + + public virtual IEnumerable<(int attributeId, object value)> ToDatabase() => Enumerable.Empty<(int, object)>(); + + public virtual void FromDatabase(IReadOnlyDictionary values, int hitCircleCount, int spinnerCount) + { + } } }