Files
tbd-station-14/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/INodeGroup.cs
py01 7b12d4e08c PipeNet (#1626)
* PipeNode

* Pipe prototypes

* Fixes Default NodeGroup not being registered by NodeGroupFactory

* GasNet

* PumpComponent

* IPipeNet

* PipeComponent

* misc naming, yaml

* PipeComponent rework

* PipeNet gas transfer from pipes

* PipeNet correctly combines gas on combining with other group

* Client ignores piping components

* AfterRemake

* PipeNet remake simplification

* IGasMixtureHolder on PipeComponent, IPipeNet

* PipeContainerComponent

* BasePump

* DebugPump

* IgnoredComponent fix

* Pipe LocalAir and Air

* comments

* Pump fix

* PipeNet fix

* name simplification

* PipeDirection name changes

* BaseVentComponent and DebugVentComponent

* Moves Pipe to own file

* DebugVentComponent moved to own file

* BaseScrubberComponent

* DebugScrubberComponent

* IgnoredComponents update

* scrubber prototype

* vent prototype fix

* comments

* Removes vent and scrubber PipeDirection check

* PipeContainer, Pipe, and PipeNode refactor

* Yaml cleanup

* pump prototype fix

* Removes AssumeAir usage from old IGasMixtureHolders

* Simplfies Vent & Scrubber to use AtmosHelper methods

* Vents and scrubbers invalidate the coordinate they changed the gas of

* UpdatedPipingComponent

* ScrubberComponent renamed to SiphonComponent

* Removes PumpSystem

* Removes framTime from UpdatedPiping

* PipeNetDevices

* PipeNetDevice updated by GridAtmosphereComponent

* PipeNets react from update in GridAtmosphereComponent

* GridAtmosphereComponent stores PipeNets/PipeNetDevices to be updated in queue

* diff fix

* Removes debug gas starting in pipes

* type safety in IPipeNet when combining groups

* null checks

* GridAtmos stores PipeNets and PipeNetDevices in List

* comments

* rogue curly bracket

* ProcessPipeNets update fix

* RemovePipeNet fix

* PipeNet update() unique index

* fix diff

* Integration test fixes

* Error Logging

* error fix

Co-authored-by: py01 <pyronetics01@gmail.com>
2020-08-27 17:45:27 +02:00

116 lines
3.4 KiB
C#

using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
/// <summary>
/// Maintains a collection of <see cref="Node"/>s, and performs operations requiring a list of
/// all connected <see cref="Node"/>s.
/// </summary>
public interface INodeGroup
{
IReadOnlyList<Node> Nodes { get; }
void Initialize(Node sourceNode);
void AddNode(Node node);
void RemoveNode(Node node);
void CombineGroup(INodeGroup newGroup);
void RemakeGroup();
}
[NodeGroup(NodeGroupID.Default)]
public class BaseNodeGroup : INodeGroup
{
[ViewVariables]
public IReadOnlyList<Node> Nodes => _nodes;
private readonly List<Node> _nodes = new List<Node>();
[ViewVariables]
public int NodeCount => Nodes.Count;
public static readonly INodeGroup NullGroup = new NullNodeGroup();
protected GridId GridId { get; private set;}
public virtual void Initialize(Node sourceNode)
{
GridId = sourceNode.Owner.Transform.GridID;
}
public void AddNode(Node node)
{
_nodes.Add(node);
OnAddNode(node);
}
public void RemoveNode(Node node)
{
_nodes.Remove(node);
OnRemoveNode(node);
IoCManager.Resolve<INodeGroupManager>().AddDirtyNodeGroup(this);
}
public void CombineGroup(INodeGroup newGroup)
{
if (newGroup.Nodes.Count < Nodes.Count)
{
newGroup.CombineGroup(this);
return;
}
OnGivingNodesForCombine(newGroup);
foreach (var node in Nodes)
{
node.NodeGroup = newGroup;
}
}
/// <summary>
/// Causes all <see cref="Node"/>s to remake their groups. Called when a <see cref="Node"/> is removed
/// and may have split a group in two, so multiple new groups may need to be formed.
/// </summary>
public void RemakeGroup()
{
foreach (var node in Nodes)
{
node.ClearNodeGroup();
}
var newGroups = new List<INodeGroup>();
foreach (var node in Nodes)
{
if (node.TryAssignGroupIfNeeded())
{
node.SpreadGroup();
newGroups.Add(node.NodeGroup);
}
}
AfterRemake(newGroups);
}
protected virtual void OnAddNode(Node node) { }
protected virtual void OnRemoveNode(Node node) { }
protected virtual void OnGivingNodesForCombine(INodeGroup newGroup) { }
protected virtual void AfterRemake(IEnumerable<INodeGroup> newGroups) { }
private class NullNodeGroup : INodeGroup
{
public IReadOnlyList<Node> Nodes => _nodes;
private readonly List<Node> _nodes = new List<Node>();
public void Initialize(Node sourceNode) { }
public void AddNode(Node node) { }
public void CombineGroup(INodeGroup newGroup) { }
public void RemoveNode(Node node) { }
public void RemakeGroup() { }
}
}
}