Files
tbd-station-14/Content.Server/Light/EntitySystems/LitOnPoweredSystem.cs
2023-09-11 19:18:06 +10:00

35 lines
1.1 KiB
C#

using Content.Server.Light.Components;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
namespace Content.Server.Light.EntitySystems
{
public sealed class LitOnPoweredSystem : EntitySystem
{
[Dependency] private readonly SharedPointLightSystem _lights = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LitOnPoweredComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<LitOnPoweredComponent, PowerNetBatterySupplyEvent>(OnPowerSupply);
}
private void OnPowerChanged(EntityUid uid, LitOnPoweredComponent component, ref PowerChangedEvent args)
{
if (_lights.TryGetLight(uid, out var light))
{
_lights.SetEnabled(uid, args.Powered, light);
}
}
private void OnPowerSupply(EntityUid uid, LitOnPoweredComponent component, ref PowerNetBatterySupplyEvent args)
{
if (_lights.TryGetLight(uid, out var light))
{
_lights.SetEnabled(uid, args.Supply, light);
}
}
}
}