Fix pipe net null error (#9508)

This commit is contained in:
Leon Friedrich
2022-07-07 15:36:07 +12:00
committed by GitHub
parent 731e9cbd9f
commit d9c247b310
6 changed files with 32 additions and 28 deletions

View File

@@ -3,7 +3,7 @@ using Content.Shared.Atmos;
namespace Content.Server.Atmos.Piping.Unary.Components namespace Content.Server.Atmos.Piping.Unary.Components
{ {
[RegisterComponent] [RegisterComponent]
public sealed class GasCanisterComponent : Component public sealed class GasCanisterComponent : Component, IGasMixtureHolder
{ {
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("port")] [DataField("port")]
@@ -18,7 +18,7 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("gasMixture")] [DataField("gasMixture")]
public GasMixture Air { get; } = new(); public GasMixture Air { get; set; } = new();
/// <summary> /// <summary>
/// Last recorded pressure, for appearance-updating purposes. /// Last recorded pressure, for appearance-updating purposes.

View File

@@ -139,6 +139,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args) private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
{ {
_atmosphereSystem.React(canister.Air, canister);
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) || !EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
return; return;
@@ -146,8 +148,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!nodeContainer.TryGetNode(canister.PortName, out PortablePipeNode? portNode)) if (!nodeContainer.TryGetNode(canister.PortName, out PortablePipeNode? portNode))
return; return;
_atmosphereSystem.React(canister.Air, portNode);
if (portNode.NodeGroup is PipeNet {NodeCount: > 1} net) if (portNode.NodeGroup is PipeNet {NodeCount: > 1} net)
{ {
var buffer = new GasMixture(net.Air.Volume + canister.Air.Volume); var buffer = new GasMixture(net.Air.Volume + canister.Air.Volume);

View File

@@ -20,7 +20,7 @@ namespace Content.Server.NodeContainer.NodeGroups
void Create(NodeGroupID groupId); void Create(NodeGroupID groupId);
void Initialize(Node sourceNode, IEntityManager? entMan = null); void Initialize(Node sourceNode, IEntityManager entMan);
void RemoveNode(Node node); void RemoveNode(Node node);
@@ -70,7 +70,7 @@ namespace Content.Server.NodeContainer.NodeGroups
GroupId = groupId; GroupId = groupId;
} }
public virtual void Initialize(Node sourceNode, IEntityManager? entMan = null) public virtual void Initialize(Node sourceNode, IEntityManager entMan)
{ {
} }

View File

@@ -24,17 +24,15 @@ namespace Content.Server.NodeContainer.NodeGroups
public EntityUid? Grid { get; private set; } public EntityUid? Grid { get; private set; }
public override void Initialize(Node sourceNode, IEntityManager? entMan = null) public override void Initialize(Node sourceNode, IEntityManager entMan)
{ {
IoCManager.Resolve(ref entMan);
base.Initialize(sourceNode, entMan); base.Initialize(sourceNode, entMan);
Grid = entMan.GetComponent<TransformComponent>(sourceNode.Owner).GridUid; Grid = entMan.GetComponent<TransformComponent>(sourceNode.Owner).GridUid;
if (Grid == null) if (Grid == null)
{ {
Logger.Error($"Created a pipe network without an associated grid. Pipe networks currently need to be tied to a grid for amtos to work. Source entity: {entMan.ToPrettyString(sourceNode.Owner)}"); // This is probably due to a cannister or something like that being spawned in space.
return; return;
} }
@@ -82,13 +80,11 @@ namespace Content.Server.NodeContainer.NodeGroups
newAir.Add(newPipeNet.Air); newAir.Add(newPipeNet.Air);
} }
_atmosphereSystem!.DivideInto(Air, newAir); _atmosphereSystem?.DivideInto(Air, newAir);
} }
private void RemoveFromGridAtmos() private void RemoveFromGridAtmos()
{ {
DebugTools.AssertNotNull(_atmosphereSystem);
if (Grid == null) if (Grid == null)
return; return;

View File

@@ -26,7 +26,7 @@ namespace Content.Server.Power.NodeGroups
[UsedImplicitly] [UsedImplicitly]
public sealed class ApcNet : BaseNetConnectorNodeGroup<IApcNet>, IApcNet public sealed class ApcNet : BaseNetConnectorNodeGroup<IApcNet>, IApcNet
{ {
private readonly PowerNetSystem _powerNetSystem = EntitySystem.Get<PowerNetSystem>(); private PowerNetSystem? _powerNetSystem;
[ViewVariables] public readonly List<ApcComponent> Apcs = new(); [ViewVariables] public readonly List<ApcComponent> Apcs = new();
[ViewVariables] public readonly List<ApcPowerProviderComponent> Providers = new(); [ViewVariables] public readonly List<ApcPowerProviderComponent> Providers = new();
@@ -42,10 +42,11 @@ namespace Content.Server.Power.NodeGroups
[ViewVariables] [ViewVariables]
public PowerState.Network NetworkNode { get; } = new(); public PowerState.Network NetworkNode { get; } = new();
public override void Initialize(Node sourceNode, IEntityManager? entMan = null) public override void Initialize(Node sourceNode, IEntityManager entMan)
{ {
base.Initialize(sourceNode, entMan); base.Initialize(sourceNode, entMan);
_powerNetSystem = entMan.EntitySysManager.GetEntitySystem<PowerNetSystem>();
_powerNetSystem.InitApcNet(this); _powerNetSystem.InitApcNet(this);
} }
@@ -53,7 +54,7 @@ namespace Content.Server.Power.NodeGroups
{ {
base.AfterRemake(newGroups); base.AfterRemake(newGroups);
_powerNetSystem.DestroyApcNet(this); _powerNetSystem?.DestroyApcNet(this);
} }
public void AddApc(ApcComponent apc) public void AddApc(ApcComponent apc)
@@ -104,7 +105,7 @@ namespace Content.Server.Power.NodeGroups
public void QueueNetworkReconnect() public void QueueNetworkReconnect()
{ {
_powerNetSystem.QueueReconnectApcNet(this); _powerNetSystem?.QueueReconnectApcNet(this);
} }
protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IApcNet> netConnectorComponent) protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IApcNet> netConnectorComponent)
@@ -114,6 +115,9 @@ namespace Content.Server.Power.NodeGroups
public override string? GetDebugData() public override string? GetDebugData()
{ {
if (_powerNetSystem == null)
return null;
// This is just recycling the multi-tool examine. // This is just recycling the multi-tool examine.
var ps = _powerNetSystem.GetNetworkStatistics(NetworkNode); var ps = _powerNetSystem.GetNetworkStatistics(NetworkNode);

View File

@@ -27,7 +27,7 @@ namespace Content.Server.Power.NodeGroups
[UsedImplicitly] [UsedImplicitly]
public sealed class PowerNet : BaseNetConnectorNodeGroup<IPowerNet>, IPowerNet public sealed class PowerNet : BaseNetConnectorNodeGroup<IPowerNet>, IPowerNet
{ {
private readonly PowerNetSystem _powerNetSystem = EntitySystem.Get<PowerNetSystem>(); private PowerNetSystem? _powerNetSystem;
[ViewVariables] public readonly List<PowerSupplierComponent> Suppliers = new(); [ViewVariables] public readonly List<PowerSupplierComponent> Suppliers = new();
[ViewVariables] public readonly List<PowerConsumerComponent> Consumers = new(); [ViewVariables] public readonly List<PowerConsumerComponent> Consumers = new();
@@ -37,10 +37,11 @@ namespace Content.Server.Power.NodeGroups
[ViewVariables] [ViewVariables]
public PowerState.Network NetworkNode { get; } = new(); public PowerState.Network NetworkNode { get; } = new();
public override void Initialize(Node sourceNode, IEntityManager? entMan = null) public override void Initialize(Node sourceNode, IEntityManager entMan)
{ {
base.Initialize(sourceNode, entMan); base.Initialize(sourceNode, entMan);
_powerNetSystem = entMan.EntitySysManager.GetEntitySystem<PowerNetSystem>();
_powerNetSystem.InitPowerNet(this); _powerNetSystem.InitPowerNet(this);
} }
@@ -48,7 +49,7 @@ namespace Content.Server.Power.NodeGroups
{ {
base.AfterRemake(newGroups); base.AfterRemake(newGroups);
_powerNetSystem.DestroyPowerNet(this); _powerNetSystem?.DestroyPowerNet(this);
} }
protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IPowerNet> netConnectorComponent) protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IPowerNet> netConnectorComponent)
@@ -60,28 +61,28 @@ namespace Content.Server.Power.NodeGroups
{ {
supplier.NetworkSupply.LinkedNetwork = default; supplier.NetworkSupply.LinkedNetwork = default;
Suppliers.Add(supplier); Suppliers.Add(supplier);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void RemoveSupplier(PowerSupplierComponent supplier) public void RemoveSupplier(PowerSupplierComponent supplier)
{ {
supplier.NetworkSupply.LinkedNetwork = default; supplier.NetworkSupply.LinkedNetwork = default;
Suppliers.Remove(supplier); Suppliers.Remove(supplier);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void AddConsumer(PowerConsumerComponent consumer) public void AddConsumer(PowerConsumerComponent consumer)
{ {
consumer.NetworkLoad.LinkedNetwork = default; consumer.NetworkLoad.LinkedNetwork = default;
Consumers.Add(consumer); Consumers.Add(consumer);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void RemoveConsumer(PowerConsumerComponent consumer) public void RemoveConsumer(PowerConsumerComponent consumer)
{ {
consumer.NetworkLoad.LinkedNetwork = default; consumer.NetworkLoad.LinkedNetwork = default;
Consumers.Remove(consumer); Consumers.Remove(consumer);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void AddDischarger(BatteryDischargerComponent discharger) public void AddDischarger(BatteryDischargerComponent discharger)
@@ -89,7 +90,7 @@ namespace Content.Server.Power.NodeGroups
var battery = IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(discharger.Owner); var battery = IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(discharger.Owner);
battery.NetworkBattery.LinkedNetworkCharging = default; battery.NetworkBattery.LinkedNetworkCharging = default;
Dischargers.Add(discharger); Dischargers.Add(discharger);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void RemoveDischarger(BatteryDischargerComponent discharger) public void RemoveDischarger(BatteryDischargerComponent discharger)
@@ -99,7 +100,7 @@ namespace Content.Server.Power.NodeGroups
battery.NetworkBattery.LinkedNetworkCharging = default; battery.NetworkBattery.LinkedNetworkCharging = default;
Dischargers.Remove(discharger); Dischargers.Remove(discharger);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void AddCharger(BatteryChargerComponent charger) public void AddCharger(BatteryChargerComponent charger)
@@ -107,7 +108,7 @@ namespace Content.Server.Power.NodeGroups
var battery = IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(charger.Owner); var battery = IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(charger.Owner);
battery.NetworkBattery.LinkedNetworkCharging = default; battery.NetworkBattery.LinkedNetworkCharging = default;
Chargers.Add(charger); Chargers.Add(charger);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public void RemoveCharger(BatteryChargerComponent charger) public void RemoveCharger(BatteryChargerComponent charger)
@@ -117,11 +118,14 @@ namespace Content.Server.Power.NodeGroups
battery.NetworkBattery.LinkedNetworkCharging = default; battery.NetworkBattery.LinkedNetworkCharging = default;
Chargers.Remove(charger); Chargers.Remove(charger);
_powerNetSystem.QueueReconnectPowerNet(this); _powerNetSystem?.QueueReconnectPowerNet(this);
} }
public override string? GetDebugData() public override string? GetDebugData()
{ {
if (_powerNetSystem == null)
return null;
// This is just recycling the multi-tool examine. // This is just recycling the multi-tool examine.
var ps = _powerNetSystem.GetNetworkStatistics(NetworkNode); var ps = _powerNetSystem.GetNetworkStatistics(NetworkNode);