SignalControlledValveSystem.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Server.Atmos.Piping.Binary.Components;
  2. using Content.Server.DeviceLinking.Events;
  3. using Content.Server.DeviceLinking.Systems;
  4. namespace Content.Server.Atmos.Piping.Binary.EntitySystems;
  5. public sealed class SignalControlledValveSystem : EntitySystem
  6. {
  7. [Dependency] private readonly DeviceLinkSystem _signal = default!;
  8. [Dependency] private readonly GasValveSystem _valve = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<SignalControlledValveComponent, ComponentInit>(OnInit);
  13. SubscribeLocalEvent<SignalControlledValveComponent, SignalReceivedEvent>(OnSignalReceived);
  14. }
  15. private void OnInit(EntityUid uid, SignalControlledValveComponent comp, ComponentInit args)
  16. {
  17. _signal.EnsureSinkPorts(uid, comp.OpenPort, comp.ClosePort, comp.TogglePort);
  18. }
  19. private void OnSignalReceived(EntityUid uid, SignalControlledValveComponent comp, ref SignalReceivedEvent args)
  20. {
  21. if (!TryComp<GasValveComponent>(uid, out var valve))
  22. return;
  23. if (args.Port == comp.OpenPort)
  24. {
  25. _valve.Set(uid, valve, true);
  26. }
  27. else if (args.Port == comp.ClosePort)
  28. {
  29. _valve.Set(uid, valve, false);
  30. }
  31. else if (args.Port == comp.TogglePort)
  32. {
  33. _valve.Toggle(uid, valve);
  34. }
  35. }
  36. }