StackComponent.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Robust.Shared.GameStates;
  2. using Robust.Shared.Serialization;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  4. namespace Content.Shared.Stacks
  5. {
  6. [RegisterComponent, NetworkedComponent]
  7. public sealed partial class StackComponent : Component
  8. {
  9. [ViewVariables(VVAccess.ReadWrite)]
  10. [DataField("stackType", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<StackPrototype>))]
  11. public string StackTypeId { get; private set; } = default!;
  12. /// <summary>
  13. /// Current stack count.
  14. /// Do NOT set this directly, use the <see cref="SharedStackSystem.SetCount"/> method instead.
  15. /// </summary>
  16. [DataField("count")]
  17. public int Count { get; set; } = 30;
  18. /// <summary>
  19. /// Max amount of things that can be in the stack.
  20. /// Overrides the max defined on the stack prototype.
  21. /// </summary>
  22. [ViewVariables(VVAccess.ReadOnly)]
  23. [DataField("maxCountOverride")]
  24. public int? MaxCountOverride { get; set; }
  25. /// <summary>
  26. /// Set to true to not reduce the count when used.
  27. /// Note that <see cref="Count"/> still limits the amount that can be used at any one time.
  28. /// </summary>
  29. [DataField("unlimited")]
  30. [ViewVariables(VVAccess.ReadOnly)]
  31. public bool Unlimited { get; set; }
  32. /// <summary>
  33. /// Lingering stacks will remain present even when there are no items.
  34. /// Instead, they will become transparent.
  35. /// </summary>
  36. [DataField("lingering"), ViewVariables(VVAccess.ReadWrite)]
  37. public bool Lingering;
  38. [DataField("throwIndividually"), ViewVariables(VVAccess.ReadWrite)]
  39. public bool ThrowIndividually { get; set; } = false;
  40. [ViewVariables]
  41. public bool UiUpdateNeeded { get; set; }
  42. /// <summary>
  43. /// Default IconLayer stack.
  44. /// </summary>
  45. [DataField("baseLayer")]
  46. [ViewVariables(VVAccess.ReadWrite)]
  47. public string BaseLayer = "";
  48. /// <summary>
  49. /// Determines if the visualizer uses composite or non-composite layers for icons. Defaults to false.
  50. ///
  51. /// <list type="bullet">
  52. /// <item>
  53. /// <description>false: they are opaque and mutually exclusive (e.g. sprites in a cable coil). <b>Default value</b></description>
  54. /// </item>
  55. /// <item>
  56. /// <description>true: they are transparent and thus layered one over another in ascending order first</description>
  57. /// </item>
  58. /// </list>
  59. ///
  60. /// </summary>
  61. [DataField("composite")]
  62. [ViewVariables(VVAccess.ReadWrite)]
  63. public bool IsComposite;
  64. /// <summary>
  65. /// Sprite layers used in stack visualizer. Sprites first in layer correspond to lower stack states
  66. /// e.g. <code>_spriteLayers[0]</code> is lower stack level than <code>_spriteLayers[1]</code>.
  67. /// </summary>
  68. [DataField("layerStates")]
  69. [ViewVariables(VVAccess.ReadWrite)]
  70. public List<string> LayerStates = new();
  71. }
  72. [Serializable, NetSerializable]
  73. public sealed class StackComponentState : ComponentState
  74. {
  75. public int Count { get; }
  76. public int? MaxCount { get; }
  77. public bool Lingering;
  78. public StackComponentState(int count, int? maxCount, bool lingering)
  79. {
  80. Count = count;
  81. MaxCount = maxCount;
  82. Lingering = lingering;
  83. }
  84. }
  85. }