1
0

ItemTogglePointLightSystem.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Shared.Item.ItemToggle.Components;
  2. using Content.Shared.Light.Components;
  3. using Content.Shared.Toggleable;
  4. using ItemTogglePointLightComponent = Content.Shared.Light.Components.ItemTogglePointLightComponent;
  5. namespace Content.Shared.Light.EntitySystems;
  6. /// <summary>
  7. /// Handles ItemToggle for PointLight
  8. /// </summary>
  9. public sealed class ItemTogglePointLightSystem : EntitySystem
  10. {
  11. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  12. [Dependency] private readonly SharedPointLightSystem _light = default!;
  13. [Dependency] private readonly SharedHandheldLightSystem _handheldLight = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<ItemTogglePointLightComponent, ItemToggledEvent>(OnLightToggled);
  18. }
  19. private void OnLightToggled(Entity<ItemTogglePointLightComponent> ent, ref ItemToggledEvent args)
  20. {
  21. if (!_light.TryGetLight(ent.Owner, out var light))
  22. return;
  23. _appearance.SetData(ent, ToggleableLightVisuals.Enabled, args.Activated);
  24. _light.SetEnabled(ent.Owner, args.Activated, comp: light);
  25. if (TryComp<HandheldLightComponent>(ent.Owner, out var handheldLight))
  26. {
  27. _handheldLight.SetActivated(ent.Owner, args.Activated, handheldLight);
  28. }
  29. }
  30. }