Files
wwdpublic/Content.Client/_Goobstation/ToggleableLightWieldable/ToggleableLightWieldableSystem.cs
Aviu00 1a6270309a Yuh
(cherry picked from commit dc051987ca50fc97848285b66eca9694e31f7941)
2025-03-21 17:37:58 +03:00

34 lines
1.1 KiB
C#

using System.Linq;
using Content.Client.Toggleable;
using Content.Shared.Hands;
using Content.Shared.Wieldable.Components;
using Robust.Shared.Utility;
namespace Content.Client._Goobstation.ToggleableLightWieldable;
public sealed class ToggleableLightWieldableSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ToggleableLightWieldableComponent, GetInhandVisualsEvent>(OnGetHeldVisuals, after: new[] { typeof(ToggleableLightVisualsSystem) });
}
private void OnGetHeldVisuals(Entity<ToggleableLightWieldableComponent> ent, ref GetInhandVisualsEvent args)
{
if (!TryComp(ent, out WieldableComponent? wieldable))
return;
var location = args.Location.ToString().ToLowerInvariant();
var layer = args.Layers.FirstOrNull(x => x.Item1 == location)?.Item2;
var layerWielded = args.Layers.FirstOrNull(x => x.Item1 == $"wielded-{location}")?.Item2;
if (layer == null || layerWielded == null)
return;
layer.Visible = !wieldable.Wielded;
layerWielded.Visible = wieldable.Wielded;
}
}