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

atmos circulation #33380

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
<FloatSpinBox Name="CVolumeRate" HorizontalExpand="True" />
</BoxContainer>
</BoxContainer>
<BoxContainer>
<CheckBox Name="CWideNet" Text="{Loc 'air-alarm-ui-scrubber-wide-net-label'}" />
<BoxContainer Orientation="Horizontal" Margin="0 0 0 2" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<CheckBox Name="CWideNet" Text="{Loc 'air-alarm-ui-scrubber-wide-net-label'}" />
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'air-alarm-ui-scrubber-target-pressure-label'}" Margin="0 0 0 1" />
<FloatSpinBox Name="CTargetPressure" HorizontalExpand="True" />
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-widget-copy'}" ToolTip="{Loc 'air-alarm-ui-widget-copy-tooltip'}" />
Expand Down
90 changes: 70 additions & 20 deletions Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.Stylesheets;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
Expand All @@ -20,14 +21,15 @@ public sealed partial class ScrubberControl : BoxContainer
private string _address;

public event Action<string, IAtmosDeviceData>? ScrubberDataChanged;
public event Action<IAtmosDeviceData>? ScrubberDataCopied;
public event Action<IAtmosDeviceData>? ScrubberDataCopied;

private CheckBox _enabled => CEnableDevice;
private CollapsibleHeading _addressLabel => CAddress;
private OptionButton _pumpDirection => CPumpDirection;
private FloatSpinBox _volumeRate => CVolumeRate;
private FloatSpinBox _targetPressure => CTargetPressure;
private CheckBox _wideNet => CWideNet;
private Button _copySettings => CCopySettings;
private Button _copySettings => CCopySettings;

private GridContainer _gases => CGasContainer;
private Dictionary<Gas, Button> _gasControls = new();
Expand Down Expand Up @@ -65,23 +67,30 @@ public ScrubberControl(GasVentScrubberData data, string address)
};
_volumeRate.IsValid += value => value >= 0;

_targetPressure.Value = _data.TargetPressure;
_targetPressure.OnValueChanged += _ =>
{
_data.TargetPressure = _targetPressure.Value;
ScrubberDataChanged?.Invoke(address, _data);
};

foreach (var value in Enum.GetValues<ScrubberPumpDirection>())
{
_pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value);
_pumpDirection.AddItem(Loc.GetString($"{value}"), (int)value);
}

_pumpDirection.SelectId((int) _data.PumpDirection);
_pumpDirection.SelectId((int)_data.PumpDirection);
_pumpDirection.OnItemSelected += args =>
{
_pumpDirection.SelectId(args.Id);
_data.PumpDirection = (ScrubberPumpDirection) args.Id;
_data.PumpDirection = (ScrubberPumpDirection)args.Id;
ScrubberDataChanged?.Invoke(_address, _data);
};
_copySettings.OnPressed += _ =>
{
ScrubberDataCopied?.Invoke(_data);
};

_copySettings.OnPressed += _ =>
{
ScrubberDataCopied?.Invoke(_data);
};

foreach (var value in Enum.GetValues<Gas>())
{
Expand All @@ -90,15 +99,43 @@ public ScrubberControl(GasVentScrubberData data, string address)
Name = value.ToString(),
Text = Loc.GetString($"{value}"),
ToggleMode = true,
HorizontalExpand = true,
Pressed = _data.FilterGases.Contains(value)
HorizontalExpand = true
};
gasButton.OnToggled += args =>
if (_data.PriorityGases.Contains(value))
{
if (args.Pressed)
_data.FilterGases.Add(value);
else
_data.FilterGases.Remove(value);
gasButton.StyleClasses.Add("ButtonColorGreen");
}
if (_data.DisabledGases.Contains(value))
{
gasButton.StyleClasses.Add(StyleBase.ButtonCaution);
}
gasButton.OnPressed += args =>
{
int state = 0;
if (_data.DisabledGases.Contains(value))
{
state = 2;
}
else if (_data.PriorityGases.Contains(value))
{
state = 1;
}

_data.PriorityGases.Remove(value);
_data.DisabledGases.Remove(value);
gasButton.StyleClasses.Remove("ButtonColorGreen");
gasButton.StyleClasses.Remove(StyleBase.ButtonCaution);
gasButton.Pressed = false;
if (state == 0)
{
_data.PriorityGases.Add(value);
gasButton.StyleClasses.Add("ButtonColorGreen");
}
else if (state == 1)
{
_data.DisabledGases.Add(value);
gasButton.StyleClasses.Add(StyleBase.ButtonCaution);
}

ScrubberDataChanged?.Invoke(_address, _data);
};
Expand All @@ -114,18 +151,31 @@ public void ChangeData(GasVentScrubberData data)
_enabled.Pressed = _data.Enabled;

