Files
tbd-station-14/Content.Server/Atmos/Piping/Binary/EntitySystems/SignalControlledValveSystem.cs
Julian Giebel 6ebd784cb6 Device Linking and better linking ui (#13645)
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-05-07 16:07:24 +10:00

45 lines
1.4 KiB
C#

using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceLinking.Systems;
using Content.Server.MachineLinking.System;
namespace Content.Server.Atmos.Piping.Binary.EntitySystems;
public sealed class SignalControlledValveSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _signal = default!;
[Dependency] private readonly GasValveSystem _valve = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SignalControlledValveComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SignalControlledValveComponent, SignalReceivedEvent>(OnSignalReceived);
}
private void OnInit(EntityUid uid, SignalControlledValveComponent comp, ComponentInit args)
{
_signal.EnsureSinkPorts(uid, comp.OpenPort, comp.ClosePort, comp.TogglePort);
}
private void OnSignalReceived(EntityUid uid, SignalControlledValveComponent comp, ref SignalReceivedEvent args)
{
if (!TryComp<GasValveComponent>(uid, out var valve))
return;
if (args.Port == comp.OpenPort)
{
_valve.Set(uid, valve, true);
}
else if (args.Port == comp.ClosePort)
{
_valve.Set(uid, valve, false);
}
else if (args.Port == comp.TogglePort)
{
_valve.Toggle(uid, valve);
}
}
}