1
0

MechSystem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Content.Shared.Mech;
  2. using Content.Shared.Mech.Components;
  3. using Content.Shared.Mech.EntitySystems;
  4. using Robust.Client.GameObjects;
  5. using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
  6. namespace Content.Client.Mech;
  7. /// <inheritdoc/>
  8. public sealed class MechSystem : SharedMechSystem
  9. {
  10. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  11. /// <inheritdoc/>
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. SubscribeLocalEvent<MechComponent, AppearanceChangeEvent>(OnAppearanceChanged);
  16. }
  17. private void OnAppearanceChanged(EntityUid uid, MechComponent component, ref AppearanceChangeEvent args)
  18. {
  19. if (args.Sprite == null)
  20. return;
  21. if (!args.Sprite.TryGetLayer((int) MechVisualLayers.Base, out var layer))
  22. return;
  23. var state = component.BaseState;
  24. var drawDepth = DrawDepth.Mobs;
  25. if (component.BrokenState != null && _appearance.TryGetData<bool>(uid, MechVisuals.Broken, out var broken, args.Component) && broken)
  26. {
  27. state = component.BrokenState;
  28. drawDepth = DrawDepth.SmallMobs;
  29. }
  30. else if (component.OpenState != null && _appearance.TryGetData<bool>(uid, MechVisuals.Open, out var open, args.Component) && open)
  31. {
  32. state = component.OpenState;
  33. drawDepth = DrawDepth.SmallMobs;
  34. }
  35. layer.SetState(state);
  36. args.Sprite.DrawDepth = (int) drawDepth;
  37. }
  38. }