| | 1 | | using DCL.Helpers; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEngine; |
| | 4 | | using NSubstitute; |
| | 5 | | using NFTShape_Internal; |
| | 6 | |
|
| | 7 | | // NOTE: NFTShapes meshes are rotated, so forward is actually backwards :S |
| | 8 | |
|
| | 9 | | public class NFTShapeHQImageHandlerShould |
| | 10 | | { |
| | 11 | | private INFTAsset asset; |
| | 12 | | private GameObject nftGO; |
| | 13 | | private NFTShapeHQImageHandler imageHandler; |
| | 14 | | private NFTShapeConfig nftShapeConfig; |
| | 15 | | private bool isHQAsset; |
| | 16 | | private Camera camera; |
| | 17 | |
|
| | 18 | | [SetUp] |
| | 19 | | protected void SetUp() |
| | 20 | | { |
| 4 | 21 | | isHQAsset = false; |
| 4 | 22 | | camera = new GameObject("Camera") { tag = "MainCamera" }.AddComponent<Camera>(); |
| | 23 | |
|
| 4 | 24 | | asset = Substitute.For<INFTAsset>(); |
| 8 | 25 | | asset.When(a => a.RestorePreviewAsset()) |
| | 26 | | .Do(i => |
| | 27 | | { |
| 4 | 28 | | isHQAsset = false; |
| 4 | 29 | | asset.isHQ.Returns(false); |
| 4 | 30 | | }); |
| 8 | 31 | | asset.WhenForAnyArgs(a => a.FetchAndSetHQAsset(null, null, null)) |
| | 32 | | .Do(i => |
| | 33 | | { |
| 4 | 34 | | isHQAsset = true; |
| 4 | 35 | | asset.isHQ.Returns(true); |
| 4 | 36 | | }); |
| | 37 | |
|
| 4 | 38 | | nftGO = new GameObject(); |
| 4 | 39 | | var nftController = NFTShapeFactory.InstantiateLoaderController(0).GetComponent<NFTShapeLoaderController>(); |
| 4 | 40 | | nftController.transform.SetParent(nftGO.transform); |
| 4 | 41 | | nftController.transform.ResetLocalTRS(); |
| | 42 | |
|
| 4 | 43 | | nftGO.transform.position = new Vector3(10, 0, 10); |
| 4 | 44 | | nftShapeConfig = nftController.config; |
| | 45 | |
|
| 4 | 46 | | var config = new NFTShapeHQImageConfig() |
| | 47 | | { |
| | 48 | | asset = asset, |
| | 49 | | controller = nftController, |
| | 50 | | nftConfig = nftShapeConfig |
| | 51 | | }; |
| 4 | 52 | | imageHandler = NFTShapeHQImageHandler.Create(config); |
| 4 | 53 | | } |
| | 54 | |
|
| | 55 | | [TearDown] |
| | 56 | | protected void TearDown() |
| | 57 | | { |
| 4 | 58 | | Object.Destroy(nftGO); |
| 4 | 59 | | Object.Destroy(camera.gameObject); |
| 4 | 60 | | } |
| | 61 | |
|
| | 62 | | [Test] |
| | 63 | | public void SetHQImageCorrectly() |
| | 64 | | { |
| 1 | 65 | | Assert.IsFalse(isHQAsset, "Shouldn't use HQ image"); |
| 1 | 66 | | SetInFrontAndLookingToNFT(); |
| 1 | 67 | | Assert.IsTrue(isHQAsset, "Should be using HQ image"); |
| 1 | 68 | | } |
| | 69 | |
|
| | 70 | | [Test] |
| | 71 | | public void SetPreviewImageWhenCameraIsBehind() |
| | 72 | | { |
| 1 | 73 | | SetInFrontAndLookingToNFT(); |
| 1 | 74 | | Assert.IsTrue(isHQAsset, "Should be using HQ image"); |
| 1 | 75 | | Camera.main.transform.position = |
| | 76 | | nftGO.transform.position + nftGO.transform.forward * nftShapeConfig.hqImgMinDistance; |
| 1 | 77 | | imageHandler.Update(); |
| 1 | 78 | | Assert.IsFalse(isHQAsset, "Shouldn't use HQ image"); |
| 1 | 79 | | } |
| | 80 | |
|
| | 81 | | [Test] |
| | 82 | | public void SetPreviewImageWhenCameraLookAway() |
| | 83 | | { |
| 1 | 84 | | SetInFrontAndLookingToNFT(); |
| 1 | 85 | | Assert.IsTrue(isHQAsset, "Should be using HQ image"); |
| 1 | 86 | | Camera.main.transform.forward = nftGO.transform.right; |
| 1 | 87 | | imageHandler.Update(); |
| 1 | 88 | | Assert.IsFalse(isHQAsset, "Shouldn't use HQ image"); |
| 1 | 89 | | } |
| | 90 | |
|
| | 91 | | [Test] |
| | 92 | | public void SetPreviewImageWhenPlayerMovesAway() |
| | 93 | | { |
| 1 | 94 | | SetInFrontAndLookingToNFT(); |
| 1 | 95 | | Assert.IsTrue(isHQAsset, "Should be using HQ image"); |
| 1 | 96 | | CommonScriptableObjects.playerUnityPosition |
| | 97 | | .Set(nftGO.transform.position - nftGO.transform.forward * (nftShapeConfig.hqImgMinDistanc |
| 1 | 98 | | Assert.IsFalse(isHQAsset, "Shouldn't use HQ image"); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | void SetInFrontAndLookingToNFT() |
| | 102 | | { |
| 4 | 103 | | CommonScriptableObjects.playerUnityPosition.Set(nftGO.transform.position - nftGO.transform.forward * nftShapeCon |
| 4 | 104 | | Camera.main.transform.position = CommonScriptableObjects.playerUnityPosition.Get(); |
| 4 | 105 | | Camera.main.transform.LookAt(nftGO.transform); |
| 4 | 106 | | imageHandler.Update(); |
| 4 | 107 | | } |
| | 108 | | } |