2024-08-25 22:30:28 +10:00
|
|
|
using Content.Shared.Item.ItemToggle.Components;
|
2025-01-16 10:34:11 +00:00
|
|
|
using Content.Shared.Light.Components;
|
2024-08-25 22:30:28 +10:00
|
|
|
using ItemTogglePointLightComponent = Content.Shared.Light.Components.ItemTogglePointLightComponent;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Light.EntitySystems;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-05-30 16:53:56 -07:00
|
|
|
/// Implements the behavior of <see cref="ItemTogglePointLightComponent"/>, causing <see cref="ItemToggledEvent"/>s to
|
|
|
|
|
/// enable and disable lights on the entity.
|
2024-08-25 22:30:28 +10:00
|
|
|
/// </summary>
|
|
|
|
|
public sealed class ItemTogglePointLightSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
2025-01-16 10:34:11 +00:00
|
|
|
[Dependency] private readonly SharedHandheldLightSystem _handheldLight = default!;
|
2024-08-25 22:30:28 +10:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
_light.SetEnabled(ent.Owner, args.Activated, comp: light);
|
2025-01-16 10:34:11 +00:00
|
|
|
if (TryComp<HandheldLightComponent>(ent.Owner, out var handheldLight))
|
|
|
|
|
{
|
|
|
|
|
_handheldLight.SetActivated(ent.Owner, args.Activated, handheldLight);
|
|
|
|
|
}
|
2024-08-25 22:30:28 +10:00
|
|
|
}
|
|
|
|
|
}
|