SharedRgbLightControllerSystem.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Shared.Light.Components;
  2. using Robust.Shared.GameStates;
  3. namespace Content.Shared.Light;
  4. public abstract class SharedRgbLightControllerSystem : EntitySystem
  5. {
  6. public override void Initialize()
  7. {
  8. base.Initialize();
  9. SubscribeLocalEvent<RgbLightControllerComponent, ComponentGetState>(OnGetState);
  10. }
  11. private void OnGetState(EntityUid uid, RgbLightControllerComponent component, ref ComponentGetState args)
  12. {
  13. args.State = new RgbLightControllerState(component.CycleRate, component.Layers);
  14. }
  15. public void SetLayers(EntityUid uid, List<int>? layers, RgbLightControllerComponent? rgb = null)
  16. {
  17. if (!Resolve(uid, ref rgb))
  18. return;
  19. rgb.Layers = layers;
  20. Dirty(uid, rgb);
  21. }
  22. public void SetCycleRate(EntityUid uid, float rate, RgbLightControllerComponent? rgb = null)
  23. {
  24. if (!Resolve(uid, ref rgb))
  25. return;
  26. rgb.CycleRate = Math.Clamp(0.01f, rate, 1); // lets not give people seizures
  27. Dirty(uid, rgb);
  28. }
  29. }