PipeNetDeviceComponent refactor (#2912)
* Removes inheritance of PipeNetDeviceComponent * Enables nullable in piping * Piping error messages report the prototype * Moves PipeNetDevice updating to ComponentMessage * Build fix * Review fixes * review fix 2 Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
using System.Linq;
|
||||
#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.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -16,13 +17,13 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
|
||||
/// <summary>
|
||||
/// Transfers gas from the tile it is on to a <see cref="PipeNode"/>.
|
||||
/// </summary>
|
||||
public abstract class BaseSiphonComponent : PipeNetDeviceComponent
|
||||
public abstract class BaseSiphonComponent : Component
|
||||
{
|
||||
|
||||
[ViewVariables]
|
||||
private PipeNode _scrubberOutlet;
|
||||
private PipeNode? _scrubberOutlet;
|
||||
|
||||
private AtmosphereSystem _atmosSystem;
|
||||
private AtmosphereSystem? _atmosSystem;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool SiphonEnabled
|
||||
@@ -36,43 +37,60 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
|
||||
}
|
||||
private bool _siphonEnabled = true;
|
||||
|
||||
private AppearanceComponent _appearance;
|
||||
private AppearanceComponent? _appearance;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponentWarn<PipeNetDeviceComponent>();
|
||||
_atmosSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
{
|
||||
JoinedGridAtmos?.RemovePipeNetDevice(this);
|
||||
Logger.Error($"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
|
||||
return;
|
||||
}
|
||||
_scrubberOutlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
|
||||
if (_scrubberOutlet == null)
|
||||
{
|
||||
JoinedGridAtmos?.RemovePipeNetDevice(this);
|
||||
Logger.Error($"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
|
||||
return;
|
||||
}
|
||||
SetOutlet();
|
||||
Owner.TryGetComponent(out _appearance);
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PipeNetUpdateMessage:
|
||||
Update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!SiphonEnabled)
|
||||
return;
|
||||
|
||||
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager);
|
||||
if (tileAtmos == null)
|
||||
|
||||
if (_scrubberOutlet == null || tileAtmos == null || tileAtmos.Air == null)
|
||||
return;
|
||||
|
||||
ScrubGas(tileAtmos.Air, _scrubberOutlet.Air);
|
||||
tileAtmos.Invalidate();
|
||||
}
|
||||
|
||||
protected abstract void ScrubGas(GasMixture inletGas, GasMixture outletGas);
|
||||
|
||||
private void SetOutlet()
|
||||
{
|
||||
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
{
|
||||
Logger.Error($"{typeof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
|
||||
return;
|
||||
}
|
||||
_scrubberOutlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
|
||||
if (_scrubberOutlet == null)
|
||||
{
|
||||
Logger.Error($"{typeof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
_appearance?.SetData(SiphonVisuals.VisualState, new SiphonVisualState(SiphonEnabled));
|
||||
|
||||
Reference in New Issue
Block a user