Files
tbd-station-14/Content.Server/Atmos/Piping/Binary/EntitySystems/SignalControlledValveSystem.cs
deltanedas 3cd30c408b add signal valve (#14830)
Co-authored-by: deltanedas <@deltanedas:kde.org>
2023-03-25 16:16:27 -07:00

44 lines
1.4 KiB
C#

using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.System;
namespace Content.Server.Atmos.Piping.Binary.EntitySystems;
public sealed class SignalControlledValveSystem : EntitySystem
{
[Dependency] private readonly SignalLinkerSystem _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.EnsureReceiverPorts(uid, comp.OpenPort, comp.ClosePort, comp.TogglePort);
}
private void OnSignalReceived(EntityUid uid, SignalControlledValveComponent comp, 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);
}
}
}