Surveillance camera's red light fixes (#31831)

several surv camera related fixes

Co-authored-by: YourUsername <you@example.com>
This commit is contained in:
godisdeadLOL
2024-09-09 22:23:57 +03:00
committed by GitHub
parent 6e911bff03
commit 7929f897c9
2 changed files with 25 additions and 5 deletions

View 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)
{

View 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)