1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Improve readability

This commit is contained in:
Fabian van Oeffelt 2024-05-22 13:59:33 +02:00
parent abc67ebbac
commit 0df634574f

View File

@ -823,47 +823,89 @@ namespace osu.Game.Screens.Select
return false; return false;
} }
private Mod getRateMod(ModType modType, Type type)
{
var modList = game.AvailableMods.Value[modType];
var multiMod = (MultiMod)modList.First(mod => mod is MultiMod multiMod && multiMod.Mods.Count(mod2 => mod2.GetType().IsSubclassOf(type)) > 0);
var mod = multiMod.Mods.First(mod => mod.GetType().IsSubclassOf(type));
return mod;
}
public void ChangeSpeed(double delta) public void ChangeSpeed(double delta)
{ {
ModNightcore modNc = (ModNightcore)((MultiMod)game.AvailableMods.Value[ModType.DifficultyIncrease].First(mod => mod is MultiMod multiMod && multiMod.Mods.Count(modType => modType is ModNightcore) > 0)).Mods.First(mod => mod is ModNightcore); ModNightcore modNc = (ModNightcore)getRateMod(ModType.DifficultyIncrease, typeof(ModNightcore));
ModDoubleTime modDt = (ModDoubleTime)((MultiMod)game.AvailableMods.Value[ModType.DifficultyIncrease].First(mod => mod is MultiMod multiMod && multiMod.Mods.Count(modType => modType is ModDoubleTime) > 0)).Mods.First(mod => mod is ModDoubleTime); ModDoubleTime modDt = (ModDoubleTime)getRateMod(ModType.DifficultyIncrease, typeof(ModDoubleTime));
ModDaycore modDc = (ModDaycore)((MultiMod)game.AvailableMods.Value[ModType.DifficultyReduction].First(mod => mod is MultiMod multiMod && multiMod.Mods.Count(modType => modType is ModDaycore) > 0)).Mods.First(mod => mod is ModDaycore); ModDaycore modDc = (ModDaycore)getRateMod(ModType.DifficultyReduction, typeof(ModDaycore));
ModHalfTime modHt = (ModHalfTime)((MultiMod)game.AvailableMods.Value[ModType.DifficultyReduction].First(mod => mod is MultiMod multiMod && multiMod.Mods.Count(modType => modType is ModHalfTime) > 0)).Mods.First(mod => mod is ModHalfTime); ModHalfTime modHt = (ModHalfTime)getRateMod(ModType.DifficultyReduction, typeof(ModHalfTime));
bool rateModActive = selectedMods.Value.Count(mod => mod is ModRateAdjust) > 0; bool rateModActive = selectedMods.Value.Count(mod => mod is ModRateAdjust) > 0;
bool incompatibleModActive = selectedMods.Value.Count(mod => modDt.IncompatibleMods.Count(incompatibleMod => (mod.GetType().IsSubclassOf(incompatibleMod) || mod.GetType() == incompatibleMod) && incompatibleMod != typeof(ModRateAdjust)) > 0) > 0; bool incompatibleModActive = selectedMods.Value.Count(mod => modDt.IncompatibleMods.Count(incompatibleMod => (mod.GetType().IsSubclassOf(incompatibleMod) || mod.GetType() == incompatibleMod) && incompatibleMod != typeof(ModRateAdjust)) > 0) > 0;
double newRate = 1d + delta; double newRate = Math.Round(1d + delta, 2);
bool isPositive = delta > 0; bool isPositive = delta > 0;
if (incompatibleModActive) if (incompatibleModActive)
return; return;
onScreenDisplay?.Display(new SpeedChangeToast(config, delta)); if (!rateModActive)
if (rateModActive)
{ {
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
// If no ModRateAdjust is active, activate one
ModRateAdjust? newMod = null;
if (isPositive && !usedPitchMods)
newMod = modDt;
if (isPositive && usedPitchMods)
newMod = modNc;
if (!isPositive && !usedPitchMods)
newMod = modHt;
if (!isPositive && usedPitchMods)
newMod = modDc;
if (!usedPitchMods && newMod is ModDoubleTime newModDt)
newModDt.AdjustPitch.Value = lastPitchState;
if (!usedPitchMods && newMod is ModHalfTime newModHt)
newModHt.AdjustPitch.Value = lastPitchState;
newMod!.SpeedChange.Value = newRate;
selectedMods.Value = selectedMods.Value.Append(newMod).ToList();
return;
}
ModRateAdjust mod = (ModRateAdjust)selectedMods.Value.First(mod => mod is ModRateAdjust); ModRateAdjust mod = (ModRateAdjust)selectedMods.Value.First(mod => mod is ModRateAdjust);
newRate = Math.Round(mod.SpeedChange.Value + delta, 2);
// Find current active rateAdjust mod and modify speed, enable HalfTime if necessary // Disable RateAdjustMods if newRate is 1
newRate = mod.SpeedChange.Value + delta;
if (newRate == 1.0) if (newRate == 1.0)
{ {
lastPitchState = false; lastPitchState = false;
usedPitchMods = false; usedPitchMods = false;
if (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value) lastPitchState = true; if (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value)
lastPitchState = true;
if (mod is ModHalfTime htmod && htmod.AdjustPitch.Value) lastPitchState = true; if (mod is ModHalfTime htmod && htmod.AdjustPitch.Value)
lastPitchState = true;
if (mod is ModNightcore || mod is ModDaycore) usedPitchMods = true; if (mod is ModNightcore || mod is ModDaycore)
usedPitchMods = true;
//Disable RateAdjustMods //Disable RateAdjustMods
selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList(); selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList();
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
return; return;
} }
if (((mod is ModDoubleTime || mod is ModNightcore) && newRate < mod.SpeedChange.MinValue) bool overMaxRateLimit = (mod is ModHalfTime || mod is ModDaycore) && newRate > mod.SpeedChange.MaxValue;
|| ((mod is ModHalfTime || mod is ModDaycore) && newRate > mod.SpeedChange.MaxValue)) bool underMinRateLimit = (mod is ModDoubleTime || mod is ModNightcore) && newRate < mod.SpeedChange.MinValue;
// Swap mod to opposite mod if newRate exceeds max/min speed values
if (overMaxRateLimit || underMinRateLimit)
{ {
bool adjustPitch = (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value) || (mod is ModHalfTime htmod && htmod.AdjustPitch.Value); bool adjustPitch = (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value) || (mod is ModHalfTime htmod && htmod.AdjustPitch.Value);
@ -897,9 +939,13 @@ namespace osu.Game.Screens.Select
oppositeMod.SpeedChange.Value = newRate; oppositeMod.SpeedChange.Value = newRate;
selectedMods.Value = selectedMods.Value.Append(oppositeMod).ToList(); selectedMods.Value = selectedMods.Value.Append(oppositeMod).ToList();
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
return; return;
} }
// Cap newRate to max/min values and change rate of current active mod
if (newRate > mod.SpeedChange.MaxValue && (mod is ModDoubleTime || mod is ModNightcore)) if (newRate > mod.SpeedChange.MaxValue && (mod is ModDoubleTime || mod is ModNightcore))
newRate = mod.SpeedChange.MaxValue; newRate = mod.SpeedChange.MaxValue;
@ -907,39 +953,8 @@ namespace osu.Game.Screens.Select
newRate = mod.SpeedChange.MinValue; newRate = mod.SpeedChange.MinValue;
mod.SpeedChange.Value = newRate; mod.SpeedChange.Value = newRate;
}
else onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
{
// If no ModRateAdjust is active, activate one
if (isPositive)
{
if (!usedPitchMods)
{
modDt.SpeedChange.Value = newRate;
modDt.AdjustPitch.Value = lastPitchState;
selectedMods.Value = selectedMods.Value.Append(modDt).ToList();
}
else
{
modNc.SpeedChange.Value = newRate;
selectedMods.Value = selectedMods.Value.Append(modNc).ToList();
}
}
else
{
if (!usedPitchMods)
{
modHt.SpeedChange.Value = newRate;
modHt.AdjustPitch.Value = lastPitchState;
selectedMods.Value = selectedMods.Value.Append(modHt).ToList();
}
else
{
modDc.SpeedChange.Value = newRate;
selectedMods.Value = selectedMods.Value.Append(modDc).ToList();
}
}
}
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)