1
0

OptionsVisualizerComponent.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Content.Shared.CCVar;
  2. namespace Content.Client.Options;
  3. /// <summary>
  4. /// Allows specifying sprite alternatives depending on the client's accessibility options.
  5. /// </summary>
  6. /// <remarks>
  7. /// A list of layer mappings is given that the component applies to,
  8. /// and it will pick one entry to apply based on the settings configuration. Example:
  9. ///
  10. /// <code>
  11. /// - type: Sprite
  12. /// sprite: Effects/optionsvisualizertest.rsi
  13. /// layers:
  14. /// - state: none
  15. /// map: [ "layer" ]
  16. /// - type: OptionsVisualizer
  17. /// visuals:
  18. /// layer:
  19. /// - options: Default
  20. /// data: { state: none }
  21. /// - options: Test
  22. /// data: { state: test }
  23. /// - options: ReducedMotion
  24. /// data: { state: motion }
  25. /// - options: [Test, ReducedMotion]
  26. /// data: { state: both }
  27. /// </code>
  28. /// </remarks>
  29. /// <seealso cref="OptionsVisualizerSystem"/>
  30. /// <seealso cref="OptionVisualizerOptions"/>
  31. [RegisterComponent]
  32. public sealed partial class OptionsVisualizerComponent : Component
  33. {
  34. /// <summary>
  35. /// A mapping storing data about which sprite layer keys should be controlled.
  36. /// </summary>
  37. /// <remarks>
  38. /// Each layer stores an array of possible options. The last entry with a
  39. /// <see cref="LayerDatum.Options"/> matching the active user preferences will be picked.
  40. /// This allows choosing a priority if multiple entries are matched.
  41. /// </remarks>
  42. [DataField(required: true)]
  43. public Dictionary<string, LayerDatum[]> Visuals = default!;
  44. /// <summary>
  45. /// A single option for a layer to be selected.
  46. /// </summary>
  47. [DataDefinition]
  48. public sealed partial class LayerDatum
  49. {
  50. /// <summary>
  51. /// Which options must be set by the user to make this datum match.
  52. /// </summary>
  53. [DataField]
  54. public OptionVisualizerOptions Options { get; set; }
  55. /// <summary>
  56. /// The sprite layer data to set on the sprite when this datum matches.
  57. /// </summary>
  58. [DataField]
  59. public PrototypeLayerData Data { get; set; }
  60. }
  61. }
  62. [Flags]
  63. public enum OptionVisualizerOptions
  64. {
  65. /// <summary>
  66. /// Corresponds to no special options being set, can be used as a "default" state.
  67. /// </summary>
  68. Default = 0,
  69. /// <summary>
  70. /// Corresponds to the <see cref="CCVars.DebugOptionVisualizerTest"/> CVar being set.
  71. /// </summary>
  72. Test = 1 << 0,
  73. /// <summary>
  74. /// Corresponds to the <see cref="CCVars.ReducedMotion"/> CVar being set.
  75. /// </summary>
  76. ReducedMotion = 1 << 1,
  77. }