| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | [CreateAssetMenu(fileName = "MinimapMetadata", menuName = "MinimapMetadata")] |
| | 6 | | public class MinimapMetadata : ScriptableObject |
| | 7 | | { |
| | 8 | | public enum TileType |
| | 9 | | { |
| | 10 | | MyParcel = 0, |
| | 11 | | MyParcelsOnSale = 1, |
| | 12 | | MyEstates = 2, |
| | 13 | | MyEstatesOnSale = 3, |
| | 14 | | WithAccess = 4, |
| | 15 | | District = 5, |
| | 16 | | Contribution = 6, |
| | 17 | | Roads = 7, |
| | 18 | | Plaza = 8, |
| | 19 | | Taken = 9, |
| | 20 | | OnSale = 10, |
| | 21 | | Unowned = 11, |
| | 22 | | Background = 12, |
| | 23 | | Loading = 13 |
| | 24 | | } |
| | 25 | |
|
| | 26 | | [Serializable] |
| | 27 | | public class MinimapSceneInfo |
| | 28 | | { |
| | 29 | | public string name; |
| | 30 | | public TileType type; |
| | 31 | | public List<Vector2Int> parcels; |
| | 32 | |
|
| | 33 | | public bool isPOI; |
| | 34 | | public string owner; |
| | 35 | | public string description; |
| | 36 | | public string previewImageUrl; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | [Serializable] |
| | 40 | | public class MinimapUserInfo |
| | 41 | | { |
| | 42 | | public string userId; |
| | 43 | | public string userName; |
| | 44 | | public Vector3 worldPosition; |
| | 45 | | } |
| | 46 | |
|
| | 47 | | public event Action<MinimapSceneInfo> OnSceneInfoUpdated; |
| | 48 | | public event Action<MinimapUserInfo> OnUserInfoUpdated; |
| | 49 | | public event Action<string> OnUserInfoRemoved; |
| | 50 | |
|
| 1 | 51 | | HashSet<MinimapSceneInfo> scenesInfo = new HashSet<MinimapSceneInfo>(); |
| 1 | 52 | | Dictionary<Vector2Int, MinimapSceneInfo> sceneInfoMap = new Dictionary<Vector2Int, MinimapSceneInfo>(); |
| 1 | 53 | | Dictionary<string, MinimapUserInfo> usersInfo = new Dictionary<string, MinimapUserInfo>(); |
| | 54 | |
|
| | 55 | | public MinimapSceneInfo GetSceneInfo(int x, int y) |
| | 56 | | { |
| 127 | 57 | | if (sceneInfoMap.TryGetValue(new Vector2Int(x, y), out MinimapSceneInfo result)) |
| 2 | 58 | | return result; |
| | 59 | |
|
| 125 | 60 | | return null; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public void AddSceneInfo(MinimapSceneInfo sceneInfo) |
| | 64 | | { |
| 5 | 65 | | if (scenesInfo.Contains(sceneInfo)) |
| 0 | 66 | | return; |
| | 67 | |
|
| 5 | 68 | | int parcelsCount = sceneInfo.parcels.Count; |
| | 69 | |
|
| 34 | 70 | | for (int i = 0; i < parcelsCount; i++) |
| | 71 | | { |
| 12 | 72 | | if (sceneInfoMap.ContainsKey(sceneInfo.parcels[i])) |
| | 73 | | { |
| | 74 | | //NOTE(Brian): I intended at first to just return; here. But turns out kernel is sending |
| | 75 | | // overlapping coordinates, sending first gigantic 'Estate' and 'Roads' scenes to |
| | 76 | | // send the proper scenes later. This will be fixed when we implement the content v3 data |
| | 77 | | // plumbing. |
| 0 | 78 | | sceneInfoMap.Remove(sceneInfo.parcels[i]); |
| | 79 | | } |
| | 80 | |
|
| 12 | 81 | | sceneInfoMap.Add(sceneInfo.parcels[i], sceneInfo); |
| | 82 | | } |
| | 83 | |
|
| 5 | 84 | | scenesInfo.Add(sceneInfo); |
| | 85 | |
|
| 5 | 86 | | OnSceneInfoUpdated?.Invoke(sceneInfo); |
| 5 | 87 | | } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Adds (or updates) the information of an user in the minimap. |
| | 91 | | /// </summary> |
| | 92 | | /// <param name="userInfo">User info model</param> |
| | 93 | | public void AddOrUpdateUserInfo(MinimapUserInfo userInfo) |
| | 94 | | { |
| 5 | 95 | | if (usersInfo.ContainsKey(userInfo.userId)) |
| | 96 | | { |
| 1 | 97 | | usersInfo[userInfo.userId] = userInfo; |
| 1 | 98 | | } |
| | 99 | | else |
| | 100 | | { |
| 4 | 101 | | usersInfo.Add(userInfo.userId, userInfo); |
| | 102 | | } |
| | 103 | |
|
| 5 | 104 | | OnUserInfoUpdated?.Invoke(userInfo); |
| 5 | 105 | | } |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Removes the information of an user from the minimap. |
| | 109 | | /// </summary> |
| | 110 | | /// <param name="userId">User Id</param> |
| | 111 | | public void RemoveUserInfo(string userId) |
| | 112 | | { |
| 3 | 113 | | if (usersInfo.Remove(userId)) |
| 3 | 114 | | OnUserInfoRemoved?.Invoke(userId); |
| 3 | 115 | | } |
| | 116 | |
|
| | 117 | | public void Clear() |
| | 118 | | { |
| 107 | 119 | | scenesInfo.Clear(); |
| 107 | 120 | | sceneInfoMap.Clear(); |
| 107 | 121 | | } |
| | 122 | |
|
| | 123 | | private static MinimapMetadata minimapMetadata; |
| | 124 | | public static MinimapMetadata GetMetadata() |
| | 125 | | { |
| 2598 | 126 | | if (minimapMetadata == null) |
| | 127 | | { |
| 1 | 128 | | minimapMetadata = Resources.Load<MinimapMetadata>("ScriptableObjects/MinimapMetadata"); |
| | 129 | | } |
| | 130 | |
|
| 2598 | 131 | | return minimapMetadata; |
| | 132 | | } |
| | 133 | | } |