Files

39 lines
1.2 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Sticky.Components;
2022-04-15 01:00:50 +03:00
using Robust.Client.GameObjects;
namespace Content.Client.Sticky.Visualizers;
public sealed class StickyVisualizerSystem : VisualizerSystem<StickyVisualizerComponent>
{
private EntityQuery<SpriteComponent> _spriteQuery;
2022-04-15 01:00:50 +03:00
public override void Initialize()
{
base.Initialize();
_spriteQuery = GetEntityQuery<SpriteComponent>();
2022-04-15 01:00:50 +03:00
SubscribeLocalEvent<StickyVisualizerComponent, ComponentInit>(OnInit);
}
private void OnInit(Entity<StickyVisualizerComponent> ent, ref ComponentInit args)
2022-04-15 01:00:50 +03:00
{
if (!_spriteQuery.TryComp(ent, out var sprite))
2022-04-15 01:00:50 +03:00
return;
ent.Comp.OriginalDrawDepth = sprite.DrawDepth;
2022-04-15 01:00:50 +03:00
}
protected override void OnAppearanceChange(EntityUid uid, StickyVisualizerComponent comp, ref AppearanceChangeEvent args)
2022-04-15 01:00:50 +03:00
{
if (args.Sprite == null)
2022-04-15 01:00:50 +03:00
return;
if (!AppearanceSystem.TryGetData<bool>(uid, StickyVisuals.IsStuck, out var isStuck, args.Component))
2022-04-15 01:00:50 +03:00
return;
var drawDepth = isStuck ? comp.StuckDrawDepth : comp.OriginalDrawDepth;
SpriteSystem.SetDrawDepth((uid, args.Sprite), drawDepth);
2022-04-15 01:00:50 +03:00
}
}