Machine Port Prototypes (#7659)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Leon Friedrich
2022-05-12 20:46:20 +12:00
committed by GitHub
parent 32c2eb7a02
commit c00b459e31
29 changed files with 422 additions and 220 deletions

View File

@@ -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;
}
}