| | 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 | | public event Action<MinimapSceneInfo> OnSceneInfoUpdated; |
| | 40 | |
|
| 1 | 41 | | HashSet<MinimapSceneInfo> scenesInfo = new HashSet<MinimapSceneInfo>(); |
| 1 | 42 | | Dictionary<Vector2Int, MinimapSceneInfo> sceneInfoMap = new Dictionary<Vector2Int, MinimapSceneInfo>(); |
| | 43 | |
|
| | 44 | | public MinimapSceneInfo GetSceneInfo(int x, int y) |
| | 45 | | { |
| 3 | 46 | | if (sceneInfoMap.TryGetValue(new Vector2Int(x, y), out MinimapSceneInfo result)) |
| 2 | 47 | | return result; |
| | 48 | |
|
| 1 | 49 | | return null; |
| | 50 | | } |
| | 51 | |
|
| | 52 | | public void AddSceneInfo(MinimapSceneInfo sceneInfo) |
| | 53 | | { |
| 4 | 54 | | if (scenesInfo.Contains(sceneInfo)) |
| 0 | 55 | | return; |
| | 56 | |
|
| 4 | 57 | | int parcelsCount = sceneInfo.parcels.Count; |
| | 58 | |
|
| 26 | 59 | | for (int i = 0; i < parcelsCount; i++) |
| | 60 | | { |
| 9 | 61 | | if (sceneInfoMap.ContainsKey(sceneInfo.parcels[i])) |
| | 62 | | { |
| | 63 | | //NOTE(Brian): I intended at first to just return; here. But turns out kernel is sending |
| | 64 | | // overlapping coordinates, sending first gigantic 'Estate' and 'Roads' scenes to |
| | 65 | | // send the proper scenes later. This will be fixed when we implement the content v3 data |
| | 66 | | // plumbing. |
| 0 | 67 | | sceneInfoMap.Remove(sceneInfo.parcels[i]); |
| | 68 | | } |
| | 69 | |
|
| 9 | 70 | | sceneInfoMap.Add(sceneInfo.parcels[i], sceneInfo); |
| | 71 | | } |
| | 72 | |
|
| 4 | 73 | | scenesInfo.Add(sceneInfo); |
| | 74 | |
|
| 4 | 75 | | OnSceneInfoUpdated?.Invoke(sceneInfo); |
| 4 | 76 | | } |
| | 77 | |
|
| | 78 | | public void Clear() |
| | 79 | | { |
| 1 | 80 | | scenesInfo.Clear(); |
| 1 | 81 | | sceneInfoMap.Clear(); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | private static MinimapMetadata minimapMetadata; |
| | 85 | | public static MinimapMetadata GetMetadata() |
| | 86 | | { |
| 147 | 87 | | if (minimapMetadata == null) |
| | 88 | | { |
| 1 | 89 | | minimapMetadata = Resources.Load<MinimapMetadata>("ScriptableObjects/MinimapMetadata"); |
| | 90 | | } |
| | 91 | |
|
| 147 | 92 | | return minimapMetadata; |
| | 93 | | } |
| | 94 | | } |