1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 23:03:21 +08:00

Improve code quality

This commit is contained in:
Givikap120 2023-11-04 17:25:09 +02:00
parent 1a70110a4e
commit 57170501cd
8 changed files with 76 additions and 153 deletions

View File

@ -238,37 +238,14 @@ namespace osu.Game.Rulesets.Catch
public float ArFromPreempt(double preempt) => (float)(preempt > 1200 ? ((1800 - preempt) / 120) : ((1200 - preempt) / 150)) + 5; public float ArFromPreempt(double preempt) => (float)(preempt > 1200 ? ((1800 - preempt) / 120) : ((1200 - preempt) / 150)) + 5;
public float ChangeArFromRate(float AR, double rate) => ArFromPreempt(PreemptFromAr(AR) / rate); public float ChangeArFromRate(float AR, double rate) => ArFromPreempt(PreemptFromAr(AR) / rate);
public override BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo) public override BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate)
{ {
BeatmapDifficulty? adjustedDifficulty = null; BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
if (mods.Any(m => m is IApplicableToDifficulty)) adjustedDifficulty.ApproachRate = ChangeArFromRate(adjustedDifficulty.ApproachRate, rate);
{
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
}
if (mods.Any(m => m is ModRateAdjust))
{
adjustedDifficulty ??= new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<ModRateAdjust>())
{
double speedChange = (float)mod.SpeedChange.Value;
float ar = adjustedDifficulty.ApproachRate;
float od = adjustedDifficulty.OverallDifficulty;
adjustedDifficulty.ApproachRate = ChangeArFromRate(ar, speedChange);
rateAdjustedInfo.AR = GetRateAdjustType(ar, adjustedDifficulty.ApproachRate);
}
}
return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty; return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty;
} }
} }
} }

View File

@ -431,34 +431,12 @@ namespace osu.Game.Rulesets.Mania
public double HitwindowFromOd(float OD) => 64.0 - 3 * OD; public double HitwindowFromOd(float OD) => 64.0 - 3 * OD;
public float OdFromHitwindow(double hitwindow300) => (float)(64.0 - hitwindow300) / 3; public float OdFromHitwindow(double hitwindow300) => (float)(64.0 - hitwindow300) / 3;
public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate); public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate);
public override BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo)
public override BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate)
{ {
BeatmapDifficulty? adjustedDifficulty = null; BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
if (mods.Any(m => m is IApplicableToDifficulty)) adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
{
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
}
if (mods.Any(m => m is ModRateAdjust))
{
adjustedDifficulty ??= new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<ModRateAdjust>())
{
double speedChange = (float)mod.SpeedChange.Value;
float od = adjustedDifficulty.OverallDifficulty;
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(od, speedChange);
rateAdjustedInfo.OD = GetRateAdjustType(od, adjustedDifficulty.OverallDifficulty);
}
}
return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty; return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty;
} }

View File

@ -335,37 +335,12 @@ namespace osu.Game.Rulesets.Osu
public float OdFromHitwindow(double hitwindow300) => (float)(80.0 - hitwindow300) / 6; public float OdFromHitwindow(double hitwindow300) => (float)(80.0 - hitwindow300) / 6;
public float ChangeArFromRate(float AR, double rate) => ArFromPreempt(PreemptFromAr(AR) / rate); public float ChangeArFromRate(float AR, double rate) => ArFromPreempt(PreemptFromAr(AR) / rate);
public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate); public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate);
public override BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo) public override BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate)
{ {
BeatmapDifficulty? adjustedDifficulty = null; BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
if (mods.Any(m => m is IApplicableToDifficulty)) adjustedDifficulty.ApproachRate = ChangeArFromRate(adjustedDifficulty.ApproachRate, rate);
{ adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
}
if (mods.Any(m => m is ModRateAdjust))
{
adjustedDifficulty ??= new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<ModRateAdjust>())
{
double speedChange = (float)mod.SpeedChange.Value;
float ar = adjustedDifficulty.ApproachRate;
float od = adjustedDifficulty.OverallDifficulty;
adjustedDifficulty.ApproachRate = ChangeArFromRate(ar, speedChange);
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(od, speedChange);
rateAdjustedInfo.AR = GetRateAdjustType(ar, adjustedDifficulty.ApproachRate);
rateAdjustedInfo.OD = GetRateAdjustType(od, adjustedDifficulty.OverallDifficulty);
}
}
return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty; return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty;
} }

