| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Configuration; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using Newtonsoft.Json; |
| | 7 | | using System.Collections; |
| | 8 | | using DCL.Controllers; |
| | 9 | | using UnityEngine; |
| | 10 | | using UnityEngine.Assertions; |
| | 11 | |
|
| | 12 | | public class IntegrationTestController : MonoBehaviour |
| | 13 | | { |
| 0 | 14 | | string entityId = "a5f571bd-bce1-4cf8-a158-b8f3e92e4fb0"; |
| 0 | 15 | | string sceneName = "the-loaded-scene"; |
| | 16 | |
|
| | 17 | | public IEnumerator Initialize() |
| | 18 | | { |
| 0 | 19 | | var sceneController = Environment.i.world.sceneController; |
| 0 | 20 | | DCLCharacterController.i.gravity = 0; |
| 0 | 21 | | DCLCharacterController.i.Teleport(JsonConvert.SerializeObject(new |
| | 22 | | { |
| | 23 | | x = 0f, |
| | 24 | | y = 0f, |
| | 25 | | z = 0f |
| | 26 | | })); |
| | 27 | |
|
| 0 | 28 | | var scenesToLoad = new LoadParcelScenesMessage.UnityParcelScene() |
| | 29 | | { |
| | 30 | | id = sceneName, |
| | 31 | | basePosition = new Vector2Int(3, 3), |
| | 32 | | parcels = new[] |
| | 33 | | { |
| | 34 | | new Vector2Int(3, 3), |
| | 35 | | new Vector2Int(3, 4) |
| | 36 | | }, |
| | 37 | | baseUrl = "http://localhost:9991/local-ipfs/contents/" |
| | 38 | | }; |
| | 39 | |
|
| 0 | 40 | | Assert.IsTrue(sceneController != null, "Cannot find SceneController"); |
| | 41 | |
|
| 0 | 42 | | sceneController.UnloadAllScenes(); |
| 0 | 43 | | sceneController.LoadParcelScenes(JsonConvert.SerializeObject(scenesToLoad)); |
| | 44 | |
|
| 0 | 45 | | yield return new WaitForAllMessagesProcessed(); |
| | 46 | |
|
| 0 | 47 | | ParcelScene scene = Environment.i.world.state.GetScene(sceneName) as ParcelScene; |
| | 48 | |
|
| | 49 | | //NOTE(Brian): This is making my eyes bleed. |
| 0 | 50 | | sceneController.SendSceneMessage( |
| | 51 | | TestHelpers.CreateSceneMessage( |
| | 52 | | sceneName, |
| | 53 | | entityId, |
| | 54 | | "CreateEntity", |
| | 55 | | JsonConvert.SerializeObject( |
| | 56 | | new Protocol.CreateEntity() |
| | 57 | | { |
| | 58 | | entityId = entityId |
| | 59 | | })) |
| | 60 | | ); |
| | 61 | |
|
| | 62 | | //NOTE(Brian): This is making my eyes bleed. (Zak): Twice |
| 0 | 63 | | sceneController.SendSceneMessage( |
| | 64 | | TestHelpers.CreateSceneMessage( |
| | 65 | | sceneName, |
| | 66 | | entityId, |
| | 67 | | "SetEntityParent", |
| | 68 | | JsonConvert.SerializeObject( |
| | 69 | | new |
| | 70 | | { |
| | 71 | | entityId = entityId, |
| | 72 | | parentId = "0" |
| | 73 | | }) |
| | 74 | | ) |
| | 75 | | ); |
| | 76 | |
|
| 0 | 77 | | yield return new WaitForAllMessagesProcessed(); |
| | 78 | |
|
| 0 | 79 | | Assert.IsTrue(scene.entities[entityId].meshRootGameObject == null, "meshGameObject must be null"); |
| | 80 | |
|
| | 81 | | // 1st message |
| 0 | 82 | | TestHelpers.CreateAndSetShape(scene as ParcelScene, entityId, CLASS_ID.BOX_SHAPE, "{}"); |
| | 83 | |
|
| | 84 | | { |
| 0 | 85 | | scene.EntityComponentCreateOrUpdate( |
| | 86 | | entityId, |
| | 87 | | CLASS_ID_COMPONENT.TRANSFORM, |
| | 88 | | "{\"tag\":\"transform\",\"position\":{\"x\":0,\"y\":0,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0,\"w |
| | 89 | | ); |
| | 90 | | } |
| | 91 | |
|
| | 92 | |
|
| | 93 | | // 2nd message |
| 0 | 94 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}"); |
| | 95 | | { |
| 0 | 96 | | scene.EntityComponentCreateOrUpdate( |
| | 97 | | entityId, |
| | 98 | | CLASS_ID_COMPONENT.TRANSFORM, |
| | 99 | | "{\"tag\":\"transform\",\"position\":{\"x\":6,\"y\":0,\"z\":5},\"rotation\":{\"x\":0,\"y\":0.39134957508 |
| | 100 | | ); |
| | 101 | | } |
| | 102 | |
|
| 0 | 103 | | TestHelpers.InstantiateEntityWithTextShape(scene, new Vector3(10, 10, 10), |
| | 104 | | new TextShape.Model() { value = "Hello World!!!" }); |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | public IEnumerator Verify() |
| | 108 | | { |
| 0 | 109 | | var scene = Environment.i.world.state.GetScene(sceneName) as ParcelScene; |
| 0 | 110 | | var cube = scene.entities[entityId]; |
| | 111 | |
|
| 0 | 112 | | Assert.IsTrue(cube != null); |
| 0 | 113 | | Vector3 cubePosition = new Vector3(6, 0, 5); |
| 0 | 114 | | Assert.AreEqual(cube.gameObject.transform.localPosition, cubePosition); |
| | 115 | |
|
| | 116 | | // because basePosition is at 3,3 |
| 0 | 117 | | Assert.AreEqual(cube.gameObject.transform.position, |
| | 118 | | new Vector3(3 * ParcelSettings.PARCEL_SIZE + cubePosition.x, cubePosition.y, |
| | 119 | | 3 * ParcelSettings.PARCEL_SIZE + cubePosition.z)); |
| 0 | 120 | | Assert.IsTrue(cube.meshRootGameObject != null); |
| 0 | 121 | | Assert.IsTrue(cube.meshRootGameObject.GetComponentInChildren<MeshFilter>() != null); |
| | 122 | |
|
| 0 | 123 | | var mesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh; |
| | 124 | |
|
| 0 | 125 | | Assert.AreEqual(mesh.name, "DCL Box Instance"); |
| | 126 | |
|
| | 127 | | { |
| | 128 | | // 3nd message, the box should remain the same, including references |
| 0 | 129 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}"); |
| | 130 | |
|
| 0 | 131 | | var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh; |
| | 132 | |
|
| 0 | 133 | | Assert.AreEqual(newMesh.name, "DCL Box Instance"); |
| 0 | 134 | | Assert.AreEqual(mesh.name, newMesh.name, "A new instance of the box was created"); |
| | 135 | | } |
| | 136 | |
|
| | 137 | | { |
| | 138 | | // 3nd message, the box should remain the same, including references |
| 0 | 139 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}"); |
| | 140 | |
|
| 0 | 141 | | var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh; |
| | 142 | |
|
| 0 | 143 | | Assert.AreEqual(newMesh.name, "DCL Box Instance"); |
| 0 | 144 | | Assert.AreEqual(mesh.name, newMesh.name, "A new instance of the box was created"); |
| | 145 | | } |
| | 146 | |
|
| | 147 | | { |
| | 148 | | // 4nd message, the box should be disposed and the new mesh should be a sphere |
| 0 | 149 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.SPHERE_SHAPE, |
| | 150 | | "{\"withCollisions\":false,\"billboard\":0,\"visible\":true,\"tag\":\"sphere\"}"); |
| | 151 | |
|
| 0 | 152 | | var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh; |
| | 153 | |
|
| 0 | 154 | | Assert.AreEqual(newMesh.name, "DCL Sphere Instance"); |
| 0 | 155 | | Assert.AreNotEqual(mesh.name, newMesh.name, |
| | 156 | | "The mesh instance remains the same, a new instance should have been created."); |
| | 157 | | } |
| | 158 | |
|
| | 159 | | // TODO: test ComponentRemoved |
| | 160 | |
|
| 0 | 161 | | yield return null; |
| 0 | 162 | | } |
| | 163 | | } |