Nodes in entities are now named. (#3825)

This commit is contained in:
Vera Aguilera Puerto
2021-04-09 20:47:31 +02:00
committed by GitHub
parent 8a26920e4c
commit 009870116d
25 changed files with 198 additions and 168 deletions

View File

@@ -59,7 +59,7 @@ namespace Content.IntegrationTests.Tests.Construction
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>()) foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{ {
foreach (var (_, node) in graph.Nodes) foreach (var node in graph.Nodes.Values)
{ {
foreach (var action in node.Actions) foreach (var action in node.Actions)
{ {
@@ -99,7 +99,7 @@ namespace Content.IntegrationTests.Tests.Construction
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>()) foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{ {
foreach (var (_, node) in graph.Nodes) foreach (var node in graph.Nodes.Values)
{ {
if (string.IsNullOrEmpty(node.Entity) || protoMan.TryIndex(node.Entity, out EntityPrototype _)) continue; if (string.IsNullOrEmpty(node.Entity) || protoMan.TryIndex(node.Entity, out EntityPrototype _)) continue;
@@ -125,7 +125,7 @@ namespace Content.IntegrationTests.Tests.Construction
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>()) foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{ {
foreach (var (_, node) in graph.Nodes) foreach (var node in graph.Nodes.Values)
{ {
foreach (var edge in node.Edges) foreach (var edge in node.Edges)
{ {

View File

@@ -23,7 +23,8 @@ namespace Content.IntegrationTests.Tests
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
supplyRate: 3000 supplyRate: 3000
@@ -39,7 +40,8 @@ namespace Content.IntegrationTests.Tests
offset: Center offset: Center
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
drawRate: 50 drawRate: 50
@@ -53,9 +55,11 @@ namespace Content.IntegrationTests.Tests
startingCharge: 1000 startingCharge: 1000
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
@@ -84,9 +88,11 @@ namespace Content.IntegrationTests.Tests
voltage: Medium voltage: Medium
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: Apc nodeGroupID: Apc
- type: SnapGrid - type: SnapGrid
offset: Center offset: Center
@@ -103,9 +109,11 @@ namespace Content.IntegrationTests.Tests
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode apc:
!type:AdjacentNode
nodeGroupID: Apc nodeGroupID: Apc
- !type:AdjacentNode wire:
!type:AdjacentNode
nodeGroupID: WireNet nodeGroupID: WireNet
- type: PowerProvider - type: PowerProvider
voltage: Apc voltage: Apc

View File

@@ -70,7 +70,7 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork
{ {
var nodes = nodeContainer.Nodes; var nodes = nodeContainer.Nodes;
foreach (var node in nodes) foreach (var node in nodes.Values)
{ {
if (node.NodeGroupID == NodeGroupID.WireNet) if (node.NodeGroupID == NodeGroupID.WireNet)
{ {

View File

@@ -5,8 +5,6 @@ using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -22,16 +20,18 @@ namespace Content.Server.GameObjects.Components.NodeContainer
public override string Name => "NodeContainer"; public override string Name => "NodeContainer";
[ViewVariables] [ViewVariables]
public IReadOnlyList<Node> Nodes => _nodes; public IReadOnlyDictionary<string, Node> Nodes => _nodes;
[DataField("nodes")] [DataField("nodes")]
private List<Node> _nodes = new(); private readonly Dictionary<string, Node> _nodes = new();
[DataField("examinable")] [DataField("examinable")]
private bool _examinable; private bool _examinable = false;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
foreach (var node in _nodes) foreach (var node in _nodes.Values)
{ {
node.Initialize(Owner); node.Initialize(Owner);
} }
@@ -40,36 +40,25 @@ namespace Content.Server.GameObjects.Components.NodeContainer
protected override void Startup() protected override void Startup()
{ {
base.Startup(); base.Startup();
foreach (var node in _nodes) foreach (var node in _nodes.Values)
{ {
node.OnContainerStartup(); node.OnContainerStartup();
} }
} }
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case AnchoredChangedMessage:
AnchorUpdate();
break;
}
}
protected override void Shutdown() protected override void Shutdown()
{ {
base.Shutdown(); base.Shutdown();
foreach (var node in _nodes) foreach (var node in _nodes.Values)
{ {
node.OnContainerShutdown(); node.OnContainerShutdown();
} }
} }
private void AnchorUpdate() public void AnchorUpdate()
{ {
foreach (var node in Nodes) foreach (var node in Nodes.Values)
{ {
node.AnchorUpdate(); node.AnchorUpdate();
} }
@@ -79,28 +68,24 @@ namespace Content.Server.GameObjects.Components.NodeContainer
{ {
if (!_examinable || !inDetailsRange) return; if (!_examinable || !inDetailsRange) return;
for (var i = 0; i < Nodes.Count; i++) foreach (var node in Nodes.Values)
{ {
var node = Nodes[i];
if (node == null) continue; if (node == null) continue;
switch (node.NodeGroupID) switch (node.NodeGroupID)
{ {
case NodeGroupID.HVPower: case NodeGroupID.HVPower:
message.AddMarkup( message.AddMarkup(
Loc.GetString("It has a connector for [color=orange]HV cables[/color].")); Loc.GetString("It has a connector for [color=orange]HV cables[/color].\n"));
break; break;
case NodeGroupID.MVPower: case NodeGroupID.MVPower:
message.AddMarkup( message.AddMarkup(
Loc.GetString("It has a connector for [color=yellow]MV cables[/color].")); Loc.GetString("It has a connector for [color=yellow]MV cables[/color].\n"));
break; break;
case NodeGroupID.Apc: case NodeGroupID.Apc:
message.AddMarkup( message.AddMarkup(
Loc.GetString("It has a connector for [color=green]APC cables[/color].")); Loc.GetString("It has a connector for [color=green]APC cables[/color].\n"));
break; break;
} }
if(i != Nodes.Count - 1)
message.AddMarkup("\n");
} }
} }
} }

View File

@@ -13,26 +13,22 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{ {
protected override IEnumerable<Node> GetReachableNodes() protected override IEnumerable<Node> GetReachableNodes()
{ {
if (!Owner.TryGetComponent(out SnapGridComponent? grid)) if (!Owner.TryGetComponent(out SnapGridComponent? snap))
yield break; yield break;
var cells = grid.GetCardinalNeighborCells(); foreach (var cell in snap.GetCardinalNeighborCells())
foreach (var cell in cells)
{
foreach (var entity in cell.GetLocal()) foreach (var entity in cell.GetLocal())
{ {
if (entity.TryGetComponent<NodeContainerComponent>(out var container)) if (!entity.TryGetComponent<NodeContainerComponent>(out var container)) continue;
{
foreach (var node in container.Nodes) foreach (var node in container.Nodes.Values)
{ {
if (node != null && node != this) if (node != null && node != this)
{ {
yield return node; yield return node;
} }
} }
}
}
} }
} }
} }

View File

@@ -179,7 +179,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
if (!entity.TryGetComponent<NodeContainerComponent>(out var container)) if (!entity.TryGetComponent<NodeContainerComponent>(out var container))
continue; continue;
foreach (var node in container.Nodes) foreach (var node in container.Nodes.Values)
{ {
if (node is PipeNode pipe) if (node is PipeNode pipe)
yield return pipe; yield return pipe;
@@ -243,7 +243,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
var netConnectedDirections = PipeDirection.None; var netConnectedDirections = PipeDirection.None;
if (Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
foreach (var node in container.Nodes) foreach (var node in container.Nodes.Values)
{ {
if (node is PipeNode pipe) if (node is PipeNode pipe)
{ {

View File

@@ -286,7 +286,7 @@ namespace Content.Server.GameObjects.Components.Power.AME
{ {
Owner.TryGetComponent(out NodeContainerComponent? nodeContainer); Owner.TryGetComponent(out NodeContainerComponent? nodeContainer);
var engineNodeGroup = nodeContainer?.Nodes var engineNodeGroup = nodeContainer?.Nodes.Values
.Select(node => node.NodeGroup) .Select(node => node.NodeGroup)
.OfType<AMENodeGroup>() .OfType<AMENodeGroup>()
.FirstOrDefault(); .FirstOrDefault();

View File

@@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Power
{ {
if (Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
var compatibleNet = container.Nodes var compatibleNet = container.Nodes.Values
.Where(node => node.NodeGroupID == (NodeGroupID) Voltage) .Where(node => node.NodeGroupID == (NodeGroupID) Voltage)
.Select(node => node.NodeGroup) .Select(node => node.NodeGroup)
.OfType<TNetType>() .OfType<TNetType>()

View File

@@ -13,30 +13,34 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<RotateEvent>(RotateEvent); SubscribeLocalEvent<NodeContainerComponent, PhysicsBodyTypeChangedEvent>(OnBodyTypeChanged);
SubscribeLocalEvent<NodeContainerComponent, RotateEvent>(OnRotateEvent);
} }
public override void Shutdown() public override void Shutdown()
{ {
base.Shutdown(); base.Shutdown();
UnsubscribeLocalEvent<RotateEvent>();
UnsubscribeLocalEvent<NodeContainerComponent, PhysicsBodyTypeChangedEvent>(OnBodyTypeChanged);
UnsubscribeLocalEvent<NodeContainerComponent, RotateEvent>(OnRotateEvent);
} }
private void RotateEvent(RotateEvent ev) private void OnBodyTypeChanged(EntityUid uid, NodeContainerComponent component, PhysicsBodyTypeChangedEvent args)
{ {
if (!ev.Sender.TryGetComponent(out NodeContainerComponent? container)) component.AnchorUpdate();
{
return;
} }
private void OnRotateEvent(EntityUid uid, NodeContainerComponent container, RotateEvent ev)
{
if (ev.NewRotation == ev.OldRotation) if (ev.NewRotation == ev.OldRotation)
{ {
return; return;
} }
foreach (var rotatableNode in container.Nodes.OfType<IRotatableNode>()) foreach (var node in container.Nodes.Values)
{ {
if (node is not IRotatableNode rotatableNode) continue;
rotatableNode.RotateEvent(ev); rotatableNode.RotateEvent(ev);
} }
} }

View File

@@ -39,6 +39,7 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South

View File

@@ -40,13 +40,16 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode inlet:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: West pipeDirection: West
- !type:PipeNode filter:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South
- !type:PipeNode outlet:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: East pipeDirection: East
- type: GasFilter - type: GasFilter

View File

@@ -41,7 +41,8 @@
- state: gasGenerator - state: gasGenerator
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: Fourway pipeDirection: Fourway

View File

@@ -27,7 +27,8 @@
- state: heaterPipe - state: heaterPipe
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode inlet:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: East pipeDirection: East
- type: PipeHeater - type: PipeHeater

View File

@@ -29,7 +29,7 @@
- type: Icon - type: Icon
sprite: Constructible/Atmos/pipe.rsi sprite: Constructible/Atmos/pipe.rsi
#Note: The PipeDirection of the PipeNode should be the east-facing version, because the entity starts at an angle of 0 (east) #Note: The PipeDirection of the PipeNode should be the south-facing version, because the entity starts at an angle of 0 (east)
- type: entity - type: entity
parent: PipeBase parent: PipeBase
@@ -38,7 +38,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South
- type: Icon - type: Icon
@@ -51,7 +52,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: Longitudinal pipeDirection: Longitudinal
- type: Icon - type: Icon
@@ -64,7 +66,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: SWBend pipeDirection: SWBend
- type: Icon - type: Icon
@@ -77,7 +80,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: TSouth pipeDirection: TSouth
- type: Icon - type: Icon
@@ -90,7 +94,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: Fourway pipeDirection: Fourway
- type: Icon - type: Icon

View File

@@ -39,10 +39,12 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode inlet:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: North pipeDirection: North
- !type:PipeNode outlet:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South
- type: PressurePump - type: PressurePump

View File

@@ -40,7 +40,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South
- type: PressureSiphon - type: PressureSiphon

View File

@@ -40,7 +40,8 @@
components: components:
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:PipeNode pipe:
!type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: South
- type: PressureVent - type: PressureVent

View File

@@ -24,7 +24,8 @@
state: wiredmachine state: wiredmachine
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
drawRate: 50 drawRate: 50
@@ -62,7 +63,8 @@
- type: Battery - type: Battery
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
@@ -90,7 +92,8 @@
- type: Battery - type: Battery
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
- type: BatteryDischarger - type: BatteryDischarger

View File

@@ -33,7 +33,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
supplyRate: 3000 supplyRate: 3000
@@ -88,7 +89,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode power:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
@@ -144,9 +146,11 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
@@ -196,9 +200,11 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: Apc nodeGroupID: Apc
- type: PowerConsumer - type: PowerConsumer
voltage: Medium voltage: Medium
@@ -249,7 +255,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode output:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
- type: SolarPanel - type: SolarPanel

View File

@@ -48,9 +48,11 @@
key: hv_cables key: hv_cables
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode power:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- !type:AdjacentNode wire:
!type:AdjacentNode
nodeGroupID: WireNet nodeGroupID: WireNet
- type: Wire - type: Wire
wireDroppedOnCutPrototype: HVWireStack1 wireDroppedOnCutPrototype: HVWireStack1
@@ -88,9 +90,11 @@
key: mv_cables key: mv_cables
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode power:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- !type:AdjacentNode wire:
!type:AdjacentNode
nodeGroupID: WireNet nodeGroupID: WireNet
- type: Wire - type: Wire
wireDroppedOnCutPrototype: MVWireStack1 wireDroppedOnCutPrototype: MVWireStack1
@@ -128,9 +132,11 @@
key: lv_cables key: lv_cables
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode power:
!type:AdjacentNode
nodeGroupID: Apc nodeGroupID: Apc
- !type:AdjacentNode wire:
!type:AdjacentNode
nodeGroupID: WireNet nodeGroupID: WireNet
- type: PowerProvider - type: PowerProvider
voltage: Apc voltage: Apc

View File

@@ -55,9 +55,11 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode ame:
!type:AdjacentNode
nodeGroupID: AMEngine nodeGroupID: AMEngine
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: PowerReceiver - type: PowerReceiver
- type: PowerSupplier - type: PowerSupplier

View File

@@ -45,7 +45,8 @@
- type: AMEShield - type: AMEShield
- type: NodeContainer - type: NodeContainer
nodes: nodes:
- !type:AdjacentNode ame:
!type:AdjacentNode
nodeGroupID: AMEngine nodeGroupID: AMEngine
- type: PointLight - type: PointLight
enabled: false enabled: false

View File

@@ -23,7 +23,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: Construction - type: Construction
graph: particleAcceleratorPowerBox graph: particleAcceleratorPowerBox

View File

@@ -36,7 +36,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: HVPower nodeGroupID: HVPower
- type: RadiationCollector - type: RadiationCollector
- type: Anchorable - type: Anchorable

View File

@@ -39,7 +39,8 @@
- type: NodeContainer - type: NodeContainer
examinable: true examinable: true
nodes: nodes:
- !type:AdjacentNode input:
!type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- type: Damageable - type: Damageable
resistances: metallicResistances resistances: metallicResistances