2023-05-07 08:07:24 +02:00
|
|
|
using Content.Server.DeviceLinking.Components;
|
|
|
|
|
using Content.Server.DeviceLinking.Events;
|
2022-04-04 01:13:03 -05:00
|
|
|
using Content.Server.Doors.Systems;
|
2023-05-07 08:07:24 +02:00
|
|
|
using Content.Server.MachineLinking.System;
|
2022-04-04 01:13:03 -05:00
|
|
|
using Content.Shared.Doors.Components;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
2023-05-07 08:07:24 +02:00
|
|
|
namespace Content.Server.DeviceLinking.Systems
|
2022-04-04 01:13:03 -05:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class DoorSignalControlSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly DoorSystem _doorSystem = default!;
|
2023-05-07 08:07:24 +02:00
|
|
|
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
|
2022-05-12 20:46:20 +12:00
|
|
|
|
2022-04-04 01:13:03 -05:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<DoorSignalControlComponent, ComponentInit>(OnInit);
|
|
|
|
|
SubscribeLocalEvent<DoorSignalControlComponent, SignalReceivedEvent>(OnSignalReceived);
|
|
|
|
|
}
|
2023-05-07 08:07:24 +02:00
|
|
|
|
2022-04-04 01:13:03 -05:00
|
|
|
private void OnInit(EntityUid uid, DoorSignalControlComponent component, ComponentInit args)
|
|
|
|
|
{
|
2023-05-07 08:07:24 +02:00
|
|
|
_signalSystem.EnsureSinkPorts(uid, component.OpenPort, component.ClosePort, component.TogglePort);
|
2022-04-04 01:13:03 -05:00
|
|
|
}
|
|
|
|
|
|
2023-05-07 08:07:24 +02:00
|
|
|
private void OnSignalReceived(EntityUid uid, DoorSignalControlComponent component, ref SignalReceivedEvent args)
|
2022-04-04 01:13:03 -05:00
|
|
|
{
|
2022-05-12 20:46:20 +12:00
|
|
|
if (!TryComp(uid, out DoorComponent? door))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (args.Port == component.OpenPort)
|
|
|
|
|
{
|
|
|
|
|
if (door.State != DoorState.Open)
|
|
|
|
|
_doorSystem.TryOpen(uid, door);
|
|
|
|
|
}
|
|
|
|
|
else if (args.Port == component.ClosePort)
|
|
|
|
|
{
|
|
|
|
|
if (door.State != DoorState.Closed)
|
|
|
|
|
_doorSystem.TryClose(uid, door);
|
|
|
|
|
}
|
|
|
|
|
else if (args.Port == component.TogglePort)
|
2022-04-04 01:13:03 -05:00
|
|
|
{
|
2022-05-12 20:46:20 +12:00
|
|
|
_doorSystem.TryToggleDoor(uid, door);
|
2022-04-04 01:13:03 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|