ItemMapperComponent.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Content.Shared.Storage.EntitySystems;
  2. using Robust.Shared.Utility;
  3. namespace Content.Shared.Storage.Components
  4. {
  5. /// <summary>
  6. /// <para><c>ItemMapperComponent</c> is a <see cref="Component"/> that maps string labels to an <see cref="Content.Shared.Whitelist.EntityWhitelist"/> of elements. Useful primarily for visualization.</para>
  7. /// <para>
  8. /// To define a mapping, create a <c>mapLayers</c> map in configuration <c>ItemMapper</c> component and with <see cref="MapLayers"/> mapping.
  9. /// Each map layer maps layer name to an <see cref="Content.Shared.Whitelist.EntityWhitelist"/>, plus special modifiers for min and max item count.
  10. /// Min and max count are useful when you need to visualize a certain number of items, for example, to display one, two, three, or more items.
  11. /// </para>
  12. /// <para>
  13. /// If you need a more straightforward way to change appearance where only variable is how many items, rather than which items
  14. /// and how many, see <see cref="ItemCounterComponent"/>
  15. /// </para>
  16. /// <para>
  17. /// For a contrived example, create a tool-belt with a Power drill slot and two light bulb slots.
  18. /// To use this for visualization, we need <see cref="AppearanceComponent"/> a or VisualizerSystem, e.g.
  19. /// <code>
  20. /// - type: Appearance
  21. /// visuals:
  22. /// - type: MappedItemVisualizer
  23. /// </code>
  24. /// To map <c>Powerdrill</c> <b><see cref="Content.Shared.Tag.TagComponent"/></b> to the given example, we need the following code.
  25. /// <code>
  26. /// - type: ItemMapper
  27. /// mapLayers:
  28. /// drill:
  29. /// whitelist:
  30. /// tags:
  31. /// - Powerdrill
  32. /// #... to be continued
  33. /// </code>
  34. /// To map <c>Lightbulb</c> <b><see cref="Component"/></b> (not tag) to two different layers (for one and two light bulbs, respectively)
  35. /// <code>
  36. /// #... to be continued
  37. /// lightbulb1:
  38. /// minCount: 1
  39. /// whitelist:
  40. /// component:
  41. /// - Lightbulb
  42. /// lightbulb2:
  43. /// minCount: 2
  44. /// whitelist:
  45. /// component:
  46. /// - Lightbulb
  47. /// </code>
  48. /// The min count will ensure that <c>lightbulb1</c> layer is only displayed when one or more light bulbs are in the belt.
  49. /// And <c>lightbulb2</c> layer will only be shown when two or more light bulbs are inserted.
  50. /// </para>
  51. /// <seealso cref="Content.Shared.Whitelist.EntityWhitelist"/>
  52. /// <seealso cref="Content.Shared.Storage.Components.SharedMapLayerData"/>
  53. /// </summary>
  54. [RegisterComponent]
  55. [Access(typeof(SharedItemMapperSystem))]
  56. public sealed partial class ItemMapperComponent : Component
  57. {
  58. [DataField("mapLayers")] public Dictionary<string, SharedMapLayerData> MapLayers = new();
  59. [DataField("sprite")] public ResPath? RSIPath;
  60. /// <summary>
  61. /// If this exists, shown layers will only consider entities in the given containers.
  62. /// </summary>
  63. [DataField("containerWhitelist")]
  64. public HashSet<string>? ContainerWhitelist;
  65. /// <summary>
  66. /// The list of map layer keys that are valid targets for changing in <see cref="MapLayers"/>
  67. /// Can be initialized if already existing on the sprite, or inferred automatically
  68. /// </summary>
  69. [DataField("spriteLayers")]
  70. public List<string> SpriteLayers = new();
  71. }
  72. }