1
0

FaxVisualsSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Robust.Client.GameObjects;
  2. using Content.Shared.Fax.Components;
  3. using Content.Shared.Fax;
  4. using Robust.Client.Animations;
  5. namespace Content.Client.Fax.System;
  6. /// <summary>
  7. /// Visualizer for the fax machine which displays the correct sprite based on the inserted entity.
  8. /// </summary>
  9. public sealed class FaxVisualsSystem : EntitySystem
  10. {
  11. [Dependency] private readonly AnimationPlayerSystem _player = default!;
  12. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<FaxMachineComponent, AppearanceChangeEvent>(OnAppearanceChanged);
  17. }
  18. private void OnAppearanceChanged(EntityUid uid, FaxMachineComponent component, ref AppearanceChangeEvent args)
  19. {
  20. if (args.Sprite == null)
  21. return;
  22. if (_player.HasRunningAnimation(uid, "faxecute"))
  23. return;
  24. if (_appearance.TryGetData(uid, FaxMachineVisuals.VisualState, out FaxMachineVisualState visuals) &&
  25. visuals == FaxMachineVisualState.Inserting)
  26. {
  27. _player.Play(uid,
  28. new Animation()
  29. {
  30. Length = TimeSpan.FromSeconds(2.4),
  31. AnimationTracks =
  32. {
  33. new AnimationTrackSpriteFlick()
  34. {
  35. LayerKey = FaxMachineVisuals.VisualState,
  36. KeyFrames =
  37. {
  38. new AnimationTrackSpriteFlick.KeyFrame(component.InsertingState, 0f),
  39. new AnimationTrackSpriteFlick.KeyFrame("icon", 2.4f),
  40. },
  41. },
  42. },
  43. },
  44. "faxecute");
  45. }
  46. }
  47. }