LitOnPoweredSystem.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Server.Light.Components;
  2. using Content.Server.Power.Components;
  3. using Content.Server.Power.EntitySystems;
  4. using Content.Shared.Power;
  5. namespace Content.Server.Light.EntitySystems
  6. {
  7. public sealed class LitOnPoweredSystem : EntitySystem
  8. {
  9. [Dependency] private readonly SharedPointLightSystem _lights = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<LitOnPoweredComponent, PowerChangedEvent>(OnPowerChanged);
  14. SubscribeLocalEvent<LitOnPoweredComponent, PowerNetBatterySupplyEvent>(OnPowerSupply);
  15. }
  16. private void OnPowerChanged(EntityUid uid, LitOnPoweredComponent component, ref PowerChangedEvent args)
  17. {
  18. if (_lights.TryGetLight(uid, out var light))
  19. {
  20. _lights.SetEnabled(uid, args.Powered, light);
  21. }
  22. }
  23. private void OnPowerSupply(EntityUid uid, LitOnPoweredComponent component, ref PowerNetBatterySupplyEvent args)
  24. {
  25. if (_lights.TryGetLight(uid, out var light))
  26. {
  27. _lights.SetEnabled(uid, args.Supply, light);
  28. }
  29. }
  30. }
  31. }