SprayPainterSystem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Content.Shared.SprayPainter;
  2. using Robust.Client.Graphics;
  3. using Robust.Client.ResourceManagement;
  4. using Robust.Shared.Serialization.TypeSerializers.Implementations;
  5. using Robust.Shared.Utility;
  6. using System.Linq;
  7. using Robust.Shared.Graphics;
  8. namespace Content.Client.SprayPainter;
  9. public sealed class SprayPainterSystem : SharedSprayPainterSystem
  10. {
  11. [Dependency] private readonly IResourceCache _resourceCache = default!;
  12. public List<SprayPainterEntry> Entries { get; private set; } = new();
  13. protected override void CacheStyles()
  14. {
  15. base.CacheStyles();
  16. Entries.Clear();
  17. foreach (var style in Styles)
  18. {
  19. var name = style.Name;
  20. string? iconPath = Groups
  21. .FindAll(x => x.StylePaths.ContainsKey(name))?
  22. .MaxBy(x => x.IconPriority)?.StylePaths[name];
  23. if (iconPath == null)
  24. {
  25. Entries.Add(new SprayPainterEntry(name, null));
  26. continue;
  27. }
  28. RSIResource doorRsi = _resourceCache.GetResource<RSIResource>(SpriteSpecifierSerializer.TextureRoot / new ResPath(iconPath));
  29. if (!doorRsi.RSI.TryGetState("closed", out var icon))
  30. {
  31. Entries.Add(new SprayPainterEntry(name, null));
  32. continue;
  33. }
  34. Entries.Add(new SprayPainterEntry(name, icon.Frame0));
  35. }
  36. }
  37. }
  38. public sealed class SprayPainterEntry
  39. {
  40. public string Name;
  41. public Texture? Icon;
  42. public SprayPainterEntry(string name, Texture? icon)
  43. {
  44. Name = name;
  45. Icon = icon;
  46. }
  47. }