Adds the ability to not play admin sounds (#8242)

Co-authored-by: ike709 <ike709@github.com>
Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
ike709
2022-06-02 08:41:19 -05:00
committed by GitHub
parent 5b3a87180f
commit 5ae56c67e1
7 changed files with 122 additions and 14 deletions

View File

@@ -0,0 +1,51 @@
using Content.Shared.Audio;
using Content.Shared.CCVar;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
namespace Content.Client.Audio;
public sealed class ClientAdminSoundSystem : SharedAdminSoundSystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
private bool _adminAudioEnabled = true;
private List<IPlayingAudioStream?> _adminAudio = new(1);
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<AdminSoundEvent>(PlayAdminSound);
_cfg.OnValueChanged(CCVars.AdminSoundsEnabled, ToggleAdminSound, true);
}
public override void Shutdown()
{
base.Shutdown();
foreach (var stream in _adminAudio)
{
stream?.Stop();
}
_adminAudio.Clear();
}
private void PlayAdminSound(AdminSoundEvent soundEvent)
{
if(!_adminAudioEnabled) return;
var stream = SoundSystem.Play(Filter.Local(), soundEvent.Filename, soundEvent.AudioParams);
_adminAudio.Add(stream);
}
private void ToggleAdminSound(bool enabled)
{
_adminAudioEnabled = enabled;
if (_adminAudioEnabled) return;
foreach (var stream in _adminAudio)
{
stream?.Stop();
}
_adminAudio.Clear();
}
}