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:
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -48,6 +50,17 @@ namespace Content.Server.GameObjects.Components.NodeContainer
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case AnchoredChangedMessage:
|
||||
AnchorUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
foreach (var node in _nodes)
|
||||
@@ -57,6 +70,14 @@ namespace Content.Server.GameObjects.Components.NodeContainer
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void AnchorUpdate()
|
||||
{
|
||||
foreach (var node in Nodes)
|
||||
{
|
||||
node.AnchorUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!_examinable || !inDetailsRange) return;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user