Files
tbd-station-14/Content.Server/GameObjects/Components/Atmos/Piping/Vents/BaseVentComponent.cs
ShadowCommander 7a842f7c22 Fix tests (#3707)
* First pass

* Fix access and rename banananium to bananium

* Fix captialization of CookTimeInfoLabel

* Fix InteractUsing calls

* Remove unused [Dependency]

* Replace obsolete references to Anchored with BodyType

* Assign default value to shoving someone in disposals

* Fix naming

* Replace Initialize TryGetComponents with EnsureComponent

* Rework AnchorableComponent

* Fix singularity component

* Replace obsolete usages of Angle.South

* Fix efcore warning

* Fix container tests

* Fix DebugPressurePump invalid PressurePump yaml

* Fix getting pathfinding region of grid 0

* Fix atmos plaque missing layer and add info message when it happens

* Fix AiSteeringSystem steering in an invalid grid in entity test

* Make content able to choose which log level leads to test failures

* Revert container test fix for Acruid

* Fix sprite, pipe and saving errors
Make EntityTest print all errors instead of stopping on the first

* Reorder singularity visualizer

* Disable pvs for container occlusion adn simple predict reconcile, they use entities other than map ones

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2021-03-31 21:41:23 +02:00

98 lines
3.0 KiB
C#

#nullable enable
using System.Linq;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents
{
/// <summary>
/// Transfers gas from a <see cref="PipeNode"/> to the tile it is on.
/// </summary>
public abstract class BaseVentComponent : Component
{
[ViewVariables]
private PipeNode? _ventInlet;
private AtmosphereSystem? _atmosSystem;
[ViewVariables(VVAccess.ReadWrite)]
public bool VentEnabled
{
get => _ventEnabled;
set
{
_ventEnabled = value;
UpdateAppearance();
}
}
private bool _ventEnabled = true;
private AppearanceComponent? _appearance;
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponentWarn<PipeNetDeviceComponent>();
_atmosSystem = EntitySystem.Get<AtmosphereSystem>();
SetInlet();
Owner.TryGetComponent(out _appearance);
UpdateAppearance();
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PipeNetUpdateMessage:
Update();
break;
}
}
public void Update()
{
if (!VentEnabled)
return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager);
if (_ventInlet == null || tileAtmos == null || tileAtmos.Air == null)
return;
VentGas(_ventInlet.Air, tileAtmos.Air);
tileAtmos.Invalidate();
}
protected abstract void VentGas(GasMixture inletGas, GasMixture outletGas);
private void SetInlet()
{
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
Logger.Warning($"{nameof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
_ventInlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_ventInlet == null)
{
Logger.Warning($"{nameof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
private void UpdateAppearance()
{
_appearance?.SetData(VentVisuals.VisualState, new VentVisualState(VentEnabled));
}
}
}