* add: add small soft light to laser weapon + fix the bluest blue energy shield * git commit * boltlights done * add: HuetaSystem * add: Doorlights finally done * add: small light to lockers * add: small light to multitool * fix: fix naming * hui pizde * fix: fix parasha * add: small light to powercells * zabil * add: code light to welders * tweak: better energy and radius * add: better color parameters * add: less radius and energy for guns * add: better lights for vending machines * add: better light to consoles * add: better light for apc * shut up * fix: thank you neuro colleague
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using Content.Server.Power.Components;
|
|
using Content.Shared.PowerCell;
|
|
using Content.Shared.Rounding;
|
|
|
|
namespace Content.Server._White.Lighting.PointLight.RealBattery;
|
|
|
|
public sealed class PointLightRealBatterySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PointLightRealBatteryComponent, ChargeChangedEvent>(OnChargeChanged);
|
|
SubscribeLocalEvent<PointLightRealBatteryComponent, ComponentInit>(OnComponentInit);
|
|
}
|
|
|
|
public void ToggleLight(EntityUid uid, string hex, bool enable = true)
|
|
{
|
|
if (!_pointLightSystem.TryGetLight(uid, out var pointLightComponent))
|
|
return;
|
|
|
|
if (enable)
|
|
{
|
|
var color = Color.FromHex(hex);
|
|
_pointLightSystem.SetColor(uid, color, pointLightComponent);
|
|
}
|
|
|
|
_pointLightSystem.SetEnabled(uid, enable, pointLightComponent);
|
|
|
|
RaiseLocalEvent(uid, new PointLightToggleEvent(enable), true);
|
|
}
|
|
|
|
public void OnComponentInit(EntityUid uid, PointLightRealBatteryComponent component, ComponentInit args)
|
|
{
|
|
if (!TryComp<BatteryComponent>(uid, out var battery))
|
|
return;
|
|
|
|
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
}
|
|
public void OnChargeChanged(EntityUid uid, PointLightRealBatteryComponent component, ChargeChangedEvent args)
|
|
{
|
|
var frac = args.Charge / args.MaxCharge;
|
|
var level = (byte) ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);
|
|
|
|
switch (level)
|
|
{
|
|
case 2:
|
|
ToggleLight(uid, component.GreenColor);
|
|
break;
|
|
|
|
case 1:
|
|
ToggleLight(uid, component.YellowColor);
|
|
break;
|
|
|
|
case 0:
|
|
ToggleLight(uid, string.Empty, false);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|