Adds the thermo-electric generator (#18840)
* Basic TEG start. Connects via node group. * Basic TEG test map * Sensor monitoring basics, TEG circulator flow * Basic power generation (it doesn't work) * More sensor monitoring work * Battery (SMES) monitoring system. * Sensor monitoring fixes Make it work properly when mapped. * Test map improvements * Revise TEG power output mechanism. Now uses a fixed supplier with a custom ramping system. * TEG test map fixes * Make air alarms and pumps open UI on activate. * Clean up thermo machines power switch. Removed separate Enabled bool from the component that always matched the power receiver's state. This enables adding a PowerSwitch component to give us alt click/verb menu. * TEG but now fancy * Make sensor monitoring console obviously WiP to mappers. * Vending machine sound, because of course. * Terrible, terrible graph background color * Examine improvements for the TEG. * Account for electrical power when equalizing gas mixtures. * Get rid of the TegCirculatorArrow logic. Use TimedDespawn instead. The "no show in right-click menuu" goes into a new general-purpose component. Thanks Julian. * Put big notice of "not ready, here's why" on the sensor monitoring console. * TryGetComponent -> TryComp * Lol there's a HideContextMenu tag * Test fixes * Guidebook for TEG Fixed rotation on GuideEntityEmbed not working correctly. Added Margin property to GuideEntityEmbed * Make TEG power bar default to invisible. So it doesn't appear in the guidebook and spawn menu.
This commit is contained in:
committed by
GitHub
parent
61bf951ec4
commit
a242af506e
32
Content.Server/SensorMonitoring/BatterySensorComponent.cs
Normal file
32
Content.Server/SensorMonitoring/BatterySensorComponent.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Server.Power.Components;
|
||||
|
||||
namespace Content.Server.SensorMonitoring;
|
||||
|
||||
/// <summary>
|
||||
/// Enables a battery entity (such as an SMES) to be monitored via the sensor monitoring console.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The entity should also have a <see cref="BatteryComponent"/> and <see cref="PowerNetworkBatteryComponent"/>.
|
||||
/// </remarks>
|
||||
[RegisterComponent]
|
||||
public sealed class BatterySensorComponent : Component
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Device network data sent by a <see cref="BatterySensorComponent"/>.
|
||||
/// </summary>
|
||||
/// <param name="Charge">The current energy charge of the battery, in joules (J).</param>
|
||||
/// <param name="MaxCharge">The maximum energy capacity of the battery, in joules (J).</param>
|
||||
/// <param name="Receiving">The current amount of power being received by the battery, in watts (W).</param>
|
||||
/// <param name="MaxReceiving">The maximum amount of power that can be received by the battery, in watts (W).</param>
|
||||
/// <param name="Supplying">The current amount of power being supplied by the battery, in watts (W).</param>
|
||||
/// <param name="MaxSupplying">The maximum amount of power that can be received by the battery, in watts (W).</param>
|
||||
public sealed record BatterySensorData(
|
||||
float Charge,
|
||||
float MaxCharge,
|
||||
float Receiving,
|
||||
float MaxReceiving,
|
||||
float Supplying,
|
||||
float MaxSupplying
|
||||
);
|
||||
45
Content.Server/SensorMonitoring/BatterySensorSystem.cs
Normal file
45
Content.Server/SensorMonitoring/BatterySensorSystem.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
|
||||
namespace Content.Server.SensorMonitoring;
|
||||
|
||||
public sealed class BatterySensorSystem : EntitySystem
|
||||
{
|
||||
public const string DeviceNetworkCommandSyncData = "bat_sync_data";
|
||||
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<BatterySensorComponent, DeviceNetworkPacketEvent>(PacketReceived);
|
||||
}
|
||||
|
||||
private void PacketReceived(EntityUid uid, BatterySensorComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd))
|
||||
return;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case DeviceNetworkCommandSyncData:
|
||||
var battery = Comp<BatteryComponent>(uid);
|
||||
var netBattery = Comp<PowerNetworkBatteryComponent>(uid);
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = DeviceNetworkCommandSyncData,
|
||||
[DeviceNetworkCommandSyncData] = new BatterySensorData(
|
||||
battery.Charge,
|
||||
battery.MaxCharge,
|
||||
netBattery.CurrentReceiving,
|
||||
netBattery.MaxChargeRate,
|
||||
netBattery.CurrentSupply,
|
||||
netBattery.MaxSupply)
|
||||
};
|
||||
|
||||
_deviceNetwork.QueuePacket(uid, args.SenderAddress, payload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Content.Shared.SensorMonitoring;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Collections;
|
||||
|
||||
namespace Content.Server.SensorMonitoring;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class SensorMonitoringConsoleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to assign network IDs for sensors and sensor streams.
|
||||
/// </summary>
|
||||
public int IdCounter;
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, additional data streams are shown intended to only be visible for debugging.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("debug_streams")]
|
||||
public bool DebugStreams = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<EntityUid, SensorData> Sensors = new();
|
||||
|
||||
[DataField("retentionTime")]
|
||||
public TimeSpan RetentionTime = TimeSpan.FromMinutes(1);
|
||||
|
||||
// UI update tracking stuff.
|
||||
public HashSet<IPlayerSession> InitialUIStateSent = new();
|
||||
public TimeSpan LastUIUpdate;
|
||||
public ValueList<int> RemovedSensors;
|
||||
|
||||
public sealed class SensorData
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int NetId;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public SensorDeviceType DeviceType;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, SensorStream> Streams = new();
|
||||
}
|
||||
|
||||
public sealed class SensorStream
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int NetId;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public SensorUnit Unit;
|
||||
|
||||
// Queue<T> is a ring buffer internally, and we can still iterate over it.
|
||||
// I don't wanna write a ring buffer myself, so this is pretty convenient!
|
||||
[ViewVariables]
|
||||
public Queue<SensorSample> Samples = new();
|
||||
}
|
||||
|
||||
public sealed class ViewingPlayer
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Shared.SensorMonitoring;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Collections;
|
||||
using ConsoleUIState = Content.Shared.SensorMonitoring.SensorMonitoringConsoleBoundInterfaceState;
|
||||
using IncrementalUIState = Content.Shared.SensorMonitoring.SensorMonitoringIncrementalUpdate;
|
||||
|
||||
namespace Content.Server.SensorMonitoring;
|
||||
|
||||
public sealed partial class SensorMonitoringConsoleSystem
|
||||
{
|
||||
private void InitUI()
|
||||
{
|
||||
SubscribeLocalEvent<SensorMonitoringConsoleComponent, BoundUIClosedEvent>(ConsoleUIClosed);
|
||||
}
|
||||
|
||||
private void UpdateConsoleUI(EntityUid uid, SensorMonitoringConsoleComponent comp)
|
||||
{
|
||||
if (!_userInterface.TryGetUi(uid, SensorMonitoringConsoleUiKey.Key, out var ui))
|
||||
return;
|
||||
|
||||
if (ui.SubscribedSessions.Count == 0)
|
||||
return;
|
||||
|
||||
ConsoleUIState? fullState = null;
|
||||
SensorMonitoringIncrementalUpdate? incrementalUpdate = null;
|
||||
|
||||
foreach (var session in ui.SubscribedSessions)
|
||||
{
|
||||
if (comp.InitialUIStateSent.Contains(session))
|
||||
{
|
||||
incrementalUpdate ??= CalculateIncrementalUpdate();
|
||||
_userInterface.TrySendUiMessage(ui, incrementalUpdate, session);
|
||||
}
|
||||
else
|
||||
{
|
||||
fullState ??= CalculateFullState();
|
||||
UserInterfaceSystem.SetUiState(ui, fullState, session);
|
||||
comp.InitialUIStateSent.Add(session);
|
||||
}
|
||||
}
|
||||
|
||||
comp.LastUIUpdate = _gameTiming.CurTime;
|
||||
comp.RemovedSensors.Clear();
|
||||
|
||||
ConsoleUIState CalculateFullState()
|
||||
{
|
||||
var sensors = new ValueList<ConsoleUIState.SensorData>();
|
||||
var streams = new ValueList<ConsoleUIState.SensorStream>();
|
||||
|
||||
foreach (var (ent, data) in comp.Sensors)
|
||||
{
|
||||
streams.Clear();
|
||||
var name = MetaData(ent).EntityName;
|
||||
var address = Comp<DeviceNetworkComponent>(ent).Address;
|
||||
|
||||
foreach (var (streamName, stream) in data.Streams)
|
||||
{
|
||||
streams.Add(new ConsoleUIState.SensorStream
|
||||
{
|
||||
NetId = stream.NetId,
|
||||
Name = streamName,
|
||||
Unit = stream.Unit,
|
||||
Samples = stream.Samples.ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
sensors.Add(new ConsoleUIState.SensorData
|
||||
{
|
||||
NetId = data.NetId,
|
||||
Name = name,
|
||||
Address = address,
|
||||
DeviceType = data.DeviceType,
|
||||
Streams = streams.ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
return new ConsoleUIState
|
||||
{
|
||||
RetentionTime = comp.RetentionTime,
|
||||
Sensors = sensors.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
SensorMonitoringIncrementalUpdate CalculateIncrementalUpdate()
|
||||
{
|
||||
var sensors = new ValueList<IncrementalUIState.SensorData>();
|
||||
var streams = new ValueList<IncrementalUIState.SensorStream>();
|
||||
var samples = new ValueList<SensorSample>();
|
||||
|
||||
foreach (var data in comp.Sensors.Values)
|
||||
{
|
||||
streams.Clear();
|
||||
|
||||
foreach (var stream in data.Streams.Values)
|
||||
{
|
||||
samples.Clear();
|
||||
foreach (var (sampleTime, value) in stream.Samples)
|
||||
{
|
||||
if (sampleTime >= comp.LastUIUpdate)
|
||||
samples.Add(new SensorSample(sampleTime - comp.LastUIUpdate, value));
|
||||
}
|
||||
|
||||
streams.Add(new IncrementalUIState.SensorStream
|
||||
{
|
||||
NetId = stream.NetId,
|
||||
Unit = stream.Unit,
|
||||
Samples = samples.ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
sensors.Add(new IncrementalUIState.SensorData { NetId = data.NetId, Streams = streams.ToArray() });
|
||||
}
|
||||
|
||||
return new IncrementalUIState
|
||||
{
|
||||
RelTime = comp.LastUIUpdate,
|
||||
RemovedSensors = comp.RemovedSensors.ToArray(),
|
||||
Sensors = sensors.ToArray(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConsoleUIClosed(
|
||||
EntityUid uid,
|
||||
SensorMonitoringConsoleComponent component,
|
||||
BoundUIClosedEvent args)
|
||||
{
|
||||
if (!args.UiKey.Equals(SensorMonitoringConsoleUiKey.Key))
|
||||
return;
|
||||
|
||||
if (args.Session is not IPlayerSession player)
|
||||
return;
|
||||
|
||||
component.InitialUIStateSent.Remove(player);
|
||||
}
|
||||
}
|
||||
329
Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs
Normal file
329
Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs
Normal file
@@ -0,0 +1,329 @@
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.Atmos.Monitor.Systems;
|
||||
using Content.Server.Atmos.Piping.Binary.Components;
|
||||
using Content.Server.Atmos.Piping.Components;
|
||||
using Content.Server.Atmos.Piping.Unary.Components;
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Power.Generation.Teg;
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Content.Shared.DeviceNetwork.Systems;
|
||||
using Content.Shared.SensorMonitoring;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using ConsoleUIState = Content.Shared.SensorMonitoring.SensorMonitoringConsoleBoundInterfaceState;
|
||||
|
||||
namespace Content.Server.SensorMonitoring;
|
||||
|
||||
public sealed partial class SensorMonitoringConsoleSystem : EntitySystem
|
||||
{
|
||||
// TODO: THIS THING IS HEAVILY WIP AND NOT READY FOR GENERAL USE BY PLAYERS.
|
||||
// Some of the issues, off the top of my head:
|
||||
// Way too huge network load when opened
|
||||
// UI doesn't update properly in cases like adding new streams/devices
|
||||
// Deleting connected devices causes exceptions
|
||||
// UI sucks. need a way to make basic dashboards like Grafana, and save them.
|
||||
|
||||
private EntityQuery<DeviceNetworkComponent> _deviceNetworkQuery;
|
||||
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
InitUI();
|
||||
|
||||
UpdatesBefore.Add(typeof(UserInterfaceSystem));
|
||||
|
||||
SubscribeLocalEvent<SensorMonitoringConsoleComponent, DeviceListUpdateEvent>(DeviceListUpdated);
|
||||
SubscribeLocalEvent<SensorMonitoringConsoleComponent, ComponentStartup>(ConsoleStartup);
|
||||
SubscribeLocalEvent<SensorMonitoringConsoleComponent, DeviceNetworkPacketEvent>(DevicePacketReceived);
|
||||
SubscribeLocalEvent<SensorMonitoringConsoleComponent, AtmosDeviceUpdateEvent>(AtmosUpdate);
|
||||
|
||||
_deviceNetworkQuery = GetEntityQuery<DeviceNetworkComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var consoles = EntityQueryEnumerator<SensorMonitoringConsoleComponent>();
|
||||
while (consoles.MoveNext(out var entityUid, out var comp))
|
||||
{
|
||||
UpdateConsole(entityUid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateConsole(EntityUid uid, SensorMonitoringConsoleComponent comp)
|
||||
{
|
||||
var minTime = _gameTiming.CurTime - comp.RetentionTime;
|
||||
|
||||
SensorUpdate(uid, comp);
|
||||
|
||||
foreach (var data in comp.Sensors.Values)
|
||||
{
|
||||
// Cull old data.
|
||||
foreach (var stream in data.Streams.Values)
|
||||
{
|
||||
while (stream.Samples.TryPeek(out var sample) && sample.Time < minTime)
|
||||
{
|
||||
stream.Samples.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpdateConsoleUI(uid, comp);
|
||||
}
|
||||
|
||||
private void ConsoleStartup(EntityUid uid, SensorMonitoringConsoleComponent component, ComponentStartup args)
|
||||
{
|
||||
if (TryComp(uid, out DeviceListComponent? network))
|
||||
UpdateDevices(uid, component, network.Devices, Array.Empty<EntityUid>());
|
||||
}
|
||||
|
||||
private void DeviceListUpdated(
|
||||
EntityUid uid,
|
||||
SensorMonitoringConsoleComponent component,
|
||||
DeviceListUpdateEvent args)
|
||||
{
|
||||
UpdateDevices(uid, component, args.Devices, args.OldDevices);
|
||||
}
|
||||
|
||||
private void UpdateDevices(
|
||||
EntityUid uid,
|
||||
SensorMonitoringConsoleComponent component,
|
||||
IEnumerable<EntityUid> newDevices,
|
||||
IEnumerable<EntityUid> oldDevices)
|
||||
{
|
||||
var kept = new HashSet<EntityUid>();
|
||||
|
||||
foreach (var newDevice in newDevices)
|
||||
{
|
||||
var deviceType = DetectDeviceType(newDevice);
|
||||
if (deviceType == SensorDeviceType.Unknown)
|
||||
continue;
|
||||
|
||||
kept.Add(newDevice);
|
||||
var sensor = component.Sensors.GetOrNew(newDevice);
|
||||
sensor.DeviceType = deviceType;
|
||||
if (sensor.NetId == 0)
|
||||
sensor.NetId = MakeNetId(component);
|
||||
}
|
||||
|
||||
foreach (var oldDevice in oldDevices)
|
||||
{
|
||||
if (kept.Contains(oldDevice))
|
||||
continue;
|
||||
|
||||
if (component.Sensors.TryGetValue(oldDevice, out var sensorData))
|
||||
{
|
||||
component.RemovedSensors.Add(sensorData.NetId);
|
||||
component.Sensors.Remove(oldDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SensorDeviceType DetectDeviceType(EntityUid entity)
|
||||
{
|
||||
if (HasComp<TegGeneratorComponent>(entity))
|
||||
return SensorDeviceType.Teg;
|
||||
|
||||
if (HasComp<AtmosMonitorComponent>(entity))
|
||||
return SensorDeviceType.AtmosSensor;
|
||||
|
||||
if (HasComp<GasThermoMachineComponent>(entity))
|
||||
return SensorDeviceType.ThermoMachine;
|
||||
|
||||
if (HasComp<GasVolumePumpComponent>(entity))
|
||||
return SensorDeviceType.VolumePump;
|
||||
|
||||
if (HasComp<BatterySensorComponent>(entity))
|
||||
return SensorDeviceType.Battery;
|
||||
|
||||
return SensorDeviceType.Unknown;
|
||||
}
|
||||
|
||||
private void DevicePacketReceived(EntityUid uid, SensorMonitoringConsoleComponent component,
|
||||
DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!component.Sensors.TryGetValue(args.Sender, out var sensorData))
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? command))
|
||||
return;
|
||||
|
||||
switch (sensorData.DeviceType)
|
||||
{
|
||||
case SensorDeviceType.Teg:
|
||||
if (command != TegSystem.DeviceNetworkCommandSyncData)
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(TegSystem.DeviceNetworkCommandSyncData, out TegSensorData? tegData))
|
||||
return;
|
||||
|
||||
// @formatter:off
|
||||
WriteSample(component, sensorData, "teg_last_generated", SensorUnit.EnergyJ, tegData.LastGeneration);
|
||||
WriteSample(component, sensorData, "teg_power", SensorUnit.PowerW, tegData.PowerOutput);
|
||||
if (component.DebugStreams)
|
||||
WriteSample(component, sensorData, "teg_ramp_pos", SensorUnit.PowerW, tegData.RampPosition);
|
||||
|
||||
WriteSample(component, sensorData, "teg_circ_a_in_pressure", SensorUnit.PressureKpa, tegData.CirculatorA.InletPressure);
|
||||
WriteSample(component, sensorData, "teg_circ_a_in_temperature", SensorUnit.TemperatureK, tegData.CirculatorA.InletTemperature);
|
||||
WriteSample(component, sensorData, "teg_circ_a_out_pressure", SensorUnit.PressureKpa, tegData.CirculatorA.OutletPressure);
|
||||
WriteSample(component, sensorData, "teg_circ_a_out_temperature", SensorUnit.TemperatureK, tegData.CirculatorA.OutletTemperature);
|
||||
|
||||
WriteSample(component, sensorData, "teg_circ_b_in_pressure", SensorUnit.PressureKpa, tegData.CirculatorB.InletPressure);
|
||||
WriteSample(component, sensorData, "teg_circ_b_in_temperature", SensorUnit.TemperatureK, tegData.CirculatorB.InletTemperature);
|
||||
WriteSample(component, sensorData, "teg_circ_b_out_pressure", SensorUnit.PressureKpa, tegData.CirculatorB.OutletPressure);
|
||||
WriteSample(component, sensorData, "teg_circ_b_out_temperature", SensorUnit.TemperatureK, tegData.CirculatorB.OutletTemperature);
|
||||
// @formatter:on
|
||||
break;
|
||||
|
||||
case SensorDeviceType.AtmosSensor:
|
||||
if (command != AtmosDeviceNetworkSystem.SyncData)
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(AtmosDeviceNetworkSystem.SyncData, out AtmosSensorData? atmosData))
|
||||
return;
|
||||
|
||||
// @formatter:off
|
||||
WriteSample(component, sensorData, "atmo_pressure", SensorUnit.PressureKpa, atmosData.Pressure);
|
||||
WriteSample(component, sensorData, "atmo_temperature", SensorUnit.TemperatureK, atmosData.Temperature);
|
||||
// @formatter:on
|
||||
break;
|
||||
|
||||
case SensorDeviceType.ThermoMachine:
|
||||
if (command != AtmosDeviceNetworkSystem.SyncData)
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(AtmosDeviceNetworkSystem.SyncData, out GasThermoMachineData? thermoData))
|
||||
return;
|
||||
|
||||
// @formatter:off
|
||||
WriteSample(component, sensorData, "abs_energy_delta", SensorUnit.EnergyJ, MathF.Abs(thermoData.EnergyDelta));
|
||||
// @formatter:on
|
||||
break;
|
||||
|
||||
case SensorDeviceType.VolumePump:
|
||||
if (command != AtmosDeviceNetworkSystem.SyncData)
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(AtmosDeviceNetworkSystem.SyncData, out GasVolumePumpData? volumePumpData))
|
||||
return;
|
||||
|
||||
// @formatter:off
|
||||
WriteSample(component, sensorData, "moles_transferred", SensorUnit.Moles, volumePumpData.LastMolesTransferred);
|
||||
// @formatter:on
|
||||
break;
|
||||
|
||||
case SensorDeviceType.Battery:
|
||||
if (command != BatterySensorSystem.DeviceNetworkCommandSyncData)
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(BatterySensorSystem.DeviceNetworkCommandSyncData, out BatterySensorData? batteryData))
|
||||
return;
|
||||
|
||||
// @formatter:off
|
||||
WriteSample(component, sensorData, "charge", SensorUnit.EnergyJ, batteryData.Charge);
|
||||
WriteSample(component, sensorData, "charge_max", SensorUnit.EnergyJ, batteryData.MaxCharge);
|
||||
|
||||
WriteSample(component, sensorData, "receiving", SensorUnit.PowerW, batteryData.Receiving);
|
||||
WriteSample(component, sensorData, "receiving_max", SensorUnit.PowerW, batteryData.MaxReceiving);
|
||||
|
||||
WriteSample(component, sensorData, "supplying", SensorUnit.PowerW, batteryData.Supplying);
|
||||
WriteSample(component, sensorData, "supplying_max", SensorUnit.PowerW, batteryData.MaxSupplying);
|
||||
// @formatter:on
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSample(
|
||||
SensorMonitoringConsoleComponent component,
|
||||
SensorMonitoringConsoleComponent.SensorData sensorData,
|
||||
string streamName,
|
||||
SensorUnit unit,
|
||||
float value)
|
||||
{
|
||||
var stream = sensorData.Streams.GetOrNew(streamName);
|
||||
stream.Unit = unit;
|
||||
if (stream.NetId == 0)
|
||||
stream.NetId = MakeNetId(component);
|
||||
|
||||
var time = _gameTiming.CurTime;
|
||||
stream.Samples.Enqueue(new SensorSample(time, value));
|
||||
}
|
||||
|
||||
private static int MakeNetId(SensorMonitoringConsoleComponent component)
|
||||
{
|
||||
return ++component.IdCounter;
|
||||
}
|
||||
|
||||
private void AtmosUpdate(
|
||||
EntityUid uid,
|
||||
SensorMonitoringConsoleComponent comp,
|
||||
AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
foreach (var (ent, data) in comp.Sensors)
|
||||
{
|
||||
// Send network requests for new data!
|
||||
NetworkPayload payload;
|
||||
switch (data.DeviceType)
|
||||
{
|
||||
case SensorDeviceType.Teg:
|
||||
payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = TegSystem.DeviceNetworkCommandSyncData
|
||||
};
|
||||
break;
|
||||
|
||||
case SensorDeviceType.AtmosSensor:
|
||||
case SensorDeviceType.ThermoMachine:
|
||||
case SensorDeviceType.VolumePump:
|
||||
payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AtmosDeviceNetworkSystem.SyncData
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unknown device type, don't do anything.
|
||||
continue;
|
||||
}
|
||||
|
||||
var address = _deviceNetworkQuery.GetComponent(ent);
|
||||
_deviceNetwork.QueuePacket(uid, address.Address, payload);
|
||||
}
|
||||
}
|
||||
|
||||
private void SensorUpdate(EntityUid uid, SensorMonitoringConsoleComponent comp)
|
||||
{
|
||||
foreach (var (ent, data) in comp.Sensors)
|
||||
{
|
||||
// Send network requests for new data!
|
||||
NetworkPayload payload;
|
||||
switch (data.DeviceType)
|
||||
{
|
||||
case SensorDeviceType.Battery:
|
||||
payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = BatterySensorSystem.DeviceNetworkCommandSyncData
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unknown device type, don't do anything.
|
||||
continue;
|
||||
}
|
||||
|
||||
var address = _deviceNetworkQuery.GetComponent(ent);
|
||||
_deviceNetwork.QueuePacket(uid, address.Address, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user