FlippableClothingVisualizerSystem.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Clothing;
  2. using Content.Shared.Clothing.Components;
  3. using Content.Shared.Clothing.EntitySystems;
  4. using Content.Shared.Foldable;
  5. using Content.Shared.Item;
  6. using Robust.Client.GameObjects;
  7. namespace Content.Client.Clothing;
  8. public sealed class FlippableClothingVisualizerSystem : VisualizerSystem<FlippableClothingVisualsComponent>
  9. {
  10. [Dependency] private readonly SharedItemSystem _itemSys = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<FlippableClothingVisualsComponent, GetEquipmentVisualsEvent>(OnGetVisuals, after: [typeof(ClothingSystem)]);
  15. SubscribeLocalEvent<FlippableClothingVisualsComponent, FoldedEvent>(OnFolded);
  16. }
  17. private void OnFolded(Entity<FlippableClothingVisualsComponent> ent, ref FoldedEvent args)
  18. {
  19. _itemSys.VisualsChanged(ent);
  20. }
  21. private void OnGetVisuals(Entity<FlippableClothingVisualsComponent> ent, ref GetEquipmentVisualsEvent args)
  22. {
  23. if (!TryComp(ent, out SpriteComponent? sprite) ||
  24. !TryComp(ent, out ClothingComponent? clothing))
  25. return;
  26. if (clothing.MappedLayer == null ||
  27. !AppearanceSystem.TryGetData<bool>(ent, FoldableSystem.FoldedVisuals.State, out var folding) ||
  28. !sprite.LayerMapTryGet(folding ? ent.Comp.FoldingLayer : ent.Comp.UnfoldingLayer, out var idx))
  29. return;
  30. // add each layer to the visuals
  31. var spriteLayer = sprite[idx];
  32. foreach (var layer in args.Layers)
  33. {
  34. if (layer.Item1 != clothing.MappedLayer)
  35. continue;
  36. layer.Item2.Scale = spriteLayer.Scale;
  37. }
  38. }
  39. }