Files
tbd-station-14/Content.Client/Audio/ClientAdminSoundSystem.cs
ike709 5ae56c67e1 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>
2022-06-02 15:41:19 +02:00

52 lines
1.3 KiB
C#

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();
}
}