using Content.Server.Atmos;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
///
/// Adds itself to a to be updated by.
/// TODO: Make compatible with unanchoring/anchoring. Currently assumes that the Owner does not move.
///
public abstract class PipeNetDeviceComponent : Component
{
public abstract void Update();
protected IGridAtmosphereComponent JoinedGridAtmos { get; private set; }
public override void Initialize()
{
base.Initialize();
JoinGridAtmos();
}
public override void OnRemove()
{
base.OnRemove();
LeaveGridAtmos();
}
private void JoinGridAtmos()
{
var gridAtmos = EntitySystem.Get()
.GetGridAtmosphere(Owner.Transform.GridID);
if (gridAtmos == null)
{
Logger.Error($"{nameof(PipeNetDeviceComponent)} on entity {Owner.Uid} could not find an {nameof(IGridAtmosphereComponent)}.");
return;
}
JoinedGridAtmos = gridAtmos;
JoinedGridAtmos.AddPipeNetDevice(this);
}
private void LeaveGridAtmos()
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
JoinedGridAtmos = null;
}
}
}