| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL.Helpers |
| | 4 | | { |
| | 5 | | public static class MapUtils |
| | 6 | | { |
| 1 | 7 | | public static readonly Vector2Int WORLD_PARCELS_OFFSET_MIN = new Vector2Int(-150, -150); |
| 1 | 8 | | public static readonly Vector2Int WORLD_PARCELS_OFFSET_MAX = new Vector2Int(175, 175); //NOTE(Brian): We use 175 |
| 1 | 9 | | public static readonly Vector2Int CHUNK_SIZE = new Vector2Int(1020, 1020); |
| 1 | 10 | | public static readonly int PARCEL_SIZE = 20; |
| | 11 | |
|
| 0 | 12 | | public static Vector2Int GetTileFromLocalPosition(Vector3 position) { return new Vector2Int((int)(position.x / P |
| | 13 | |
|
| | 14 | | public static Vector3 GetTileToLocalPosition(float x, float y) |
| | 15 | | { |
| 1 | 16 | | x -= WORLD_PARCELS_OFFSET_MIN.x; |
| 1 | 17 | | y -= WORLD_PARCELS_OFFSET_MIN.y; |
| | 18 | |
|
| 1 | 19 | | Vector3 result = new Vector3(x * PARCEL_SIZE, y * PARCEL_SIZE, 0); |
| 1 | 20 | | return result; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public static string GetMarketPlaceThumbnailUrl(Vector2Int[] parcels, int width, int height, int sizeFactor) |
| | 24 | | { |
| 5 | 25 | | string parcelsStr = ""; |
| 5 | 26 | | Vector2Int min = new Vector2Int(int.MaxValue, int.MaxValue); |
| 5 | 27 | | Vector2Int max = new Vector2Int(int.MinValue, int.MinValue); |
| | 28 | | Vector2Int coord; |
| | 29 | |
|
| 20 | 30 | | for (int i = 0; i < parcels.Length; i++) |
| | 31 | | { |
| 5 | 32 | | coord = parcels[i]; |
| 5 | 33 | | parcelsStr += string.Format("{0},{1}", coord.x, coord.y); |
| 5 | 34 | | if (i < parcels.Length - 1) |
| 0 | 35 | | parcelsStr += ";"; |
| | 36 | |
|
| 5 | 37 | | if (coord.x < min.x) |
| 5 | 38 | | min.x = coord.x; |
| 5 | 39 | | if (coord.y < min.y) |
| 5 | 40 | | min.y = coord.y; |
| 5 | 41 | | if (coord.x > max.x) |
| 5 | 42 | | max.x = coord.x; |
| 5 | 43 | | if (coord.y > max.y) |
| 5 | 44 | | max.y = coord.y; |
| | 45 | | } |
| | 46 | |
|
| 5 | 47 | | int centerX = (int)(min.x + (max.x - min.x) * 0.5f); |
| 5 | 48 | | int centerY = (int)(min.y + (max.y - min.y) * 0.5f); |
| 5 | 49 | | int sceneMaxSize = Mathf.Clamp(Mathf.Max(max.x - min.x, max.y - min.y), 1, int.MaxValue); |
| 5 | 50 | | int size = sizeFactor / sceneMaxSize; |
| | 51 | |
|
| 5 | 52 | | return $"https://api.decentraland.org/v1/map.png?width={width}&height={height}&size={size}¢er={centerX}, |
| | 53 | | } |
| | 54 | | } |
| | 55 | | } |