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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
|
||||
_lightBulbContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, "light_bulb");
|
||||
_lightBulbContainer = Owner.EnsureContainer<ContainerSlot>("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);
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Content.Shared.Light
|
||||
public enum PoweredLightVisuals : byte
|
||||
{
|
||||
BulbState,
|
||||
BulbColor,
|
||||
Blinking
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user