Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix air devices ignoring settings after power cycle #34887

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[RegisterComponent]
public sealed partial class GasVentPumpComponent : Component
{
[DataField]
public bool Powered { get; set; } = false;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the power components please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretend I'm stupid. don't suppose theres an example of this >.>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running myself ragged trying to find an existing powered component. The only thing I'm seeing that has a powered variable is ApcPowerReceiverComponent. Is that what you're referring to? I also noticed that the particle accelerator is enabling/disabling power in a similar manner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe for the most part you can do a trycomp to check power like so.

TryComp<ApcPowerReceiverComponent>(uid, out var power) && power.Powered

You can see an example in GasPressurePumpSystem, where we check if the device is not powered, if so we stop making sound and return early.

private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args)
    {
        if (!pump.Enabled
            || (TryComp<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
            || !_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet))
        {
            _ambientSoundSystem.SetAmbience(uid, false);
            return;
        }

Here's an example for checking if a scrubber is powered:

            else if (!scrubber.Enabled || TryComp<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
            {
                _ambientSoundSystem.SetAmbience(uid, false);
                _appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Off, appearance);
            }

That might work. Feel free to shoot me if it doesn't sloth (godo)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it may be something along those lines but thought that may be a bit bloated. I'll write it up and give it a shot. Thanks Roomba.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got it right? Do I have to use an if statement for the trycomp in OnPowerChanged? That bugs me a tad.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore that last message, we're no longer setting anything but the visual state in OnPowerChange.

[ViewVariables(VVAccess.ReadWrite)]
public bool Enabled { get; set; } = false;
public bool Enabled { get; set; } = true;
Partmedia marked this conversation as resolved.
Show resolved Hide resolved

[ViewVariables]
public bool IsDirty { get; set; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace Content.Server.Atmos.Piping.Unary.Components
public sealed partial class GasVentScrubberComponent : Component
{
[DataField]
public bool Enabled { get; set; } = false;
public bool Powered { get; set; } = false;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

[DataField]
public bool Enabled { get; set; } = true;
Partmedia marked this conversation as resolved.
Show resolved Hide resolved

[DataField]
public bool IsDirty { get; set; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
_ => throw new ArgumentOutOfRangeException()
};

if (!vent.Powered)
return;

if (!vent.Enabled || !_nodeContainer.TryGetNode(uid, nodeName, out PipeNode? pipe))
{
return;
Expand Down Expand Up @@ -207,7 +210,7 @@ private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosAl

private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, ref PowerChangedEvent args)
{
component.Enabled = args.Powered;
component.Powered = args.Powered;
UpdateState(uid, component);
}

Expand Down Expand Up @@ -277,7 +280,7 @@ private void UpdateState(EntityUid uid, GasVentPumpComponent vent, AppearanceCom
_ambientSoundSystem.SetAmbience(uid, false);
_appearance.SetData(uid, VentPumpVisuals.State, VentPumpState.Welded, appearance);
}
else if (!vent.Enabled)
else if (!vent.Enabled || !vent.Powered)
{
_ambientSoundSystem.SetAmbience(uid, false);
_appearance.SetData(uid, VentPumpVisuals.State, VentPumpState.Off, appearance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrub

var timeDelta = args.dt;

if (!scrubber.Powered)
return;

if (!scrubber.Enabled || !_nodeContainer.TryGetNode(uid, scrubber.OutletName, out PipeNode? outlet))
return;

Expand Down Expand Up @@ -138,7 +141,7 @@ private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, Atm

private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, ref PowerChangedEvent args)
{
component.Enabled = args.Powered;
component.Powered = args.Powered;
UpdateState(uid, component);
}

Expand Down Expand Up @@ -185,7 +188,7 @@ private void UpdateState(EntityUid uid, GasVentScrubberComponent scrubber,
_ambientSoundSystem.SetAmbience(uid, false);
_appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Welded, appearance);
}
else if (!scrubber.Enabled)
else if (!scrubber.Powered || !scrubber.Enabled)
{
_ambientSoundSystem.SetAmbience(uid, false);
_appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Off, appearance);
Expand Down
Loading