CatStation/Content.Server/DeviceLinking/Systems/SignalSwitchSystem.cs
Stanislav b22d38f9c0
Yaml audio params are often ignored (#36259)
* Replace WithVolume() with AddVolume(),
Remove AudioHelpers.WithVariation(),
Use specifier options for audio params

* Undo switching to AudioParams.AddVariation()

* Replace AudioHelpers.WithVariation with AudioParams.AddVariation()

* Test AudioParams.AddVariation() and change input parameters to sound like previous AudioHelpers.WithVariation()

* Fix build error

* Fix build error v2

* Remove DoAfter

* fixes

---------

Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
2026-07-25 16:16:23 +00:00

52 lines
1.7 KiB
C#

using Content.Server.DeviceLinking.Components;
using Content.Server.DeviceNetwork;
using Content.Shared.Interaction;
using Content.Shared.Lock;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
namespace Content.Server.DeviceLinking.Systems;
public sealed partial class SignalSwitchSystem : EntitySystem
{
[Dependency] private DeviceLinkSystem _deviceLink = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private LockSystem _lock = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SignalSwitchComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
}
private void OnInit(EntityUid uid, SignalSwitchComponent comp, ComponentInit args)
{
_deviceLink.EnsureSourcePorts(uid, comp.OnPort, comp.OffPort, comp.StatusPort);
}
private void OnActivated(EntityUid uid, SignalSwitchComponent comp, ActivateInWorldEvent args)
{
if (args.Handled || !args.Complex)
return;
if (_lock.IsLocked(uid))
return;
comp.State = !comp.State;
_deviceLink.InvokePort(uid, comp.State ? comp.OnPort : comp.OffPort);
// only send status if it's a toggle switch and not a button
if (comp.OnPort != comp.OffPort)
{
_deviceLink.SendSignal(uid, comp.StatusPort, comp.State);
}
var audioParams = comp.ClickSound?.Params ?? AudioParams.Default;
audioParams = audioParams.WithVariation(0.125f).AddVolume(8f);
_audio.PlayPvs(comp.ClickSound, uid, audioParams);
args.Handled = true;
}
}