LightFadeSystem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Content.Client.Light.Components;
  2. using Robust.Client.Animations;
  3. using Robust.Client.GameObjects;
  4. using Robust.Shared.Animations;
  5. namespace Content.Client.Light.EntitySystems;
  6. public sealed class LightFadeSystem : EntitySystem
  7. {
  8. [Dependency] private readonly AnimationPlayerSystem _player = default!;
  9. private const string FadeTrack = "light-fade";
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<LightFadeComponent, ComponentStartup>(OnFadeStartup);
  14. }
  15. private void OnFadeStartup(EntityUid uid, LightFadeComponent component, ComponentStartup args)
  16. {
  17. if (!TryComp<PointLightComponent>(uid, out var light))
  18. return;
  19. var animation = new Animation()
  20. {
  21. Length = TimeSpan.FromSeconds(component.Duration),
  22. AnimationTracks =
  23. {
  24. new AnimationTrackComponentProperty()
  25. {
  26. Property = nameof(PointLightComponent.Energy),
  27. ComponentType = typeof(PointLightComponent),
  28. InterpolationMode = AnimationInterpolationMode.Cubic,
  29. KeyFrames =
  30. {
  31. new AnimationTrackProperty.KeyFrame(light.Energy, 0f),
  32. new AnimationTrackProperty.KeyFrame(0f, component.Duration)
  33. }
  34. }
  35. }
  36. };
  37. _player.Play(uid, animation, FadeTrack);
  38. }
  39. }