SharedShuttleSystem.IFF.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Content.Shared.Shuttles.Components;
  2. using JetBrains.Annotations;
  3. namespace Content.Shared.Shuttles.Systems;
  4. public abstract partial class SharedShuttleSystem
  5. {
  6. /*
  7. * Handles the label visibility on radar controls. This can be hiding the label or applying other effects.
  8. */
  9. protected virtual void UpdateIFFInterfaces(EntityUid gridUid, IFFComponent component) {}
  10. public Color GetIFFColor(EntityUid gridUid, bool self = false, IFFComponent? component = null)
  11. {
  12. if (self)
  13. {
  14. return IFFComponent.SelfColor;
  15. }
  16. if (!Resolve(gridUid, ref component, false))
  17. {
  18. return IFFComponent.IFFColor;
  19. }
  20. return component.Color;
  21. }
  22. public string? GetIFFLabel(EntityUid gridUid, bool self = false, IFFComponent? component = null)
  23. {
  24. var entName = MetaData(gridUid).EntityName;
  25. if (self)
  26. {
  27. return entName;
  28. }
  29. if (Resolve(gridUid, ref component, false) && (component.Flags & (IFFFlags.HideLabel | IFFFlags.Hide)) != 0x0)
  30. {
  31. return null;
  32. }
  33. return string.IsNullOrEmpty(entName) ? Loc.GetString("shuttle-console-unknown") : entName;
  34. }
  35. /// <summary>
  36. /// Sets the color for this grid to appear as on radar.
  37. /// </summary>
  38. [PublicAPI]
  39. public void SetIFFColor(EntityUid gridUid, Color color, IFFComponent? component = null)
  40. {
  41. component ??= EnsureComp<IFFComponent>(gridUid);
  42. if (component.Color.Equals(color))
  43. return;
  44. component.Color = color;
  45. Dirty(gridUid, component);
  46. UpdateIFFInterfaces(gridUid, component);
  47. }
  48. [PublicAPI]
  49. public void AddIFFFlag(EntityUid gridUid, IFFFlags flags, IFFComponent? component = null)
  50. {
  51. component ??= EnsureComp<IFFComponent>(gridUid);
  52. if ((component.Flags & flags) == flags)
  53. return;
  54. component.Flags |= flags;
  55. Dirty(gridUid, component);
  56. UpdateIFFInterfaces(gridUid, component);
  57. }
  58. [PublicAPI]
  59. public void RemoveIFFFlag(EntityUid gridUid, IFFFlags flags, IFFComponent? component = null)
  60. {
  61. if (!Resolve(gridUid, ref component, false))
  62. return;
  63. if ((component.Flags & flags) == 0x0)
  64. return;
  65. component.Flags &= ~flags;
  66. Dirty(gridUid, component);
  67. UpdateIFFInterfaces(gridUid, component);
  68. }
  69. }