MapViewerData.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System.Collections.Generic;
  2. using System.Numerics;
  3. using Robust.Shared.Maths;
  4. using SixLabors.ImageSharp.PixelFormats;
  5. namespace Content.MapRenderer;
  6. public sealed class MapViewerData
  7. {
  8. public string Id { get; set; } = string.Empty;
  9. public string Name { get; set; } = string.Empty;
  10. public List<GridLayer> Grids { get; set; } = new();
  11. public string? Attributions { get; set; }
  12. public List<LayerGroup> ParallaxLayers { get; set; } = new();
  13. }
  14. public sealed class GridLayer
  15. {
  16. public string GridId { get; set; } = string.Empty;
  17. public Position Offset { get; set; }
  18. public bool Tiled { get; set; } = false;
  19. public string Url { get; set; }
  20. public Extent Extent { get; set; }
  21. public GridLayer(RenderedGridImage<Rgba32> gridImage, string url)
  22. {
  23. //Get the internal _uid as string
  24. if (gridImage.GridUid.HasValue)
  25. GridId = gridImage.GridUid.Value.GetHashCode().ToString();
  26. Offset = new Position(gridImage.Offset);
  27. Extent = new Extent(gridImage.Image.Width, gridImage.Image.Height);
  28. Url = url;
  29. }
  30. }
  31. public sealed class LayerGroup
  32. {
  33. public Position Scale { get; set; } = Position.One();
  34. public Position Offset { get; set; } = Position.Zero();
  35. public bool Static { get; set; } = false;
  36. public float? MinScale { get; set; }
  37. public GroupSource Source { get; set; } = new();
  38. public List<Layer> Layers { get; set; } = new();
  39. public static LayerGroup DefaultParallax()
  40. {
  41. return new LayerGroup
  42. {
  43. Scale = new Position(0.1f, 0.1f),
  44. Source = new GroupSource
  45. {
  46. Url = "https://i.imgur.com/3YO8KRd.png",
  47. Extent = new Extent(6000, 4000)
  48. },
  49. Layers = new List<Layer>
  50. {
  51. new()
  52. {
  53. Url = "https://i.imgur.com/IannmmK.png"
  54. },
  55. new()
  56. {
  57. Url = "https://i.imgur.com/T3W6JsE.png",
  58. Composition = "lighter",
  59. ParallaxScale = new Position(0.2f, 0.2f)
  60. },
  61. new()
  62. {
  63. Url = "https://i.imgur.com/T3W6JsE.png",
  64. Composition = "lighter",
  65. ParallaxScale = new Position(0.3f, 0.3f)
  66. }
  67. }
  68. };
  69. }
  70. }
  71. public sealed class GroupSource
  72. {
  73. public string Url { get; set; } = string.Empty;
  74. public Extent Extent { get; set; } = new();
  75. }
  76. public sealed class Layer
  77. {
  78. public string Url { get; set; } = string.Empty;
  79. public string Composition { get; set; } = "source-over";
  80. public Position ParallaxScale { get; set; } = new(0.1f, 0.1f);
  81. }
  82. public readonly struct Extent
  83. {
  84. public readonly float X1;
  85. public readonly float Y1;
  86. public readonly float X2;
  87. public readonly float Y2;
  88. public Extent()
  89. {
  90. X1 = 0;
  91. Y1 = 0;
  92. X2 = 0;
  93. Y2 = 0;
  94. }
  95. public Extent(float x2, float y2)
  96. {
  97. X1 = 0;
  98. Y1 = 0;
  99. X2 = x2;
  100. Y2 = y2;
  101. }
  102. public Extent(float x1, float y1, float x2, float y2)
  103. {
  104. X1 = x1;
  105. Y1 = y1;
  106. X2 = x2;
  107. Y2 = y2;
  108. }
  109. }
  110. public readonly struct Position
  111. {
  112. public readonly float X;
  113. public readonly float Y;
  114. public Position(float x, float y)
  115. {
  116. X = x;
  117. Y = y;
  118. }
  119. public Position(Vector2 vector2)
  120. {
  121. X = vector2.X;
  122. Y = vector2.Y;
  123. }
  124. public static Position Zero()
  125. {
  126. return new Position(0, 0);
  127. }
  128. public static Position One()
  129. {
  130. return new Position(0, 0);
  131. }
  132. }