| | 1 | | using DCL; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | | using Assert = UnityEngine.Assertions.Assert; |
| | 8 | |
|
| | 9 | | namespace Tests |
| | 10 | | { |
| | 11 | | public class MapRendererShould : IntegrationTestSuite_Legacy |
| | 12 | | { |
| | 13 | | private GameObject viewport; |
| | 14 | |
|
| | 15 | | [UnitySetUp] |
| | 16 | | protected override IEnumerator SetUp() |
| | 17 | | { |
| 2 | 18 | | yield return base.SetUp(); |
| | 19 | |
|
| 2 | 20 | | if (MapRenderer.i == null) |
| 0 | 21 | | Object.Instantiate(Resources.Load("Map Renderer")); |
| | 22 | |
|
| 2 | 23 | | MapRenderer.i.atlas.mapChunkPrefab = (GameObject) Resources.Load("Map Chunk Mock"); |
| 2 | 24 | | viewport = new GameObject("Viewport"); |
| 2 | 25 | | var rt = viewport.AddComponent<RectTransform>(); |
| 2 | 26 | | rt.sizeDelta = Vector2.one * 100; |
| 2 | 27 | | viewport.transform.SetParent(MapRenderer.i.atlas.transform, false); |
| 2 | 28 | | viewport.transform.localPosition = Vector3.zero; |
| 2 | 29 | | MapRenderer.i.atlas.viewport = rt; |
| | 30 | |
|
| 2 | 31 | | MapRenderer.i.Initialize(); |
| | 32 | |
|
| | 33 | | //NOTE(Brian): Needed to wait for Start() call in MapRenderer |
| 2 | 34 | | yield return null; |
| 2 | 35 | | } |
| | 36 | |
|
| | 37 | | protected override IEnumerator TearDown() |
| | 38 | | { |
| 2 | 39 | | MapRenderer.i.Cleanup(); |
| 2 | 40 | | UnityEngine.Object.Destroy(viewport); |
| | 41 | |
|
| 2 | 42 | | yield return base.TearDown(); |
| 2 | 43 | | } |
| | 44 | |
|
| | 45 | | [Test] |
| | 46 | | [Category("Explicit")] |
| | 47 | | [Explicit("For some reason this test fails when running after other test in this suite.")] |
| | 48 | | public void CenterAsIntended() |
| | 49 | | { |
| 0 | 50 | | Transform atlasContainerTransform = MapRenderer.i.atlas.container.transform; |
| | 51 | |
|
| 0 | 52 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(1, 1, 1)); |
| 0 | 53 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(0, 0, 0)); |
| 0 | 54 | | Assert.AreApproximatelyEqual(-1500, atlasContainerTransform.position.x); |
| 0 | 55 | | Assert.AreApproximatelyEqual(-1500, atlasContainerTransform.position.y); |
| | 56 | |
|
| 0 | 57 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(100, 0, 100)); |
| 0 | 58 | | Assert.AreApproximatelyEqual(-1562.5f, atlasContainerTransform.position.x); |
| 0 | 59 | | Assert.AreApproximatelyEqual(-1562.5f, atlasContainerTransform.position.y); |
| | 60 | |
|
| 0 | 61 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(-100, 0, -100)); |
| 0 | 62 | | Assert.AreApproximatelyEqual(-1437.5f, atlasContainerTransform.position.x); |
| 0 | 63 | | Assert.AreApproximatelyEqual(-1437.5f, atlasContainerTransform.position.y); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | [UnityTest] |
| | 67 | | [Category("Explicit")] |
| | 68 | | [Explicit("For some reason this test fails when running after other test in this suite.")] |
| | 69 | | public IEnumerator PerformCullingAsIntended() |
| | 70 | | { |
| 0 | 71 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(0, 0, 0)); |
| 0 | 72 | | Assert.AreEqual("0000000000000000000000001000000000000000000000000", GetChunkStatesAsString()); |
| 0 | 73 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(1000, 0, 1000)); |
| 0 | 74 | | Assert.AreEqual("0000000000000000000000000000000011000001100000000", GetChunkStatesAsString()); |
| 0 | 75 | | CommonScriptableObjects.playerWorldPosition.Set(new Vector3(-1000, 0, -1000)); |
| 0 | 76 | | Assert.AreEqual("0000000011000001100000000000000000000000000000000", GetChunkStatesAsString()); |
| 0 | 77 | | yield break; |
| | 78 | | } |
| | 79 | |
|
| | 80 | | [Test] |
| | 81 | | public void DisplayParcelOfInterestIconsProperly() |
| | 82 | | { |
| 1 | 83 | | var sceneInfo = new MinimapMetadata.MinimapSceneInfo(); |
| 1 | 84 | | sceneInfo.name = "important scene"; |
| 1 | 85 | | sceneInfo.isPOI = true; |
| 1 | 86 | | sceneInfo.parcels = new List<Vector2Int>() |
| | 87 | | { |
| | 88 | | new Vector2Int() { x = 0, y = 0 }, |
| | 89 | | new Vector2Int() { x = 0, y = 1 }, |
| | 90 | | new Vector2Int() { x = 1, y = 0 }, |
| | 91 | | new Vector2Int() { x = 1, y = 1 } |
| | 92 | | }; |
| | 93 | |
|
| 1 | 94 | | MinimapMetadata.GetMetadata().AddSceneInfo(sceneInfo); |
| | 95 | |
|
| 1 | 96 | | var sceneInfo2 = new MinimapMetadata.MinimapSceneInfo(); |
| 1 | 97 | | sceneInfo2.name = "non-important scene"; |
| 1 | 98 | | sceneInfo2.isPOI = false; |
| 1 | 99 | | sceneInfo2.parcels = new List<Vector2Int>() |
| | 100 | | { |
| | 101 | | new Vector2Int() { x = 5, y = 0 }, |
| | 102 | | }; |
| | 103 | |
|
| 1 | 104 | | MinimapMetadata.GetMetadata().AddSceneInfo(sceneInfo2); |
| | 105 | |
|
| 1 | 106 | | MapSceneIcon[] icons = MapRenderer.i.GetComponentsInChildren<MapSceneIcon>(); |
| | 107 | |
|
| 1 | 108 | | Assert.AreEqual(1, icons.Length, "Only 1 icon is marked as POI, but 2 icons were spawned"); |
| 1 | 109 | | Assert.AreEqual(sceneInfo.name, icons[0].title.text); |
| 1 | 110 | | Assert.AreEqual(new Vector3(3010, 3010, 0), icons[0].transform.localPosition); |
| 1 | 111 | | } |
| | 112 | |
|
| | 113 | | [UnityTest] |
| | 114 | | public IEnumerator DisplayAndUpdateUserIconProperly() |
| | 115 | | { |
| 1 | 116 | | Vector3 initialPosition = new Vector3(100, 0, 50); |
| 1 | 117 | | Vector3 modifiedPosition = new Vector3(150, 0, -30); |
| | 118 | |
|
| 1 | 119 | | var userInfo = new MinimapMetadata.MinimapUserInfo(); |
| 1 | 120 | | userInfo.userId = "testuser"; |
| 1 | 121 | | userInfo.worldPosition = initialPosition; |
| | 122 | |
|
| | 123 | | // Create an user icon |
| 1 | 124 | | MinimapMetadata.GetMetadata().AddOrUpdateUserInfo(userInfo); |
| | 125 | |
|
| 1 | 126 | | MapSceneIcon[] icons = MapRenderer.i.GetComponentsInChildren<MapSceneIcon>(); |
| | 127 | |
|
| 1 | 128 | | Assert.AreEqual(1, icons.Length, "There should be only 1 user icon"); |
| 1 | 129 | | Vector2 iconGridPosition = DCL.Helpers.Utils.WorldToGridPositionUnclamped(initialPosition); |
| 1 | 130 | | Assert.AreEqual(DCL.Helpers.MapUtils.GetTileToLocalPosition(iconGridPosition.x, iconGridPosition.y), icons[0 |
| | 131 | |
|
| | 132 | | // Modifify the position of the user icon |
| 1 | 133 | | userInfo.worldPosition = modifiedPosition; |
| | 134 | |
|
| 1 | 135 | | MinimapMetadata.GetMetadata().AddOrUpdateUserInfo(userInfo); |
| | 136 | |
|
| 1 | 137 | | icons = MapRenderer.i.GetComponentsInChildren<MapSceneIcon>(); |
| | 138 | |
|
| 1 | 139 | | Assert.AreEqual(1, icons.Length, "There should still be the same user icon"); |
| 1 | 140 | | iconGridPosition = DCL.Helpers.Utils.WorldToGridPositionUnclamped(modifiedPosition); |
| 1 | 141 | | Assert.AreEqual(DCL.Helpers.MapUtils.GetTileToLocalPosition(iconGridPosition.x, iconGridPosition.y), icons[0 |
| | 142 | |
|
| | 143 | | // Remove the user icon |
| 1 | 144 | | MinimapMetadata.GetMetadata().RemoveUserInfo(userInfo.userId); |
| | 145 | |
|
| 1 | 146 | | icons = MapRenderer.i.GetComponentsInChildren<MapSceneIcon>(); |
| | 147 | |
|
| 1 | 148 | | Assert.AreEqual(0, icons.Length, "There should not be any user icon"); |
| 1 | 149 | | yield break; |
| | 150 | | } |
| | 151 | |
|
| | 152 | | public string GetChunkStatesAsString() |
| | 153 | | { |
| 0 | 154 | | string result = ""; |
| 0 | 155 | | for (int x = 0; x < 7; x++) |
| | 156 | | { |
| 0 | 157 | | for (int y = 0; y < 7; y++) |
| | 158 | | { |
| 0 | 159 | | MapChunk chunk = MapRenderer.i.atlas.GetChunk(x, y); |
| | 160 | |
|
| 0 | 161 | | if (chunk == null) |
| 0 | 162 | | result += "-"; |
| 0 | 163 | | else if (chunk.targetImage.enabled) |
| 0 | 164 | | result += "1"; |
| | 165 | | else |
| 0 | 166 | | result += "0"; |
| | 167 | | } |
| | 168 | | } |
| | 169 | |
|
| 0 | 170 | | return result; |
| | 171 | | } |
| | 172 | | } |
| | 173 | | } |