_data.PumpDirection = data.PumpDirection;
_pumpDirection.Select((int) _data.PumpDirection);
_pumpDirection.Select((int)_data.PumpDirection);

_data.VolumeRate = data.VolumeRate;
_volumeRate.Value = _data.VolumeRate;

_data.TargetPressure = data.TargetPressure;
_targetPressure.Value = _data.TargetPressure;

_data.WideNet = data.WideNet;
_wideNet.Pressed = _data.WideNet;
_data.FilterGases = data.FilterGases;
_data.PriorityGases = data.PriorityGases;
_data.DisabledGases = data.DisabledGases;

foreach (var value in Enum.GetValues<Gas>())
{
_gasControls[value].Pressed = data.FilterGases.Contains(value);
_gasControls[value].StyleClasses.Remove("ButtonColorGreen");
_gasControls[value].StyleClasses.Remove(StyleBase.ButtonCaution);
if (data.DisabledGases.Contains(value))
{
_gasControls[value].StyleClasses.Add(StyleBase.ButtonCaution);
}
else if (data.PriorityGases.Contains(value))
{
_gasControls[value].StyleClasses.Add("ButtonColorGreen");
}
}
}
}
29 changes: 23 additions & 6 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.Gases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public float GetHeatCapacity(GasMixture mixture, bool applyScaling)
}

