Реврайт освещения от дверей на клиент (#375)
* fix: doors no longer light up without power * rework: rewrite PointLightAirlockSystem on client * public to private * cleanup
This commit is contained in:
@@ -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<PointLightAirlockComponent, AppearanceChangeEvent>(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<PointLightAirlockComponent, PowerChangedEvent>(OnPowerChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPowerChanged(EntityUid uid, PointLightAirlockComponent component, PowerChangedEvent args)
|
|
||||||
{
|
|
||||||
if (!TryComp<DoorComponent>(uid, out var door))
|
|
||||||
return;
|
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new DoorlightsChangedEvent(args.Powered ? door.State : null, args.Powered), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -121,7 +121,6 @@ public abstract class SharedAirlockSystem : EntitySystem
|
|||||||
|
|
||||||
public void UpdateEmergencyLightStatus(EntityUid uid, AirlockComponent component)
|
public void UpdateEmergencyLightStatus(EntityUid uid, AirlockComponent component)
|
||||||
{
|
{
|
||||||
RaiseLocalEvent(uid, new DoorlightsChangedEvent(DoorVisuals.EmergencyLights, component.EmergencyAccess));
|
|
||||||
Appearance.SetData(uid, DoorVisuals.EmergencyLights, component.EmergencyAccess);
|
Appearance.SetData(uid, DoorVisuals.EmergencyLights, component.EmergencyAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,8 +86,6 @@ public abstract partial class SharedDoorSystem
|
|||||||
Dirty(ent, ent.Comp);
|
Dirty(ent, ent.Comp);
|
||||||
UpdateBoltLightStatus(ent);
|
UpdateBoltLightStatus(ent);
|
||||||
|
|
||||||
RaiseLocalEvent(ent, new DoorlightsChangedEvent(DoorVisuals.BoltLights, value), true);
|
|
||||||
|
|
||||||
var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound;
|
var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound;
|
||||||
if (predicted)
|
if (predicted)
|
||||||
Audio.PlayPredicted(sound, ent, user: user);
|
Audio.PlayPredicted(sound, ent, user: user);
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ public abstract partial class SharedDoorSystem : EntitySystem
|
|||||||
|
|
||||||
SetCollidable(ent, collidable, door);
|
SetCollidable(ent, collidable, door);
|
||||||
|
|
||||||
RaiseLocalEvent(ent, new DoorlightsChangedEvent(door.State, true), true);
|
|
||||||
AppearanceSystem.SetData(ent, DoorVisuals.State, door.State);
|
AppearanceSystem.SetData(ent, DoorVisuals.State, door.State);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +166,6 @@ public abstract partial class SharedDoorSystem : EntitySystem
|
|||||||
_activeDoors.Add(ent);
|
_activeDoors.Add(ent);
|
||||||
|
|
||||||
RaiseLocalEvent(ent, new DoorStateChangedEvent(door.State));
|
RaiseLocalEvent(ent, new DoorStateChangedEvent(door.State));
|
||||||
RaiseLocalEvent(ent, new DoorlightsChangedEvent(door.State, true), true);
|
|
||||||
|
|
||||||
AppearanceSystem.SetData(ent, DoorVisuals.State, door.State);
|
AppearanceSystem.SetData(ent, DoorVisuals.State, door.State);
|
||||||
}
|
}
|
||||||
@@ -219,7 +217,6 @@ public abstract partial class SharedDoorSystem : EntitySystem
|
|||||||
Dirty(uid, door);
|
Dirty(uid, door);
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new DoorStateChangedEvent(state));
|
RaiseLocalEvent(uid, new DoorStateChangedEvent(state));
|
||||||
RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true), true);
|
|
||||||
|
|
||||||
AppearanceSystem.SetData(uid, DoorVisuals.State, door.State);
|
AppearanceSystem.SetData(uid, DoorVisuals.State, door.State);
|
||||||
return true;
|
return true;
|
||||||
@@ -525,7 +522,6 @@ public abstract partial class SharedDoorSystem : EntitySystem
|
|||||||
door.NextStateChange = GameTiming.CurTime + door.OpenTimeTwo;
|
door.NextStateChange = GameTiming.CurTime + door.OpenTimeTwo;
|
||||||
door.State = DoorState.Opening;
|
door.State = DoorState.Opening;
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new DoorlightsChangedEvent(door.State, true), true);
|
|
||||||
AppearanceSystem.SetData(uid, DoorVisuals.State, DoorState.Opening);
|
AppearanceSystem.SetData(uid, DoorVisuals.State, DoorState.Opening);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,14 +6,20 @@ namespace Content.Shared._White.Lighting.PointLight.Airlock;
|
|||||||
public sealed partial class PointLightAirlockComponent : Component
|
public sealed partial class PointLightAirlockComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public string RedColor = "#D56C6C";
|
public bool IsLightsEnabled;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public string BlueColor = "#7F93C0";
|
public bool LastBoltsState;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public string YellowColor = "#BDC07F";
|
public readonly string RedColor = "#D56C6C";
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public string GreenColor = "#7FC080";
|
public readonly string BlueColor = "#7F93C0";
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public readonly string YellowColor = "#BDC07F";
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public readonly string GreenColor = "#7FC080";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user