2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs;
|
2022-06-16 07:14:06 +03:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
|
|
|
|
|
2023-01-13 16:57:10 -08:00
|
|
|
namespace Content.Client.DamageState;
|
2022-06-16 07:14:06 +03:00
|
|
|
|
|
|
|
|
public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
|
|
|
|
|
{
|
|
|
|
|
protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
|
|
|
|
|
{
|
|
|
|
|
var sprite = args.Sprite;
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
if (sprite == null || !AppearanceSystem.TryGetData<MobState>(uid, MobStateVisuals.State, out var data, args.Component))
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!component.States.TryGetValue(data, out var layers))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Brain no worky rn so this was just easier.
|
2025-05-13 21:58:03 -04:00
|
|
|
foreach (var key in new[] { DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
2025-05-23 14:12:20 -04:00
|
|
|
if (!SpriteSystem.LayerMapTryGet((uid, sprite), key, out _, false)) continue;
|
2022-06-16 17:56:00 +10:00
|
|
|
|
2025-05-23 14:12:20 -04:00
|
|
|
SpriteSystem.LayerSetVisible((uid, sprite), key, false);
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (key, state) in layers)
|
|
|
|
|
{
|
2022-06-16 16:14:59 +10:00
|
|
|
// Inheritance moment.
|
2025-05-23 14:12:20 -04:00
|
|
|
if (!SpriteSystem.LayerMapTryGet((uid, sprite), key, out _, false)) continue;
|
2022-06-16 16:14:59 +10:00
|
|
|
|
2025-05-23 14:12:20 -04:00
|
|
|
SpriteSystem.LayerSetVisible((uid, sprite), key, true);
|
|
|
|
|
SpriteSystem.LayerSetRsiState((uid, sprite), key, state);
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// So they don't draw over mobs anymore
|
2023-01-13 16:57:10 -08:00
|
|
|
if (data == MobState.Dead)
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
2025-05-13 21:58:03 -04:00
|
|
|
if (sprite.DrawDepth > (int)DrawDepth.DeadMobs)
|
2022-09-06 00:28:23 +10:00
|
|
|
{
|
|
|
|
|
component.OriginalDrawDepth = sprite.DrawDepth;
|
2025-05-23 14:12:20 -04:00
|
|
|
SpriteSystem.SetDrawDepth((uid, sprite), (int)DrawDepth.DeadMobs);
|
2022-09-06 00:28:23 +10:00
|
|
|
}
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
else if (component.OriginalDrawDepth != null)
|
|
|
|
|
{
|
2025-05-23 14:12:20 -04:00
|
|
|
SpriteSystem.SetDrawDepth((uid, sprite), component.OriginalDrawDepth.Value);
|
2022-09-06 00:28:23 +10:00
|
|
|
component.OriginalDrawDepth = null;
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|