using Content.Shared.Examine;
using Content.Server.Atmos;
using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Atmos;
namespace Content.Server.Singularity.EntitySystems;
SubscribeLocalEvent<RadiationCollectorComponent, OnIrradiatedEvent>(OnRadiation);
SubscribeLocalEvent<RadiationCollectorComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<RadiationCollectorComponent, GasAnalyzerScanEvent>(OnAnalyzed);
+ SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
+ SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
+ SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
}
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
return true;
}
+ private void OnMapInit(EntityUid uid, RadiationCollectorComponent component, MapInitEvent args)
+ {
+ TryGetLoadedGasTank(uid, out var gasTank);
+ UpdateTankAppearance(uid, component, gasTank);
+ }
+
+ private void OnTankChanged(EntityUid uid, RadiationCollectorComponent component, ContainerModifiedMessage args)
+ {
+ TryGetLoadedGasTank(uid, out var gasTank);
+ UpdateTankAppearance(uid, component, gasTank);
+ }
+
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
{
var curTime = _gameTiming.CurTime;
{
batteryComponent.CurrentCharge += charge;
}
+
+ // Update appearance
+ UpdatePressureIndicatorAppearance(uid, component, gasTankComponent);
}
private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
{
- if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
+ if (!TryGetLoadedGasTank(uid, out var gasTank))
{
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-missing"));
return;
}
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-present"));
-
- if (gasTankComponent.IsLowPressure)
- {
- args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-low-pressure"));
- }
}
private void OnAnalyzed(EntityUid uid, RadiationCollectorComponent component, GasAnalyzerScanEvent args)
public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = null, RadiationCollectorComponent? component = null)
{
- if (!Resolve(uid, ref component))
+ if (!Resolve(uid, ref component, false))
return;
component.Enabled = enabled;
}
// Update appearance
- UpdateAppearance(uid, component);
+ UpdateMachineAppearance(uid, component);
}
- private void UpdateAppearance(EntityUid uid, RadiationCollectorComponent? component, AppearanceComponent? appearance = null)
+ private void UpdateMachineAppearance(EntityUid uid, RadiationCollectorComponent component, AppearanceComponent? appearance = null)
{
- if (!Resolve(uid, ref component, ref appearance))
+ if (!Resolve(uid, ref appearance))
return;
var state = component.Enabled ? RadiationCollectorVisualState.Active : RadiationCollectorVisualState.Deactive;
_appearance.SetData(uid, RadiationCollectorVisuals.VisualState, state, appearance);
}
+
+ private void UpdatePressureIndicatorAppearance(EntityUid uid, RadiationCollectorComponent component, GasTankComponent? gasTank = null, AppearanceComponent? appearance = null)
+ {
+ if (!Resolve(uid, ref appearance, false))
+ return;
+
+ if (gasTank == null || gasTank.Air.Pressure < 10)
+ _appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 0, appearance);
+
+ else if (gasTank.Air.Pressure < Atmospherics.OneAtmosphere)
+ _appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 1, appearance);
+
+ else if (gasTank.Air.Pressure < 3f * Atmospherics.OneAtmosphere)
+ _appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 2, appearance);
+
+ else
+ _appearance.SetData(uid, RadiationCollectorVisuals.PressureState, 3, appearance);
+ }
+
+ private void UpdateTankAppearance(EntityUid uid, RadiationCollectorComponent component, GasTankComponent? gasTank = null, AppearanceComponent? appearance = null)
+ {
+ if (!Resolve(uid, ref appearance, false))
+ return;
+
+ _appearance.SetData(uid, RadiationCollectorVisuals.TankInserted, gasTank != null, appearance);
+
+ UpdatePressureIndicatorAppearance(uid, component, gasTank, appearance);
+ }
}