]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix possible bug in my fix of IFF console. Add documentation to HideOnInit. (#42122)
authorEchoOfNothing <52498373+EchoOfNothing@users.noreply.github.com>
Mon, 29 Dec 2025 08:53:18 +0000 (10:53 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Dec 2025 08:53:18 +0000 (08:53 +0000)
* Refactor OnIFFShow and OnInitIFFConsole by extracting AddAllSupportedIFFFlags method. Fix possible addition of unallowed flags.

Fix posible addition of unallowed flags in OnInitIFFConsole by performing AllowedFlags check in the extracted function.

* Add documentation to HideOnInit

* Update IFFConsoleComponent.cs

---------

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Content.Server/Shuttles/Components/IFFConsoleComponent.cs
Content.Server/Shuttles/Systems/ShuttleSystem.IFF.cs

index 8db81dc1fd58746c5ab4ac789ca0d7e1281a5fae..c2cf913c2c44f60766e12495658291f87f085485 100644 (file)
@@ -12,6 +12,9 @@ public sealed partial class IFFConsoleComponent : Component
     [ViewVariables(VVAccess.ReadWrite), DataField("allowedFlags")]
     public IFFFlags AllowedFlags = IFFFlags.HideLabel;
 
+    /// <summary>
+    /// If true, automatically applies all supported IFF flags to the console's grid on MapInitEvent.
+    /// </summary>
     [DataField]
     public bool HideOnInit = false;
 }
index e8d2e13e800825fe80c6b919f145abaf51b98596..738fb765e14bcb5dc9ceaab7f046c6ced51ea57d 100644 (file)
@@ -42,28 +42,14 @@ public sealed partial class ShuttleSystem
             return;
         }
 
-        // Merged toggle controls both HideLabel and Hide flags
         if (!args.Show)
         {
-            if ((component.AllowedFlags & IFFFlags.HideLabel) != 0x0)
-            {
-                AddIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
-            }
-            if ((component.AllowedFlags & IFFFlags.Hide) != 0x0)
-            {
-                AddIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
-            }
+            AddAllSupportedIFFFlags(xform, component);
         }
         else
         {
-            if ((component.AllowedFlags & IFFFlags.HideLabel) != 0x0)
-            {
-                RemoveIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
-            }
-            if ((component.AllowedFlags & IFFFlags.Hide) != 0x0)
-            {
-                RemoveIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
-            }
+            RemoveIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
+            RemoveIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
         }
     }
 
@@ -76,8 +62,7 @@ public sealed partial class ShuttleSystem
 
         if (component.HideOnInit)
         {
-            AddIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
-            AddIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
+            AddAllSupportedIFFFlags(xform, component);
         }
     }
 
@@ -121,4 +106,25 @@ public sealed partial class ShuttleSystem
             });
         }
     }
+
+    // Made this method to avoid copy and pasting.
+    /// <summary>
+    /// Adds all IFF flags that are allowed by AllowedFlags to the grid.
+    /// </summary>
+    private void AddAllSupportedIFFFlags(TransformComponent xform, IFFConsoleComponent component)
+    {
+        if (xform.GridUid == null)
+        {
+            return;
+        }
+
+        if ((component.AllowedFlags & IFFFlags.HideLabel) != 0x0)
+        {
+            AddIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
+        }
+        if ((component.AllowedFlags & IFFFlags.Hide) != 0x0)
+        {
+            AddIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
+        }
+    }
 }