Machine Port Prototypes (#7659)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
public sealed class TwoWayLeverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -18,14 +18,14 @@ namespace Content.Server.MachineLinking.System
|
||||
|
||||
private void OnInit(EntityUid uid, TwoWayLeverComponent component, ComponentInit args)
|
||||
{
|
||||
var transmitter = EnsureComp<SignalTransmitterComponent>(uid);
|
||||
foreach (string state in Enum.GetNames<TwoWayLeverState>())
|
||||
if (!transmitter.Outputs.ContainsKey(state))
|
||||
transmitter.AddPort(state);
|
||||
_signalSystem.EnsureTransmitterPorts(uid, component.LeftPort, component.RightPort, component.MiddlePort);
|
||||
}
|
||||
|
||||
private void OnActivated(EntityUid uid, TwoWayLeverComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
component.State = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Middle => component.NextSignalLeft ? TwoWayLeverState.Left : TwoWayLeverState.Right,
|
||||
@@ -35,16 +35,20 @@ namespace Content.Server.MachineLinking.System
|
||||
};
|
||||
|
||||
if (component.State == TwoWayLeverState.Middle)
|
||||
{
|
||||
component.NextSignalLeft = !component.NextSignalLeft;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearanceComponent))
|
||||
{
|
||||
if (TryComp(uid, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(TwoWayLeverVisuals.State, component.State);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(uid, new InvokePortEvent(component.State.ToString()));
|
||||
var port = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Left => component.LeftPort,
|
||||
TwoWayLeverState.Right => component.RightPort,
|
||||
TwoWayLeverState.Middle => component.MiddlePort,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
_signalSystem.InvokePort(uid, port);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user