using System.Linq; using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; using Content.Server.Medical.SuitSensors; using Content.Server.UserInterface; using Content.Shared.Medical.CrewMonitoring; using Robust.Shared.Map; using Content.Shared.Medical.SuitSensor; using Robust.Shared.Timing; namespace Content.Server.Medical.CrewMonitoring { public sealed class CrewMonitoringConsoleSystem : EntitySystem { [Dependency] private readonly SuitSensorSystem _sensors = default!; [Dependency] private readonly SharedTransformSystem _xform = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IMapManager _mapManager = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnRemove); SubscribeLocalEvent(OnPacketReceived); SubscribeLocalEvent(OnUIOpened); } private void OnRemove(EntityUid uid, CrewMonitoringConsoleComponent component, ComponentRemove args) { component.ConnectedSensors.Clear(); } private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent component, DeviceNetworkPacketEvent args) { var payload = args.Data; // check command if (!payload.TryGetValue(DeviceNetworkConstants.Command, out string? command)) return; if (command != DeviceNetworkConstants.CmdUpdatedState) return; if (!payload.TryGetValue(SuitSensorConstants.NET_STATUS_COLLECTION, out Dictionary? sensorStatus)) return; component.ConnectedSensors = sensorStatus; UpdateUserInterface(uid, component); } private void OnUIOpened(EntityUid uid, CrewMonitoringConsoleComponent component, BoundUIOpenedEvent args) { UpdateUserInterface(uid, component); } private void UpdateUserInterface(EntityUid uid, CrewMonitoringConsoleComponent? component = null) { if (!Resolve(uid, ref component)) return; var ui = component.Owner.GetUIOrNull(CrewMonitoringUIKey.Key); if (ui == null) return; // update all sensors info var xform = Transform(uid); var allSensors = component.ConnectedSensors.Values.ToList(); var uiState = new CrewMonitoringState(allSensors, xform.WorldPosition, component.Snap, component.Precision); ui.SetState(uiState); } } }