Remove client state from server AirAlarmComponent (#31236)
* Remove client state from server AirAlarmComponent Send information for all connected devices, not just the ones for the current tab, as attempting to limit this breaks multiple users viewing the same UI. Fixes #12842 * Send device data as a list, rather than a dictionary --------- Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
This commit is contained in:
@@ -30,7 +30,6 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
|
||||
_window.AutoModeChanged += OnAutoModeChanged;
|
||||
_window.ResyncAllRequested += ResyncAllDevices;
|
||||
_window.AirAlarmTabChange += OnTabChanged;
|
||||
}
|
||||
|
||||
private void ResyncAllDevices()
|
||||
@@ -63,11 +62,6 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
SendMessage(new AirAlarmUpdateAlarmThresholdMessage(address, type, threshold, gas));
|
||||
}
|
||||
|
||||
private void OnTabChanged(AirAlarmTab tab)
|
||||
{
|
||||
SendMessage(new AirAlarmTabSetMessage(tab));
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
@@ -23,7 +23,6 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
public event Action<AirAlarmMode>? AirAlarmModeChanged;
|
||||
public event Action<bool>? AutoModeChanged;
|
||||
public event Action? ResyncAllRequested;
|
||||
public event Action<AirAlarmTab>? AirAlarmTabChange;
|
||||
|
||||
private RichTextLabel _address => CDeviceAddress;
|
||||
private RichTextLabel _deviceTotal => CDeviceTotal;
|
||||
@@ -80,11 +79,6 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
_tabContainer.SetTabTitle(1, Loc.GetString("air-alarm-ui-window-tab-scrubbers"));
|
||||
_tabContainer.SetTabTitle(2, Loc.GetString("air-alarm-ui-window-tab-sensors"));
|
||||
|
||||
_tabContainer.OnTabChanged += idx =>
|
||||
{
|
||||
AirAlarmTabChange!((AirAlarmTab) idx);
|
||||
};
|
||||
|
||||
_resyncDevices.OnPressed += _ =>
|
||||
{
|
||||
_ventDevices.RemoveAllChildren();
|
||||
@@ -117,8 +111,6 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
{
|
||||
UpdateDeviceData(addr, dev);
|
||||
}
|
||||
|
||||
_tabContainer.CurrentTab = (int) state.Tab;
|
||||
}
|
||||
|
||||
public void UpdateModeSelector(AirAlarmMode mode)
|
||||
|
||||
@@ -17,8 +17,6 @@ public sealed partial class AirAlarmComponent : Component
|
||||
// Remember to null this afterwards.
|
||||
[ViewVariables] public IAirAlarmModeUpdate? CurrentModeUpdater { get; set; }
|
||||
|
||||
[ViewVariables] public AirAlarmTab CurrentTab { get; set; }
|
||||
|
||||
public readonly HashSet<string> KnownDevices = new();
|
||||
public readonly Dictionary<string, GasVentPumpData> VentData = new();
|
||||
public readonly Dictionary<string, GasVentScrubberData> ScrubberData = new();
|
||||
|
||||
@@ -173,7 +173,6 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
subs.Event<AirAlarmUpdateAlarmThresholdMessage>(OnUpdateThreshold);
|
||||
subs.Event<AirAlarmUpdateDeviceDataMessage>(OnUpdateDeviceData);
|
||||
subs.Event<AirAlarmCopyDeviceDataMessage>(OnCopyDeviceData);
|
||||
subs.Event<AirAlarmTabSetMessage>(OnTabChange);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -200,12 +199,6 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
SyncRegisterAllDevices(uid);
|
||||
}
|
||||
|
||||
private void OnTabChange(EntityUid uid, AirAlarmComponent component, AirAlarmTabSetMessage msg)
|
||||
{
|
||||
component.CurrentTab = msg.Tab;
|
||||
UpdateUI(uid, component);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, AirAlarmComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
if (args.Powered)
|
||||
@@ -598,34 +591,19 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
|
||||
var pressure = CalculatePressureAverage(alarm);
|
||||
var temperature = CalculateTemperatureAverage(alarm);
|
||||
var dataToSend = new Dictionary<string, IAtmosDeviceData>();
|
||||
var dataToSend = new List<(string, IAtmosDeviceData)>();
|
||||
|
||||
if (alarm.CurrentTab != AirAlarmTab.Settings)
|
||||
foreach (var (addr, data) in alarm.VentData)
|
||||
{
|
||||
switch (alarm.CurrentTab)
|
||||
{
|
||||
case AirAlarmTab.Vent:
|
||||
foreach (var (addr, data) in alarm.VentData)
|
||||
{
|
||||
dataToSend.Add(addr, data);
|
||||
}
|
||||
|
||||
break;
|
||||
case AirAlarmTab.Scrubber:
|
||||
foreach (var (addr, data) in alarm.ScrubberData)
|
||||
{
|
||||
dataToSend.Add(addr, data);
|
||||
}
|
||||
|
||||
break;
|
||||
case AirAlarmTab.Sensors:
|
||||
foreach (var (addr, data) in alarm.SensorData)
|
||||
{
|
||||
dataToSend.Add(addr, data);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
dataToSend.Add((addr, data));
|
||||
}
|
||||
foreach (var (addr, data) in alarm.ScrubberData)
|
||||
{
|
||||
dataToSend.Add((addr, data));
|
||||
}
|
||||
foreach (var (addr, data) in alarm.SensorData)
|
||||
{
|
||||
dataToSend.Add((addr, data));
|
||||
}
|
||||
|
||||
var deviceCount = alarm.KnownDevices.Count;
|
||||
@@ -638,7 +616,7 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
_ui.SetUiState(
|
||||
uid,
|
||||
SharedAirAlarmInterfaceKey.Key,
|
||||
new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, highestAlarm.Value, alarm.AutoMode));
|
||||
new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, highestAlarm.Value, alarm.AutoMode));
|
||||
}
|
||||
|
||||
private const float Delay = 8f;
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface IAtmosDeviceData
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
{
|
||||
public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosAlarmType alarmType, bool autoMode)
|
||||
public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, List<(string, IAtmosDeviceData)> deviceData, AirAlarmMode mode, AtmosAlarmType alarmType, bool autoMode)
|
||||
{
|
||||
Address = address;
|
||||
DeviceCount = deviceCount;
|
||||
@@ -45,7 +45,6 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
TemperatureAverage = temperatureAverage;
|
||||
DeviceData = deviceData;
|
||||
Mode = mode;
|
||||
Tab = tab;
|
||||
AlarmType = alarmType;
|
||||
AutoMode = autoMode;
|
||||
}
|
||||
@@ -57,27 +56,16 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
/// <summary>
|
||||
/// Every single device data that can be seen from this
|
||||
/// air alarm. This includes vents, scrubbers, and sensors.
|
||||
/// The device data you get, however, depends on the current
|
||||
/// selected tab.
|
||||
/// Each entry is a tuple of device address and the device
|
||||
/// data. The same address may appear multiple times, if
|
||||
/// that device provides multiple functions.
|
||||
/// </summary>
|
||||
public Dictionary<string, IAtmosDeviceData> DeviceData { get; }
|
||||
public List<(string, IAtmosDeviceData)> DeviceData { get; }
|
||||
public AirAlarmMode Mode { get; }
|
||||
public AirAlarmTab Tab { get; }
|
||||
public AtmosAlarmType AlarmType { get; }
|
||||
public bool AutoMode { get; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public AirAlarmTabSetMessage(AirAlarmTab tab)
|
||||
{
|
||||
Tab = tab;
|
||||
}
|
||||
|
||||
public AirAlarmTab Tab { get; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmResyncAllDevicesMessage : BoundUserInterfaceMessage
|
||||
{}
|
||||
@@ -144,11 +132,3 @@ public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMess
|
||||
Gas = gas;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AirAlarmTab
|
||||
{
|
||||
Vent,
|
||||
Scrubber,
|
||||
Sensors,
|
||||
Settings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user