1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 05:22:54 +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 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;
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
if (mods.Any(m => m is IApplicableToDifficulty))
{
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);
}
}
adjustedDifficulty.ApproachRate = ChangeArFromRate(adjustedDifficulty.ApproachRate, rate);
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 float OdFromHitwindow(double hitwindow300) => (float)(64.0 - hitwindow300) / 3;
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;
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
if (mods.Any(m => m is IApplicableToDifficulty))
{
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);
}
}
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
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 ChangeArFromRate(float AR, double rate) => ArFromPreempt(PreemptFromAr(AR) / 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;
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
if (mods.Any(m => m is IApplicableToDifficulty))
{
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);
}
}
adjustedDifficulty.ApproachRate = ChangeArFromRate(adjustedDifficulty.ApproachRate, rate);
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
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 float OdFromHitwindow(double hitwindow300) => (float)(5 * (35 - hitwindow300) / 15 + 5);
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;
rateAdjustedInfo = (RateAdjustType.NotChanged, RateAdjustType.NotChanged);
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
if (mods.Any(m => m is IApplicableToDifficulty))
{
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);
}
}
adjustedDifficulty.OverallDifficulty = ChangeOdFromRate(adjustedDifficulty.OverallDifficulty, rate);
return adjustedDifficulty ?? (BeatmapDifficulty)baseDifficulty;
}

View File

@ -251,17 +251,21 @@ namespace osu.Game.Overlays.Mods
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();
BeatmapDifficulty adjustedDifficulty = ruleset.GetEffectiveDifficulty(BeatmapInfo.Value.Difficulty, mods.Value, ref rateAdjustType);
approachRateDisplay.RateChangeType.Value = rateAdjustType.AR;
overallDifficultyDisplay.RateChangeType.Value = rateAdjustType.OD;
var rateAdjustedDifficulty = ruleset.GetRateAdjustedDifficulty(moddedDifficulty, rate);
circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize;
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.ApproachRate, rateAdjustedDifficulty.ApproachRate);
overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.OverallDifficulty, rateAdjustedDifficulty.OverallDifficulty);
circleSizeDisplay.Current.Value = rateAdjustedDifficulty.CircleSize;
drainRateDisplay.Current.Value = rateAdjustedDifficulty.DrainRate;
approachRateDisplay.Current.Value = rateAdjustedDifficulty.ApproachRate;
overallDifficultyDisplay.Current.Value = rateAdjustedDifficulty.OverallDifficulty;
});
private void updateCollapsedState()

View File

@ -12,7 +12,6 @@ using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osuTK.Graphics;
@ -28,7 +27,7 @@ namespace osu.Game.Overlays.Mods
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>
/// Text to display in the top area of the display.
@ -43,22 +42,22 @@ namespace osu.Game.Overlays.Mods
private void updateTextColor()
{
Color4 newColor;
switch (RateChangeType.Value)
switch (AdjustType.Value)
{
case Ruleset.RateAdjustType.NotChanged:
case ModEffect.NotChanged:
newColor = Color4.White;
break;
case Ruleset.RateAdjustType.DifficultyReduction:
case ModEffect.DifficultyReduction:
newColor = colours.ForModType(ModType.DifficultyReduction);
break;
case Ruleset.RateAdjustType.DifficultyIncrease:
case ModEffect.DifficultyIncrease:
newColor = colours.ForModType(ModType.DifficultyIncrease);
break;
default:
throw new ArgumentOutOfRangeException(nameof(RateChangeType.Value));
throw new ArgumentOutOfRangeException(nameof(AdjustType.Value));
}
text.Colour = newColor;
@ -74,7 +73,7 @@ namespace osu.Game.Overlays.Mods
Origin = Anchor.CentreLeft;
Anchor = Anchor.CentreLeft;
RateChangeType.BindValueChanged(_ => updateTextColor());
AdjustType.BindValueChanged(_ => updateTextColor());
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>
{
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.
/// </summary>
public virtual DifficultySection? CreateEditorDifficultySection() => null;
public virtual BeatmapDifficulty GetEffectiveDifficulty(IBeatmapDifficultyInfo baseDifficulty, IReadOnlyList<Mod> mods, ref (RateAdjustType AR, RateAdjustType OD) rateAdjustedInfo) => (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;
}
public virtual BeatmapDifficulty GetRateAdjustedDifficulty(IBeatmapDifficultyInfo baseDifficulty, double rate) => new BeatmapDifficulty(baseDifficulty);
}
}

View File

@ -24,6 +24,7 @@ using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using System.Linq;
namespace osu.Game.Screens.Select.Details
{
@ -116,12 +117,21 @@ namespace osu.Game.Screens.Select.Details
{
IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty;
BeatmapDifficulty adjustedDifficulty = null;
(Ruleset.RateAdjustType AR, Ruleset.RateAdjustType OD) rateAdjustInfo = (Ruleset.RateAdjustType.NotChanged, Ruleset.RateAdjustType.NotChanged);
if (baseDifficulty != null)
{
Ruleset ruleset = gameRuleset.Value.CreateInstance();
adjustedDifficulty = ruleset.GetEffectiveDifficulty(baseDifficulty, mods.Value, ref rateAdjustInfo);
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
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)
@ -130,18 +140,18 @@ namespace osu.Game.Screens.Select.Details
// Account for mania differences locally for now
// Eventually this should be handled in a more modular way, allowing rulesets to return arbitrary difficulty attributes
FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania;
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, null, false);
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, null);
break;
default:
FirstValue.Title = BeatmapsetsStrings.ShowStatsCs;
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, adjustedDifficulty?.CircleSize, false);
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, adjustedDifficulty?.CircleSize);
break;
}
HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate, false);
Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty, rateAdjustInfo.OD != Ruleset.RateAdjustType.NotChanged);
ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate, rateAdjustInfo.OD != Ruleset.RateAdjustType.NotChanged);
HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate);
Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty);
ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate);
updateStarDifficulty();
}
@ -175,7 +185,7 @@ namespace osu.Game.Screens.Select.Details
if (normalDifficulty == null || moddedDifficulty == null)
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);
});
@ -206,11 +216,11 @@ namespace osu.Game.Screens.Select.Details
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
{
if (value == this.value)
@ -221,7 +231,6 @@ namespace osu.Game.Screens.Select.Details
bar.Length = value.baseValue / maxValue;
valueText.Text = (value.adjustedValue ?? value.baseValue).ToString(forceDecimalPlaces ? "0.00" : "0.##");
if (value.isRateAdjusted) valueText.Text += "*";
ModBar.Length = (value.adjustedValue ?? 0) / maxValue;
if (Precision.AlmostEquals(value.baseValue, value.adjustedValue ?? value.baseValue, 0.05f))