Files
OldThink/Content.Server/MachineLinking/System/SignalSwitchSystem.cs

40 lines
1.4 KiB
C#
Raw Normal View History

using Content.Server.MachineLinking.Components;
2022-06-22 03:51:42 +03:00
using Content.Shared.Audio;
using Content.Shared.Interaction;
2022-06-22 03:51:42 +03:00
using Robust.Shared.Audio;
using Robust.Shared.Player;
namespace Content.Server.MachineLinking.System
{
public sealed class SignalSwitchSystem : EntitySystem
{
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
public override void Initialize()
{
base.Initialize();
2022-04-04 01:13:03 -05:00
SubscribeLocalEvent<SignalSwitchComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
}
2022-04-04 01:13:03 -05:00
private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
{
_signalSystem.EnsureTransmitterPorts(uid, component.OnPort, component.OffPort);
}
private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
{
if (args.Handled)
return;
component.State = !component.State;
_signalSystem.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
2022-06-22 03:51:42 +03:00
SoundSystem.Play(component.ClickSound.GetSound(), Filter.Pvs(component.Owner), component.Owner,
AudioHelpers.WithVariation(0.125f).WithVolume(8f));
args.Handled = true;
}
}
}