Files
tbd-station-14/Content.Shared/Atmos/EntitySystems/SharedGasPressureRegulatorSystem.cs
ArtisticRoomba f874459092 Pressure Relief Valve (#36708)
* initial system (this math is probably WRONG)

* General code cleanup and OnExamined support
(holy moly this code sucks)

* UICode and related events foundation
TODO:
- Actually write the XAML UI and the underlying system
- Un-shitcode the entire thing
- Actually test everything...

* Working UI code
TODO: Make predicted, as this certainly isn't predicted. Even though I said it was. It isn't.

* Remove one TODO for unshitcoding the examine code

* Add reminder
yea

* Make predicted (defenitely isn't)
(also defenitely isn't a copypaste from pressure pump code)

* It's predicted!
TODO:
- Give it snazzy predicted visuals!
- Have a different field for pressure entry, lest it gets bulldozed every UI update.

* Improve gas pressure relief valve UI
TODO: Reminder to reduce amount of dirties using deltafields

* Implement DirtyField prediction

* Entity<T> cleanup
A lot of Entity<T> conversions and lukewarm cleanup.

Also got caught copy pasting code in 4K UHD but it's not like you couldn't tell.

* More cleanup and comments

* Remove TODO comment on bulldozing window title

* """refactoring"""
- Move appearance out of shared and finally fix it. Pointless to predict appearance in this instance.
- More Entity<T> conversions because I like them.
- Move UI creation handling over entirely to the ActivatableUI system.
- Fix a hardcoded locale string (why????).

* Add visuals

* Revert debugging variable replacememt
yea

* Revert skissue

* Remove unused using directives and remove TODO

* Localize, cleanup, document

* Fix adminlogging discrepancy

* Add ability to construct, add guidebook entry

* Clear up comment

* Add guidebook tooltip to valve

* Convert GasPressureReliefValveBoundUserInterface declaration into primary constructor

* Adds more input handling and adds autofill on open

* Un-deepfry input validator shitcode
Genuinely what was I smoking

* improve visuals logic

* Refactor again
- Update math to the correct implementation
- Moved code that could be re-used in the future into a helper method under AtmosphereSystem.Gases.cs

* I'm sorry but I hate warnings

* Remove unused using directive in AtmosphereSystem.Gases.cs

* Review and cleanup

* Lukewarm UI glossup

* Maintainer for the upstream project btw

* Remove redundant state sets and messy logic

* Unduplicate valve updater code

* Redo UI (im sorry Slarti)

* run tests

* Test refactored UI messaging

* Second round of UI improvements
- God please find a way to improve this system. Feels bad.

* Update loop implementation

* Further predict UI

* Clear up SetToCurrentThreshold

* cleanup

* Update to master + pipe layers and bug fixes
want to run tests

* fixes

* Deploy rename pipebomb

* Documentation and requested changes

* Rename the method that wiggled away

* Undo rounding changes

* Fix comment

* Rename and cleanup

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-07-03 18:00:34 +02:00

71 lines
2.9 KiB
C#

using Content.Shared.Administration.Logs;
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Database;
using Content.Shared.Examine;
namespace Content.Shared.Atmos.EntitySystems;
/// <summary>
/// Handles all shared interactions with the gas pressure regulator.
/// </summary>
public abstract class SharedGasPressureRegulatorSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] protected readonly SharedUserInterfaceSystem UserInterfaceSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasPressureRegulatorComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasPressureRegulatorComponent, GasPressureRegulatorChangeThresholdMessage>(
OnThresholdChangeMessage);
}
/// <summary>
/// Presents predicted examine information to the person examining the valve.
/// </summary>
/// <param name="ent"> <see cref="Entity{T}"/> of the valve</param>
/// <param name="args">Event arguments for examination</param>
private void OnExamined(Entity<GasPressureRegulatorComponent> ent, ref ExaminedEvent args)
{
if (!Transform(ent).Anchored || !args.IsInDetailsRange)
return;
using (args.PushGroup(nameof(GasPressureRegulatorComponent)))
{
args.PushMarkup(Loc.GetString("gas-pressure-regulator-system-examined",
("statusColor", ent.Comp.Enabled ? "green" : "red"),
("open", ent.Comp.Enabled)));
args.PushMarkup(Loc.GetString("gas-pressure-regulator-examined-threshold-pressure",
("threshold", $"{ent.Comp.Threshold:0.#}")));
args.PushMarkup(Loc.GetString("gas-pressure-regulator-examined-flow-rate",
("flowRate", $"{ent.Comp.FlowRate:0.#}")));
}
}
/// <summary>
/// Validates, logs, and updates the pressure threshold of the valve.
/// </summary>
/// <param name="ent">The <see cref="Entity{T}"/> of the valve.</param>
/// <param name="args">The received pressure from the <see cref="GasPressurePumpChangeOutputPressureMessage"/>message.</param>
private void OnThresholdChangeMessage(Entity<GasPressureRegulatorComponent> ent,
ref GasPressureRegulatorChangeThresholdMessage args)
{
ent.Comp.Threshold = Math.Max(0f, args.ThresholdPressure);
_adminLogger.Add(LogType.AtmosVolumeChanged,
LogImpact.Medium,
$"{ToPrettyString(args.Actor):player} set the pressure threshold on {ToPrettyString(ent):device} to {ent.Comp.Threshold}");
// Dirty the entire entity to ensure we get all of that Fresh:tm: UI info from the server.
Dirty(ent);
UpdateUi(ent);
}
protected virtual void UpdateUi(Entity<GasPressureRegulatorComponent> ent)
{
}
}