< Summary

Class:ECSTransformUtils
Assembly:DCL.ECSComponents.Transform.Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Transform/Utils/ECSTransformUtils.cs
Covered lines:24
Uncovered lines:3
Coverable lines:27
Total lines:90
Line coverage:88.8% (24 of 27)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:6
Method coverage:83.3% (5 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OrphanEntity(...)0%110100%
TrySetParent(...)0%110100%
TrySetParent(...)0%330100%
IsCircularParenting(...)0%660100%
GetRootEntityTransform(...)0%110100%
IsInsideSceneBoundaries(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Transform/Utils/ECSTransformUtils.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Models;
 3using System.Linq;
 4using UnityEngine;
 5
 6public static class ECSTransformUtils
 7{
 8    public readonly struct OrphanEntity
 9    {
 10        public readonly IParcelScene scene;
 11        public readonly IDCLEntity entity;
 12        public readonly long parentId;
 13
 14        public OrphanEntity(IParcelScene scene, IDCLEntity entity, long parentId)
 15        {
 1216            this.scene = scene;
 1217            this.entity = entity;
 1218            this.parentId = parentId;
 1219        }
 20    }
 21
 22    public static KeyValueSet<IDCLEntity, OrphanEntity> orphanEntities = null;
 23
 24    public static bool TrySetParent(IParcelScene scene, IDCLEntity child, long parentId)
 25    {
 726        return TrySetParent(scene, child, parentId, out IDCLEntity parent);
 27    }
 28
 29    public static bool TrySetParent(IParcelScene scene, IDCLEntity child, long parentId, out IDCLEntity parent)
 30    {
 1331        if (parentId == SpecialEntityId.SCENE_ROOT_ENTITY)
 32        {
 933            child.gameObject.transform.SetParent(GetRootEntityTransform(scene), false);
 934            parent = null;
 935            return true;
 36        }
 37
 438        if (scene.entities.TryGetValue(parentId, out parent))
 39        {
 340            child.gameObject.transform.SetParent(parent.gameObject.transform, false);
 341            return true;
 42        }
 43
 144        return false;
 45    }
 46
 47    public static bool IsCircularParenting(IParcelScene scene, IDCLEntity entity, long parentId)
 48    {
 2049        if (parentId == SpecialEntityId.SCENE_ROOT_ENTITY)
 50        {
 451            return false;
 52        }
 53
 1654        if (parentId == entity.entityId)
 55        {
 156            return true;
 57        }
 58
 59        do
 60        {
 3261            if (!scene.entities.TryGetValue(parentId, out IDCLEntity parent))
 62                break;
 63
 2964            if (entity.entityId == parentId)
 65            {
 566                return true;
 67            }
 68
 2469            parentId = parent.parentId;
 70        }
 2471        while (parentId != SpecialEntityId.SCENE_ROOT_ENTITY);
 72
 1073        return false;
 74    }
 75
 76    public static Transform GetRootEntityTransform(IParcelScene scene)
 77    {
 978        return scene.GetSceneTransform();
 79    }
 80
 81    public static bool IsInsideSceneBoundaries(IParcelScene scene, Vector2Int position)
 82    {
 083        if (scene.isPersistent)
 84        {
 085            return true;
 86        }
 87
 088        return scene.sceneData.parcels.Contains(position);
 89    }
 90}