Fix possible bug in my fix of IFF console. Add documentation to HideOnInit. (#42122)

* 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>
This commit is contained in:
EchoOfNothing
2025-12-29 10:53:18 +02:00
committed by GitHub
parent be7653c131
commit ac3a91eac1
2 changed files with 28 additions and 19 deletions

View 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;
}

View 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);
}
}
}