Cleanup relays on joint deletion (#4497)

This commit is contained in:
metalgearsloth
2023-10-22 16:53:10 +11:00
committed by GitHub
parent 9e5c1e9c95
commit 21b7c5f93e
2 changed files with 12 additions and 4 deletions

View File

@@ -51,7 +51,7 @@ public abstract partial class SharedJointSystem
{
foreach (var relay in component.Relayed)
{
if (Deleted(relay) || !_jointsQuery.TryGetComponent(relay, out var joint))
if (TerminatingOrDeleted(relay) || !_jointsQuery.TryGetComponent(relay, out var joint))
continue;
RefreshRelay(relay, component: joint);
@@ -73,13 +73,13 @@ public abstract partial class SharedJointSystem
relay = container.Owner;
}
RefreshRelay(uid, relay, component);
SetRelay(uid, relay, component);
}
/// <summary>
/// Refreshes the joint relay for this entity.
/// </summary>
public void RefreshRelay(EntityUid uid, EntityUid? relay, JointComponent? component = null)
public void SetRelay(EntityUid uid, EntityUid? relay, JointComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
@@ -91,7 +91,11 @@ public abstract partial class SharedJointSystem
{
if (relayTarget.Relayed.Remove(uid))
{
// TODO: Comp cleanup.
if (relayTarget.Relayed.Count == 0)
{
RemCompDeferred<JointRelayTargetComponent>(component.Relay.Value);
}
Dirty(component.Relay.Value, relayTarget);
}
}

View File

@@ -90,6 +90,10 @@ public abstract partial class SharedJointSystem : EntitySystem
{
RemoveJoint(joint);
}
// If we're relaying elsewhere then cleanup our old data.
if (component.Relay != null && !TerminatingOrDeleted(component.Relay.Value))
SetRelay(uid, null, component);
}
#endregion