From df7d6c4d9021f3af5adbfbaa337c62bc29b59c47 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 31 Aug 2021 18:45:02 +1000 Subject: [PATCH] PoweredLight uses PointLights for appearance (#4540) * PoweredLight uses PointLights for appearance Previously this just set PointLightComponent data via the visualizer which lead to desyncs in the data between client and server. If the server pointlight was dirtied at any point then the pointlight data set via appearance visualizers was bulldozed. * Address review --- .../Visualizers/PoweredLightVisualizer.cs | 8 ------- .../Light/Components/PoweredLightComponent.cs | 23 ++++++++++++++----- .../Light/SharedPoweredLightVisuals.cs | 1 - 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs b/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs index 626da3a2e1..9b61da8e49 100644 --- a/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs +++ b/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs @@ -29,7 +29,6 @@ namespace Content.Client.Light.Visualizers base.OnChangeData(component); if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; - if (!component.Owner.TryGetComponent(out PointLightComponent? light)) return; if (!component.TryGetData(PoweredLightVisuals.BulbState, out PoweredLightState state)) return; switch (state) @@ -37,33 +36,26 @@ namespace Content.Client.Light.Visualizers case PoweredLightState.Empty: sprite.LayerSetState(PoweredLightLayers.Base, "empty"); ToggleBlinkingAnimation(component, false); - light.Enabled = false; break; case PoweredLightState.Off: sprite.LayerSetState(PoweredLightLayers.Base, "off"); ToggleBlinkingAnimation(component, false); - light.Enabled = false; break; case PoweredLightState.On: - if (component.TryGetData(PoweredLightVisuals.BulbColor, out Color color)) - light.Color = color; if (component.TryGetData(PoweredLightVisuals.Blinking, out bool isBlinking)) ToggleBlinkingAnimation(component, isBlinking); if (!isBlinking) { sprite.LayerSetState(PoweredLightLayers.Base, "on"); - light.Enabled = true; } break; case PoweredLightState.Broken: sprite.LayerSetState(PoweredLightLayers.Base, "broken"); ToggleBlinkingAnimation(component, false); - light.Enabled = false; break; case PoweredLightState.Burned: sprite.LayerSetState(PoweredLightLayers.Base, "burn"); ToggleBlinkingAnimation(component, false); - light.Enabled = false; break; } } diff --git a/Content.Server/Light/Components/PoweredLightComponent.cs b/Content.Server/Light/Components/PoweredLightComponent.cs index 46a7d60408..f5fc932908 100644 --- a/Content.Server/Light/Components/PoweredLightComponent.cs +++ b/Content.Server/Light/Components/PoweredLightComponent.cs @@ -17,6 +17,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Localization; +using Robust.Shared.Maths; using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; @@ -89,7 +90,7 @@ namespace Content.Server.Light.Components { base.Initialize(); DamageType = IoCManager.Resolve().Index(_damageTypeID); - _lightBulbContainer = ContainerHelpers.EnsureContainer(Owner, "light_bulb"); + _lightBulbContainer = Owner.EnsureContainer("light_bulb"); } [ViewVariables] @@ -236,10 +237,9 @@ namespace Content.Server.Light.Components case LightBulbState.Normal: if (powerReceiver.Powered && _on) { - _currentLit = true; + SetLight(true, LightBulb.Color); powerReceiver.Load = LightBulb.PowerUse; _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.On); - _appearance?.SetData(PoweredLightVisuals.BulbColor, LightBulb.Color); var time = _gameTiming.CurTime; if (time > _lastThunk + _thunkDelay) { @@ -249,21 +249,32 @@ namespace Content.Server.Light.Components } else { - _currentLit = false; + SetLight(false); _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Off); } break; case LightBulbState.Broken: - _currentLit = false; + SetLight(false); _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Broken); break; case LightBulbState.Burned: - _currentLit = false; + SetLight(false); _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Burned); break; } } + private void SetLight(bool value, Color? color = null) + { + _currentLit = value; + + if (!Owner.TryGetComponent(out PointLightComponent? pointLight)) return; + pointLight.Enabled = value; + + if (color != null) + pointLight.Color = color.Value; + } + public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); diff --git a/Content.Shared/Light/SharedPoweredLightVisuals.cs b/Content.Shared/Light/SharedPoweredLightVisuals.cs index 20f4ddd61e..8fe1e8f37c 100644 --- a/Content.Shared/Light/SharedPoweredLightVisuals.cs +++ b/Content.Shared/Light/SharedPoweredLightVisuals.cs @@ -7,7 +7,6 @@ namespace Content.Shared.Light public enum PoweredLightVisuals : byte { BulbState, - BulbColor, Blinking }