Files
tbd-station-14/Content.Server/Disposal/Tube/DisposalSignalRouterSystem.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

51 lines
1.8 KiB
C#

using Content.Server.DeviceLinking.Systems;
using Content.Shared.DeviceLinking.Events;
namespace Content.Server.Disposal.Tube;
/// <summary>
/// Handles signals and the routing get next direction event.
/// </summary>
public sealed class DisposalSignalRouterSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DisposalSignalRouterComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<DisposalSignalRouterComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<DisposalSignalRouterComponent, GetDisposalsNextDirectionEvent>(OnGetNextDirection, after: new[] { typeof(DisposalTubeSystem) });
}
private void OnInit(EntityUid uid, DisposalSignalRouterComponent comp, ComponentInit args)
{
_deviceLink.EnsureSinkPorts(uid, comp.OnPort, comp.OffPort, comp.TogglePort);
}
private void OnSignalReceived(EntityUid uid, DisposalSignalRouterComponent comp, ref SignalReceivedEvent args)
{
// TogglePort flips it
// OnPort sets it to true
// OffPort sets it to false
comp.Routing = args.Port == comp.TogglePort
? !comp.Routing
: args.Port == comp.OnPort;
}
private void OnGetNextDirection(EntityUid uid, DisposalSignalRouterComponent comp, ref GetDisposalsNextDirectionEvent args)
{
if (!comp.Routing)
{
args.Next = Transform(uid).LocalRotation.GetDir();
return;
}
// use the junction side direction when a tag matches
var ev = new GetDisposalsConnectableDirectionsEvent();
RaiseLocalEvent(uid, ref ev);
args.Next = ev.Connectable[1];
}
}