CableVisualizerSystem.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Client.SubFloor;
  2. using Content.Shared.Wires;
  3. using Robust.Client.GameObjects;
  4. namespace Content.Client.Power.Visualizers;
  5. public sealed class CableVisualizerSystem : EntitySystem
  6. {
  7. [Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
  8. public override void Initialize()
  9. {
  10. base.Initialize();
  11. SubscribeLocalEvent<CableVisualizerComponent, AppearanceChangeEvent>(OnAppearanceChange, after: new[] { typeof(SubFloorHideSystem) });
  12. }
  13. private void OnAppearanceChange(EntityUid uid, CableVisualizerComponent component, ref AppearanceChangeEvent args)
  14. {
  15. if (args.Sprite == null)
  16. return;
  17. if (!args.Sprite.Visible)
  18. {
  19. // This entity is probably below a floor and is not even visible to the user -> don't bother updating sprite data.
  20. // Note that if the subfloor visuals change, then another AppearanceChangeEvent will get triggered.
  21. return;
  22. }
  23. if (!_appearanceSystem.TryGetData<WireVisDirFlags>(uid, WireVisVisuals.ConnectedMask, out var mask, args.Component))
  24. mask = WireVisDirFlags.None;
  25. args.Sprite.LayerSetState(0, $"{component.StatePrefix}{(int) mask}");
  26. }
  27. }