Files
tbd-station-14/Content.Server/DeviceLinking/Systems/EdgeDetectorSystem.cs
metalgearsloth 63dfd21b14 Predict dumping (#32394)
* Predict dumping

- This got soaped really fucking hard.
- Dumping is predicted, this required disposals to be predicte.d
- Disposals required mailing (because it's tightly coupled), and a smidge of other content systems.
- I also had to fix a compnetworkgenerator issue at the same time so it wouldn't mispredict.

* Fix a bunch of stuff

* nasty merge

* Some reviews

* Some more reviews while I stash

* Fix merge

* Fix merge

* Half of review

* Review

* re(h)f

* lizards

* feexes

* feex
2025-04-19 16:20:40 +10:00

47 lines
1.5 KiB
C#

using Content.Server.DeviceLinking.Components;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.DeviceNetwork;
namespace Content.Server.DeviceLinking.Systems;
public sealed class EdgeDetectorSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EdgeDetectorComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<EdgeDetectorComponent, SignalReceivedEvent>(OnSignalReceived);
}
private void OnInit(EntityUid uid, EdgeDetectorComponent comp, ComponentInit args)
{
_deviceLink.EnsureSinkPorts(uid, comp.InputPort);
_deviceLink.EnsureSourcePorts(uid, comp.OutputHighPort, comp.OutputLowPort);
}
private void OnSignalReceived(EntityUid uid, EdgeDetectorComponent comp, ref SignalReceivedEvent args)
{
// only handle signals with edges
var state = SignalState.Momentary;
if (args.Data == null ||
!args.Data.TryGetValue(DeviceNetworkConstants.LogicState, out state) ||
state == SignalState.Momentary)
return;
if (args.Port != comp.InputPort)
return;
// make sure the level changed, multiple devices sending the same level are treated as one spamming
if (comp.State != state)
{
comp.State = state;
var port = state == SignalState.High ? comp.OutputHighPort : comp.OutputLowPort;
_deviceLink.InvokePort(uid, port);
}
}
}