fish-station/Content.Client/_Sunrise/Eye/NightVision/NightVisionSystem.cs
2024-10-07 16:41:26 +03:00

56 lines
1.8 KiB
C#

using Content.Shared._Sunrise.Eye.NightVision.Components;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;
namespace Content.Client._Sunrise.Eye.NightVision;
public sealed class NightVisionSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
private NightVisionOverlay _overlay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NightVisionComponent, ComponentInit>(OnNightVisionInit);
SubscribeLocalEvent<NightVisionComponent, ComponentShutdown>(OnNightVisionShutdown);
SubscribeLocalEvent<NightVisionComponent, PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<NightVisionComponent, PlayerDetachedEvent>(OnPlayerDetached);
_overlay = new();
}
private void OnPlayerAttached(EntityUid uid, NightVisionComponent component, PlayerAttachedEvent args)
{
if (_overlay == default!)
return;
_overlayMan.AddOverlay(_overlay);
}
private void OnPlayerDetached(EntityUid uid, NightVisionComponent component, PlayerDetachedEvent args)
{
if (_overlay == default!)
return;
_overlayMan.RemoveOverlay(_overlay);
}
private void OnNightVisionInit(EntityUid uid, NightVisionComponent component, ComponentInit args)
{
if (_player.LocalSession?.AttachedEntity != uid)
return;
_overlayMan.AddOverlay(_overlay);
}
private void OnNightVisionShutdown(EntityUid uid, NightVisionComponent component, ComponentShutdown args)
{
if (_player.LocalSession?.AttachedEntity != uid)
return;
if (_overlay == default!)
return;
_overlayMan.RemoveOverlay(_overlay);
}
}