diff --git a/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs index 348ba46956..215d33fa1f 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System; using Content.Server.Atmos; using Content.Server.GameObjects.Components.Atmos.Piping; @@ -92,7 +92,6 @@ namespace Content.Server.GameObjects.Components.Atmos if (Owner.TryGetComponent(out var physics)) { AnchorUpdate(); - physics.AnchoredChanged += AnchorUpdate; } if (UserInterface != null) { @@ -107,15 +106,22 @@ namespace Content.Server.GameObjects.Components.Atmos UpdateAppearance(); } + public override void HandleMessage(ComponentMessage message, IComponent? component) + { + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage: + AnchorUpdate(); + break; + } + } + #region Connector port methods public override void OnRemove() { base.OnRemove(); - if (Owner.TryGetComponent(out var physics)) - { - physics.AnchoredChanged -= AnchorUpdate; - } if (UserInterface != null) { UserInterface.OnReceiveMessage -= OnUiReceiveMessage; diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs index 365703861c..0bc3be51b7 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs @@ -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; diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs index 03342d9db9..853d4bab77 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs @@ -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(Name, Owner); Owner.EnsureComponent(); - - var physics = Owner.EnsureComponent(); - - physics.AnchoredChanged += AnchoredChanged; } protected override void Startup() @@ -254,9 +250,6 @@ namespace Content.Server.GameObjects.Components.Disposal { base.OnRemove(); - var physics = Owner.EnsureComponent(); - physics.AnchoredChanged -= AnchoredChanged; - Disconnect(); } @@ -275,6 +268,10 @@ namespace Content.Server.GameObjects.Components.Disposal _lastClang = _gameTiming.CurTime; EntitySystem.Get().PlayAtCoords(_clangSound, Owner.Transform.Coordinates); break; + + case AnchoredChangedMessage: + AnchoredChanged(); + break; } } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 9811a4f021..b1abeb9455 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -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; diff --git a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs index 30de8613cd..adf31160cf 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs @@ -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; diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs index 6e2420da7a..09c45000df 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs @@ -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(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(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(); - } - } } } diff --git a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorPartComponent.cs b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorPartComponent.cs index 3f078cd71f..6c549c050b 100644 --- a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorPartComponent.cs +++ b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorPartComponent.cs @@ -1,8 +1,9 @@ -#nullable enable +#nullable enable using Content.Server.Utility; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.Transform; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Log; using Robust.Shared.ViewVariables; @@ -10,7 +11,6 @@ namespace Content.Server.GameObjects.Components.PA { public abstract class ParticleAcceleratorPartComponent : Component { - [ViewVariables] private PhysicsComponent? _collidableComponent; [ViewVariables] public ParticleAcceleratorControlBoxComponent? Master; [ViewVariables] protected SnapGridComponent? SnapGrid; @@ -18,14 +18,6 @@ namespace Content.Server.GameObjects.Components.PA { base.Initialize(); // FIXME: this has to be an entity system, full stop. - if (!Owner.TryGetComponent(out _collidableComponent)) - { - Logger.Error("ParticleAcceleratorPartComponent created with no CollidableComponent"); - } - else - { - _collidableComponent.AnchoredChanged += OnAnchorChanged; - } if (!Owner.TryGetComponent(out SnapGrid)) { @@ -33,6 +25,17 @@ namespace Content.Server.GameObjects.Components.PA } } + public override void HandleMessage(ComponentMessage message, IComponent? component) + { + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage: + OnAnchorChanged(); + break; + } + } + public void OnAnchorChanged() { RescanIfPossible(); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs index 5b208920aa..c20495e5b1 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs @@ -1,6 +1,5 @@ #nullable enable using System; -using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.EntitySystems; @@ -9,6 +8,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.Components; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; @@ -99,16 +99,11 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents if (_physicsComponent != null) { AnchorUpdate(); - _physicsComponent.AnchoredChanged += AnchorUpdate; } } public override void OnRemove() { - if (_physicsComponent != null) - { - _physicsComponent.AnchoredChanged -= AnchorUpdate; - } _provider.RemoveReceiver(this); base.OnRemove(); } @@ -121,6 +116,17 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents } } + public override void HandleMessage(ComponentMessage message, IComponent? component) + { + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage: + AnchorUpdate(); + break; + } + } + public void ApcPowerChanged() { var oldPowered = Powered; diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs index 51d378b5d0..b6b63ffc2c 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs @@ -9,6 +9,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -36,7 +37,17 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents Logger.Error("RadiationCollectorComponent created with no CollidableComponent"); return; } - _collidableComponent.AnchoredChanged += OnAnchoredChanged; + } + + public override void HandleMessage(ComponentMessage message, IComponent component) + { + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage: + OnAnchoredChanged(); + break; + } } private void OnAnchoredChanged() diff --git a/Content.Server/GameObjects/Components/Singularity/ContainmentFieldGeneratorComponent.cs b/Content.Server/GameObjects/Components/Singularity/ContainmentFieldGeneratorComponent.cs index 62423d18bc..ba5e54100a 100644 --- a/Content.Server/GameObjects/Components/Singularity/ContainmentFieldGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Singularity/ContainmentFieldGeneratorComponent.cs @@ -79,9 +79,18 @@ namespace Content.Server.GameObjects.Components.Singularity Logger.Error("ContainmentFieldGeneratorComponent created with no CollidableComponent"); return; } - _collidableComponent.AnchoredChanged += OnAnchoredChanged; } + public override void HandleMessage(ComponentMessage message, IComponent? component) + { + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage: + OnAnchoredChanged(); + break; + } + } private void OnAnchoredChanged() { diff --git a/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs b/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs index c396bb74a5..1707e94086 100644 --- a/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs +++ b/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs @@ -16,6 +16,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Systems; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -43,7 +44,6 @@ namespace Content.Server.GameObjects.Components.Singularity private CancellationTokenSource? _timerCancel; - private PhysicsComponent _collidableComponent = default!; private PowerConsumerComponent _powerConsumer = default!; // whether the power switch is in "on" @@ -79,19 +79,11 @@ namespace Content.Server.GameObjects.Components.Singularity { base.Initialize(); - if (!Owner.TryGetComponent(out _collidableComponent!)) - { - Logger.Error($"EmitterComponent {Owner} created with no CollidableComponent"); - return; - } - if (!Owner.TryGetComponent(out _powerConsumer!)) { Logger.Error($"EmitterComponent {Owner} created with no PowerConsumerComponent"); return; } - - _collidableComponent.AnchoredChanged += OnAnchoredChanged; _powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged; } @@ -112,9 +104,20 @@ namespace Content.Server.GameObjects.Components.Singularity } } - private void OnAnchoredChanged() + public override void HandleMessage(ComponentMessage message, IComponent? component) { - if (_collidableComponent.Anchored) + base.HandleMessage(message, component); + switch (message) + { + case AnchoredChangedMessage anchoredChanged: + OnAnchoredChanged(anchoredChanged); + break; + } + } + + private void OnAnchoredChanged(AnchoredChangedMessage anchoredChanged) + { + if (anchoredChanged.Anchored) Owner.SnapToGrid(); }