diff --git a/Content.Client/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs b/Content.Client/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs new file mode 100644 index 0000000000..e903457e17 --- /dev/null +++ b/Content.Client/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs @@ -0,0 +1,95 @@ +using Content.Shared._White.Lighting.PointLight.Airlock; +using Content.Shared.Doors.Components; +using Robust.Client.GameObjects; + +namespace Content.Client._White.Lighting.PointLight.Airlock; + +public sealed class PointLightAirlockSystem : EntitySystem +{ + [Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!; + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnLightsChanged); + } + + private void ToggleLight(EntityUid uid, string hex, PointLightAirlockComponent airlockLight, 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); + airlockLight.IsLightsEnabled = enable; + + } + + private void OnLightsChanged(EntityUid uid, PointLightAirlockComponent component, AppearanceChangeEvent args) + { + if (args.AppearanceData.TryGetValue(DoorVisuals.Powered, out var isPowered) && !(bool) isPowered) + { + if (component.IsLightsEnabled) + ToggleLight(uid, string.Empty, component, false); + + return; + } + + if (!args.AppearanceData.TryGetValue(DoorVisuals.State, out var state)) + return; + + HandleState(uid, component, (DoorState) state); + + if (args.AppearanceData.TryGetValue(DoorVisuals.EmergencyLights, out var emergency)) + ToggleLight(uid, component.YellowColor, component, (bool) emergency); + + if (!args.AppearanceData.TryGetValue(DoorVisuals.BoltLights, out var boltsDown)) + return; + + if (component.LastBoltsState != (bool) boltsDown) + { + if ((bool) boltsDown) + ToggleLight(uid, component.RedColor, component, (bool) boltsDown); + else if (args.AppearanceData.TryGetValue(DoorVisuals.EmergencyLights, out var emergencyLights) && (bool) emergencyLights) + ToggleLight(uid, component.YellowColor, component); + else + HandleState(uid, component, (DoorState) state); + } + + component.LastBoltsState = (bool) boltsDown; + + } + + private void HandleState(EntityUid uid, PointLightAirlockComponent component, DoorState state) + { + switch (state) + { + case DoorState.Open: + ToggleLight(uid, component.BlueColor, component); + break; + + case DoorState.Opening: + ToggleLight(uid, component.GreenColor, component); + break; + + case DoorState.Closing: + ToggleLight(uid, component.GreenColor, component); + break; + + case DoorState.Closed: + ToggleLight(uid, component.BlueColor, component); + break; + + case DoorState.Denying: + ToggleLight(uid, component.RedColor, component); + break; + } + } + +} diff --git a/Content.Server/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs b/Content.Server/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs deleted file mode 100644 index 76ed618309..0000000000 --- a/Content.Server/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Content.Server.Power.Components; -using Content.Shared._White.Lighting; -using Content.Shared._White.Lighting.PointLight.Airlock; -using Content.Shared.Doors.Components; - -namespace Content.Server._White.Lighting.Pointlight.Airlock; - -public sealed class PointLightAirlockSystem : EntitySystem -{ - public override void Initialize() - { - base.Initialize(); - SubscribeLocalEvent(OnPowerChanged); - } - - private void OnPowerChanged(EntityUid uid, PointLightAirlockComponent component, PowerChangedEvent args) - { - if (!TryComp(uid, out var door)) - return; - - RaiseLocalEvent(uid, new DoorlightsChangedEvent(args.Powered ? door.State : null, args.Powered), true); - } - -} diff --git a/Content.Shared/Doors/Systems/SharedAirlockSystem.cs b/Content.Shared/Doors/Systems/SharedAirlockSystem.cs index fa96e6856a..e99660ff31 100644 --- a/Content.Shared/Doors/Systems/SharedAirlockSystem.cs +++ b/Content.Shared/Doors/Systems/SharedAirlockSystem.cs @@ -121,7 +121,6 @@ public abstract class SharedAirlockSystem : EntitySystem public void UpdateEmergencyLightStatus(EntityUid uid, AirlockComponent component) { - RaiseLocalEvent(uid, new DoorlightsChangedEvent(DoorVisuals.EmergencyLights, component.EmergencyAccess)); Appearance.SetData(uid, DoorVisuals.EmergencyLights, component.EmergencyAccess); } diff --git a/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs b/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs index 5546e272f6..24a5991d29 100644 --- a/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs +++ b/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs @@ -86,8 +86,6 @@ public abstract partial class SharedDoorSystem Dirty(ent, ent.Comp); UpdateBoltLightStatus(ent); - RaiseLocalEvent(ent, new DoorlightsChangedEvent(DoorVisuals.BoltLights, value), true); - var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound; if (predicted) Audio.PlayPredicted(sound, ent, user: user); diff --git a/Content.Shared/Doors/Systems/SharedDoorSystem.cs b/Content.Shared/Doors/Systems/SharedDoorSystem.cs index 3b00282f4d..220ff6bdc5 100644 --- a/Content.Shared/Doors/Systems/SharedDoorSystem.cs +++ b/Content.Shared/Doors/Systems/SharedDoorSystem.cs @@ -118,7 +118,6 @@ public abstract partial class SharedDoorSystem : EntitySystem SetCollidable(ent, collidable, door); - RaiseLocalEvent(ent, new DoorlightsChangedEvent(door.State, true), true); AppearanceSystem.SetData(ent, DoorVisuals.State, door.State); } @@ -167,7 +166,6 @@ public abstract partial class SharedDoorSystem : EntitySystem _activeDoors.Add(ent); RaiseLocalEvent(ent, new DoorStateChangedEvent(door.State)); - RaiseLocalEvent(ent, new DoorlightsChangedEvent(door.State, true), true); AppearanceSystem.SetData(ent, DoorVisuals.State, door.State); } @@ -219,7 +217,6 @@ public abstract partial class SharedDoorSystem : EntitySystem Dirty(uid, door); RaiseLocalEvent(uid, new DoorStateChangedEvent(state)); - RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true), true); AppearanceSystem.SetData(uid, DoorVisuals.State, door.State); return true; @@ -525,7 +522,6 @@ public abstract partial class SharedDoorSystem : EntitySystem door.NextStateChange = GameTiming.CurTime + door.OpenTimeTwo; door.State = DoorState.Opening; - RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true), true); AppearanceSystem.SetData(uid, DoorVisuals.State, DoorState.Opening); return false; } diff --git a/Content.Shared/_White/Lighting/AppearanceChangedEvent.cs b/Content.Shared/_White/Lighting/AppearanceChangedEvent.cs deleted file mode 100644 index 1d69d5f851..0000000000 --- a/Content.Shared/_White/Lighting/AppearanceChangedEvent.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Content.Shared._White.Lighting; - -public sealed class DoorlightsChangedEvent : EntityEventArgs -{ - public Enum? State; - public bool Value; - - public DoorlightsChangedEvent(Enum? key, bool value) - { - State = key; - Value = value; - } -} diff --git a/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockComponent.cs b/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockComponent.cs index b658c0d97e..210f9a2a84 100644 --- a/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockComponent.cs +++ b/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockComponent.cs @@ -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"; } diff --git a/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs b/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs deleted file mode 100644 index b572c70dc6..0000000000 --- a/Content.Shared/_White/Lighting/PointLight/Airlock/PointLightAirlockSystem.cs +++ /dev/null @@ -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(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(uid, out var door)) - return; - - if (TryComp(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; - } - - } - -}