Files
OldThink/Content.Server/MachineLinking/System/SignalSwitchSystem.cs

34 lines
1.2 KiB
C#
Raw Normal View History

using Content.Server.MachineLinking.Components;
using Content.Server.MachineLinking.Events;
using Content.Shared.Interaction;
using Robust.Shared.GameObjects;
namespace Content.Server.MachineLinking.System
{
public sealed class SignalSwitchSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
2022-04-04 01:13:03 -05:00
SubscribeLocalEvent<SignalSwitchComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
}
2022-04-04 01:13:03 -05:00
private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
{
2022-04-04 01:13:03 -05:00
var transmitter = EnsureComp<SignalTransmitterComponent>(uid);
foreach (string port in new[] { "On", "Off" })
if (!transmitter.Outputs.ContainsKey(port))
transmitter.AddPort(port);
}
private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
{
component.State = !component.State;
2022-04-04 01:13:03 -05:00
RaiseLocalEvent(uid, new InvokePortEvent(component.State ? "On" : "Off"), false);
args.Handled = true;
}
}
}