< 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:28
Uncovered lines:1
Coverable lines:29
Total lines:91
Line coverage:96.5% (28 of 29)
Covered branches:0
Total branches:0

Metrics

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

File(s)

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

#LineLine coverage
 1using System.Linq;
 2using DCL.Controllers;
 3using DCL.Models;
 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    {
 1126        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    {
 1731        if (parentId == SpecialEntityId.SCENE_ROOT_ENTITY)
 32        {
 1333            child.gameObject.transform.SetParent(GetRootEntityTransform(scene), false);
 1334            parent = null;
 1335            return true;
 36        }
 437        if (parentId == SpecialEntityId.PLAYER_ENTITY)
 38        {
 039            parentId = SpecialEntityId.INTERNAL_PLAYER_ENTITY_REPRESENTATION;
 40        }
 41
 442        if (scene.entities.TryGetValue(parentId, out parent))
 43        {
 344            child.gameObject.transform.SetParent(parent.gameObject.transform, false);
 345            return true;
 46        }
 47
 148        return false;
 49    }
 50
 51    public static bool IsCircularParenting(IParcelScene scene, IDCLEntity entity, long parentId)
 52    {
 2053        if (parentId == SpecialEntityId.SCENE_ROOT_ENTITY)
 54        {
 455            return false;
 56        }
 57
 1658        if (parentId == entity.entityId)
 59        {
 160            return true;
 61        }
 62
 63        do
 64        {
 3265            if (!scene.entities.TryGetValue(parentId, out IDCLEntity parent))
 66                break;
 67
 2968            if (entity.entityId == parentId)
 69            {
 570                return true;
 71            }
 2472            parentId = parent.parentId;
 2473        } while (parentId != SpecialEntityId.SCENE_ROOT_ENTITY);
 74
 1075        return false;
 76    }
 77
 78    public static Transform GetRootEntityTransform(IParcelScene scene)
 79    {
 1380        return scene.GetSceneTransform();
 81    }
 82
 83    public static bool IsInsideSceneBoundaries(IParcelScene scene, Vector2Int position)
 84    {
 385        if (scene.isPersistent)
 86        {
 187            return true;
 88        }
 289        return scene.sceneData.parcels.Contains(position);
 90    }
 91}