]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix the component toggler (#37309)
authorSamuka-C <47865393+Samuka-C@users.noreply.github.com>
Fri, 9 May 2025 18:00:58 +0000 (15:00 -0300)
committerGitHub <noreply@github.com>
Fri, 9 May 2025 18:00:58 +0000 (20:00 +0200)
* Make the ComponentToggle remember what entity it gave components to

* fix the null problem by just ignoring the null problem

* Add documentation to the new datafield + removing the "= null" that is not necessary

* small fixes and cleaning the code

* whitespace my beloved

* wait, I dont need those lines, why did I add them?

Content.Shared/Item/ItemToggle/ComponentTogglerSystem.cs
Content.Shared/Item/ItemToggle/Components/ComponentTogglerComponent.cs

index 59a04201a3863a3a57d581cf364de78517e6bc40..168b32713c21d47c66d844bfb676154279d49ae4 100644 (file)
@@ -16,13 +16,26 @@ public sealed class ComponentTogglerSystem : EntitySystem
 
     private void OnToggled(Entity<ComponentTogglerComponent> ent, ref ItemToggledEvent args)
     {
-        var target = ent.Comp.Parent ? Transform(ent).ParentUid : ent.Owner;
-        if (TerminatingOrDeleted(target))
-            return;
-
         if (args.Activated)
+        {
+            var target = ent.Comp.Parent ? Transform(ent).ParentUid : ent.Owner;
+
+            if (TerminatingOrDeleted(target))
+                return;
+
+            ent.Comp.Target = target;
+
             EntityManager.AddComponents(target, ent.Comp.Components);
+        }
         else
-            EntityManager.RemoveComponents(target, ent.Comp.RemoveComponents ?? ent.Comp.Components);
+        {
+            if (ent.Comp.Target == null)
+                return;
+
+            if (TerminatingOrDeleted(ent.Comp.Target.Value))
+                return;
+
+            EntityManager.RemoveComponents(ent.Comp.Target.Value, ent.Comp.RemoveComponents ?? ent.Comp.Components);
+        }
     }
 }
index 20ef0a0231537f3d1543aa4ee61d7cb5bdbcd873..cecdb4dc772e5cc9e3638c12358de741275de895 100644 (file)
@@ -29,4 +29,10 @@ public sealed partial class ComponentTogglerComponent : Component
     /// </summary>
     [DataField]
     public bool Parent;
+
+    // <summary>
+    // It holds the entity that the component gave the component to, so it can remove from it even if it changes parent.
+    // </summary>
+    [DataField]
+    public EntityUid? Target;
 }