Files
tbd-station-14/Content.Client/Eye/Blinding/BlindingSystem.cs
Rane 037feb3ad0 Fix blindfold round cleanup bug (#9821)
* Blindness public api

* fix blinding round cleanup bug
2022-07-19 17:10:08 +10:00

71 lines
2.1 KiB
C#

using Content.Shared.Eye.Blinding;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Content.Shared.GameTicking;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
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, PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<BlindableComponent, PlayerDetachedEvent>(OnPlayerDetached);
SubscribeNetworkEvent<RoundRestartCleanupEvent>(RoundRestartCleanup);
_overlay = new();
}
private void OnPlayerAttached(EntityUid uid, BlindableComponent component, PlayerAttachedEvent args)
{
_overlayMan.AddOverlay(_overlay);
}
private void OnPlayerDetached(EntityUid uid, BlindableComponent component, PlayerDetachedEvent args)
{
_overlayMan.RemoveOverlay(_overlay);
_lightManager.Enabled = true;
}
private void OnBlindInit(EntityUid uid, BlindableComponent component, ComponentInit args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
_overlayMan.AddOverlay(_overlay);
}
private void OnBlindShutdown(EntityUid uid, BlindableComponent component, ComponentShutdown args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
}
private void RoundRestartCleanup(RoundRestartCleanupEvent ev)
{
_lightManager.Enabled = true;
}
}