2022-04-09 13:50:59 +12:00
|
|
|
using System.Linq;
|
2023-01-23 02:07:57 +01:00
|
|
|
using Content.Server.DeviceNetwork;
|
2021-12-29 08:19:00 +03:00
|
|
|
using Content.Server.DeviceNetwork.Systems;
|
|
|
|
|
using Content.Server.Medical.SuitSensors;
|
|
|
|
|
using Content.Server.UserInterface;
|
|
|
|
|
using Content.Shared.Medical.CrewMonitoring;
|
2023-01-09 08:25:46 -05:00
|
|
|
using Robust.Shared.Map;
|
2023-01-23 02:07:57 +01:00
|
|
|
using Content.Shared.Medical.SuitSensor;
|
2021-12-29 08:19:00 +03:00
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Medical.CrewMonitoring
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class CrewMonitoringConsoleSystem : EntitySystem
|
2021-12-29 08:19:00 +03:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SuitSensorSystem _sensors = default!;
|
2022-10-16 13:07:42 +13:00
|
|
|
[Dependency] private readonly SharedTransformSystem _xform = default!;
|
2021-12-29 08:19:00 +03:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2023-01-23 02:07:57 +01:00
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
2021-12-29 08:19:00 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<CrewMonitoringConsoleComponent, ComponentRemove>(OnRemove);
|
2022-04-09 00:27:10 +12:00
|
|
|
SubscribeLocalEvent<CrewMonitoringConsoleComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
2023-01-23 02:07:57 +01:00
|
|
|
SubscribeLocalEvent<CrewMonitoringConsoleComponent, BoundUIOpenedEvent>(OnUIOpened);
|
2021-12-29 08:19:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRemove(EntityUid uid, CrewMonitoringConsoleComponent component, ComponentRemove args)
|
|
|
|
|
{
|
|
|
|
|
component.ConnectedSensors.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-09 00:27:10 +12:00
|
|
|
private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent component, DeviceNetworkPacketEvent args)
|
2021-12-29 08:19:00 +03:00
|
|
|
{
|
2023-01-23 02:07:57 +01:00
|
|
|
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<string, SuitSensorStatus>? sensorStatus))
|
2021-12-29 08:19:00 +03:00
|
|
|
return;
|
|
|
|
|
|
2023-01-23 02:07:57 +01:00
|
|
|
component.ConnectedSensors = sensorStatus;
|
|
|
|
|
UpdateUserInterface(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUIOpened(EntityUid uid, CrewMonitoringConsoleComponent component, BoundUIOpenedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateUserInterface(uid, component);
|
2021-12-29 08:19:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2023-01-09 08:25:46 -05:00
|
|
|
var xform = Transform(uid);
|
2021-12-29 08:19:00 +03:00
|
|
|
var allSensors = component.ConnectedSensors.Values.ToList();
|
2023-01-09 08:25:46 -05:00
|
|
|
var uiState = new CrewMonitoringState(allSensors, xform.WorldPosition, component.Snap, component.Precision);
|
2021-12-29 08:19:00 +03:00
|
|
|
ui.SetState(uiState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|