Optimize vent/scrubber (#7473)

This commit is contained in:
mirrorcult
2022-04-08 19:52:44 -07:00
committed by GitHub
parent ea86d4f44d
commit 7573a4601a
3 changed files with 87 additions and 42 deletions

View File

@@ -33,6 +33,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceUpdateEvent>(OnGasVentPumpUpdated);
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceDisabledEvent>(OnGasVentPumpLeaveAtmosphere);
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceEnabledEvent>(OnGasVentPumpEnterAtmosphere);
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<GasVentPumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
@@ -40,11 +41,9 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
{
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(vent.Owner); //Bingo waz here
//Bingo waz here
if (vent.Welded)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Welded);
return;
}
@@ -53,8 +52,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
_ambientSoundSystem.SetAmbience(vent.Owner, false);
return;
}
@@ -63,8 +60,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
// We're in an air-blocked tile... Do nothing.
if (environment == null)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
_ambientSoundSystem.SetAmbience(vent.Owner, false);
return;
}
@@ -73,9 +68,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Out);
_ambientSoundSystem.SetAmbience(vent.Owner, true);
if (environment.Pressure > vent.MaxPressure)
return;
@@ -105,8 +97,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
}
else if (vent.PumpDirection == VentPumpDirection.Siphoning && environment.Pressure > 0)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.In);
if (pipe.Air.Pressure > vent.MaxPressure)
return;
@@ -139,10 +129,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnGasVentPumpLeaveAtmosphere(EntityUid uid, GasVentPumpComponent component, AtmosDeviceDisabledEvent args)
{
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(VentPumpVisuals.State, VentPumpState.Off);
}
UpdateState(uid, component);
}
private void OnGasVentPumpEnterAtmosphere(EntityUid uid, GasVentPumpComponent component, AtmosDeviceEnabledEvent args)
{
UpdateState(uid, component);
}
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosMonitorAlarmEvent args)
@@ -155,11 +147,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
component.Enabled = true;
}
UpdateState(uid, component);
}
private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, PowerChangedEvent args)
{
component.Enabled = args.Powered;
UpdateState(uid, component);
}
private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, DeviceNetworkPacketEvent args)
@@ -185,6 +180,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
break;
component.FromAirAlarmData(setData);
UpdateState(uid, component);
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
@@ -195,5 +191,30 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
}
}
private void UpdateState(EntityUid uid, GasVentPumpComponent vent, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref appearance, false))
return;
_ambientSoundSystem.SetAmbience(uid, true);
if (!vent.Enabled)
{
_ambientSoundSystem.SetAmbience(uid, false);
appearance.SetData(VentPumpVisuals.State, VentPumpState.Off);
}
else if (vent.PumpDirection == VentPumpDirection.Releasing)
{
appearance.SetData(VentPumpVisuals.State, VentPumpState.Out);
}
else if (vent.PumpDirection == VentPumpDirection.Siphoning)
{
appearance.SetData(VentPumpVisuals.State, VentPumpState.In);
}
else if (vent.Welded)
{
_ambientSoundSystem.SetAmbience(uid, false);
appearance.SetData(VentPumpVisuals.State, VentPumpState.Welded);
}
}
}
}