| | 1 | | using DCL; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using Tests; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | |
|
| | 11 | | public class BIWActionsShould : IntegrationTestSuite_Legacy |
| | 12 | | { |
| | 13 | | private const string ENTITY_ID = "1"; |
| | 14 | | private BuilderInWorldController controller; |
| | 15 | | private ActionController actionController; |
| | 16 | | private BuilderInWorldEntityHandler entityHandler; |
| | 17 | | private BIWFloorHandler biwFloorHandler; |
| | 18 | | private BIWCreatorController biwCreatorController; |
| | 19 | |
|
| | 20 | | protected override IEnumerator SetUp() |
| | 21 | | { |
| 5 | 22 | | yield return base.SetUp(); |
| 5 | 23 | | controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0]; |
| 5 | 24 | | actionController = controller.actionController; |
| 5 | 25 | | entityHandler = controller.builderInWorldEntityHandler; |
| 5 | 26 | | biwFloorHandler = controller.biwFloorHandler; |
| 5 | 27 | | biwCreatorController = controller.biwCreatorController; |
| 5 | 28 | | entityHandler.Init(); |
| | 29 | |
|
| 5 | 30 | | TestHelpers.CreateSceneEntity(scene, ENTITY_ID); |
| 5 | 31 | | entityHandler.EnterEditMode(scene); |
| 5 | 32 | | } |
| | 33 | |
|
| | 34 | | [Test] |
| | 35 | | public void UndoRedoMoveAction() |
| | 36 | | { |
| 1 | 37 | | BuildInWorldCompleteAction buildModeAction = new BuildInWorldCompleteAction(); |
| | 38 | |
|
| 1 | 39 | | Vector3 oldPosition = scene.entities[ENTITY_ID].gameObject.transform.position; |
| 1 | 40 | | Vector3 newPosition = new Vector3(5, 5, 5); |
| | 41 | |
|
| 1 | 42 | | BuilderInWorldEntityAction entityAction = new BuilderInWorldEntityAction(ENTITY_ID); |
| 1 | 43 | | entityAction.oldValue = oldPosition; |
| 1 | 44 | | entityAction.newValue = newPosition; |
| | 45 | |
|
| 1 | 46 | | buildModeAction.CreateActionType(entityAction, BuildInWorldCompleteAction.ActionType.MOVE); |
| | 47 | |
|
| 1 | 48 | | scene.entities[ENTITY_ID].gameObject.transform.position = newPosition; |
| 1 | 49 | | actionController.AddAction(buildModeAction); |
| | 50 | |
|
| 1 | 51 | | actionController.TryToUndoAction(); |
| 1 | 52 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.position == oldPosition); |
| | 53 | |
|
| 1 | 54 | | actionController.TryToRedoAction(); |
| 1 | 55 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.position == newPosition); |
| 1 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void UndoRedoRotateAction() |
| | 60 | | { |
| 1 | 61 | | BuildInWorldCompleteAction buildModeAction = new BuildInWorldCompleteAction(); |
| | 62 | |
|
| 1 | 63 | | Vector3 oldRotation = scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles; |
| 1 | 64 | | Vector3 newRotation = new Vector3(5, 5, 5); |
| | 65 | |
|
| 1 | 66 | | BuilderInWorldEntityAction entityAction = new BuilderInWorldEntityAction(ENTITY_ID); |
| 1 | 67 | | entityAction.oldValue = oldRotation; |
| 1 | 68 | | entityAction.newValue = newRotation; |
| | 69 | |
|
| 1 | 70 | | buildModeAction.CreateActionType(entityAction, BuildInWorldCompleteAction.ActionType.ROTATE); |
| | 71 | |
|
| 1 | 72 | | scene.entities[ENTITY_ID].gameObject.transform.rotation = Quaternion.Euler(newRotation); |
| 1 | 73 | | actionController.AddAction(buildModeAction); |
| | 74 | |
|
| 1 | 75 | | actionController.TryToUndoAction(); |
| 1 | 76 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles == oldRotation); |
| | 77 | |
|
| 1 | 78 | | actionController.TryToRedoAction(); |
| 1 | 79 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles == newRotation); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | [Test] |
| | 83 | | public void UndoRedoScaleAction() |
| | 84 | | { |
| 1 | 85 | | BuildInWorldCompleteAction buildModeAction = new BuildInWorldCompleteAction(); |
| | 86 | |
|
| 1 | 87 | | Vector3 oldScale = scene.entities[ENTITY_ID].gameObject.transform.localScale; |
| 1 | 88 | | Vector3 newScale = new Vector3(5, 5, 5); |
| | 89 | |
|
| 1 | 90 | | BuilderInWorldEntityAction entityAction = new BuilderInWorldEntityAction(ENTITY_ID); |
| 1 | 91 | | entityAction.oldValue = oldScale; |
| 1 | 92 | | entityAction.newValue = newScale; |
| | 93 | |
|
| 1 | 94 | | buildModeAction.CreateActionType(entityAction, BuildInWorldCompleteAction.ActionType.SCALE); |
| | 95 | |
|
| 1 | 96 | | scene.entities[ENTITY_ID].gameObject.transform.localScale = newScale; |
| 1 | 97 | | actionController.AddAction(buildModeAction); |
| | 98 | |
|
| 1 | 99 | | actionController.TryToUndoAction(); |
| 1 | 100 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.localScale == oldScale); |
| | 101 | |
|
| 1 | 102 | | actionController.TryToRedoAction(); |
| 1 | 103 | | Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.localScale == newScale); |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | [Test] |
| | 107 | | public void UndoRedoCreateDeleteActions() |
| | 108 | | { |
| 1 | 109 | | actionController.CreateActionEntityCreated(scene.entities[ENTITY_ID]); |
| 1 | 110 | | actionController.TryToUndoAction(); |
| 1 | 111 | | Assert.IsFalse(scene.entities.ContainsKey(ENTITY_ID)); |
| | 112 | |
|
| 1 | 113 | | actionController.TryToRedoAction(); |
| 1 | 114 | | Assert.IsTrue(scene.entities.ContainsKey(ENTITY_ID)); |
| | 115 | |
|
| 1 | 116 | | DCLBuilderInWorldEntity biwEntity = Utils.GetOrCreateComponent<DCLBuilderInWorldEntity>(scene.entities[ENTITY_ID |
| 1 | 117 | | biwEntity.Init(scene.entities[ENTITY_ID], null); |
| | 118 | |
|
| 1 | 119 | | actionController.CreateActionEntityDeleted(biwEntity); |
| 1 | 120 | | actionController.TryToUndoAction(); |
| 1 | 121 | | Assert.IsTrue(scene.entities.ContainsKey(ENTITY_ID)); |
| | 122 | |
|
| 1 | 123 | | actionController.TryToRedoAction(); |
| 1 | 124 | | Assert.IsFalse(scene.entities.ContainsKey(ENTITY_ID)); |
| 1 | 125 | | } |
| | 126 | |
|
| | 127 | | [Test] |
| | 128 | | public void UndoRedoChangeFloorAction() |
| | 129 | | { |
| 1 | 130 | | BIWCatalogManager.Init(); |
| | 131 | |
|
| 1 | 132 | | BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects(); |
| | 133 | |
|
| 1 | 134 | | CatalogItem oldFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| 1 | 135 | | CatalogItem newFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[1]; |
| 1 | 136 | | BuildInWorldCompleteAction buildModeAction = new BuildInWorldCompleteAction(); |
| | 137 | |
|
| 1 | 138 | | controller.InitGameObjects(); |
| 1 | 139 | | controller.FindSceneToEdit(); |
| 1 | 140 | | controller.InitControllers(); |
| | 141 | |
|
| 1 | 142 | | biwCreatorController.EnterEditMode(scene); |
| 1 | 143 | | biwFloorHandler.EnterEditMode(scene); |
| | 144 | |
|
| 1 | 145 | | biwFloorHandler.CreateFloor(oldFloor); |
| 1 | 146 | | biwFloorHandler.ChangeFloor(newFloor); |
| | 147 | |
|
| 1 | 148 | | buildModeAction.CreateChangeFloorAction(oldFloor, newFloor); |
| 1 | 149 | | actionController.AddAction(buildModeAction); |
| | 150 | |
|
| 5 | 151 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 152 | | { |
| 2 | 153 | | if (entity.isFloor) |
| | 154 | | { |
| 1 | 155 | | Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id); |
| 1 | 156 | | break; |
| | 157 | | } |
| | 158 | | } |
| | 159 | |
|
| 1 | 160 | | actionController.TryToUndoAction(); |
| | 161 | |
|
| 5 | 162 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 163 | | { |
| 2 | 164 | | if (entity.isFloor) |
| | 165 | | { |
| 1 | 166 | | Assert.AreEqual(entity.GetCatalogItemAssociated().id, oldFloor.id); |
| | 167 | |
|
| 1 | 168 | | break; |
| | 169 | | } |
| | 170 | | } |
| | 171 | |
|
| 1 | 172 | | actionController.TryToRedoAction(); |
| | 173 | |
|
| 5 | 174 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 175 | | { |
| 2 | 176 | | if (entity.isFloor) |
| | 177 | | { |
| 1 | 178 | | Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id); |
| 1 | 179 | | break; |
| | 180 | | } |
| | 181 | | } |
| 1 | 182 | | } |
| | 183 | |
|
| | 184 | | protected override IEnumerator TearDown() |
| | 185 | | { |
| 5 | 186 | | BIWCatalogManager.ClearCatalog(); |
| 5 | 187 | | BuilderInWorldNFTController.i.ClearNFTs(); |
| 5 | 188 | | controller.CleanItems(); |
| 5 | 189 | | actionController.Clear(); |
| 5 | 190 | | yield return base.TearDown(); |
| 5 | 191 | | } |
| | 192 | | } |