NodeGroups are dirtied when one of the nodes' snapgrid position changes.
Adds method to add behavior to a node when its snapgrid position changes.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
|
||||
.GetAllComponents<TNetConnector>()
|
||||
.Where(powerComp => (NodeGroupID) powerComp.Voltage == node.NodeGroupID)
|
||||
.ToList();
|
||||
_netConnectorComponents.Add(node, newNetConnectorComponents);
|
||||
_netConnectorComponents[node] = newNetConnectorComponents;
|
||||
foreach (var netConnectorComponent in newNetConnectorComponents)
|
||||
{
|
||||
SetNetConnectorNet(netConnectorComponent);
|
||||
|
||||
@@ -73,6 +73,10 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnSnapGridMove()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnContainerShutdown()
|
||||
{
|
||||
_deleting = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.NodeContainer;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -10,6 +11,22 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
private readonly HashSet<INodeGroup> _dirtyNodeGroups = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<NodeContainerComponent, SnapGridPositionChangedEvent>(OnSnapGridPositionChanged);
|
||||
}
|
||||
|
||||
private void OnSnapGridPositionChanged(EntityUid uid, NodeContainerComponent component, SnapGridPositionChangedEvent args)
|
||||
{
|
||||
foreach (var node in component.Nodes.Values)
|
||||
{
|
||||
node.OnSnapGridMove();
|
||||
AddDirtyNodeGroup(node.NodeGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddDirtyNodeGroup(INodeGroup nodeGroup)
|
||||
{
|
||||
_dirtyNodeGroups.Add(nodeGroup);
|
||||
|
||||
Reference in New Issue
Block a user