Predict gas volume pumps (#33835)
* Predict gas volume pumps * Also this one * Review
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||||
|
using Content.Shared.Atmos.Piping.Binary.Systems;
|
||||||
|
using Robust.Client.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Client.Atmos.Piping.Binary.Systems;
|
||||||
|
|
||||||
|
public sealed class GasVolumePumpSystem : SharedGasVolumePumpSystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, AfterAutoHandleStateEvent>(OnPumpState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateUi(Entity<GasVolumePumpComponent> entity)
|
||||||
|
{
|
||||||
|
if (_ui.TryGetOpenUi(entity.Owner, GasVolumePumpUiKey.Key, out var bui))
|
||||||
|
{
|
||||||
|
bui.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPumpState(Entity<GasVolumePumpComponent> ent, ref AfterAutoHandleStateEvent args)
|
||||||
|
{
|
||||||
|
UpdateUi(ent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
using Content.Shared.IdentityManagement;
|
||||||
using Content.Shared.Localizations;
|
using Content.Shared.Localizations;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.UI
|
namespace Content.Client.Atmos.UI
|
||||||
@@ -14,7 +13,7 @@ namespace Content.Client.Atmos.UI
|
|||||||
public sealed class GasVolumePumpBoundUserInterface : BoundUserInterface
|
public sealed class GasVolumePumpBoundUserInterface : BoundUserInterface
|
||||||
{
|
{
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private const float MaxTransferRate = Atmospherics.MaxTransferRate;
|
private float _maxTransferRate;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private GasVolumePumpWindow? _window;
|
private GasVolumePumpWindow? _window;
|
||||||
@@ -29,38 +28,41 @@ namespace Content.Client.Atmos.UI
|
|||||||
|
|
||||||
_window = this.CreateWindow<GasVolumePumpWindow>();
|
_window = this.CreateWindow<GasVolumePumpWindow>();
|
||||||
|
|
||||||
|
if (EntMan.TryGetComponent(Owner, out GasVolumePumpComponent? pump))
|
||||||
|
{
|
||||||
|
_maxTransferRate = pump.MaxTransferRate;
|
||||||
|
}
|
||||||
|
|
||||||
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
|
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
|
||||||
_window.PumpTransferRateChanged += OnPumpTransferRatePressed;
|
_window.PumpTransferRateChanged += OnPumpTransferRatePressed;
|
||||||
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnToggleStatusButtonPressed()
|
private void OnToggleStatusButtonPressed()
|
||||||
{
|
{
|
||||||
if (_window is null) return;
|
if (_window is null) return;
|
||||||
SendMessage(new GasVolumePumpToggleStatusMessage(_window.PumpStatus));
|
|
||||||
|
SendPredictedMessage(new GasVolumePumpToggleStatusMessage(_window.PumpStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPumpTransferRatePressed(string value)
|
private void OnPumpTransferRatePressed(string value)
|
||||||
{
|
{
|
||||||
var rate = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;
|
var rate = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;
|
||||||
if (rate > MaxTransferRate)
|
rate = Math.Clamp(rate, 0f, _maxTransferRate);
|
||||||
rate = MaxTransferRate;
|
|
||||||
|
|
||||||
SendMessage(new GasVolumePumpChangeTransferRateMessage(rate));
|
SendPredictedMessage(new GasVolumePumpChangeTransferRateMessage(rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public override void Update()
|
||||||
/// Update the UI state based on server-sent info
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="state"></param>
|
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
|
||||||
{
|
{
|
||||||
base.UpdateState(state);
|
base.Update();
|
||||||
if (_window == null || state is not GasVolumePumpBoundUserInterfaceState cast)
|
|
||||||
|
if (_window is null || !EntMan.TryGetComponent(Owner, out GasVolumePumpComponent? pump))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_window.Title = cast.PumpLabel;
|
_window.Title = Identity.Name(Owner, EntMan);
|
||||||
_window.SetPumpStatus(cast.Enabled);
|
_window.SetPumpStatus(pump.Enabled);
|
||||||
_window.SetTransferRate(cast.TransferRate);
|
_window.SetTransferRate(pump.TransferRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<DefaultWindow xmlns="https://spacestation14.io"
|
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||||
MinSize="200 120" Title="Volume Pump">
|
MinSize="200 120" Title="Volume Pump">
|
||||||
<BoxContainer Orientation="Vertical" Margin="5 5 5 5" SeparationOverride="10">
|
<BoxContainer Orientation="Vertical" Margin="5 5 5 5" SeparationOverride="10">
|
||||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||||
@@ -19,4 +20,4 @@
|
|||||||
<Button Name="SetTransferRateButton" Text="{Loc comp-gas-pump-ui-pump-set-rate}" HorizontalAlignment="Right" Disabled="True"/>
|
<Button Name="SetTransferRateButton" Text="{Loc comp-gas-pump-ui-pump-set-rate}" HorizontalAlignment="Right" Disabled="True"/>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</DefaultWindow>
|
</controls:FancyWindow>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Content.Client.Atmos.EntitySystems;
|
using Content.Client.Atmos.EntitySystems;
|
||||||
|
using Content.Client.UserInterface.Controls;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Atmos.Prototypes;
|
using Content.Shared.Atmos.Prototypes;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
@@ -16,7 +17,7 @@ namespace Content.Client.Atmos.UI
|
|||||||
/// Client-side UI used to control a gas volume pump.
|
/// Client-side UI used to control a gas volume pump.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class GasVolumePumpWindow : DefaultWindow
|
public sealed partial class GasVolumePumpWindow : FancyWindow
|
||||||
{
|
{
|
||||||
public bool PumpStatus = true;
|
public bool PumpStatus = true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
using Content.Shared.Atmos;
|
|
||||||
using Content.Shared.Guidebook;
|
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Piping.Binary.Components
|
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed partial class GasVolumePumpComponent : Component
|
|
||||||
{
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("enabled")]
|
|
||||||
public bool Enabled { get; set; } = true;
|
|
||||||
|
|
||||||
[DataField("blocked")]
|
|
||||||
public bool Blocked { get; set; } = false;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public bool Overclocked { get; set; } = false;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("inlet")]
|
|
||||||
public string InletName { get; set; } = "inlet";
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("outlet")]
|
|
||||||
public string OutletName { get; set; } = "outlet";
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("transferRate")]
|
|
||||||
public float TransferRate { get; set; } = Atmospherics.MaxTransferRate;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("maxTransferRate")]
|
|
||||||
public float MaxTransferRate { get; set; } = Atmospherics.MaxTransferRate;
|
|
||||||
|
|
||||||
[DataField("leakRatio")]
|
|
||||||
public float LeakRatio { get; set; } = 0.1f;
|
|
||||||
|
|
||||||
[DataField("lowerThreshold")]
|
|
||||||
public float LowerThreshold { get; set; } = 0.01f;
|
|
||||||
|
|
||||||
[DataField("higherThreshold")]
|
|
||||||
[GuidebookData]
|
|
||||||
public float HigherThreshold { get; set; } = DefaultHigherThreshold;
|
|
||||||
public static readonly float DefaultHigherThreshold = 2 * Atmospherics.MaxOutputPressure;
|
|
||||||
|
|
||||||
[DataField("overclockThreshold")]
|
|
||||||
public float OverclockThreshold { get; set; } = 1000;
|
|
||||||
|
|
||||||
[DataField("lastMolesTransferred")]
|
|
||||||
public float LastMolesTransferred;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Content.Server.Administration.Logs;
|
|
||||||
using Content.Server.Atmos.EntitySystems;
|
using Content.Server.Atmos.EntitySystems;
|
||||||
using Content.Server.Atmos.Monitor.Systems;
|
using Content.Server.Atmos.Monitor.Systems;
|
||||||
using Content.Server.Atmos.Piping.Binary.Components;
|
|
||||||
using Content.Server.Atmos.Piping.Components;
|
using Content.Server.Atmos.Piping.Components;
|
||||||
using Content.Server.DeviceNetwork;
|
using Content.Server.DeviceNetwork;
|
||||||
using Content.Server.DeviceNetwork.Components;
|
using Content.Server.DeviceNetwork.Components;
|
||||||
@@ -10,73 +8,34 @@ using Content.Server.NodeContainer.EntitySystems;
|
|||||||
using Content.Server.NodeContainer.Nodes;
|
using Content.Server.NodeContainer.Nodes;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||||
|
using Content.Shared.Atmos.Piping.Binary.Systems;
|
||||||
using Content.Shared.Atmos.Piping.Components;
|
using Content.Shared.Atmos.Piping.Components;
|
||||||
using Content.Shared.Atmos.Visuals;
|
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Database;
|
|
||||||
using Content.Shared.DeviceNetwork;
|
using Content.Shared.DeviceNetwork;
|
||||||
using Content.Shared.Examine;
|
|
||||||
using Content.Shared.Interaction;
|
|
||||||
using Content.Shared.Popups;
|
|
||||||
using Content.Shared.Power;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Player;
|
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class GasVolumePumpSystem : EntitySystem
|
public sealed class GasVolumePumpSystem : SharedGasVolumePumpSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||||
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
||||||
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
||||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
||||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
||||||
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, ComponentInit>(OnInit);
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated);
|
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated);
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceDisabledEvent>(OnVolumePumpLeaveAtmosphere);
|
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceDisabledEvent>(OnVolumePumpLeaveAtmosphere);
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, ActivateInWorldEvent>(OnPumpActivate);
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, PowerChangedEvent>(OnPowerChanged);
|
|
||||||
// Bound UI subscriptions
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
|
|
||||||
|
|
||||||
SubscribeLocalEvent<GasVolumePumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
SubscribeLocalEvent<GasVolumePumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, GasVolumePumpComponent pump, ComponentInit args)
|
|
||||||
{
|
|
||||||
UpdateAppearance(uid, pump);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args)
|
|
||||||
{
|
|
||||||
if (!EntityManager.GetComponent<TransformComponent>(uid).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Loc.TryGetString("gas-volume-pump-system-examined", out var str,
|
|
||||||
("statusColor", "lightblue"), // TODO: change with volume?
|
|
||||||
("rate", pump.TransferRate)
|
|
||||||
))
|
|
||||||
args.PushMarkup(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPowerChanged(EntityUid uid, GasVolumePumpComponent component, ref PowerChangedEvent args)
|
|
||||||
{
|
|
||||||
UpdateAppearance(uid, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnVolumePumpUpdated(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceUpdateEvent args)
|
private void OnVolumePumpUpdated(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceUpdateEvent args)
|
||||||
{
|
{
|
||||||
if (!pump.Enabled ||
|
if (!pump.Enabled ||
|
||||||
@@ -134,78 +93,18 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
|||||||
private void OnVolumePumpLeaveAtmosphere(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceDisabledEvent args)
|
private void OnVolumePumpLeaveAtmosphere(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceDisabledEvent args)
|
||||||
{
|
{
|
||||||
pump.Enabled = false;
|
pump.Enabled = false;
|
||||||
|
Dirty(uid, pump);
|
||||||
UpdateAppearance(uid, pump);
|
UpdateAppearance(uid, pump);
|
||||||
|
|
||||||
DirtyUI(uid, pump);
|
|
||||||
_userInterfaceSystem.CloseUi(uid, GasVolumePumpUiKey.Key);
|
_userInterfaceSystem.CloseUi(uid, GasVolumePumpUiKey.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPumpActivate(EntityUid uid, GasVolumePumpComponent pump, ActivateInWorldEvent args)
|
|
||||||
{
|
|
||||||
if (args.Handled || !args.Complex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Transform(uid).Anchored)
|
|
||||||
{
|
|
||||||
_userInterfaceSystem.OpenUi(uid, GasVolumePumpUiKey.Key, actor.PlayerSession);
|
|
||||||
DirtyUI(uid, pump);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_popup.PopupCursor(Loc.GetString("comp-gas-pump-ui-needs-anchor"), args.User);
|
|
||||||
}
|
|
||||||
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnToggleStatusMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpToggleStatusMessage args)
|
|
||||||
{
|
|
||||||
pump.Enabled = args.Enabled;
|
|
||||||
_adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
|
|
||||||
$"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
|
|
||||||
DirtyUI(uid, pump);
|
|
||||||
UpdateAppearance(uid, pump);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTransferRateChangeMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpChangeTransferRateMessage args)
|
|
||||||
{
|
|
||||||
pump.TransferRate = Math.Clamp(args.TransferRate, 0f, pump.MaxTransferRate);
|
|
||||||
_adminLogger.Add(LogType.AtmosVolumeChanged, LogImpact.Medium,
|
|
||||||
$"{ToPrettyString(args.Actor):player} set the transfer rate on {ToPrettyString(uid):device} to {args.TransferRate}");
|
|
||||||
DirtyUI(uid, pump);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DirtyUI(EntityUid uid, GasVolumePumpComponent? pump)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref pump))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_userInterfaceSystem.SetUiState(uid, GasVolumePumpUiKey.Key,
|
|
||||||
new GasVolumePumpBoundUserInterfaceState(Name(uid), pump.TransferRate, pump.Enabled));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateAppearance(EntityUid uid, GasVolumePumpComponent? pump = null, AppearanceComponent? appearance = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref pump, ref appearance, false))
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool pumpOn = pump.Enabled && (TryComp<ApcPowerReceiverComponent>(uid, out var power) && power.Powered);
|
|
||||||
if (!pumpOn)
|
|
||||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Off, appearance);
|
|
||||||
else if (pump.Blocked)
|
|
||||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Blocked, appearance);
|
|
||||||
else
|
|
||||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.On, appearance);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPacketRecv(EntityUid uid, GasVolumePumpComponent component, DeviceNetworkPacketEvent args)
|
private void OnPacketRecv(EntityUid uid, GasVolumePumpComponent component, DeviceNetworkPacketEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|
||||||
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var payload = new NetworkPayload();
|
var payload = new NetworkPayload();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Atmos.Piping.Binary.Components;
|
||||||
|
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||||
|
public sealed partial class GasVolumePumpComponent : Component
|
||||||
|
{
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool Enabled = true;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public bool Blocked = false;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public bool Overclocked = false;
|
||||||
|
|
||||||
|
[DataField("inlet")]
|
||||||
|
public string InletName = "inlet";
|
||||||
|
|
||||||
|
[DataField("outlet")]
|
||||||
|
public string OutletName = "outlet";
|
||||||
|
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public float TransferRate = Atmospherics.MaxTransferRate;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float MaxTransferRate = Atmospherics.MaxTransferRate;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float LeakRatio = 0.1f;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float LowerThreshold = 0.01f;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float HigherThreshold = DefaultHigherThreshold;
|
||||||
|
|
||||||
|
public static readonly float DefaultHigherThreshold = 2 * Atmospherics.MaxOutputPressure;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float OverclockThreshold = 1000;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public float LastMolesTransferred;
|
||||||
|
}
|
||||||
@@ -5,26 +5,11 @@ namespace Content.Shared.Atmos.Piping.Binary.Components
|
|||||||
public sealed record GasVolumePumpData(float LastMolesTransferred);
|
public sealed record GasVolumePumpData(float LastMolesTransferred);
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum GasVolumePumpUiKey
|
public enum GasVolumePumpUiKey : byte
|
||||||
{
|
{
|
||||||
Key,
|
Key,
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class GasVolumePumpBoundUserInterfaceState : BoundUserInterfaceState
|
|
||||||
{
|
|
||||||
public string PumpLabel { get; }
|
|
||||||
public float TransferRate { get; }
|
|
||||||
public bool Enabled { get; }
|
|
||||||
|
|
||||||
public GasVolumePumpBoundUserInterfaceState(string pumpLabel, float transferRate, bool enabled)
|
|
||||||
{
|
|
||||||
PumpLabel = pumpLabel;
|
|
||||||
TransferRate = transferRate;
|
|
||||||
Enabled = enabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class GasVolumePumpToggleStatusMessage : BoundUserInterfaceMessage
|
public sealed class GasVolumePumpToggleStatusMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
using Content.Shared.Administration.Logs;
|
||||||
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||||
|
using Content.Shared.Atmos.Visuals;
|
||||||
|
using Content.Shared.Database;
|
||||||
|
using Content.Shared.Examine;
|
||||||
|
using Content.Shared.Power;
|
||||||
|
using Content.Shared.Power.EntitySystems;
|
||||||
|
|
||||||
|
namespace Content.Shared.Atmos.Piping.Binary.Systems;
|
||||||
|
|
||||||
|
public abstract class SharedGasVolumePumpSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||||
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, ComponentInit>(OnInit);
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
|
||||||
|
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInit(Entity<GasVolumePumpComponent> ent, ref ComponentInit args)
|
||||||
|
{
|
||||||
|
UpdateAppearance(ent.Owner, ent.Comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPowerChanged(Entity<GasVolumePumpComponent> ent, ref PowerChangedEvent args)
|
||||||
|
{
|
||||||
|
UpdateAppearance(ent.Owner, ent.Comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void UpdateUi(Entity<GasVolumePumpComponent> entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnToggleStatusMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpToggleStatusMessage args)
|
||||||
|
{
|
||||||
|
pump.Enabled = args.Enabled;
|
||||||
|
_adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
|
||||||
|
$"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
|
||||||
|
|
||||||
|
Dirty(uid, pump);
|
||||||
|
UpdateUi((uid, pump));
|
||||||
|
UpdateAppearance(uid, pump);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTransferRateChangeMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpChangeTransferRateMessage args)
|
||||||
|
{
|
||||||
|
pump.TransferRate = Math.Clamp(args.TransferRate, 0f, pump.MaxTransferRate);
|
||||||
|
Dirty(uid, pump);
|
||||||
|
UpdateUi((uid, pump));
|
||||||
|
_adminLogger.Add(LogType.AtmosVolumeChanged, LogImpact.Medium,
|
||||||
|
$"{ToPrettyString(args.Actor):player} set the transfer rate on {ToPrettyString(uid):device} to {args.TransferRate}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args)
|
||||||
|
{
|
||||||
|
if (!Transform(uid).Anchored)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Loc.TryGetString("gas-volume-pump-system-examined",
|
||||||
|
out var str,
|
||||||
|
("statusColor", "lightblue"), // TODO: change with volume?
|
||||||
|
("rate", pump.TransferRate)
|
||||||
|
))
|
||||||
|
{
|
||||||
|
args.PushMarkup(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void UpdateAppearance(EntityUid uid, GasVolumePumpComponent? pump = null, AppearanceComponent? appearance = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref pump, ref appearance, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool pumpOn = pump.Enabled && _receiver.IsPowered(uid);
|
||||||
|
if (!pumpOn)
|
||||||
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Off, appearance);
|
||||||
|
else if (pump.Blocked)
|
||||||
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Blocked, appearance);
|
||||||
|
else
|
||||||
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.On, appearance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -120,6 +120,9 @@
|
|||||||
- type: PipeColorVisuals
|
- type: PipeColorVisuals
|
||||||
- type: GasVolumePump
|
- type: GasVolumePump
|
||||||
enabled: false
|
enabled: false
|
||||||
|
- type: ActivatableUI
|
||||||
|
key: enum.GasVolumePumpUiKey.Key
|
||||||
|
- type: ActivatableUIRequiresAnchor
|
||||||
- type: UserInterface
|
- type: UserInterface
|
||||||
interfaces:
|
interfaces:
|
||||||
enum.GasVolumePumpUiKey.Key:
|
enum.GasVolumePumpUiKey.Key:
|
||||||
|
|||||||
Reference in New Issue
Block a user