Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/SignalLinkerSystem.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

96 lines
2.7 KiB
C#

using System.Collections.Generic;
using Content.Server.GameObjects.Components.MachineLinking;
using Content.Server.GameObjects.EntitySystems.Click;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems
{
public class SignalLinkerSystem : EntitySystem
{
private Dictionary<NetUserId, SignalTransmitterComponent> _transmitters;
public override void Initialize()
{
base.Initialize();
_transmitters = new Dictionary<NetUserId, SignalTransmitterComponent>();
}
public bool SignalLinkerKeybind(NetUserId id, bool? enable)
{
if (enable == null)
{
enable = !_transmitters.ContainsKey(id);
}
if (enable == true)
{
if (_transmitters.ContainsKey(id))
{
return true;
}
if (_transmitters.Count == 0)
{
CommandBinds.Builder
.BindBefore(EngineKeyFunctions.Use, new PointerInputCmdHandler(HandleUse), typeof(InteractionSystem))
.Register<SignalLinkerSystem>();
}
_transmitters.Add(id, null);
}
else if (enable == false)
{
if (!_transmitters.ContainsKey(id))
{
return false;
}
_transmitters.Remove(id);
if (_transmitters.Count == 0)
{
CommandBinds.Unregister<SignalLinkerSystem>();
}
}
return enable == true;
}
private bool HandleUse(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
if (!_transmitters.TryGetValue(session.UserId, out var signalTransmitter))
{
return false;
}
if (!EntityManager.TryGetEntity(uid, out var entity))
{
return false;
}
if (entity.TryGetComponent<SignalReceiverComponent>(out var signalReceiver))
{
if (signalReceiver.Interact(session.AttachedEntity, signalTransmitter))
{
return true;
}
}
if (entity.TryGetComponent<SignalTransmitterComponent>(out var transmitter))
{
_transmitters[session.UserId] = transmitter.GetSignal(session.AttachedEntity);
return true;
}
return false;
}
}
}