using System.Linq; using Content.Shared.Shuttles.Components; using JetBrains.Annotations; namespace Content.Shared.Shuttles.Systems; public abstract partial class SharedShuttleSystem { /* * Handles the label visibility on radar controls. This can be hiding the label or applying other effects. */ protected virtual void UpdateIFFInterfaces(EntityUid gridUid, IFFComponent component) {} public Color GetIFFColor(EntityUid gridUid, bool self = false, IFFComponent? component = null) { if (self) { return IFFComponent.SelfColor; } if (!Resolve(gridUid, ref component, false)) { return IFFComponent.IFFColor; } return component.Color; } public string? GetIFFLabel(EntityUid gridUid, bool self = false, IFFComponent? component = null) { var entName = MetaData(gridUid).EntityName; if (self) { return entName; } if (Resolve(gridUid, ref component, false) && (component.Flags & (IFFFlags.HideLabel | IFFFlags.Hide)) != 0x0) { return null; } // Frontier var suffix = component != null ? GetServiceFlagsSuffix(component.ServiceFlags) : string.Empty; return string.IsNullOrEmpty(entName) ? Loc.GetString("shuttle-console-unknown") : entName + suffix; } /// /// Sets the color for this grid to appear as on radar. /// [PublicAPI] public void SetIFFColor(EntityUid gridUid, Color color, IFFComponent? component = null) { component ??= EnsureComp(gridUid); if (component.ReadOnly) // Frontier: POI IFF protection return; // Frontier: POI IFF protection if (component.Color.Equals(color)) return; component.Color = color; Dirty(gridUid, component); UpdateIFFInterfaces(gridUid, component); } [PublicAPI] public void AddIFFFlag(EntityUid gridUid, IFFFlags flags, IFFComponent? component = null) { component ??= EnsureComp(gridUid); if (component.ReadOnly) // Frontier: POI IFF protection return; // Frontier: POI IFF protection if ((component.Flags & flags) == flags) return; component.Flags |= flags; Dirty(gridUid, component); UpdateIFFInterfaces(gridUid, component); } /// /// Frontier: Service flags /// Sets the service flags for this grid to appear as on radar. /// /// The grid to set the flags for. /// The flags to set. /// The IFF component to set the flags for. public void SetServiceFlags(EntityUid gridUid, ServiceFlags flags, IFFComponent? component = null) { component ??= EnsureComp(gridUid); if (component.ReadOnly) // Frontier: POI IFF protection return; // Frontier: POI IFF protection if (component.ServiceFlags == flags) return; component.ServiceFlags = flags; Dirty(gridUid, component); UpdateIFFInterfaces(gridUid, component); } /// /// Turns the service flags into a string for display. /// IE. [M] for Medical, [R] for Research, etc. /// This function also handles duplicate first characters by using the first two characters of the flag name. /// /// The IFF flags to get the suffix for /// The string to display. public string GetServiceFlagsSuffix(ServiceFlags flags) { if (flags == ServiceFlags.None) return string.Empty; string outputString = ""; foreach (var flag in Enum.GetValues()) { if (flag == ServiceFlags.None || !flags.HasFlag(flag)) continue; if (Loc.TryGetString($"shuttle-console-service-flag-{flag}-shortform", out var flagString)) outputString = string.Concat(outputString, flagString); else outputString = string.Concat(outputString, flag.ToString()[0]); // Fallback: use first character of string } return $"[{outputString}]"; } [PublicAPI] public void RemoveIFFFlag(EntityUid gridUid, IFFFlags flags, IFFComponent? component = null) { if (!Resolve(gridUid, ref component, false)) return; if (component.ReadOnly) // Frontier: POI IFF protection return; // Frontier: POI IFF protection if ((component.Flags & flags) == 0x0) return; component.Flags &= ~flags; Dirty(gridUid, component); UpdateIFFInterfaces(gridUid, component); } // Frontier: POI IFF protection [PublicAPI] public void SetIFFReadOnly(EntityUid gridUid, bool readOnly, IFFComponent? component = null) { if (!Resolve(gridUid, ref component, false)) return; if (component.ReadOnly == readOnly) return; component.ReadOnly = readOnly; } // End Frontier }