< Summary

Class:DCL.Components.UIContainerRect
Assembly:DCL.Components.UI
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIContainer/UIContainerRect.cs
Covered lines:18
Uncovered lines:21
Coverable lines:39
Total lines:93
Line coverage:46.1% (18 of 39)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:10
Method coverage:60% (6 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
GetDataFromPb(...)0%2401500%
UIContainerRect()0%110100%
GetClassId()0%2100%
AttachTo(...)0%2100%
DetachFrom(...)0%2100%
ApplyChanges(...)0%440100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIContainer/UIContainerRect.cs

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.Models;
 3using System.Collections;
 4using UnityEngine;
 5using UnityEngine.UI;
 6using Decentraland.Sdk.Ecs6;
 7using MainScripts.DCL.Components;
 8
 9namespace DCL.Components
 10{
 11    public class UIContainerRect : UIShape<UIContainerRectReferencesContainer, UIContainerRect.Model>
 12    {
 13        [System.Serializable]
 14        public new class Model : UIShape.Model
 15        {
 16            public float thickness;
 15717            public Color color = Color.clear;
 18
 19            public override BaseModel GetDataFromJSON(string json) =>
 6120                Utils.SafeFromJson<Model>(json);
 21
 22            public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel)
 23            {
 024                if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.UiContainerRect)
 025                    return Utils.SafeUnimplemented<UIContainerRect, Model>(expected: ComponentBodyPayload.PayloadOneofCa
 26
 027                var pb = new Model();
 028                if (pbModel.UiContainerRect.HasName) pb.name = pbModel.UiContainerRect.Name;
 029                if (pbModel.UiContainerRect.HasParentComponent) pb.parentComponent = pbModel.UiContainerRect.ParentCompo
 030                if (pbModel.UiContainerRect.HasVisible) pb.visible = pbModel.UiContainerRect.Visible;
 031                if (pbModel.UiContainerRect.HasOpacity) pb.opacity = pbModel.UiContainerRect.Opacity;
 032                if (pbModel.UiContainerRect.HasHAlign) pb.hAlign = pbModel.UiContainerRect.HAlign;
 033                if (pbModel.UiContainerRect.HasVAlign) pb.vAlign = pbModel.UiContainerRect.VAlign;
 034                if (pbModel.UiContainerRect.Width != null) pb.width = SDK6DataMapExtensions.FromProtobuf(pb.width, pbMod
 035                if (pbModel.UiContainerRect.Height != null) pb.height = SDK6DataMapExtensions.FromProtobuf(pb.height, pb
 036                if (pbModel.UiContainerRect.PositionX != null) pb.positionX = SDK6DataMapExtensions.FromProtobuf(pb.posi
 037                if (pbModel.UiContainerRect.PositionY != null) pb.positionY = SDK6DataMapExtensions.FromProtobuf(pb.posi
 038                if (pbModel.UiContainerRect.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.UiContainerRect.IsPointer
 39
 040                if (pbModel.UiContainerRect.Color != null) pb.color = pbModel.UiContainerRect.Color.AsUnityColor();
 041                if (pbModel.UiContainerRect.HasThickness) pb.thickness = pbModel.UiContainerRect.Thickness;
 42
 043                return pb;
 44            }
 45        }
 46
 3347        public override string referencesContainerPrefabName => "UIContainerRect";
 48
 9949        public UIContainerRect() { model = new Model(); }
 50
 051        public override int GetClassId() { return (int) CLASS_ID.UI_CONTAINER_RECT; }
 52
 53        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 54        {
 055            Debug.LogError(
 56                "Aborted UIContainerRectShape attachment to an entity. UIShapes shouldn't be attached to entities.");
 057        }
 58
 059        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { }
 60
 61        public override IEnumerator ApplyChanges(BaseModel newModel)
 62        {
 6263            referencesContainer.image.color = new Color(model.color.r, model.color.g, model.color.b, model.color.a);
 6264            referencesContainer.image.raycastTarget = model.color.a >= RAYCAST_ALPHA_THRESHOLD;
 65
 6266            Outline outline = referencesContainer.image.GetComponent<Outline>();
 67
 6268            if (model.thickness > 0f)
 69            {
 370                if (outline == null)
 71                {
 372                    outline = referencesContainer.image.gameObject.AddComponent<Outline>();
 73                }
 74
 375                outline.effectDistance = new Vector2(model.thickness, model.thickness);
 76            }
 5977            else if (outline != null)
 78            {
 179                Object.DestroyImmediate(outline, false);
 80            }
 81
 6282            return null;
 83        }
 84
 85        public override void Dispose()
 86        {
 187            if (referencesContainer != null)
 188                Utils.SafeDestroy(referencesContainer.gameObject);
 89
 190            base.Dispose();
 191        }
 92    }
 93}