Predict gasthermomachines (#33837)

* Predict gasthermomachines

* despawn

* smellby
This commit is contained in:
metalgearsloth
2025-05-13 21:49:43 +10:00
committed by GitHub
parent 24141aa1e9
commit df2257cd92
16 changed files with 236 additions and 135 deletions

View File

@@ -1,5 +1,8 @@
using Content.Shared.Atmos;
using Content.Client.Power.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Piping.Unary.Systems;
using Content.Shared.Power.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
@@ -36,6 +39,8 @@ namespace Content.Client.Atmos.UI
_window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
_window.TemperatureSpinbox.OnValueChanged += _ => OnTemperatureChanged(_window.TemperatureSpinbox.Value);
_window.Entity = Owner;
Update();
}
private void OnToggleStatusButtonPressed()
@@ -43,7 +48,7 @@ namespace Content.Client.Atmos.UI
if (_window is null) return;
_window.SetActive(!_window.Active);
SendMessage(new GasThermomachineToggleMessage());
SendPredictedMessage(new GasThermomachineToggleMessage());
}
private void OnTemperatureChanged(float value)
@@ -60,25 +65,32 @@ namespace Content.Client.Atmos.UI
return;
}
SendMessage(new GasThermomachineChangeTemperatureMessage(actual));
SendPredictedMessage(new GasThermomachineChangeTemperatureMessage(actual));
}
/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
/// <param name="state"></param>
protected override void UpdateState(BoundUserInterfaceState state)
public override void Update()
{
base.UpdateState(state);
if (_window == null || state is not GasThermomachineBoundUserInterfaceState cast)
if (_window == null || !EntMan.TryGetComponent(Owner, out GasThermoMachineComponent? thermo))
return;
_minTemp = cast.MinTemperature;
_maxTemp = cast.MaxTemperature;
_isHeater = cast.IsHeater;
var system = EntMan.System<SharedGasThermoMachineSystem>();
_minTemp = thermo.MinTemperature;
_maxTemp = thermo.MaxTemperature;
_isHeater = system.IsHeater(thermo);
_window.SetTemperature(thermo.TargetTemperature);
var receiverSys = EntMan.System<PowerReceiverSystem>();
SharedApcPowerReceiverComponent? receiver = null;
receiverSys.ResolveApc(Owner, ref receiver);
// Also set in frameupdates.
if (receiver != null)
{
_window.SetActive(!receiver.PowerDisabled);
}
_window.SetTemperature(cast.Temperature);
_window.SetActive(cast.Enabled);
_window.Title = _isHeater switch
{
false => Loc.GetString("comp-gas-thermomachine-ui-title-freezer"),