View File

@ -266,34 +266,12 @@ namespace osu.Game.Rulesets.Taiko
public double HitwindowFromOd(float OD) => 35.0 - 15.0 * (OD - 5) / 5; public double HitwindowFromOd(float OD) => 35.0 - 15.0 * (OD - 5) / 5;
public float OdFromHitwindow(double hitwindow300) => (float)(5 * (35 - hitwindow300) / 15 + 5); public float OdFromHitwindow(double hitwindow300) => (float)(5 * (35 - hitwindow300) / 15 + 5);
public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate); public float ChangeOdFromRate(float OD, double rate) => OdFromHitwindow(HitwindowFromOd(OD) / rate);
public override BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo)
public override BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate)
{ {
BeatmapDifficulty? adjustedDifficulty = null; BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
if (mods.Any(m => m is IApplicableToDifficulty)) adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
{
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
}
if (mods.Any(m => m is ModRateAdjust))
{
adjustedDifficulty ??= new BeatmapDifficulty(baseDifficulty);
foreach (var mod in mods.OfType<ModRateAdjust>())
{
double speedChange = (float)mod.SpeedChange.Value;
float od = adjustedDifficulty.OverallDifficulty;
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(od, speedChange);
rateAdjustedInfo.OD = GetRateAdjustType(od, adjustedDifficulty.OverallDifficulty);
}
}
return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty; return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty;
} }

View File

@ -251,17 +251,21 @@ namespace osu.Game.Overlays.Mods
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate; bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
(Ruleset.RateAdjustType AR, Ruleset.RateAdjustType OD) rateAdjustType = (Ruleset.RateAdjustType.NotChanged, Ruleset.RateAdjustType.NotChanged); var moddedDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(moddedDifficulty);
Ruleset ruleset = gameRuleset.Value.CreateInstance(); Ruleset ruleset = gameRuleset.Value.CreateInstance();
BeatmapDifficulty adjustedDifficulty = ruleset.GetEffectiveDifficulty(BeatmapInfo.Value.Difficulty, mods.Value, ref rateAdjustType); var rateAdjustedDifficulty = ruleset.GetRateAdjustedDifficulty(moddedDifficulty, rate);
approachRateDisplay.RateChangeType.Value = rateAdjustType.AR;
overallDifficultyDisplay.RateChangeType.Value = rateAdjustType.OD;
circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize; approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.ApproachRate, rateAdjustedDifficulty.ApproachRate);
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate; overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.OverallDifficulty, rateAdjustedDifficulty.OverallDifficulty);
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty; circleSizeDisplay.Current.Value = rateAdjustedDifficulty.CircleSize;
drainRateDisplay.Current.Value = rateAdjustedDifficulty.DrainRate;
approachRateDisplay.Current.Value = rateAdjustedDifficulty.ApproachRate;
overallDifficultyDisplay.Current.Value = rateAdjustedDifficulty.OverallDifficulty;
}); });
private void updateCollapsedState() private void updateCollapsedState()

View File

