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

@@ -614,22 +614,12 @@ namespace Content.Server.GameObjects.Components.Disposal
Logger.WarningS("VitalComponentMissing", $"Disposal unit {Owner.Uid} is missing an anchorable component");
}
if (Owner.TryGetComponent(out IPhysicsComponent? physics))
{
physics.AnchoredChanged += UpdateVisualState;
}
UpdateTargetList();
UpdateVisualState();
}
public override void OnRemove()
{
if (Owner.TryGetComponent(out IPhysicsComponent? physics))
{
physics.AnchoredChanged -= UpdateVisualState;
}
if (_container != null)
{
foreach (var entity in _container.ContainedEntities.ToArray())
@@ -671,6 +661,10 @@ namespace Content.Server.GameObjects.Components.Disposal
Remove(msg.Entity);
break;
case AnchoredChangedMessage:
UpdateVisualState();
break;
case PowerChangedMessage powerChanged:
PowerStateChanged(powerChanged);
break;

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Linq;
using Content.Shared.GameObjects.Components.Disposal;
@@ -231,10 +231,6 @@ namespace Content.Server.GameObjects.Components.Disposal
Contents = ContainerManagerComponent.Ensure<Container>(Name, Owner);
Owner.EnsureComponent<AnchorableComponent>();
var physics = Owner.EnsureComponent<PhysicsComponent>();
physics.AnchoredChanged += AnchoredChanged;
}
protected override void Startup()
@@ -254,9 +250,6 @@ namespace Content.Server.GameObjects.Components.Disposal
{
base.OnRemove();
var physics = Owner.EnsureComponent<PhysicsComponent>();
physics.AnchoredChanged -= AnchoredChanged;
Disconnect();
}
@@ -275,6 +268,10 @@ namespace Content.Server.GameObjects.Components.Disposal
_lastClang = _gameTiming.CurTime;
EntitySystem.Get<AudioSystem>().PlayAtCoords(_clangSound, Owner.Transform.Coordinates);
break;
case AnchoredChangedMessage:
AnchoredChanged();
break;
}
}

View File

@@ -569,21 +569,11 @@ namespace Content.Server.GameObjects.Components.Disposal
Logger.WarningS("VitalComponentMissing", $"Disposal unit {Owner.Uid} is missing an anchorable component");
}
if (Owner.TryGetComponent(out IPhysicsComponent? physics))
{
physics.AnchoredChanged += UpdateVisualState;
}
UpdateVisualState();
}
public override void OnRemove()
{
if (Owner.TryGetComponent(out IPhysicsComponent? physics))
{
physics.AnchoredChanged -= UpdateVisualState;
}
foreach (var entity in _container.ContainedEntities.ToArray())
{
_container.ForceRemove(entity);
@@ -617,6 +607,10 @@ namespace Content.Server.GameObjects.Components.Disposal
Remove(msg.Entity);
break;
case AnchoredChangedMessage:
UpdateVisualState();
break;
case PowerChangedMessage powerChanged:
PowerStateChanged(powerChanged);
break;