Skip to content

Commit

Permalink
change to single Function,
Browse files Browse the repository at this point in the history
Nightcore now switches into Daycore, keep Adjustpitch after change
  • Loading branch information
Fabian van Oeffelt committed May 18, 2024
1 parent 99f30d9 commit 3fdbd73
Showing 1 changed file with 106 additions and 70 deletions.
176 changes: 106 additions & 70 deletions osu.Game/Screens/Select/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind
new OsuMenuItem(@"Select", MenuItemType.Highlighted, () => FinaliseSelection(getBeatmap()))
};

[Resolved]
private OsuGameBase? game { get; set; }

[Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;

Expand Down Expand Up @@ -144,6 +147,10 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind

private Bindable<bool> configBackgroundBlur = null!;

private bool lastPitchState;

private bool usedPitchMods;

[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog? manageCollectionsDialog, DifficultyRecommender? recommender, OsuConfigManager config)
{
Expand Down Expand Up @@ -809,94 +816,123 @@ public override bool OnBackButton()
return false;
}

private void increaseSpeed()
public void ChangeSpeed(double delta)
{
var rateAdjustStates = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust);
var stateDoubleTime = ModSelect.AllAvailableMods.First(pair => pair.Mod is ModDoubleTime);
bool rateModActive = ModSelect.AllAvailableMods.Count(pair => pair.Mod is ModRateAdjust && pair.Active.Value) > 0;
const double stepsize = 0.05d;
double newRate = 1d + stepsize;

// If no mod rateAdjust mod is currently active activate DoubleTime with speed newRate
if (!rateModActive)
{
stateDoubleTime.Active.Value = true;
((ModDoubleTime)stateDoubleTime.Mod).SpeedChange.Value = newRate;
// Mod Change from 0.95 DC to 1.0 none to 1.05 DT/NC ?

if (game == null) return;

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);
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);
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);
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);
bool rateModActive = selectedMods.Value.Count(mod => mod is ModRateAdjust) > 0;
bool incompatiableModActive = selectedMods.Value.Count(mod => modDt.IncompatibleMods.Count(incompatibleMod => (mod.GetType().IsSubclassOf(incompatibleMod) || mod.GetType() == incompatibleMod) && incompatibleMod != typeof(ModRateAdjust)) > 0) > 0;
double newRate = 1d + delta;
bool isPositive = delta > 0;

if (incompatiableModActive)
return;
}

// Find current active rateAdjust mod and modify speed, enable DoubleTime if necessary
foreach (var state in rateAdjustStates)
if (rateModActive)
{
ModRateAdjust mod = (ModRateAdjust)state.Mod;
ModRateAdjust mod = (ModRateAdjust)selectedMods.Value.First(mod => mod is ModRateAdjust);

if (!state.Active.Value) continue;
// Find current active rateAdjust mod and modify speed, enable HalfTime if necessary
newRate = mod.SpeedChange.Value + delta;

newRate = mod.SpeedChange.Value + stepsize;
if (newRate == 1.0)
{
lastPitchState = false;
usedPitchMods = false;

if (mod.Acronym == "DT" || mod.Acronym == "NC")
mod.SpeedChange.Value = newRate;
else
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))
{
if (newRate == 1.0d)
state.Active.Value = false;
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();

if (newRate > 1d)
ModRateAdjust? oppositeMod = null;

switch (mod)
{
state.Active.Value = false;
stateDoubleTime.Active.Value = true;
((ModDoubleTime)stateDoubleTime.Mod).SpeedChange.Value = newRate;
break;
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 (newRate < 1d)
mod.SpeedChange.Value = newRate;
}
}
}
if (oppositeMod == null) return;

private void decreaseSpeed()
{
var rateAdjustStates = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust);
var stateHalfTime = ModSelect.AllAvailableMods.First(pair => pair.Mod is ModHalfTime);
bool rateModActive = ModSelect.AllAvailableMods.Count(pair => pair.Mod is ModRateAdjust && pair.Active.Value) > 0;
const double stepsize = 0.05d;
double newRate = 1d - stepsize;

// If no mod rateAdjust mod is currently active activate HalfTime with speed newRate
if (!rateModActive)
{
stateHalfTime.Active.Value = true;
((ModHalfTime)stateHalfTime.Mod).SpeedChange.Value = newRate;
return;
}

// Find current active rateAdjust mod and modify speed, enable HalfTime if necessary
foreach (var state in rateAdjustStates)
{
ModRateAdjust mod = (ModRateAdjust)state.Mod;
oppositeMod.SpeedChange.Value = newRate;
selectedMods.Value = selectedMods.Value.Append(oppositeMod).ToList();
return;
}

if (!state.Active.Value) continue;
if (newRate > mod.SpeedChange.MaxValue && (mod is ModDoubleTime || mod is ModNightcore))
newRate = mod.SpeedChange.MaxValue;

newRate = mod.SpeedChange.Value - stepsize;
if (newRate < mod.SpeedChange.MinValue && (mod is ModHalfTime || mod is ModDaycore))
newRate = mod.SpeedChange.MinValue;

if (mod.Acronym == "HT" || mod.Acronym == "DC")
mod.SpeedChange.Value = newRate;
mod.SpeedChange.Value = newRate;
}
else
{
// If no ModRateAdjust is actived 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 (newRate == 1.0d)
state.Active.Value = false;

if (newRate < 1d)
if (!usedPitchMods)
{
state.Active.Value = false;
stateHalfTime.Active.Value = true;
((ModHalfTime)stateHalfTime.Mod).SpeedChange.Value = newRate;
break;
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();
}

if (newRate > 1d)
mod.SpeedChange.Value = newRate;
}
}
}
Expand Down Expand Up @@ -1111,11 +1147,11 @@ public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
return true;

case GlobalAction.IncreaseSpeed:
increaseSpeed();
ChangeSpeed(0.05);
return true;

case GlobalAction.DecreaseSpeed:
decreaseSpeed();
ChangeSpeed(-0.05);
return true;
}

Expand Down

0 comments on commit 3fdbd73

Please sign in to comment.