mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Improve readability
This commit is contained in:
parent
abc67ebbac
commit
0df634574f
@ -823,123 +823,138 @@ 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)
|
|
||||||
{
|
{
|
||||||
ModRateAdjust mod = (ModRateAdjust)selectedMods.Value.First(mod => mod is ModRateAdjust);
|
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
|
||||||
|
|
||||||
// Find current active rateAdjust mod and modify speed, enable HalfTime if necessary
|
|
||||||
newRate = mod.SpeedChange.Value + delta;
|
|
||||||
|
|
||||||
if (newRate == 1.0)
|
|
||||||
{
|
|
||||||
lastPitchState = false;
|
|
||||||
usedPitchMods = false;
|
|
||||||
|
|
||||||
if (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value) lastPitchState = true;
|
|
||||||
|
|
||||||
if (mod is ModHalfTime htmod && htmod.AdjustPitch.Value) lastPitchState = true;
|
|
||||||
|
|
||||||
if (mod is ModNightcore || mod is ModDaycore) usedPitchMods = true;
|
|
||||||
|
|
||||||
//Disable RateAdjustMods
|
|
||||||
selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((mod is ModDoubleTime || mod is ModNightcore) && newRate < mod.SpeedChange.MinValue)
|
|
||||||
|| ((mod is ModHalfTime || mod is ModDaycore) && newRate > mod.SpeedChange.MaxValue))
|
|
||||||
{
|
|
||||||
bool adjustPitch = (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value) || (mod is ModHalfTime htmod && htmod.AdjustPitch.Value);
|
|
||||||
|
|
||||||
//Disable RateAdjustMods
|
|
||||||
selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList();
|
|
||||||
|
|
||||||
ModRateAdjust? oppositeMod = null;
|
|
||||||
|
|
||||||
switch (mod)
|
|
||||||
{
|
|
||||||
case ModDoubleTime:
|
|
||||||
modHt.AdjustPitch.Value = adjustPitch;
|
|
||||||
oppositeMod = modHt;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ModHalfTime:
|
|
||||||
modDt.AdjustPitch.Value = adjustPitch;
|
|
||||||
oppositeMod = modDt;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ModNightcore:
|
|
||||||
oppositeMod = modDc;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ModDaycore:
|
|
||||||
oppositeMod = modNc;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oppositeMod == null) return;
|
|
||||||
|
|
||||||
oppositeMod.SpeedChange.Value = newRate;
|
|
||||||
selectedMods.Value = selectedMods.Value.Append(oppositeMod).ToList();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newRate > mod.SpeedChange.MaxValue && (mod is ModDoubleTime || mod is ModNightcore))
|
|
||||||
newRate = mod.SpeedChange.MaxValue;
|
|
||||||
|
|
||||||
if (newRate < mod.SpeedChange.MinValue && (mod is ModHalfTime || mod is ModDaycore))
|
|
||||||
newRate = mod.SpeedChange.MinValue;
|
|
||||||
|
|
||||||
mod.SpeedChange.Value = newRate;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If no ModRateAdjust is active, activate one
|
// If no ModRateAdjust is active, activate one
|
||||||
if (isPositive)
|
ModRateAdjust? newMod = null;
|
||||||
{
|
|
||||||
if (!usedPitchMods)
|
if (isPositive && !usedPitchMods)
|
||||||
{
|
newMod = modDt;
|
||||||
modDt.SpeedChange.Value = newRate;
|
|
||||||
modDt.AdjustPitch.Value = lastPitchState;
|
if (isPositive && usedPitchMods)
|
||||||
selectedMods.Value = selectedMods.Value.Append(modDt).ToList();
|
newMod = modNc;
|
||||||
}
|
|
||||||
else
|
if (!isPositive && !usedPitchMods)
|
||||||
{
|
newMod = modHt;
|
||||||
modNc.SpeedChange.Value = newRate;
|
|
||||||
selectedMods.Value = selectedMods.Value.Append(modNc).ToList();
|
if (!isPositive && usedPitchMods)
|
||||||
}
|
newMod = modDc;
|
||||||
}
|
|
||||||
else
|
if (!usedPitchMods && newMod is ModDoubleTime newModDt)
|
||||||
{
|
newModDt.AdjustPitch.Value = lastPitchState;
|
||||||
if (!usedPitchMods)
|
|
||||||
{
|
if (!usedPitchMods && newMod is ModHalfTime newModHt)
|
||||||
modHt.SpeedChange.Value = newRate;
|
newModHt.AdjustPitch.Value = lastPitchState;
|
||||||
modHt.AdjustPitch.Value = lastPitchState;
|
|
||||||
selectedMods.Value = selectedMods.Value.Append(modHt).ToList();
|
newMod!.SpeedChange.Value = newRate;
|
||||||
}
|
selectedMods.Value = selectedMods.Value.Append(newMod).ToList();
|
||||||
else
|
return;
|
||||||
{
|
|
||||||
modDc.SpeedChange.Value = newRate;
|
|
||||||
selectedMods.Value = selectedMods.Value.Append(modDc).ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModRateAdjust mod = (ModRateAdjust)selectedMods.Value.First(mod => mod is ModRateAdjust);
|
||||||
|
newRate = Math.Round(mod.SpeedChange.Value + delta, 2);
|
||||||
|
|
||||||
|
// Disable RateAdjustMods if newRate is 1
|
||||||
|
if (newRate == 1.0)
|
||||||
|
{
|
||||||
|
lastPitchState = false;
|
||||||
|
usedPitchMods = false;
|
||||||
|
|
||||||
|
if (mod is ModDoubleTime dtmod && dtmod.AdjustPitch.Value)
|
||||||
|
lastPitchState = true;
|
||||||
|
|
||||||
|
if (mod is ModHalfTime htmod && htmod.AdjustPitch.Value)
|
||||||
|
lastPitchState = true;
|
||||||
|
|
||||||
|
if (mod is ModNightcore || mod is ModDaycore)
|
||||||
|
usedPitchMods = true;
|
||||||
|
|
||||||
|
//Disable RateAdjustMods
|
||||||
|
selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList();
|
||||||
|
|
||||||
|
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool overMaxRateLimit = (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);
|
||||||
|
|
||||||
|
//Disable RateAdjustMods
|
||||||
|
selectedMods.Value = selectedMods.Value.Where(search => search is not ModRateAdjust).ToList();
|
||||||
|
|
||||||
|
ModRateAdjust? oppositeMod = null;
|
||||||
|
|
||||||
|
switch (mod)
|
||||||
|
{
|
||||||
|
case ModDoubleTime:
|
||||||
|
modHt.AdjustPitch.Value = adjustPitch;
|
||||||
|
oppositeMod = modHt;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ModHalfTime:
|
||||||
|
modDt.AdjustPitch.Value = adjustPitch;
|
||||||
|
oppositeMod = modDt;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ModNightcore:
|
||||||
|
oppositeMod = modDc;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ModDaycore:
|
||||||
|
oppositeMod = modNc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oppositeMod == null) return;
|
||||||
|
|
||||||
|
oppositeMod.SpeedChange.Value = newRate;
|
||||||
|
selectedMods.Value = selectedMods.Value.Append(oppositeMod).ToList();
|
||||||
|
|
||||||
|
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
|
||||||
|
|
||||||
|
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))
|
||||||
|
newRate = mod.SpeedChange.MaxValue;
|
||||||
|
|
||||||
|
if (newRate < mod.SpeedChange.MinValue && (mod is ModHalfTime || mod is ModDaycore))
|
||||||
|
newRate = mod.SpeedChange.MinValue;
|
||||||
|
|
||||||
|
mod.SpeedChange.Value = newRate;
|
||||||
|
|
||||||
|
onScreenDisplay?.Display(new SpeedChangeToast(config, newRate));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
Loading…
Reference in New Issue
Block a user