using Content.Shared.Administration.Logs; using Content.Shared.Atmos.Components; using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Components; using Content.Shared.Database; using Content.Shared.Examine; using Content.Shared.Power; using Content.Shared.Power.EntitySystems; namespace Content.Shared.Atmos.EntitySystems; public abstract class SharedGasPressurePumpSystem : EntitySystem { [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!; [Dependency] protected readonly SharedUserInterfaceSystem UserInterfaceSystem = default!; // TODO: Check enabled for activatableUI // TODO: Add activatableUI to it. public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnPowerChanged); SubscribeLocalEvent(OnOutputPressureChangeMessage); SubscribeLocalEvent(OnToggleStatusMessage); SubscribeLocalEvent(OnPumpLeaveAtmosphere); SubscribeLocalEvent(OnExamined); } private void OnExamined(Entity ent, ref ExaminedEvent args) { if (!Transform(ent).Anchored) return; if (Loc.TryGetString("gas-pressure-pump-system-examined", out var str, ("statusColor", "lightblue"), // TODO: change with pressure? ("pressure", ent.Comp.TargetPressure) )) { args.PushMarkup(str); } } private void OnInit(Entity ent, ref ComponentInit args) { UpdateAppearance(ent); } private void OnPowerChanged(Entity ent, ref PowerChangedEvent args) { UpdateAppearance(ent); } private void UpdateAppearance(Entity ent) { if (!Resolve(ent, ref ent.Comp2, false)) return; var pumpOn = ent.Comp1.Enabled && _receiver.IsPowered(ent.Owner); _appearance.SetData(ent, PumpVisuals.Enabled, pumpOn, ent.Comp2); } private void OnToggleStatusMessage(Entity ent, ref GasPressurePumpToggleStatusMessage args) { ent.Comp.Enabled = args.Enabled; _adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium, $"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(ent):device} to {args.Enabled}"); Dirty(ent); UpdateAppearance(ent); UpdateUi(ent); } private void OnOutputPressureChangeMessage(Entity ent, ref GasPressurePumpChangeOutputPressureMessage args) { ent.Comp.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure); _adminLogger.Add(LogType.AtmosPressureChanged, LogImpact.Medium, $"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(ent):device} to {args.Pressure}kPa"); Dirty(ent); UpdateUi(ent); } private void OnPumpLeaveAtmosphere(Entity ent, ref AtmosDeviceDisabledEvent args) { ent.Comp.Enabled = false; Dirty(ent); UpdateAppearance(ent); UserInterfaceSystem.CloseUi(ent.Owner, GasPressurePumpUiKey.Key); } protected virtual void UpdateUi(Entity ent) { } }