machine linking refactor to ecs (#4323)
* started work * some more work, ui working (somewhat) * stuff * reorganization * some more reorg * conveyors * conveyors working * finalized (dis)connection added linkattempt added feedback text work on conveyors * removed command add rangecheck * fixed inrange check * handling * ui no longer kanser, ship it * adresses reviews * reformats file * reformats file Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
This commit is contained in:
54
Content.Server/MachineLinking/System/TwoWayLeverSystem.cs
Normal file
54
Content.Server/MachineLinking/System/TwoWayLeverSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
public class TwoWayLeverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IComponentManager _componentManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TwoWayLeverComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<TwoWayLeverComponent, SignalValueRequestedEvent>(OnSignalValueRequested);
|
||||
}
|
||||
|
||||
private void OnSignalValueRequested(EntityUid uid, TwoWayLeverComponent component, SignalValueRequestedEvent args)
|
||||
{
|
||||
args.Signal = component.State;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, TwoWayLeverComponent component, InteractHandEvent args)
|
||||
{
|
||||
component.State = component.State switch
|
||||
{
|
||||
TwoWayLeverSignal.Middle => component.NextSignalLeft ? TwoWayLeverSignal.Left : TwoWayLeverSignal.Right,
|
||||
TwoWayLeverSignal.Right => TwoWayLeverSignal.Middle,
|
||||
TwoWayLeverSignal.Left => TwoWayLeverSignal.Middle,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
if (component.State == TwoWayLeverSignal.Middle)
|
||||
{
|
||||
component.NextSignalLeft = !component.NextSignalLeft;
|
||||
}
|
||||
|
||||
if (_componentManager.TryGetComponent<AppearanceComponent>(uid, out var appearanceComponent))
|
||||
{
|
||||
appearanceComponent.SetData(TwoWayLeverVisuals.State, component.State);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(uid, new InvokePortEvent("state", component.State));
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user