Files
tbd-station-14/Content.Server/DeviceLinking/Systems/SignalSwitchSystem.cs
Nemanja a1a8f04036 Decouple interactions from hands, cleanup old events, add new fears (#28393)
* ok basic shit

* second part

* pretend it isn't real it can't hurt you.

* 👁️ 👁️

* shadowcommander review
2024-05-31 13:26:19 -07:00

46 lines
1.5 KiB
C#

using Content.Server.DeviceLinking.Components;
using Content.Server.DeviceNetwork;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
namespace Content.Server.DeviceLinking.Systems;
public sealed class SignalSwitchSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
[Dependency] private readonly SharedAudioSystem _audio = 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;
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);
}
_audio.PlayPvs(comp.ClickSound, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(8f));
args.Handled = true;
}
}