mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 19:01:13 +03:00
# Conflicts: # .github/CODEOWNERS # Content.Client/Entry/EntryPoint.cs # Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs # Content.Server/Zombies/ZombifyOnDeathSystem.cs # Resources/Prototypes/Corvax/Roles/Jobs/Engineering/chief_engineer.yml # Resources/Prototypes/Datasets/Names/cargo_shuttle.yml # Resources/Prototypes/Datasets/tips.yml # Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml # Resources/Prototypes/Entities/Mobs/Species/base.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml # Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml # Resources/Prototypes/Roles/Jobs/Command/captain.yml # Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml # Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml # Resources/Prototypes/Roles/Jobs/Science/research_director.yml # Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml # Resources/Prototypes/Voice/speech_emotes.yml # Resources/ServerInfo/Guidebook/Science/Robotics.xml # Resources/Textures/Clothing/Head/Bandanas/brown.rsi/meta.json # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/equipped-HELMET.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-equipped-HELMET.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-inhand-left.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-inhand-right.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/icon.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/inhand-left.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/inhand-right.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/meta.json # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-equipped-HELMET.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-inhand-left.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-inhand-right.png # Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit.png # Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/inhand-right.png # Resources/Textures/Effects/speech.rsi/meta.json # Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json # Resources/Textures/Objects/Misc/stock_parts.rsi/adv_capacitor.png # Resources/Textures/Objects/Misc/stock_parts.rsi/advanced_matter_bin.png # Resources/Textures/Objects/Misc/stock_parts.rsi/bluespace_matter_bin.png # Resources/Textures/Objects/Misc/stock_parts.rsi/capacitor.png # Resources/Textures/Objects/Misc/stock_parts.rsi/femto_mani.png # Resources/Textures/Objects/Misc/stock_parts.rsi/matter_bin.png # Resources/Textures/Objects/Misc/stock_parts.rsi/micro_mani.png # Resources/Textures/Objects/Misc/stock_parts.rsi/nano_mani.png # Resources/Textures/Objects/Misc/stock_parts.rsi/pico_mani.png # Resources/Textures/Objects/Misc/stock_parts.rsi/quadratic_capacitor.png # Resources/Textures/Objects/Misc/stock_parts.rsi/super_capacitor.png # Resources/Textures/Objects/Misc/stock_parts.rsi/super_matter_bin.png # Resources/Textures/Structures/Furniture/chairs.rsi/meta.json
106 lines
3.9 KiB
C#
106 lines
3.9 KiB
C#
using Content.Server.DeviceLinking.Components;
|
|
using Content.Server.DeviceNetwork;
|
|
using Content.Server.Doors.Systems;
|
|
using Content.Shared.Doors.Components;
|
|
using Content.Shared.Doors;
|
|
using JetBrains.Annotations;
|
|
using SignalReceivedEvent = Content.Server.DeviceLinking.Events.SignalReceivedEvent;
|
|
|
|
namespace Content.Server.DeviceLinking.Systems
|
|
{
|
|
[UsedImplicitly]
|
|
public sealed class DoorSignalControlSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly DoorBoltSystem _bolts = default!;
|
|
[Dependency] private readonly DoorSystem _doorSystem = default!;
|
|
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<DoorSignalControlComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<DoorSignalControlComponent, SignalReceivedEvent>(OnSignalReceived);
|
|
SubscribeLocalEvent<DoorSignalControlComponent, DoorStateChangedEvent>(OnStateChanged);
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, DoorSignalControlComponent component, ComponentInit args)
|
|
{
|
|
|
|
_signalSystem.EnsureSinkPorts(uid, component.OpenPort, component.ClosePort, component.TogglePort);
|
|
_signalSystem.EnsureSourcePorts(uid, component.OutOpen);
|
|
}
|
|
|
|
private void OnSignalReceived(EntityUid uid, DoorSignalControlComponent component, ref SignalReceivedEvent args)
|
|
{
|
|
if (!TryComp(uid, out DoorComponent? door))
|
|
return;
|
|
|
|
var state = SignalState.Momentary;
|
|
args.Data?.TryGetValue(DeviceNetworkConstants.LogicState, out state);
|
|
|
|
|
|
if (args.Port == component.OpenPort)
|
|
{
|
|
if (state == SignalState.High || state == SignalState.Momentary)
|
|
{
|
|
if (door.State == DoorState.Closed)
|
|
_doorSystem.TryOpen(uid, door);
|
|
}
|
|
}
|
|
else if (args.Port == component.ClosePort)
|
|
{
|
|
if (state == SignalState.High || state == SignalState.Momentary)
|
|
{
|
|
if (door.State == DoorState.Open)
|
|
_doorSystem.TryClose(uid, door);
|
|
}
|
|
}
|
|
else if (args.Port == component.TogglePort)
|
|
{
|
|
if (state == SignalState.High || state == SignalState.Momentary)
|
|
{
|
|
if (door.State is DoorState.Closed or DoorState.Open)
|
|
_doorSystem.TryToggleDoor(uid, door);
|
|
}
|
|
}
|
|
else if (args.Port == component.InBolt)
|
|
{
|
|
if (!TryComp<DoorBoltComponent>(uid, out var bolts))
|
|
return;
|
|
|
|
// if its a pulse toggle, otherwise set bolts to high/low
|
|
bool bolt;
|
|
if (state == SignalState.Momentary)
|
|
{
|
|
bolt = !bolts.BoltsDown;
|
|
}
|
|
else
|
|
{
|
|
bolt = state == SignalState.High;
|
|
}
|
|
|
|
_bolts.SetBoltsWithAudio(uid, bolts, bolt);
|
|
}
|
|
}
|
|
|
|
private void OnStateChanged(EntityUid uid, DoorSignalControlComponent door, DoorStateChangedEvent args)
|
|
{
|
|
var data = new NetworkPayload()
|
|
{
|
|
{ DeviceNetworkConstants.LogicState, SignalState.Momentary }
|
|
};
|
|
|
|
if (args.State == DoorState.Closed)
|
|
{
|
|
data[DeviceNetworkConstants.LogicState] = SignalState.Low;
|
|
_signalSystem.InvokePort(uid, door.OutOpen, data);
|
|
}
|
|
else if (args.State == DoorState.Open
|
|
|| args.State == DoorState.Emagging)
|
|
{
|
|
data[DeviceNetworkConstants.LogicState] = SignalState.High;
|
|
_signalSystem.InvokePort(uid, door.OutOpen, data);
|
|
}
|
|
}
|
|
}
|
|
}
|