Files
tbd-station-14/Content.Client/Eye/Blinding/BlindingSystem.cs
Pieter-Jan Briers 68ce53ae17 Random spontaneous cleanup PR (#25131)
* Use new Subs.CVar helper

Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe.

This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown.

* Fix a bunch of warnings

* More warning fixes

* Use new DateTime serializer to get rid of ISerializationHooks in changelog code.

* Get rid of some more ISerializationHooks for enums

* And a little more

* Apply suggestions from code review

Co-authored-by: 0x6273 <0x40@keemail.me>

---------

Co-authored-by: 0x6273 <0x40@keemail.me>
2024-02-13 16:48:39 -05:00

63 lines
1.9 KiB
C#

using Robust.Client.Graphics;
using Robust.Client.Player;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.GameTicking;
using Robust.Shared.Player;
namespace Content.Client.Eye.Blinding;
public sealed class BlindingSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] ILightManager _lightManager = default!;
private BlindOverlay _overlay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlindableComponent, ComponentInit>(OnBlindInit);
SubscribeLocalEvent<BlindableComponent, ComponentShutdown>(OnBlindShutdown);
SubscribeLocalEvent<BlindableComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<BlindableComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
SubscribeNetworkEvent<RoundRestartCleanupEvent>(RoundRestartCleanup);
_overlay = new();
}
private void OnPlayerAttached(EntityUid uid, BlindableComponent component, LocalPlayerAttachedEvent args)
{
_overlayMan.AddOverlay(_overlay);
}
private void OnPlayerDetached(EntityUid uid, BlindableComponent component, LocalPlayerDetachedEvent args)
{
_overlayMan.RemoveOverlay(_overlay);
_lightManager.Enabled = true;
}
private void OnBlindInit(EntityUid uid, BlindableComponent component, ComponentInit args)
{
if (_player.LocalEntity == uid)
_overlayMan.AddOverlay(_overlay);
}
private void OnBlindShutdown(EntityUid uid, BlindableComponent component, ComponentShutdown args)
{
if (_player.LocalEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
}
private void RoundRestartCleanup(RoundRestartCleanupEvent ev)
{
_lightManager.Enabled = true;
}
}