Skip to content

Commit

Permalink
Surveillance camera's red light fixes (space-wizards#31831)
Browse files Browse the repository at this point in the history
several surv camera related fixes

Co-authored-by: YourUsername <you@example.com>
  • Loading branch information
godisdeadLOL and YourUsername authored Sep 9, 2024
1 parent 58eddbb commit ccd9474
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void Initialize()
{
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, SurveillanceCameraDeactivateEvent>(OnSurveillanceCameraDeactivate);
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<SurveillanceCameraMonitorComponent, AfterActivatableUIOpenEvent>(OnToggleInterface);
Expand Down Expand Up @@ -196,6 +197,12 @@ private void OnPowerChanged(EntityUid uid, SurveillanceCameraMonitorComponent co
}
}

private void OnShutdown(EntityUid uid, SurveillanceCameraMonitorComponent component, ComponentShutdown args)
{
RemoveActiveCamera(uid, component);
}


private void OnToggleInterface(EntityUid uid, SurveillanceCameraMonitorComponent component,
AfterActivatableUIOpenEvent args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ public void AddActiveViewers(EntityUid camera, HashSet<EntityUid> players, Entit
{
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.
Expand Down Expand Up @@ -349,13 +356,12 @@ public void SwitchActiveViewers(EntityUid oldCamera, EntityUid newCamera, HashSe

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)
Expand All @@ -377,6 +383,13 @@ public void RemoveActiveViewers(EntityUid camera, HashSet<EntityUid> players, En
{
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)
Expand Down

0 comments on commit ccd9474

Please sign in to comment.