< Summary

Class:DCL.Backpack.OutfitsSectionComponentView
Assembly:BackpackEditorHUDV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/Outfits/OutfitsSectionComponentView.cs
Covered lines:0
Uncovered lines:61
Coverable lines:61
Total lines:151
Line coverage:0% (0 of 61)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:12
Method coverage:0% (0 of 12)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%30500%
CompleteDiscardOutfit()0%6200%
RefreshControl()0%2100%
DiscardOutfit(...)0%2100%
Initialize(...)0%2100%
ShowOutfit()0%42600%
SetSlotsAsLoading(...)0%12300%
OnEquipOutfit(...)0%6200%
OnSaveOutfit(...)0%20400%
SetIsGuest(...)0%2100%
SaveAnimation(...)0%2100%
DeleteAnimation(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/Outfits/OutfitsSectionComponentView.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DG.Tweening;
 3using MainScripts.DCL.Controllers.HUD.CharacterPreview;
 4using System;
 5using System.Threading;
 6using UnityEngine;
 7using UnityEngine.UI;
 8
 9namespace DCL.Backpack
 10{
 11    public class OutfitsSectionComponentView : BaseComponentView, IOutfitsSectionComponentView
 12    {
 13        [SerializeField] internal Button backButton;
 14        [SerializeField] internal OutfitComponentView[] outfitComponentViews;
 15        [SerializeField] private RawImage avatarPreviewImage;
 16        [SerializeField] private GameObject discardOutfitModal;
 17        [SerializeField] private Button confirmDiscardOutfit;
 18        [SerializeField] private Button cancelDiscardOutfit;
 19        [SerializeField] private Button closeDiscardOutfit;
 20
 21        private ICharacterPreviewController characterPreviewController;
 22        private bool isGuest;
 23
 24        public event Action OnBackButtonPressed;
 25        public event Action<OutfitItem> OnOutfitEquipped;
 26        public event Action<int> OnOutfitDiscarded;
 27        public event Action<int> OnOutfitLocalSave;
 28        public event Action OnTrySaveAsGuest;
 29
 30        private int indexToBeDiscarded;
 31
 32        public override void Awake()
 33        {
 034            base.Awake();
 35
 036            backButton.onClick.RemoveAllListeners();
 037            backButton.onClick.AddListener(() => OnBackButtonPressed?.Invoke());
 38
 039            foreach (OutfitComponentView outfitComponentView in outfitComponentViews)
 40            {
 041                outfitComponentView.OnEquipOutfit += OnEquipOutfit;
 042                outfitComponentView.OnSaveOutfit += OnSaveOutfit;
 043                outfitComponentView.OnDiscardOutfit += DiscardOutfit;
 44            }
 45
 046            if (confirmDiscardOutfit != null)
 47            {
 048                confirmDiscardOutfit.onClick.RemoveAllListeners();
 049                confirmDiscardOutfit.onClick.AddListener(CompleteDiscardOutfit);
 50            }
 51
 052            if (cancelDiscardOutfit != null)
 53            {
 054                cancelDiscardOutfit.onClick.RemoveAllListeners();
 055                cancelDiscardOutfit.onClick.AddListener(() => discardOutfitModal.SetActive(false));
 56            }
 57
 058            if (closeDiscardOutfit != null)
 59            {
 060                closeDiscardOutfit.onClick.RemoveAllListeners();
 061                closeDiscardOutfit.onClick.AddListener(() => discardOutfitModal.SetActive(false));
 62            }
 063        }
 64
 65        private void CompleteDiscardOutfit()
 66        {
 067            outfitComponentViews[indexToBeDiscarded].SetIsEmpty(true);
 068            OnOutfitDiscarded?.Invoke(indexToBeDiscarded);
 069            DeleteAnimation(outfitComponentViews[indexToBeDiscarded].transform);
 070            discardOutfitModal.SetActive(false);
 071        }
 72
 073        public override void RefreshControl() { }
 74
 75        private void DiscardOutfit(int outfitIndex)
 76        {
 077            indexToBeDiscarded = outfitIndex;
 078            discardOutfitModal.SetActive(true);
 079        }
 80
 81        public void Initialize(ICharacterPreviewFactory characterPreviewFactory)
 82        {
 083            characterPreviewController = characterPreviewFactory.Create(
 84                loadingMode: CharacterPreviewMode.WithoutHologram,
 85                renderTexture: (RenderTexture)avatarPreviewImage.texture,
 86                isVisible: false,
 87                previewCameraFocus: PreviewCameraFocus.DefaultEditing,
 88                isAvatarShadowActive: true);
 89
 090            characterPreviewController.SetFocus(PreviewCameraFocus.BodySnapshot);
 091        }
 92
 93        public async UniTask<bool> ShowOutfit(OutfitItem outfit, AvatarModel newModel, CancellationToken ct)
 94        {
 095            if (string.IsNullOrEmpty(outfit.outfit.bodyShape))
 096                return false;
 97
 098            characterPreviewController.SetEnabled(true);
 099            outfitComponentViews[outfit.slot].SetIsEmpty(false);
 0100            outfitComponentViews[outfit.slot].SetOutfit(outfit);
 0101            await characterPreviewController.TryUpdateModelAsync(newModel, ct);
 0102            Texture2D bodySnapshot = await characterPreviewController.TakeBodySnapshotAsync();
 0103            AudioScriptableObjects.listItemAppear.Play(true);
 0104            outfitComponentViews[outfit.slot].SetOutfitPreviewImage(bodySnapshot);
 0105            outfitComponentViews[outfit.slot].SetIsLoading(false);
 0106            characterPreviewController.SetEnabled(false);
 0107            return true;
 0108        }
 109
 110        public void SetSlotsAsLoading(OutfitItem[] outfitsToShow)
 111        {
 0112            foreach (var outfitItem in outfitsToShow)
 113            {
 0114                if (string.IsNullOrEmpty(outfitItem.outfit.bodyShape))
 115                {
 0116                    outfitComponentViews[outfitItem.slot].SetIsLoading(false);
 0117                    outfitComponentViews[outfitItem.slot].SetIsEmpty(true);
 118                }
 0119                else { outfitComponentViews[outfitItem.slot].SetIsLoading(true); }
 120            }
 0121        }
 122
 123        private void OnEquipOutfit(OutfitItem outfitItem) =>
 0124            OnOutfitEquipped?.Invoke(outfitItem);
 125
 126        private void OnSaveOutfit(int outfitIndex)
 127        {
 0128            if (isGuest)
 129            {
 0130                OnTrySaveAsGuest?.Invoke();
 0131                return;
 132            }
 133
 0134            outfitComponentViews[outfitIndex].SetIsLoading(true);
 0135            outfitComponentViews[outfitIndex].SetIsEmpty(false);
 0136            OnOutfitLocalSave?.Invoke(outfitIndex);
 0137            SaveAnimation(outfitComponentViews[outfitIndex].transform);
 0138        }
 139
 140        public void SetIsGuest(bool guest)
 141        {
 0142            this.isGuest = guest;
 0143        }
 144
 145        private void SaveAnimation(Transform transformToAnimate) =>
 0146            transformToAnimate.DOJump(transformToAnimate.position, 20, 1, 0.6f);
 147
 148        private void DeleteAnimation(Transform transformToAnimate) =>
 0149            transformToAnimate.DOPunchPosition(new Vector3(5, 2, 1), 0.6f);
 150    }
 151}