| | 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); |
| | 10 | | public const int PARCEL_SIZE = 20; |
| | 11 | |
|
| | 12 | | public static Vector3 GetTileToLocalPosition(float x, float y) |
| | 13 | | { |
| 5 | 14 | | x -= WORLD_PARCELS_OFFSET_MIN.x; |
| 5 | 15 | | y -= WORLD_PARCELS_OFFSET_MIN.y; |
| | 16 | |
|
| 5 | 17 | | Vector3 result = new Vector3(x * PARCEL_SIZE, y * PARCEL_SIZE, 0); |
| 5 | 18 | | return result; |
| | 19 | | } |
| | 20 | |
|
| 0 | 21 | | public static Vector2 CoordsToPositionUnclamped(Vector2 coords) => CoordsToPositionUnclamped(coords, PARCEL_SIZE |
| 0 | 22 | | public static Vector2 CoordsToPositionUnclamped(Vector2 coords, int parcelSize) { return coords * parcelSize; } |
| 0 | 23 | | public static Vector2 CoordsToPosition(Vector2Int coords) => CoordsToPosition(coords, PARCEL_SIZE); |
| 0 | 24 | | public static Vector2 CoordsToPosition(Vector2Int coords, int parcelSize) { return ((Vector2)coords) * parcelSiz |
| 5 | 25 | | public static Vector2 CoordsToPositionWithOffset(Vector3 coords) => CoordsToPositionWithOffset(coords, PARCEL_SI |
| 5 | 26 | | public static Vector2 CoordsToPositionWithOffset(Vector3 coords, int parcelSize) { return (((Vector2)coords) * p |
| 0 | 27 | | public static Vector2 CoordsToPosition(Vector2 coords) => CoordsToPosition(coords, PARCEL_SIZE); |
| 0 | 28 | | public static Vector2 CoordsToPosition(Vector2 coords, int parcelSize) { return coords * parcelSize; } |
| | 29 | |
|
| | 30 | | public static string GetMarketPlaceThumbnailUrl(Vector2Int[] parcels, int width, int height, int sizeFactor) |
| | 31 | | { |
| 5 | 32 | | string parcelsStr = ""; |
| 5 | 33 | | Vector2Int min = new Vector2Int(int.MaxValue, int.MaxValue); |
| 5 | 34 | | Vector2Int max = new Vector2Int(int.MinValue, int.MinValue); |
| | 35 | | Vector2Int coord; |
| | 36 | |
|
| 20 | 37 | | for (int i = 0; i < parcels.Length; i++) |
| | 38 | | { |
| 5 | 39 | | coord = parcels[i]; |
| 5 | 40 | | parcelsStr += string.Format("{0},{1}", coord.x, coord.y); |
| 5 | 41 | | if (i < parcels.Length - 1) |
| 0 | 42 | | parcelsStr += ";"; |
| | 43 | |
|
| 5 | 44 | | if (coord.x < min.x) |
| 5 | 45 | | min.x = coord.x; |
| 5 | 46 | | if (coord.y < min.y) |
| 5 | 47 | | min.y = coord.y; |
| 5 | 48 | | if (coord.x > max.x) |
| 5 | 49 | | max.x = coord.x; |
| 5 | 50 | | if (coord.y > max.y) |
| 5 | 51 | | max.y = coord.y; |
| | 52 | | } |
| | 53 | |
|
| 5 | 54 | | int centerX = (int)(min.x + (max.x - min.x) * 0.5f); |
| 5 | 55 | | int centerY = (int)(min.y + (max.y - min.y) * 0.5f); |
| 5 | 56 | | int sceneMaxSize = Mathf.Clamp(Mathf.Max(max.x - min.x, max.y - min.y), 1, int.MaxValue); |
| 5 | 57 | | int size = sizeFactor / sceneMaxSize; |
| | 58 | |
|
| 5 | 59 | | return $"https://api.decentraland.org/v1/map.png?width={width}&height={height}&size={size}¢er={centerX}, |
| | 60 | | } |
| | 61 | | } |
| | 62 | | } |