@ -12,7 +12,6 @@ using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osuTK.Graphics; using osuTK.Graphics;
@ -28,7 +27,7 @@ namespace osu.Game.Overlays.Mods
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>(); private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
public Bindable<Ruleset.RateAdjustType> RateChangeType = new Bindable<Ruleset.RateAdjustType>(Ruleset.RateAdjustType.NotChanged); public Bindable<ModEffect> AdjustType = new Bindable<ModEffect>();
/// <summary> /// <summary>
/// Text to display in the top area of the display. /// Text to display in the top area of the display.
@ -43,22 +42,22 @@ namespace osu.Game.Overlays.Mods
private void updateTextColor() private void updateTextColor()
{ {
Color4 newColor; Color4 newColor;
switch (RateChangeType.Value) switch (AdjustType.Value)
{ {
case Ruleset.RateAdjustType.NotChanged: case ModEffect.NotChanged:
newColor = Color4.White; newColor = Color4.White;
break; break;
case Ruleset.RateAdjustType.DifficultyReduction: case ModEffect.DifficultyReduction:
newColor = colours.ForModType(ModType.DifficultyReduction); newColor = colours.ForModType(ModType.DifficultyReduction);
break; break;
case Ruleset.RateAdjustType.DifficultyIncrease: case ModEffect.DifficultyIncrease:
newColor = colours.ForModType(ModType.DifficultyIncrease); newColor = colours.ForModType(ModType.DifficultyIncrease);
break; break;
default: default:
throw new ArgumentOutOfRangeException(nameof(RateChangeType.Value)); throw new ArgumentOutOfRangeException(nameof(AdjustType.Value));
} }
text.Colour = newColor; text.Colour = newColor;
@ -74,7 +73,7 @@ namespace osu.Game.Overlays.Mods
Origin = Anchor.CentreLeft; Origin = Anchor.CentreLeft;
Anchor = Anchor.CentreLeft; Anchor = Anchor.CentreLeft;
RateChangeType.BindValueChanged(_ => updateTextColor()); AdjustType.BindValueChanged(_ => updateTextColor());
InternalChild = new FillFlowContainer InternalChild = new FillFlowContainer
{ {
@ -101,6 +100,24 @@ namespace osu.Game.Overlays.Mods
} }
}; };
} }
public static ModEffect CalculateEffect(double oldValue, double newValue)
{
if (newValue == oldValue)
return ModEffect.NotChanged;
if (newValue < oldValue)
return ModEffect.DifficultyReduction;
return ModEffect.DifficultyIncrease;
}
public enum ModEffect
{
NotChanged,
DifficultyReduction,
DifficultyIncrease,
}
private partial class EffectCounter : RollingCounter<double> private partial class EffectCounter : RollingCounter<double>
{ {
protected override double RollingDuration => 500; protected override double RollingDuration => 500;

View File

@ -389,21 +389,6 @@ namespace osu.Game.Rulesets
/// Can be overridden to alter the difficulty section to the editor beatmap setup screen. /// Can be overridden to alter the difficulty section to the editor beatmap setup screen.
/// </summary> /// </summary>
public virtual DifficultySection? CreateEditorDifficultySection() => null; public virtual DifficultySection? CreateEditorDifficultySection() => null;
public virtual BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo) => (BeatmapDifficulty)baseDifficulty; public virtual BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate) => new BeatmapDifficulty(baseDifficulty);
public enum RateAdjustType
{
NotChanged,
DifficultyReduction,
DifficultyIncrease
}
protected RateAdjustType GetRateAdjustType(float baseValue, float adjustedValue)
{
if (adjustedValue > baseValue)
return RateAdjustType.DifficultyIncrease;
if (adjustedValue < baseValue)
return RateAdjustType.DifficultyReduction;
return RateAdjustType.NotChanged;
}
} }
} }

View File

