]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Surveillance camera's red light fixes (#31831)
authorgodisdeadLOL <169250097+godisdeadLOL@users.noreply.github.com>
Mon, 9 Sep 2024 19:23:57 +0000 (22:23 +0300)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2024 19:23:57 +0000 (13:23 -0600)
several surv camera related fixes

Co-authored-by: YourUsername <you@example.com>
Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs
Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs

index 5e50740ae698c77c2778b30817023842bca6de86..21e71c43168491c79778c75cb603325eff889e08 100644 (file)
@@ -21,6 +21,7 @@ public sealed class SurveillanceCameraMonitorSystem : EntitySystem
     {
         SubscribeLocalEvent<SurveillanceCameraMonitorComponent, SurveillanceCameraDeactivateEvent>(OnSurveillanceCameraDeactivate);
         SubscribeLocalEvent<SurveillanceCameraMonitorComponent, PowerChangedEvent>(OnPowerChanged);
+        SubscribeLocalEvent<SurveillanceCameraMonitorComponent, ComponentShutdown>(OnShutdown);
         SubscribeLocalEvent<SurveillanceCameraMonitorComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
         SubscribeLocalEvent<SurveillanceCameraMonitorComponent, ComponentStartup>(OnComponentStartup);
         SubscribeLocalEvent<SurveillanceCameraMonitorComponent, AfterActivatableUIOpenEvent>(OnToggleInterface);
@@ -196,6 +197,12 @@ public sealed class SurveillanceCameraMonitorSystem : EntitySystem
         }
     }
 
+    private void OnShutdown(EntityUid uid, SurveillanceCameraMonitorComponent component, ComponentShutdown args)
+    {
+        RemoveActiveCamera(uid, component);
+    }
+
+
     private void OnToggleInterface(EntityUid uid, SurveillanceCameraMonitorComponent component,
         AfterActivatableUIOpenEvent args)
     {
index 9d1dd00590a991709bc39c3aa2210f24cf4f3c81..f1d1b58bf57c24cd16144e38345624cc441da8c6 100644 (file)
@@ -321,6 +321,13 @@ public sealed class SurveillanceCameraSystem : EntitySystem
         {
             AddActiveViewer(camera, player, monitor, component);
         }
+
+        // Add monitor without viewers
+        if (players.Count == 0 && monitor != null)
+        {
+            component.ActiveMonitors.Add(monitor.Value);
+            UpdateVisuals(camera, component);
+        }
     }
 
     // Switch the set of active viewers from one camera to another.
@@ -349,13 +356,12 @@ public sealed class SurveillanceCameraSystem : EntitySystem
 
     public void RemoveActiveViewer(EntityUid camera, EntityUid player, EntityUid? monitor = null, SurveillanceCameraComponent? component = null, ActorComponent? actor = null)
     {
-        if (!Resolve(camera, ref component)
-            || !Resolve(player, ref actor))
-        {
+        if (!Resolve(camera, ref component))
             return;
-        }
 
-        _viewSubscriberSystem.RemoveViewSubscriber(camera, actor.PlayerSession);
+        if (Resolve(player, ref actor))
+            _viewSubscriberSystem.RemoveViewSubscriber(camera, actor.PlayerSession);
+
         component.ActiveViewers.Remove(player);
 
         if (monitor != null)
@@ -377,6 +383,13 @@ public sealed class SurveillanceCameraSystem : EntitySystem
         {
             RemoveActiveViewer(camera, player, monitor, component);
         }
+
+        // Even if not removing any viewers, remove the monitor
+        if (players.Count == 0 && monitor != null)
+        {
+            component.ActiveMonitors.Remove(monitor.Value);
+            UpdateVisuals(camera, component);
+        }
     }
 
     private void UpdateVisuals(EntityUid uid, SurveillanceCameraComponent? component = null, AppearanceComponent? appearance = null)