Files
Delta-v/Content.Client/_Goobstation/Overlays/NightVisionSystem.cs
William Lemonandpre-commit-ci[bot] 01088086dc Adds Skia (σκιά, shade) as a Midround Antagonist (#4152)
* AAAAAAAAadds skia

* Added to the spawn options table

* Fix EOR, Added shatter ability, Fix Reroll popup

* Fixed the death of the Skia

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed taco's silly mistake

* Skia need pry-ability

* Adds Goob Nightvision

* Added some missing Protos

* Appease the Yaml gods

* Did the Delta Fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Lathes fix

* Update attributions.yml

* More yaml fixes

* The Yaml Linter shall never be sated

* More fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed objective reroll

* Bring up to date

* aaaaaaaaaaa

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed damageset, removed unneeded point light

* I'm so sorry Deltandas

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: William Lemon <William.Lemon2@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-09-01 08:46:23 +00:00

112 lines
3.5 KiB
C#

// SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
// SPDX-FileCopyrightText: 2025 Aviu00 <93730715+Aviu00@users.noreply.github.com>
// SPDX-FileCopyrightText: 2025 Misandry <mary@thughunt.ing>
// SPDX-FileCopyrightText: 2025 Spatison <137375981+Spatison@users.noreply.github.com>
// SPDX-FileCopyrightText: 2025 gus <august.eymann@gmail.com>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
using Content.Client.Overlays;
using Content.Shared._Goobstation.Overlays;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Robust.Client.Graphics;
namespace Content.Client._Goobstation.Overlays;
public sealed class NightVisionSystem : EquipmentHudSystem<NightVisionComponent>
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly ILightManager _lightManager = default!;
private BaseSwitchableOverlay<NightVisionComponent> _overlay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NightVisionComponent, SwitchableOverlayToggledEvent>(OnToggle);
_overlay = new BaseSwitchableOverlay<NightVisionComponent>();
}
protected override void OnRefreshComponentHud(Entity<NightVisionComponent> ent,
ref RefreshEquipmentHudEvent<NightVisionComponent> args)
{
if (!ent.Comp.IsEquipment)
base.OnRefreshComponentHud(ent, ref args);
}
protected override void OnRefreshEquipmentHud(Entity<NightVisionComponent> ent,
ref InventoryRelayedEvent<RefreshEquipmentHudEvent<NightVisionComponent>> args)
{
if (ent.Comp.IsEquipment)
base.OnRefreshEquipmentHud(ent, ref args);
}
private void OnToggle(Entity<NightVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
RefreshOverlay();
}
protected override void UpdateInternal(RefreshEquipmentHudEvent<NightVisionComponent> args)
{
base.UpdateInternal(args);
var active = false;
NightVisionComponent? nvComp = null;
foreach (var comp in args.Components)
{
if (comp.IsActive || comp.PulseTime > 0f && comp.PulseAccumulator < comp.PulseTime)
active = true;
else
continue;
if (comp.DrawOverlay)
{
if (nvComp == null)
nvComp = comp;
else if (nvComp.PulseTime > 0f && comp.PulseTime <= 0f)
nvComp = comp;
}
if (active && nvComp is { PulseTime: <= 0 })
break;
}
UpdateNightVision(active);
UpdateOverlay(nvComp);
}
protected override void DeactivateInternal()
{
base.DeactivateInternal();
UpdateNightVision(false);
UpdateOverlay(null);
}
private void UpdateNightVision(bool active)
{
_lightManager.DrawLighting = !active;
}
private void UpdateOverlay(NightVisionComponent? nvComp)
{
_overlay.Comp = nvComp;
switch (nvComp)
{
case not null when !_overlayMan.HasOverlay<BaseSwitchableOverlay<NightVisionComponent>>():
_overlayMan.AddOverlay(_overlay);
break;
case null:
_overlayMan.RemoveOverlay(_overlay);
break;
}
if (_overlayMan.TryGetOverlay<BaseSwitchableOverlay<ThermalVisionComponent>>(out var overlay))
overlay.IsActive = nvComp == null;
}
}