Files
tbd-station-14/Content.Shared/Light/EntitySystems/ItemTogglePointLightSystem.cs
eoineoineoin 820517eb38 Fix inconsistent borg flashlight state (#33027)
* Fix borg light being stuck on if no cell is inserted

* Fix HandheldLightComponent.Activted becoming out of sync with SharedPointLightComponent.Enabled

* Fix for entities which don't have a handheld light component
2025-01-16 11:34:11 +01:00

36 lines
1.3 KiB
C#

using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Light.Components;
using Content.Shared.Toggleable;
using ItemTogglePointLightComponent = Content.Shared.Light.Components.ItemTogglePointLightComponent;
namespace Content.Shared.Light.EntitySystems;
/// <summary>
/// Handles ItemToggle for PointLight
/// </summary>
public sealed class ItemTogglePointLightSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly SharedHandheldLightSystem _handheldLight = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ItemTogglePointLightComponent, ItemToggledEvent>(OnLightToggled);
}
private void OnLightToggled(Entity<ItemTogglePointLightComponent> ent, ref ItemToggledEvent args)
{
if (!_light.TryGetLight(ent.Owner, out var light))
return;
_appearance.SetData(ent, ToggleableLightVisuals.Enabled, args.Activated);
_light.SetEnabled(ent.Owner, args.Activated, comp: light);
if (TryComp<HandheldLightComponent>(ent.Owner, out var handheldLight))
{
_handheldLight.SetActivated(ent.Owner, args.Activated, handheldLight);
}
}
}