Resolves LightBulbVisualizer is Obsolete (#13889)

This commit is contained in:
TemporalOroboros
2023-02-13 19:43:51 -08:00
committed by GitHub
parent 1e93d1e5a8
commit 5b23048497
11 changed files with 187 additions and 142 deletions

View File

@@ -0,0 +1,36 @@
using Content.Shared.Light.Component;
using Robust.Client.GameObjects;
namespace Content.Client.Light.Visualizers;
public sealed class LightBulbSystem : VisualizerSystem<LightBulbComponent>
{
protected override void OnAppearanceChange(EntityUid uid, LightBulbComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
// update sprite state
if (AppearanceSystem.TryGetData<LightBulbState>(uid, LightBulbVisuals.State, out var state, args.Component))
{
switch (state)
{
case LightBulbState.Normal:
args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.NormalSpriteState);
break;
case LightBulbState.Broken:
args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.BrokenSpriteState);
break;
case LightBulbState.Burned:
args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.BurnedSpriteState);
break;
}
}
// also update sprites color
if (AppearanceSystem.TryGetData<Color>(uid, LightBulbVisuals.Color, out var color, args.Component))
{
args.Sprite.Color = color;
}
}
}

View File

@@ -1,46 +0,0 @@
using Content.Shared.Light;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public sealed class LightBulbVisualizer : AppearanceVisualizer
{
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
return;
// update sprite state
if (component.TryGetData(LightBulbVisuals.State, out LightBulbState state))
{
switch (state)
{
case LightBulbState.Normal:
sprite.LayerSetState(0, "normal");
break;
case LightBulbState.Broken:
sprite.LayerSetState(0, "broken");
break;
case LightBulbState.Burned:
sprite.LayerSetState(0, "burned");
break;
}
}
// also update sprites color
if (component.TryGetData(LightBulbVisuals.Color, out Color color))
{
sprite.Color = color;
}
}
}
}