Skip to content

Commit

Permalink
feat(ModAudioPreview): add enabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Apr 16, 2024
1 parent 44f5303 commit be314c4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
30 changes: 30 additions & 0 deletions Osu.Patcher.Hook/Patches/Mods/AudioPreview/AudioPreviewOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Osu.Stubs.GameModes.Options;
using Osu.Stubs.Wrappers;

namespace Osu.Patcher.Hook.Patches.Mods.AudioPreview;

[UsedImplicitly]
internal class AudioPreviewOptions : PatchOptions
{
/// <summary>
/// Global toggle for disabling and enabling the patch.
/// </summary>
public static readonly BindableWrapper<bool> Enabled =
new(BindableType.Bool, false, Settings.Default.EnableModAudioPreview);

public override IEnumerable<object> CreateOptions() =>
[
OptionCheckbox.Constructor.Invoke([
/* title: */ "Apply DT/NC/HT audio effects live",
/* tooltip: */ "Applies the speed & pitch modifiers during song selection, like osu!lazer.",
/* binding: */ Enabled.Bindable,
/* onChange: */ new EventHandler((_, _) => ModAudioEffects.ApplyModEffects(!Enabled.Value)),
]),
];

public override void Load(Settings config) => Enabled.Value = config.EnableModAudioPreview;
public override void Save(Settings config) => config.EnableModAudioPreview = Enabled.Value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ internal static class ModAudioEffects
/// <summary>
/// Applies the audio changes to the AudioEngine based on the current global mods.
/// </summary>
internal static void ApplyModEffects()
internal static void ApplyModEffects(bool clear = false)
{
ResetChanges();
if (clear) return;

var mods = ModManager.ModStatus.Get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ internal class ModSelectAudioPreview

[UsedImplicitly]
[HarmonyPostfix]
private static void After() => Task.Run(ModAudioEffects.ApplyModEffects);
private static void After()
{
if (!AudioPreviewOptions.Enabled.Value)
return;

Task.Run(() => ModAudioEffects.ApplyModEffects());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ public class TrackUpdatePreviewMusic

[HarmonyPostfix]
[UsedImplicitly]
private static void After() => Task.Run(ModAudioEffects.ApplyModEffects);
private static void After()
{
if (!AudioPreviewOptions.Enabled.Value)
return;

Task.Run(() => ModAudioEffects.ApplyModEffects());
}
}
2 changes: 2 additions & 0 deletions Osu.Patcher.Hook/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ public static void WriteToDisk(Settings settings, string osuDir)

#region Options

public bool EnableModAudioPreview { get; set; } = true;

#endregion
}

0 comments on commit be314c4

Please sign in to comment.