Files
tbd-station-14/Content.Client/DamageState/DamageStateVisualizerSystem.cs
Tayrtahn a9e0d8725e Cleanup warnings in DamageStateVisualizerSystem (#37435)
Cleanup warnings in DamageStateVisualizerSystem
2025-05-14 03:58:03 +02:00

58 lines
1.9 KiB
C#

using Content.Shared.Mobs;
using Robust.Client.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.DamageState;
public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
{
[Dependency] private readonly SpriteSystem _sprite = default!;
protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
{
var sprite = args.Sprite;
if (sprite == null || !AppearanceSystem.TryGetData<MobState>(uid, MobStateVisuals.State, out var data, args.Component))
{
return;
}
if (!component.States.TryGetValue(data, out var layers))
{
return;
}
// Brain no worky rn so this was just easier.
foreach (var key in new[] { DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
{
if (!_sprite.LayerMapTryGet((uid, sprite), key, out _, false)) continue;
_sprite.LayerSetVisible((uid, sprite), key, false);
}
foreach (var (key, state) in layers)
{
// Inheritance moment.
if (!_sprite.LayerMapTryGet((uid, sprite), key, out _, false)) continue;
_sprite.LayerSetVisible((uid, sprite), key, true);
_sprite.LayerSetRsiState((uid, sprite), key, state);
}
// So they don't draw over mobs anymore
if (data == MobState.Dead)
{
if (sprite.DrawDepth > (int)DrawDepth.DeadMobs)
{
component.OriginalDrawDepth = sprite.DrawDepth;
_sprite.SetDrawDepth((uid, sprite), (int)DrawDepth.DeadMobs);
}
}
else if (component.OriginalDrawDepth != null)
{
_sprite.SetDrawDepth((uid, sprite), component.OriginalDrawDepth.Value);
component.OriginalDrawDepth = null;
}
}
}