@ -24,6 +24,7 @@ using osu.Framework.Utils;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using System.Linq;
namespace osu.Game.Screens.Select.Details namespace osu.Game.Screens.Select.Details
{ {
@ -116,12 +117,21 @@ namespace osu.Game.Screens.Select.Details
{ {
IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty; IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty;
BeatmapDifficulty adjustedDifficulty = null; BeatmapDifficulty adjustedDifficulty = null;
(Ruleset.RateAdjustType AR, Ruleset.RateAdjustType OD) rateAdjustInfo = (Ruleset.RateAdjustType.NotChanged, Ruleset.RateAdjustType.NotChanged);
if (baseDifficulty != null) if (baseDifficulty != null)
{ {
Ruleset ruleset = gameRuleset.Value.CreateInstance(); adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
adjustedDifficulty = ruleset.GetEffectiveDifficulty(baseDifficulty, mods.Value, ref rateAdjustInfo);
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
// For now we not using rate adjusted difficulty here
//Ruleset ruleset = gameRuleset.Value.CreateInstance();
//double rate = 1;
//foreach (var mod in mods.Value.OfType<IApplicableToRate>())
// rate = mod.ApplyToRate(0, rate);
//adjustedDifficulty = ruleset.GetRateAdjustedDifficulty(adjustedDifficulty, rate);
} }
switch (BeatmapInfo?.Ruleset.OnlineID) switch (BeatmapInfo?.Ruleset.OnlineID)
@ -130,18 +140,18 @@ namespace osu.Game.Screens.Select.Details
// Account for mania differences locally for now // Account for mania differences locally for now
// Eventually this should be handled in a more modular way, allowing rulesets to return arbitrary difficulty attributes // Eventually this should be handled in a more modular way, allowing rulesets to return arbitrary difficulty attributes
FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania; FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania;
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, null, false); FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, null);
break; break;
default: default:
FirstValue.Title = BeatmapsetsStrings.ShowStatsCs; FirstValue.Title = BeatmapsetsStrings.ShowStatsCs;
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, adjustedDifficulty?.CircleSize, false); FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, adjustedDifficulty?.CircleSize);
break; break;
} }
HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate, false); HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate);
Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty, rateAdjustInfo.OD != Ruleset.RateAdjustType.NotChanged); Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty);
ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate, rateAdjustInfo.OD != Ruleset.RateAdjustType.NotChanged); ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate);
updateStarDifficulty(); updateStarDifficulty();
} }
@ -175,7 +185,7 @@ namespace osu.Game.Screens.Select.Details
if (normalDifficulty == null || moddedDifficulty == null) if (normalDifficulty == null || moddedDifficulty == null)
return; return;
starDifficulty.Value = ((float)normalDifficulty.Value.Stars, (float)moddedDifficulty.Value.Stars, false); starDifficulty.Value = ((float)normalDifficulty.Value.Stars, (float)moddedDifficulty.Value.Stars);
}), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current); }), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);
}); });
@ -206,11 +216,11 @@ namespace osu.Game.Screens.Select.Details
set => name.Text = value; set => name.Text = value;
} }
private (float baseValue, float? adjustedValue, bool isRateAdjusted)? value; private (float baseValue, float? adjustedValue)? value;
public (float baseValue, float? adjustedValue, bool isRateAdjusted) Value public (float baseValue, float? adjustedValue) Value
{ {
get => value ?? (0, null, false); get => value ?? (0, null);
set set
{ {
if (value == this.value) if (value == this.value)
@ -221,7 +231,6 @@ namespace osu.Game.Screens.Select.Details
bar.Length = value.baseValue / maxValue; bar.Length = value.baseValue / maxValue;
valueText.Text = (value.adjustedValue ?? value.baseValue).ToString(forceDecimalPlaces ? "0.00" : "0.##"); valueText.Text = (value.adjustedValue ?? value.baseValue).ToString(forceDecimalPlaces ? "0.00" : "0.##");
if (value.isRateAdjusted) valueText.Text += "*";
ModBar.Length = (value.adjustedValue ?? 0) / maxValue; ModBar.Length = (value.adjustedValue ?? 0) / maxValue;
if (Precision.AlmostEquals(value.baseValue, value.adjustedValue ?? value.baseValue, 0.05f)) if (Precision.AlmostEquals(value.baseValue, value.adjustedValue ?? value.baseValue, 0.05f))