Replaces AnchoredChanged C# event with ComponentMessage (#2905)

* Replaces AnchoredChanged C# event with ComponentMessage

* Removes unneeded fields

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-04 22:32:59 -06:00
committed by GitHub
parent 350f7313be
commit 1032576a20
11 changed files with 126 additions and 87 deletions

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
@@ -66,17 +66,29 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
physics.AnchoredChanged += AnchorUpdate;
}
}
public void AnchorUpdate()
{
if (Anchored)
{
if (_needsGroup)
{
TryAssignGroupIfNeeded();
CombineGroupWithReachable();
}
}
else
{
NodeGroup.RemoveNode(this);
ClearNodeGroup();
}
}
public void OnContainerRemove()
{
_deleting = true;
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.AnchoredChanged -= AnchorUpdate;
}
NodeGroup.RemoveNode(this);
}
@@ -153,22 +165,5 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
return _nodeGroupFactory.MakeNodeGroup(this);
}
private void AnchorUpdate()
{
if (Anchored)
{
if (_needsGroup)
{
TryAssignGroupIfNeeded();
CombineGroupWithReachable();
}
}
else
{
NodeGroup.RemoveNode(this);
ClearNodeGroup();
}
}
}
}