private float GetHeatCapacity(GasMixture mixture)
=> GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);
=> GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private float GetHeatCapacityCalculation(float[] moles, bool space)
Expand Down Expand Up @@ -202,7 +202,7 @@ public bool ReleaseGasTo(GasMixture mixture, GasMixture? output, float targetPre
// And now we transfer the gas.
var removed = mixture.Remove(transferMoles);

if(output != null)
if (output != null)
Merge(output, removed);

return true;
Expand Down Expand Up @@ -241,7 +241,7 @@ public bool PumpGasTo(GasMixture mixture, GasMixture output, float targetPressur
/// </summary>
public void ScrubInto(GasMixture mixture, GasMixture destination, IReadOnlyCollection<Gas> filterGases)
{
var buffer = new GasMixture(mixture.Volume){Temperature = mixture.Temperature};
var buffer = new GasMixture(mixture.Volume) { Temperature = mixture.Temperature };

foreach (var gas in filterGases)
{
Expand All @@ -252,6 +252,23 @@ public void ScrubInto(GasMixture mixture, GasMixture destination, IReadOnlyColle
Merge(destination, buffer);
}

/// <summary>
/// Scrubs a fraction of specified gases from a gas mixture into a <see cref="destination"/> gas mixture.
/// </summary>
public void ScrubInto(GasMixture mixture, GasMixture destination, IReadOnlyCollection<Gas> filterGases, float fraction)
{
var buffer = new GasMixture(mixture.Volume) { Temperature = mixture.Temperature };

foreach (var gas in filterGases)
{
var moles = mixture.GetMoles(gas) * fraction;
buffer.AdjustMoles(gas, moles);
mixture.AdjustMoles(gas, -moles);
}

Merge(destination, buffer);
}

/// <summary>
/// Checks whether a gas mixture is probably safe.
/// This only checks temperature and pressure, not gas composition.
Expand Down Expand Up @@ -299,7 +316,7 @@ public GasCompareResult CompareExchange(GasMixture sample, GasMixture otherSampl
{
var moles = 0f;

for(var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
{
var gasMoles = sample.Moles[i];
var delta = MathF.Abs(gasMoles - otherSample.Moles[i]);
Expand Down Expand Up @@ -338,7 +355,7 @@ public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder)
var doReaction = true;
for (var i = 0; i < prototype.MinimumRequirements.Length; i++)
{
if(i >= Atmospherics.TotalNumberOfGases)
if (i >= Atmospherics.TotalNumberOfGases)
throw new IndexOutOfRangeException("Reaction Gas Minimum Requirements Array Prototype exceeds total number of gases!");

var req = prototype.MinimumRequirements[i];
Expand All @@ -354,7 +371,7 @@ public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder)
continue;

reaction = prototype.React(mixture, holder, this, HeatScale);
if(reaction.HasFlag(ReactionResult.StopReactions))
if (reaction.HasFlag(ReactionResult.StopReactions))
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public sealed partial class GasVentPumpComponent : Component
[DataField]
public bool IsPressureLockoutManuallyDisabled = false;
/// <summary>
/// The time when the manual pressure lockout will be reenabled.
/// The time when the manual pressure lockout will be reenabled.
/// </summary>
[DataField]
[AutoPausedField]
Expand All @@ -83,7 +83,7 @@ public float ExternalPressureBound
}
}

private float _externalPressureBound = Atmospherics.OneAtmosphere;
private float _externalPressureBound = Atmospherics.OneAtmosphereTarget;

[DataField]
public float InternalPressureBound
Expand Down Expand Up @@ -138,7 +138,7 @@ public float InternalPressureBound
public string DepressurizePort = "Depressurize";

[DataField]
public float PressurizePressure = Atmospherics.OneAtmosphere;
public float PressurizePressure = Atmospherics.OneAtmosphereTarget;

[DataField]
public float DepressurizePressure = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public sealed partial class GasVentScrubberComponent : Component
public string OutletName { get; set; } = "pipe";

[DataField]
public HashSet<Gas> FilterGases = new(GasVentScrubberData.DefaultFilterGases);
public HashSet<Gas> PriorityGases = new(GasVentScrubberData.DefaultPriorityGases);
[DataField]
public HashSet<Gas> DisabledGases = new();

[DataField]
public ScrubberPumpDirection PumpDirection { get; set; } = ScrubberPumpDirection.Scrubbing;
Expand All @@ -36,6 +38,17 @@ public float TransferRate

private float _transferRate = Atmospherics.MaxTransferRate;

/// <summary>
/// Target pressure. If the pressure is below this value only priority gases are getting scrubbed.
/// </summary>
[DataField]
public float TargetPressure
{
get => _targetPressure;
set => _targetPressure = Math.Max(value, 0f);
}
private float _targetPressure = Atmospherics.OneAtmosphere;

[DataField]
public float MaxTransferRate = Atmospherics.MaxTransferRate;

Expand All @@ -55,9 +68,11 @@ public GasVentScrubberData ToAirAlarmData()
{
Enabled = Enabled,
Dirty = IsDirty,
FilterGases = FilterGases,
PriorityGases = PriorityGases,
DisabledGases = DisabledGases,
PumpDirection = PumpDirection,
VolumeRate = TransferRate,
TargetPressure = TargetPressure,
WideNet = WideNet
};
}
Expand All @@ -68,13 +83,20 @@ public void FromAirAlarmData(GasVentScrubberData data)
IsDirty = data.Dirty;
PumpDirection = data.PumpDirection;
TransferRate = data.VolumeRate;
TargetPressure = data.TargetPressure;
WideNet = data.WideNet;

if (!data.FilterGases.SequenceEqual(FilterGases))
if (!data.PriorityGases.SequenceEqual(PriorityGases))
{
PriorityGases.Clear();
foreach (var gas in data.PriorityGases)
PriorityGases.Add(gas);
}
if (!data.DisabledGases.SequenceEqual(DisabledGases))
{
FilterGases.Clear();
foreach (var gas in data.FilterGases)
FilterGases.Add(gas);
DisabledGases.Clear();
foreach (var gas in data.DisabledGases)
DisabledGases.Add(gas);
}
}
}
Expand Down
Loading
Loading