1
0

LightCycleSystem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Client.GameTicking.Managers;
  2. using Content.Shared;
  3. using Content.Shared.Light.Components;
  4. using Content.Shared.Light.EntitySystems;
  5. using Robust.Shared.Map.Components;
  6. using Robust.Shared.Timing;
  7. namespace Content.Client.Light;
  8. /// <inheritdoc/>
  9. public sealed class LightCycleSystem : SharedLightCycleSystem
  10. {
  11. [Dependency] private readonly ClientGameTicker _ticker = default!;
  12. [Dependency] private readonly IGameTiming _timing = default!;
  13. [Dependency] private readonly MetaDataSystem _metadata = default!;
  14. public override void Update(float frameTime)
  15. {
  16. base.Update(frameTime);
  17. if (!_timing.IsFirstTimePredicted)
  18. return;
  19. var mapQuery = AllEntityQuery<LightCycleComponent, MapLightComponent>();
  20. while (mapQuery.MoveNext(out var uid, out var cycle, out var map))
  21. {
  22. if (!cycle.Running)
  23. continue;
  24. // We still iterate paused entities as we still want to override the lighting color and not have
  25. // it apply the server state
  26. var pausedTime = _metadata.GetPauseTime(uid);
  27. var time = (float) _timing.CurTime
  28. .Add(cycle.Offset)
  29. .Subtract(_ticker.RoundStartTimeSpan)
  30. .Subtract(pausedTime)
  31. .TotalSeconds;
  32. var color = GetColor((uid, cycle), cycle.OriginalColor, time);
  33. map.AmbientLightColor = color;
  34. }
  35. }
  36. }