< Summary

Class:Builder.DCLBuilderWebInterface
Assembly:Builder
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Builder/Scripts/DCLBuilderWebInterface.cs
Covered lines:22
Uncovered lines:37
Coverable lines:59
Total lines:145
Line coverage:37.2% (22 of 59)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DCLBuilderWebInterface()0%110100%
BuilderSceneStartEvent()0%2100%
TransformPayload()0%2100%
GizmosEventPayload()0%110100%
SendEntityStartLoad(...)0%2.012085.71%
SendEntityFinishLoad(...)0%2.012085.71%
SendEntitiesOutOfBoundaries(...)0%6200%
SendBuilderSceneStart(...)0%2.062075%
SendCameraTargetPosition(...)0%6200%
SendEntitySelected(...)0%42600%
SendEntitiesTransform(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Builder/Scripts/DCLBuilderWebInterface.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3using DCL.Interface;
 4using DCL.Components;
 5using DCL.Models;
 6
 7namespace Builder
 8{
 9    public class DCLBuilderWebInterface
 10    {
 111        static bool LOG_MESSAGES = false;
 12
 13        [System.Serializable]
 14        private class EntityLoadingPayload
 15        {
 16            public string type;
 17            public string entityId;
 18        };
 19
 20        [System.Serializable]
 21        private class OnEntityLoadingEvent : DCL.Interface.WebInterface.UUIDEvent<EntityLoadingPayload> { };
 22
 23        [System.Serializable]
 24        private class EntitiesOutOfBoundariesEventPayload
 25        {
 26            public string[] entities;
 27        };
 28
 29        [System.Serializable]
 30        public class BuilderSceneStartEvent
 31        {
 32            public string sceneId;
 033            public string eventType = "builderSceneStart";
 34        };
 35
 36        [System.Serializable]
 37        private class ReportCameraTargetPosition
 38        {
 39            public Vector3 cameraTarget;
 40            public string id;
 41        };
 42
 43        [System.Serializable]
 44        private class GizmosEventPayload
 45        {
 46            [System.Serializable]
 47            public class TransformPayload
 48            {
 049                public string entityId = string.Empty;
 050                public Vector3 position = Vector3.zero;
 051                public Quaternion rotation = Quaternion.identity;
 052                public Vector3 scale = Vector3.one;
 53            }
 54
 55            public string[] entities = null;
 56            public TransformPayload[] transforms = null;
 157            public string gizmoType = DCLGizmos.Gizmo.NONE;
 158            public string type = string.Empty;
 59        };
 60
 161        private static OnEntityLoadingEvent onGetLoadingEntity = new OnEntityLoadingEvent();
 162        private static EntitiesOutOfBoundariesEventPayload outOfBoundariesEventPayload = new EntitiesOutOfBoundariesEven
 163        private static ReportCameraTargetPosition onReportCameraTarget = new ReportCameraTargetPosition();
 164        private static GizmosEventPayload onGizmoEventPayload = new GizmosEventPayload();
 65
 66        public void SendEntityStartLoad(IDCLEntity entity)
 67        {
 168            onGetLoadingEntity.uuid = entity.entityId;
 169            onGetLoadingEntity.payload.entityId = entity.entityId;
 170            onGetLoadingEntity.payload.type = "onEntityLoading";
 171            if (LOG_MESSAGES)
 072                Debug.Log($"SEND: OnEntityLoadingEvent {entity.entityId}");
 173            WebInterface.SendSceneEvent(entity.scene.sceneData.id, "uuidEvent", onGetLoadingEntity);
 174        }
 75
 76        public void SendEntityFinishLoad(IDCLEntity entity)
 77        {
 178            onGetLoadingEntity.uuid = entity.entityId;
 179            onGetLoadingEntity.payload.entityId = entity.entityId;
 180            onGetLoadingEntity.payload.type = "onEntityFinishLoading";
 181            if (LOG_MESSAGES)
 082                Debug.Log($"SEND: onEntityFinishLoading {entity.entityId}");
 183            WebInterface.SendSceneEvent(entity.scene.sceneData.id, "uuidEvent", onGetLoadingEntity);
 184        }
 85
 86        public void SendEntitiesOutOfBoundaries(string[] entitiesId, string sceneId)
 87        {
 088            outOfBoundariesEventPayload.entities = entitiesId;
 089            if (LOG_MESSAGES)
 090                Debug.Log($"SEND: entitiesOutOfBoundaries {outOfBoundariesEventPayload.entities.Length}");
 091            WebInterface.SendSceneEvent<EntitiesOutOfBoundariesEventPayload>(sceneId, "entitiesOutOfBoundaries", outOfBo
 092        }
 93
 94        public void SendBuilderSceneStart(string sceneId)
 95        {
 196            if (LOG_MESSAGES)
 097                Debug.Log($"SEND: BuilderSceneStartEvent {sceneId}");
 198            WebInterface.SendMessage("SceneEvent", new BuilderSceneStartEvent() { sceneId = sceneId });
 199        }
 100
 101        public void SendCameraTargetPosition(Vector3 targetPosition, string promiseId)
 102        {
 0103            onReportCameraTarget.cameraTarget = targetPosition;
 0104            onReportCameraTarget.id = promiseId;
 0105            if (LOG_MESSAGES)
 0106                Debug.Log($"SEND: ReportBuilderCameraTarget {targetPosition}");
 0107            WebInterface.SendMessage("ReportBuilderCameraTarget", onReportCameraTarget);
 0108        }
 109
 110        public void SendEntitySelected(EditableEntity entity, string gizmoType, string sceneId)
 111        {
 0112            onGizmoEventPayload.type = "gizmoSelected";
 0113            onGizmoEventPayload.entities = entity ? new string[] { entity.rootEntity.entityId } : null;
 0114            onGizmoEventPayload.gizmoType = gizmoType != null ? gizmoType : DCLGizmos.Gizmo.NONE;
 0115            onGizmoEventPayload.transforms = null;
 116
 0117            if (LOG_MESSAGES)
 0118                Debug.Log($"SEND: NotifyGizmosSelectedEvent {JsonUtility.ToJson(onGizmoEventPayload)}");
 0119            WebInterface.SendSceneEvent(sceneId, "gizmoEvent", onGizmoEventPayload);
 0120        }
 121
 122        public void SendEntitiesTransform(List<EditableEntity> entities, string gizmoType, string sceneId)
 123        {
 0124            onGizmoEventPayload.type = "gizmoDragEnded";
 0125            onGizmoEventPayload.entities = null;
 0126            onGizmoEventPayload.gizmoType = gizmoType != null ? gizmoType : DCLGizmos.Gizmo.NONE;
 0127            onGizmoEventPayload.transforms = new GizmosEventPayload.TransformPayload[entities.Count];
 128
 0129            for (int i = 0; i < entities.Count; i++)
 130            {
 0131                onGizmoEventPayload.transforms[i] = new GizmosEventPayload.TransformPayload()
 132                {
 133                    entityId = entities[i].rootEntity.entityId,
 134                    position = entities[i].transform.position,
 135                    rotation = entities[i].transform.rotation,
 136                    scale = entities[i].transform.lossyScale
 137                };
 138            }
 139
 0140            if (LOG_MESSAGES)
 0141                Debug.Log($"SEND: NotifyGizmosTransformEvent {JsonUtility.ToJson(onGizmoEventPayload)}");
 0142            WebInterface.SendSceneEvent(sceneId, "gizmoEvent", onGizmoEventPayload);
 0143        }
 144    }
 145}