Files
tbd-station-14/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs
py01 68ec6e6be5 Pipe Sprites & Visualizer (#1954)
* Pipe sprites

* pipe copyright

* SharedPipeComponent

* Pipe Visualizer draft

* missing longitudinal pipe sprites

* expanded rsi states

* pipe prototype fixes

* Fixed pipe visualizer

* ConduitLayer enum

* PipeVisualizer update

* halfpipe sprites

* yaml unneeded proto removal

* PipeVisualizer uses its own RSI

* Removes unused field from PipeVisualizer

Co-authored-by: py01 <pyronetics01@gmail.com>
2020-08-31 02:13:15 +02:00

70 lines
2.6 KiB
C#

using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Transfer gas from one <see cref="PipeNode"/> to another.
/// </summary>
public abstract class BasePumpComponent : PipeNetDeviceComponent
{
/// <summary>
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
/// </summary>
[ViewVariables]
private PipeDirection _inletDirection;
/// <summary>
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
/// </summary>
[ViewVariables]
private PipeDirection _outletDirection;
[ViewVariables]
private PipeNode _inletPipe;
[ViewVariables]
private PipeNode _outletPipe;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _inletDirection, "inletDirection", PipeDirection.None);
serializer.DataField(ref _outletDirection, "outletDirection", PipeDirection.None);
}
public override void Initialize()
{
base.Initialize();
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
var pipeNodes = container.Nodes.OfType<PipeNode>();
_inletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _inletDirection).FirstOrDefault();
_outletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _outletDirection).FirstOrDefault();
if (_inletPipe == null | _outletPipe == null)
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
public override void Update()
{
PumpGas(_inletPipe.Air, _outletPipe.Air);
}
protected abstract void PumpGas(GasMixture inletGas, GasMixture outletGas);
}
}