IconSmoothComponent.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using JetBrains.Annotations;
  2. using Robust.Client.Graphics;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  4. namespace Content.Client.IconSmoothing
  5. {
  6. /// <summary>
  7. /// Makes sprites of other grid-aligned entities like us connect.
  8. /// </summary>
  9. /// <remarks>
  10. /// The system is based on Baystation12's smoothwalling, and thus will work with those.
  11. /// To use, set <c>base</c> equal to the prefix of the corner states in the sprite base RSI.
  12. /// Any objects with the same <c>key</c> will connect.
  13. /// </remarks>
  14. [RegisterComponent]
  15. public sealed partial class IconSmoothComponent : Component
  16. {
  17. [ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
  18. public bool Enabled = true;
  19. public (EntityUid?, Vector2i)? LastPosition;
  20. /// <summary>
  21. /// We will smooth with other objects with the same key.
  22. /// </summary>
  23. [ViewVariables(VVAccess.ReadWrite), DataField("key")]
  24. public string? SmoothKey { get; private set; }
  25. /// <summary>
  26. /// Additional keys to smooth with.
  27. /// </summary>
  28. [DataField]
  29. public List<string> AdditionalKeys = new();
  30. /// <summary>
  31. /// Prepended to the RSI state.
  32. /// </summary>
  33. [ViewVariables(VVAccess.ReadWrite), DataField("base")]
  34. public string StateBase { get; set; } = string.Empty;
  35. [DataField("shader", customTypeSerializer:typeof(PrototypeIdSerializer<ShaderPrototype>))]
  36. public string? Shader;
  37. /// <summary>
  38. /// Mode that controls how the icon should be selected.
  39. /// </summary>
  40. [ViewVariables(VVAccess.ReadWrite), DataField("mode")]
  41. public IconSmoothingMode Mode = IconSmoothingMode.Corners;
  42. /// <summary>
  43. /// Used by <see cref="IconSmoothSystem"/> to reduce redundant updates.
  44. /// </summary>
  45. internal int UpdateGeneration { get; set; }
  46. }
  47. /// <summary>
  48. /// Controls the mode with which icon smoothing is calculated.
  49. /// </summary>
  50. [PublicAPI]
  51. public enum IconSmoothingMode : byte
  52. {
  53. /// <summary>
  54. /// Each icon is made up of 4 corners, each of which can get a different state depending on
  55. /// adjacent entities clockwise, counter-clockwise and diagonal with the corner.
  56. /// </summary>
  57. Corners,
  58. /// <summary>
  59. /// There are 16 icons, only one of which is used at once.
  60. /// The icon selected is a bit field made up of the cardinal direction flags that have adjacent entities.
  61. /// </summary>
  62. CardinalFlags,
  63. /// <summary>
  64. /// The icon represents a triangular sprite with only 2 states, representing South / East being occupied or not.
  65. /// </summary>
  66. Diagonal,
  67. /// <summary>
  68. /// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
  69. /// </summary>
  70. NoSprite,
  71. }
  72. }