Replace Component.OnRemove with ComponentRemove event subscriptions (#21072)

This commit is contained in:
DrSmugleaf
2023-10-17 19:35:36 -07:00
committed by GitHub
parent cb1b067a21
commit a136616531
7 changed files with 22 additions and 36 deletions

View File

@@ -59,13 +59,6 @@ namespace Content.Server.Power.Components
}; };
public float PowerReceived => NetworkLoad.ReceivingPower; public float PowerReceived => NetworkLoad.ReceivingPower;
protected override void OnRemove()
{
Provider?.RemoveReceiver(this);
base.OnRemove();
}
} }
/// <summary> /// <summary>

View File

@@ -33,12 +33,6 @@ namespace Content.Server.Power.Components
[DataField("node")] public string? NodeId { get; set; } [DataField("node")] public string? NodeId { get; set; }
protected override void OnRemove()
{
ClearNet();
base.OnRemove();
}
public void TryFindAndSetNet() public void TryFindAndSetNet()
{ {
if (TryFindNet(out var net)) if (TryFindNet(out var net))

View File

@@ -12,6 +12,21 @@ public sealed class PowerNetConnectorSystem : EntitySystem
SubscribeLocalEvent<ApcPowerProviderComponent, ComponentInit>(OnApcPowerProviderInit); SubscribeLocalEvent<ApcPowerProviderComponent, ComponentInit>(OnApcPowerProviderInit);
SubscribeLocalEvent<BatteryChargerComponent, ComponentInit>(OnBatteryChargerInit); SubscribeLocalEvent<BatteryChargerComponent, ComponentInit>(OnBatteryChargerInit);
SubscribeLocalEvent<BatteryDischargerComponent, ComponentInit>(OnBatteryDischargerInit); SubscribeLocalEvent<BatteryDischargerComponent, ComponentInit>(OnBatteryDischargerInit);
// TODO please end my life
SubscribeLocalEvent<ApcComponent, ComponentRemove>(OnRemove<ApcComponent, IApcNet>);
SubscribeLocalEvent<ApcPowerProviderComponent, ComponentRemove>(OnRemove<ApcPowerProviderComponent, IApcNet>);
SubscribeLocalEvent<BatteryChargerComponent, ComponentRemove>(OnRemove<BatteryChargerComponent, IPowerNet>);
SubscribeLocalEvent<BatteryDischargerComponent, ComponentRemove>(OnRemove<BatteryDischargerComponent, IPowerNet>);
SubscribeLocalEvent<PowerConsumerComponent, ComponentRemove>(OnRemove<PowerConsumerComponent, IBasePowerNet>);
SubscribeLocalEvent<PowerSupplierComponent, ComponentRemove>(OnRemove<PowerSupplierComponent, IBasePowerNet>);
}
private void OnRemove<TComp, TNet>(EntityUid uid, TComp component, ComponentRemove args)
where TComp : BaseNetConnectorComponent<TNet>
where TNet : class
{
component.ClearNet();
} }
private void OnPowerSupplierInit(EntityUid uid, PowerSupplierComponent component, ComponentInit args) private void OnPowerSupplierInit(EntityUid uid, PowerSupplierComponent component, ComponentInit args)

View File

@@ -3,8 +3,8 @@ using Content.Server.NodeContainer.EntitySystems;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Power.NodeGroups; using Content.Server.Power.NodeGroups;
using Content.Server.Power.Pow3r; using Content.Server.Power.Pow3r;
using JetBrains.Annotations;
using Content.Shared.Power; using Content.Shared.Power;
using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Threading; using Robust.Shared.Threading;
@@ -34,6 +34,7 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentInit>(ApcPowerReceiverInit); SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentInit>(ApcPowerReceiverInit);
SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentShutdown>(ApcPowerReceiverShutdown); SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentShutdown>(ApcPowerReceiverShutdown);
SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentRemove>(ApcPowerReceiverRemove);
SubscribeLocalEvent<ApcPowerReceiverComponent, EntityPausedEvent>(ApcPowerReceiverPaused); SubscribeLocalEvent<ApcPowerReceiverComponent, EntityPausedEvent>(ApcPowerReceiverPaused);
SubscribeLocalEvent<ApcPowerReceiverComponent, EntityUnpausedEvent>(ApcPowerReceiverUnpaused); SubscribeLocalEvent<ApcPowerReceiverComponent, EntityUnpausedEvent>(ApcPowerReceiverUnpaused);
@@ -64,6 +65,11 @@ namespace Content.Server.Power.EntitySystems
_powerState.Loads.Free(component.NetworkLoad.Id); _powerState.Loads.Free(component.NetworkLoad.Id);
} }
private void ApcPowerReceiverRemove(EntityUid uid, ApcPowerReceiverComponent component, ComponentRemove args)
{
component.Provider?.RemoveReceiver(component);
}
private static void ApcPowerReceiverPaused( private static void ApcPowerReceiverPaused(
EntityUid uid, EntityUid uid,
ApcPowerReceiverComponent component, ApcPowerReceiverComponent component,

View File

@@ -1,6 +1,5 @@
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Pulling.Components namespace Content.Shared.Pulling.Components
@@ -39,16 +38,6 @@ namespace Content.Shared.Pulling.Components
[Access(typeof(SharedPullingSystem), Other = AccessPermissions.ReadExecute)] [Access(typeof(SharedPullingSystem), Other = AccessPermissions.ReadExecute)]
[ViewVariables] [ViewVariables]
public bool PrevFixedRotation; public bool PrevFixedRotation;
protected override void OnRemove()
{
if (Puller != null)
{
// This is absolute paranoia but it's also absolutely necessary. Too many puller state bugs. - 20kdc
Logger.ErrorS("c.go.c.pulling", "PULLING STATE CORRUPTION IMMINENT IN PULLABLE {0} - OnRemove called when Puller is set!", Owner);
}
base.OnRemove();
}
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -17,15 +17,5 @@
/// </summary> /// </summary>
[DataField("needsHands")] [DataField("needsHands")]
public bool NeedsHands = true; public bool NeedsHands = true;
protected override void OnRemove()
{
if (Pulling != default)
{
// This is absolute paranoia but it's also absolutely necessary. Too many puller state bugs. - 20kdc
Logger.ErrorS("c.go.c.pulling", "PULLING STATE CORRUPTION IMMINENT IN PULLER {0} - OnRemove called when Pulling is set!", Owner);
}
base.OnRemove();
}
} }
} }

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Content.Shared.Physics.Pull; using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components; using Content.Shared.Pulling.Components;
using JetBrains.Annotations; using JetBrains.Annotations;