Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/NodeGroupSystem.cs
Vera Aguilera Puerto 20243052cb NodeGroups are dirtied when one of the nodes' snapgrid position changes.
Adds method to add behavior to a node when its snapgrid position changes.
2021-06-01 11:48:24 +02:00

48 lines
1.3 KiB
C#

using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class NodeGroupSystem : EntitySystem
{
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);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var group in _dirtyNodeGroups)
{
group.RemakeGroup();
}
_dirtyNodeGroups.Clear();
}
}
}