From e56ff33271932eeda3776034562af8a91b05b178 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 18 Oct 2023 17:23:14 +0900 Subject: [PATCH] Also share `ScoreMultiplier` implementation --- osu.Game/Rulesets/Mods/ModDaycore.cs | 17 +++---------- osu.Game/Rulesets/Mods/ModDoubleTime.cs | 17 +------------ osu.Game/Rulesets/Mods/ModHalfTime.cs | 14 +---------- osu.Game/Rulesets/Mods/ModNightcore.cs | 18 ++++--------- osu.Game/Rulesets/Mods/RateAdjustModHelper.cs | 25 +++++++++++++++++-- 5 files changed, 34 insertions(+), 57 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModDaycore.cs b/osu.Game/Rulesets/Mods/ModDaycore.cs index 60ce610d7d..0b32788bf3 100644 --- a/osu.Game/Rulesets/Mods/ModDaycore.cs +++ b/osu.Game/Rulesets/Mods/ModDaycore.cs @@ -27,9 +27,12 @@ namespace osu.Game.Rulesets.Mods private readonly BindableNumber tempoAdjust = new BindableDouble(1); private readonly BindableNumber freqAdjust = new BindableDouble(1); + private readonly RateAdjustModHelper rateAdjustHelper; protected ModDaycore() { + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + SpeedChange.BindValueChanged(val => { freqAdjust.Value = SpeedChange.Default; @@ -43,18 +46,6 @@ namespace osu.Game.Rulesets.Mods track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjust); } - public override double ScoreMultiplier - { - get - { - // Round to the nearest multiple of 0.1. - double value = (int)(SpeedChange.Value * 10) / 10.0; - - // Offset back to 0. - value -= 1; - - return 1 + value; - } - } + public override double ScoreMultiplier => rateAdjustHelper.ScoreMultiplier; } } diff --git a/osu.Game/Rulesets/Mods/ModDoubleTime.cs b/osu.Game/Rulesets/Mods/ModDoubleTime.cs index 938c6268e2..f20cdcb18d 100644 --- a/osu.Game/Rulesets/Mods/ModDoubleTime.cs +++ b/osu.Game/Rulesets/Mods/ModDoubleTime.cs @@ -42,21 +42,6 @@ namespace osu.Game.Rulesets.Mods rateAdjustHelper.ApplyToTrack(track); } - public override double ScoreMultiplier - { - get - { - // Round to the nearest multiple of 0.1. - double value = (int)(SpeedChange.Value * 10) / 10.0; - - // Offset back to 0. - value -= 1; - - // Each 0.1 multiple changes score multiplier by 0.02. - value /= 5; - - return 1 + value; - } - } + public override double ScoreMultiplier => rateAdjustHelper.ScoreMultiplier; } } diff --git a/osu.Game/Rulesets/Mods/ModHalfTime.cs b/osu.Game/Rulesets/Mods/ModHalfTime.cs index 965e94efcb..4d75ee16bd 100644 --- a/osu.Game/Rulesets/Mods/ModHalfTime.cs +++ b/osu.Game/Rulesets/Mods/ModHalfTime.cs @@ -42,18 +42,6 @@ namespace osu.Game.Rulesets.Mods rateAdjustHelper.ApplyToTrack(track); } - public override double ScoreMultiplier - { - get - { - // Round to the nearest multiple of 0.1. - double value = (int)(SpeedChange.Value * 10) / 10.0; - - // Offset back to 0. - value -= 1; - - return 1 + value; - } - } + public override double ScoreMultiplier => rateAdjustHelper.ScoreMultiplier; } } diff --git a/osu.Game/Rulesets/Mods/ModNightcore.cs b/osu.Game/Rulesets/Mods/ModNightcore.cs index 520ee6319a..933c9c9fc5 100644 --- a/osu.Game/Rulesets/Mods/ModNightcore.cs +++ b/osu.Game/Rulesets/Mods/ModNightcore.cs @@ -39,8 +39,12 @@ namespace osu.Game.Rulesets.Mods private readonly BindableNumber tempoAdjust = new BindableDouble(1); private readonly BindableNumber freqAdjust = new BindableDouble(1); + private readonly RateAdjustModHelper rateAdjustHelper; + protected ModNightcore() { + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + SpeedChange.BindValueChanged(val => { freqAdjust.Value = SpeedChange.Default; @@ -54,19 +58,7 @@ namespace osu.Game.Rulesets.Mods track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjust); } - public override double ScoreMultiplier - { - get - { - // Round to the nearest multiple of 0.1. - double value = (int)(SpeedChange.Value * 10) / 10.0; - - // Offset back to 0. - value -= 1; - - return 1 + value; - } - } + public override double ScoreMultiplier => rateAdjustHelper.ScoreMultiplier; } public abstract partial class ModNightcore : ModNightcore, IApplicableToDrawableRuleset diff --git a/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs b/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs index a54be77338..034c20fc78 100644 --- a/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs +++ b/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs @@ -6,13 +6,18 @@ using osu.Framework.Bindables; namespace osu.Game.Rulesets.Mods { + /// + /// Provides common functionality shared across various rate adjust mods. + /// public class RateAdjustModHelper : IApplicableToTrack { private readonly BindableBool? adjustPitch; + private readonly BindableNumber speedChange; private IAdjustableAudioComponent? track; - public RateAdjustModHelper(BindableNumber speedChange, BindableBool? adjustPitch) + public RateAdjustModHelper(BindableNumber speedChange, BindableBool? adjustPitch = null) { + this.speedChange = speedChange; this.adjustPitch = adjustPitch; // When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale. @@ -29,8 +34,24 @@ namespace osu.Game.Rulesets.Mods public void ApplyToTrack(IAdjustableAudioComponent track) { this.track = track; - adjustPitch?.TriggerChange(); } + + public double ScoreMultiplier + { + get + { + // Round to the nearest multiple of 0.1. + double value = (int)(speedChange.Value * 10) / 10.0; + + // Offset back to 0. + value -= 1; + + if (speedChange.Value >= 1) + value /= 5; + + return 1 + value; + } + } } }