Files
OldThink/Content.Shared/_Miracle/Systems/SharedNightVisionSystem.cs
Aviu00 1105109152 - add: Toggleable night vision (#31)
* - add: Toggleable night vision

* - add: Add death squad huds & night vision
2024-02-06 15:40:41 +00:00

45 lines
1.5 KiB
C#

using Content.Shared._White.Overlays;
using Content.Shared.Actions;
using Robust.Shared.Audio.Systems;
namespace Content.Shared._Miracle.Systems;
public abstract class SharedNightVisionSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NightVisionComponent, ToggleNightVisionEvent>(OnToggle);
SubscribeLocalEvent<NightVisionComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<NightVisionComponent, ComponentRemove>(OnRemove);
}
private void OnRemove(EntityUid uid, NightVisionComponent component, ComponentRemove args)
{
_actions.RemoveAction(uid, component.ToggleActionEntity);
UpdateNightVision(uid, false);
}
private void OnInit(EntityUid uid, NightVisionComponent component, ComponentInit args)
{
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
UpdateNightVision(uid, component.IsActive);
}
protected virtual void UpdateNightVision(EntityUid uid, bool active) { }
private void OnToggle(EntityUid uid, NightVisionComponent component, ToggleNightVisionEvent args)
{
component.IsActive = !component.IsActive;
_audio.PlayPredicted(component.ToggleSound, uid, uid);
UpdateNightVision(uid, component.IsActive);
Dirty(uid, component);
args.Handled = true;
}
}