Machine Linking Overhaul (#7160)

This commit is contained in:
Jack Fox
2022-04-04 01:13:03 -05:00
committed by GitHub
parent fd7ea3f1e7
commit f957c58906
40 changed files with 605 additions and 696 deletions

View File

@@ -10,25 +10,23 @@ namespace Content.Server.MachineLinking.System
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SignalSwitchComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SignalSwitchComponent, InteractHandEvent>(OnInteracted);
SubscribeLocalEvent<SignalSwitchComponent, SignalValueRequestedEvent>(OnSignalValueRequested);
}
private void OnSignalValueRequested(EntityUid uid, SignalSwitchComponent component, SignalValueRequestedEvent args)
private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
{
if (args.Port == "state")
{
args.Handled = true;
args.Signal = component.State;
}
var transmitter = EnsureComp<SignalTransmitterComponent>(uid);
foreach (string port in new[] { "On", "Off" })
if (!transmitter.Outputs.ContainsKey(port))
transmitter.AddPort(port);
}
private void OnInteracted(EntityUid uid, SignalSwitchComponent component, InteractHandEvent args)
{
component.State = !component.State;
RaiseLocalEvent(uid, new InvokePortEvent("state", component.State), false);
RaiseLocalEvent(uid, new InvokePortEvent("stateChange"), false);
RaiseLocalEvent(uid, new InvokePortEvent(component.State ? "On" : "Off"), false);
args.Handled = true;
}
}