Реврайт освещения от дверей на клиент (#375)

* fix: doors no longer light up without power

* rework: rewrite PointLightAirlockSystem on client

* public to private

* cleanup
This commit is contained in:
ThereDrD0
2024-06-22 13:53:37 +03:00
committed by GitHub
parent 22ffee3d18
commit 77696fa638
8 changed files with 105 additions and 131 deletions

View File

@@ -6,14 +6,20 @@ namespace Content.Shared._White.Lighting.PointLight.Airlock;
public sealed partial class PointLightAirlockComponent : Component
{
[ViewVariables]
public string RedColor = "#D56C6C";
public bool IsLightsEnabled;
[ViewVariables]
public string BlueColor = "#7F93C0";
public bool LastBoltsState;
[ViewVariables]
public string YellowColor = "#BDC07F";
public readonly string RedColor = "#D56C6C";
[ViewVariables]
public string GreenColor = "#7FC080";
public readonly string BlueColor = "#7F93C0";
[ViewVariables]
public readonly string YellowColor = "#BDC07F";
[ViewVariables]
public readonly string GreenColor = "#7FC080";
}

View File

@@ -1,83 +0,0 @@
using Content.Shared.Doors.Components;
namespace Content.Shared._White.Lighting.PointLight.Airlock;
//TODO: Когда-нибудь починить эту хуйню: Когда дверь открыта на аварийный доступ и ее болтируют, то свет будет желтым, хотя должен быть красным из-за болтов.
public sealed class SharedPointLightAirlockSystem : EntitySystem
{
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PointLightAirlockComponent, DoorlightsChangedEvent>(OnDoorLightChanged);
}
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 OnDoorLightChanged(EntityUid uid, PointLightAirlockComponent component, DoorlightsChangedEvent args)
{
if (!TryComp<DoorComponent>(uid, out var door))
return;
if (TryComp<AirlockComponent>(uid, out var airlockComponent) && airlockComponent.EmergencyAccess && args.Value && args.State is not DoorVisuals.EmergencyLights && args.State != null)
return; // While emergency access lights must be yellow no matter what
switch (args.State)
{
case DoorVisuals.BoltLights:
if (args.Value)
ToggleLight(uid, component.RedColor);
else
RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true));
break;
case DoorState.Denying:
ToggleLight(uid, component.RedColor);
break;
case DoorState.Closed:
ToggleLight(uid, component.BlueColor);
break;
case DoorVisuals.EmergencyLights:
if (args.Value)
ToggleLight(uid, component.YellowColor);
else
RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true));
break;
case DoorState.Open:
ToggleLight(uid, component.BlueColor);
break;
case DoorState.Opening:
ToggleLight(uid, component.GreenColor);
break;
case DoorState.Closing:
ToggleLight(uid, component.GreenColor);
break;
default:
ToggleLight(uid, "", false);
break;
}
}
}