From fe73b9f8d3919a0a983965f5db17569b4f2bd83d Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Dec 2019 16:45:32 +0800 Subject: [PATCH] make HP and OD generic and instantiate CS and AR to modes that need it --- .../Mods/CatchModDifficultyAdjust.cs | 37 ++++++------ .../Mods/ManiaModDifficultyAdjust.cs | 19 ------ .../Mods/OsuModDifficultyAdjust.cs | 37 ++++++------ .../Mods/TaikoModDifficultyAdjust.cs | 19 ------ osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs | 59 +++++++++++-------- 5 files changed, 68 insertions(+), 103 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs index 127b6c1c0b..2e1e655844 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Rulesets.Mods; @@ -9,18 +10,8 @@ namespace osu.Game.Rulesets.Catch.Mods { public class CatchModDifficultyAdjust : ModDifficultyAdjust { - [SettingSource("Drain Rate", "Override a beatmap's set HP.")] - public override BindableNumber DrainRate { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; - [SettingSource("Fruit Size", "Override a beatmap's set CS.")] - public override BindableNumber CircleSize { get; } = new BindableFloat() + public BindableNumber CircleSize { get; } = new BindableFloat() { Precision = 0.1f, MinValue = 1, @@ -30,7 +21,7 @@ namespace osu.Game.Rulesets.Catch.Mods }; [SettingSource("Approach Rate", "Override a beatmap's set AR.")] - public override BindableNumber ApproachRate { get; } = new BindableFloat() + public BindableNumber ApproachRate { get; } = new BindableFloat() { Precision = 0.1f, MinValue = 1, @@ -39,14 +30,20 @@ namespace osu.Game.Rulesets.Catch.Mods Value = 5, }; - [SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] - public override BindableNumber OverallDifficulty { get; } = new BindableFloat() + protected override void UpdateSettings(BeatmapDifficulty difficulty) { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; + base.UpdateSettings(difficulty); + + CircleSize.Value = CircleSize.Default = difficulty.CircleSize; + ApproachRate.Value = ApproachRate.Default = difficulty.ApproachRate; + } + + protected override void ApplySettings(BeatmapDifficulty difficulty) + { + base.ApplySettings(difficulty); + + difficulty.CircleSize = CircleSize.Value; + difficulty.ApproachRate = ApproachRate.Value; + } } } diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs index fd1315523c..5920e0c3b8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs @@ -9,24 +9,5 @@ namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModDifficultyAdjust : ModDifficultyAdjust { - [SettingSource("Drain Rate", "Override a beatmap's set HP.")] - public override BindableNumber DrainRate { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; - - [SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] - public override BindableNumber OverallDifficulty { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs index 4847ddc3c4..3e9c51db85 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Rulesets.Mods; @@ -9,18 +10,8 @@ namespace osu.Game.Rulesets.Osu.Mods { public class OsuModDifficultyAdjust : ModDifficultyAdjust { - [SettingSource("Drain Rate", "Override a beatmap's set HP.")] - public override BindableNumber DrainRate { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; - [SettingSource("Circle Size", "Override a beatmap's set CS.")] - public override BindableNumber CircleSize { get; } = new BindableFloat() + public BindableNumber CircleSize { get; } = new BindableFloat() { Precision = 0.1f, MinValue = 1, @@ -30,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Mods }; [SettingSource("Approach Rate", "Override a beatmap's set AR.")] - public override BindableNumber ApproachRate { get; } = new BindableFloat() + public BindableNumber ApproachRate { get; } = new BindableFloat() { Precision = 0.1f, MinValue = 1, @@ -39,14 +30,20 @@ namespace osu.Game.Rulesets.Osu.Mods Value = 5, }; - [SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] - public override BindableNumber OverallDifficulty { get; } = new BindableFloat() + protected override void UpdateSettings(BeatmapDifficulty difficulty) { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; + base.UpdateSettings(difficulty); + + CircleSize.Value = CircleSize.Default = difficulty.CircleSize; + ApproachRate.Value = ApproachRate.Default = difficulty.ApproachRate; + } + + protected override void ApplySettings(BeatmapDifficulty difficulty) + { + base.ApplySettings(difficulty); + + difficulty.CircleSize = CircleSize.Value; + difficulty.ApproachRate = ApproachRate.Value; + } } } diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs index b7007eedcd..3c4812f922 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs @@ -9,24 +9,5 @@ namespace osu.Game.Rulesets.Taiko.Mods { public class TaikoModDifficultyAdjust : ModDifficultyAdjust { - [SettingSource("Drain Rate", "Override a beatmap's set HP.")] - public override BindableNumber DrainRate { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; - - [SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] - public override BindableNumber OverallDifficulty { get; } = new BindableFloat() - { - Precision = 0.1f, - MinValue = 1, - MaxValue = 10, - Default = 5, - Value = 5, - }; } } diff --git a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs index 546533709e..1405ccec8d 100644 --- a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs +++ b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs @@ -5,6 +5,7 @@ using osu.Game.Beatmaps; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using System; +using osu.Game.Configuration; namespace osu.Game.Rulesets.Mods { @@ -24,41 +25,49 @@ namespace osu.Game.Rulesets.Mods public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) }; - public virtual BindableNumber DrainRate { get; } + [SettingSource("Drain Rate", "Override a beatmap's set HP.")] + public BindableNumber DrainRate { get; } = new BindableFloat() + { + Precision = 0.1f, + MinValue = 1, + MaxValue = 10, + Default = 5, + Value = 5, + }; - public virtual BindableNumber CircleSize { get; } - - public virtual BindableNumber ApproachRate { get; } - - public virtual BindableNumber OverallDifficulty { get; } + [SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] + public BindableNumber OverallDifficulty { get; } = new BindableFloat() + { + Precision = 0.1f, + MinValue = 1, + MaxValue = 10, + Default = 5, + Value = 5, + }; private BeatmapDifficulty difficulty; - public virtual void ApplyToDifficulty(BeatmapDifficulty difficulty) + public void ApplyToDifficulty(BeatmapDifficulty difficulty) { if (this.difficulty == null || this.difficulty.ID != difficulty.ID) { this.difficulty = difficulty; - - if (DrainRate != null) - DrainRate.Value = DrainRate.Default = difficulty.DrainRate; - - if (CircleSize != null) - CircleSize.Value = CircleSize.Default = difficulty.CircleSize; - - if (ApproachRate != null) - ApproachRate.Value = ApproachRate.Default = difficulty.ApproachRate; - - if (OverallDifficulty != null) - OverallDifficulty.Value = OverallDifficulty.Default = difficulty.OverallDifficulty; + UpdateSettings(difficulty); } else - { - difficulty.DrainRate = DrainRate?.Value ?? difficulty.DrainRate; - difficulty.CircleSize = CircleSize?.Value ?? difficulty.CircleSize; - difficulty.ApproachRate = ApproachRate?.Value ?? difficulty.ApproachRate; - difficulty.OverallDifficulty = OverallDifficulty?.Value ?? difficulty.OverallDifficulty; - } + ApplySettings(difficulty); + } + + protected virtual void UpdateSettings(BeatmapDifficulty difficulty) + { + DrainRate.Value = DrainRate.Default = difficulty.DrainRate; + OverallDifficulty.Value = OverallDifficulty.Default = difficulty.OverallDifficulty; + } + + protected virtual void ApplySettings(BeatmapDifficulty difficulty) + { + difficulty.DrainRate = DrainRate.Value; + difficulty.OverallDifficulty = OverallDifficulty.Value; } } }