1
0

ResourceCacheExtensions.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using JetBrains.Annotations;
  2. using Robust.Client.Graphics;
  3. using Robust.Client.ResourceManagement;
  4. using Robust.Shared.Graphics;
  5. using Robust.Shared.Utility;
  6. namespace Content.Client.Resources
  7. {
  8. [PublicAPI]
  9. public static class ResourceCacheExtensions
  10. {
  11. public static Texture GetTexture(this IResourceCache cache, ResPath path)
  12. {
  13. return cache.GetResource<TextureResource>(path);
  14. }
  15. public static Texture GetTexture(this IResourceCache cache, string path)
  16. {
  17. return GetTexture(cache, new ResPath(path));
  18. }
  19. public static Font GetFont(this IResourceCache cache, ResPath path, int size)
  20. {
  21. return new VectorFont(cache.GetResource<FontResource>(path), size);
  22. }
  23. public static Font GetFont(this IResourceCache cache, string path, int size)
  24. {
  25. return cache.GetFont(new ResPath(path), size);
  26. }
  27. public static Font GetFont(this IResourceCache cache, ResPath[] path, int size)
  28. {
  29. var fs = new Font[path.Length];
  30. for (var i = 0; i < path.Length; i++)
  31. fs[i] = new VectorFont(cache.GetResource<FontResource>(path[i]), size);
  32. return new StackedFont(fs);
  33. }
  34. public static Font GetFont(this IResourceCache cache, string[] path, int size)
  35. {
  36. var rp = new ResPath[path.Length];
  37. for (var i = 0; i < path.Length; i++)
  38. rp[i] = new ResPath(path[i]);
  39. return cache.GetFont(rp, size);
  40. }
  41. }
  42. }