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 (_, node) in graph.Nodes)
foreach (var node in graph.Nodes.Values)
{
foreach (var action in node.Actions)
{
@@ -99,7 +99,7 @@ namespace Content.IntegrationTests.Tests.Construction
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;
@@ -125,7 +125,7 @@ namespace Content.IntegrationTests.Tests.Construction
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)
{

View File

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

View File

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

View File

@@ -5,8 +5,6 @@ using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -22,16 +20,18 @@ namespace Content.Server.GameObjects.Components.NodeContainer
public override string Name => "NodeContainer";
[ViewVariables]
public IReadOnlyList<Node> Nodes => _nodes;
public IReadOnlyDictionary<string, Node> Nodes => _nodes;
[DataField("nodes")]
private List<Node> _nodes = new();
private readonly Dictionary<string, Node> _nodes = new();
[DataField("examinable")]
private bool _examinable;
private bool _examinable = false;
public override void Initialize()
{
base.Initialize();
foreach (var node in _nodes)
foreach (var node in _nodes.Values)
{
node.Initialize(Owner);
}
@@ -40,36 +40,25 @@ namespace Content.Server.GameObjects.Components.NodeContainer
protected override void Startup()
{
base.Startup();
foreach (var node in _nodes)
foreach (var node in _nodes.Values)
{
node.OnContainerStartup();
}
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case AnchoredChangedMessage:
AnchorUpdate();
break;
}
}
protected override void Shutdown()
{
base.Shutdown();
foreach (var node in _nodes)
foreach (var node in _nodes.Values)
{
node.OnContainerShutdown();
}
}
private void AnchorUpdate()
public void AnchorUpdate()
{
foreach (var node in Nodes)
foreach (var node in Nodes.Values)
{
node.AnchorUpdate();
}
@@ -79,28 +68,24 @@ namespace Content.Server.GameObjects.Components.NodeContainer
{
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;
switch (node.NodeGroupID)
{
case NodeGroupID.HVPower:
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;
case NodeGroupID.MVPower:
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;
case NodeGroupID.Apc:
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;
}
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()
{
if (!Owner.TryGetComponent(out SnapGridComponent? grid))
if (!Owner.TryGetComponent(out SnapGridComponent? snap))
yield break;
var cells = grid.GetCardinalNeighborCells();
foreach (var cell in cells)
{
foreach (var cell in snap.GetCardinalNeighborCells())
foreach (var entity in cell.GetLocal())
{
if (entity.TryGetComponent<NodeContainerComponent>(out var container))
{
foreach (var node in container.Nodes)
if (!entity.TryGetComponent<NodeContainerComponent>(out var container)) continue;
foreach (var node in container.Nodes.Values)
{
if (node != null && node != this)
{
yield return node;
}
}
}
}
}
}
}

View File

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

View File

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

View File

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

View File

@@ -13,30 +13,34 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Initialize();
SubscribeLocalEvent<RotateEvent>(RotateEvent);
SubscribeLocalEvent<NodeContainerComponent, PhysicsBodyTypeChangedEvent>(OnBodyTypeChanged);
SubscribeLocalEvent<NodeContainerComponent, RotateEvent>(OnRotateEvent);
}
public override void 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))
{
return;
component.AnchorUpdate();
}
private void OnRotateEvent(EntityUid uid, NodeContainerComponent container, RotateEvent ev)
{
if (ev.NewRotation == ev.OldRotation)
{
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);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -29,7 +29,7 @@
- type: Icon
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
parent: PipeBase
@@ -38,7 +38,8 @@
components:
- type: NodeContainer
nodes:
- !type:PipeNode
pipe:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: South
- type: Icon
@@ -51,7 +52,8 @@
components:
- type: NodeContainer
nodes:
- !type:PipeNode
pipe:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: Longitudinal
- type: Icon
@@ -64,7 +66,8 @@
components:
- type: NodeContainer
nodes:
- !type:PipeNode
pipe:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: SWBend
- type: Icon
@@ -77,7 +80,8 @@
components:
- type: NodeContainer
nodes:
- !type:PipeNode
pipe:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: TSouth
- type: Icon
@@ -90,7 +94,8 @@
components:
- type: NodeContainer
nodes:
- !type:PipeNode
pipe:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: Fourway
- type: Icon

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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