Files
tbd-station-14/Content.Server/GameObjects/Components/MachineLinking/SignalTwoWayLeverComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

65 lines
2.0 KiB
C#

#nullable enable
using Content.Shared.GameObjects.Components.MachineLinking;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GameObjects.Components.MachineLinking
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
public class SignalTwoWayLeverComponent : SignalTransmitterComponent, IInteractHand, IActivate
{
public override string Name => "TwoWayLever";
private TwoWayLeverSignal _state = TwoWayLeverSignal.Middle;
private bool _nextForward = true;
public TwoWayLeverSignal State
{
get => _state;
private set
{
_state = value;
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(TwoWayLeverVisuals.State, value);
}
}
}
private void NextState(IEntity user)
{
State = State switch
{
TwoWayLeverSignal.Left => TwoWayLeverSignal.Middle,
TwoWayLeverSignal.Middle => _nextForward ? TwoWayLeverSignal.Right : TwoWayLeverSignal.Left,
TwoWayLeverSignal.Right => TwoWayLeverSignal.Middle,
_ => TwoWayLeverSignal.Middle
};
if (State == TwoWayLeverSignal.Left || State == TwoWayLeverSignal.Right) _nextForward = !_nextForward;
if (!TransmitSignal(State))
{
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
}
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
NextState(eventArgs.User);
return true;
}
void IActivate.Activate(ActivateEventArgs eventArgs)
{
NextState(eventArgs.User);
}
}
}