< Summary

Class:DCL.Builder.BuilderInWorldBridge
Assembly:BIWBridge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldBridge/BuilderInWorldBridge.cs
Covered lines:70
Uncovered lines:37
Coverable lines:107
Total lines:248
Line coverage:65.4% (70 of 107)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BuilderInWorldBridge()0%110100%
Awake()0%110100%
SetScene(...)0%3.583060%
PublishSceneResult(...)0%20400%
AddAssets(...)0%2100%
RequestedHeaders(...)0%6200%
AskKernelForCatalogHeadersWithParams(...)0%2100%
UpdateSmartItemComponent(...)0%3.462028.57%
ChangeEntityLockStatus(...)0%220100%
ChangedEntityName(...)0%220100%
ChangeEntityComponent(...)0%2.152066.67%
AddEntityOnKernel(...)0%13.048057.14%
EntityTransformReport(...)0%110100%
RemoveEntityOnKernel(...)0%220100%
StartIsolatedMode(...)0%110100%
StopIsolatedMode()0%110100%
PublishScene(...)0%110100%
SendNewEntityToKernel(...)0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldBridge/BuilderInWorldBridge.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Controllers;
 5using DCL.Interface;
 6using DCL.Models;
 7using Newtonsoft.Json;
 8using System;
 9using System.Collections.Generic;
 10using DCL.Builder;
 11using UnityEngine;
 12using static ProtocolV2;
 13
 14namespace DCL.Builder
 15{
 16    /// <summary>
 17    /// This class will handle all the messages that will be sent to kernel.
 18    /// </summary>
 19    public class BuilderInWorldBridge : MonoBehaviour
 20    {
 21        //Note Adrian: OnKernelUpdated in not called in the update of the transform, since it will give a lot of
 22        //events and probably dont need to get called with that frecuency
 23        public event Action OnKernelUpdated;
 24        public event Action<bool, string> OnPublishEnd;
 25        public event Action<RequestHeader> OnHeadersReceived;
 26
 3827        private PublishPayload payload = new PublishPayload();
 3828        private EntitySingleComponentPayload entitySingleComponentPayload = new EntitySingleComponentPayload();
 29
 30        private IComponentSendHandler componentSendHandler;
 31
 32        private void Awake()
 33        {
 3834            componentSendHandler = new LegacyComponentSender();
 3835        }
 36
 37        public void SetScene(IBuilderScene builderScene)
 38        {
 139            switch (builderScene.sceneVersion)
 40            {
 41                case IBuilderScene.SceneVersion.LEGACY:
 142                    componentSendHandler = new LegacyComponentSender();
 143                    break;
 44                case IBuilderScene.SceneVersion.ECS:
 045                    componentSendHandler = new ECSComponentSenderHandler();
 46                    break;
 47            }
 048        }
 49
 50        #region MessagesFromKernel
 51
 52        public void PublishSceneResult(string payload)
 53        {
 054            PublishSceneResultPayload publishSceneResultPayload = JsonUtility.FromJson<PublishSceneResultPayload>(payloa
 55
 056            if (publishSceneResultPayload.ok)
 57            {
 058                OnPublishEnd?.Invoke(true, "");
 59
 060                AudioScriptableObjects.confirm.Play();
 061            }
 62            else
 63            {
 064                OnPublishEnd?.Invoke(false, publishSceneResultPayload.error);
 65
 066                AudioScriptableObjects.error.Play();
 67            }
 068        }
 69
 70        public void AddAssets(string payload)
 71        {
 72            //We remove the old assets to they don't collide with the new ones
 073            BIWUtils.RemoveAssetsFromCurrentScene();
 74
 075            AssetCatalogBridge.i.AddScenesObjectToSceneCatalog(payload);
 076        }
 77
 078        public void RequestedHeaders(string payload) { OnHeadersReceived?.Invoke(JsonConvert.DeserializeObject<RequestHe
 79
 80        #endregion
 81
 82        #region MessagesToKernel
 83
 084        public void AskKernelForCatalogHeadersWithParams(string method, string url) { WebInterface.SendRequestHeadersFor
 85
 86        public void UpdateSmartItemComponent(BIWEntity entity, IParcelScene scene)
 87        {
 188            if (scene.componentsManagerLegacy.TryGetBaseComponent(entity.rootEntity, CLASS_ID_COMPONENT.SMART_ITEM, out 
 189                return;
 90
 091            entitySingleComponentPayload.entityId = entity.rootEntity.entityId;
 092            entitySingleComponentPayload.componentId = (int) CLASS_ID_COMPONENT.SMART_ITEM;
 93
 094            entitySingleComponentPayload.data = ((SmartItemComponent)component).GetValues();
 95
 096            ChangeEntityComponent(entitySingleComponentPayload, scene);
 097        }
 98
 99        public void ChangeEntityLockStatus(BIWEntity entity, IParcelScene scene)
 100        {
 1101            entitySingleComponentPayload.entityId = entity.rootEntity.entityId;
 1102            entitySingleComponentPayload.componentId = (int) CLASS_ID.LOCKED_ON_EDIT;
 103
 1104            if (scene.componentsManagerLegacy.TryGetSharedComponent(entity.rootEntity, CLASS_ID.LOCKED_ON_EDIT, out ISha
 105            {
 1106                entitySingleComponentPayload.data = ((DCLLockedOnEdit) component).GetModel();
 107            }
 108
 1109            ChangeEntityComponent(entitySingleComponentPayload, scene);
 1110        }
 111
 112        public void ChangedEntityName(BIWEntity entity, IParcelScene scene)
 113        {
 1114            entitySingleComponentPayload.entityId = entity.rootEntity.entityId;
 1115            entitySingleComponentPayload.componentId = (int) CLASS_ID.NAME;
 116
 1117            if (scene.componentsManagerLegacy.TryGetSharedComponent(entity.rootEntity, CLASS_ID.NAME, out ISharedCompone
 118            {
 1119                entitySingleComponentPayload.data = ((DCLName) component).GetModel();
 120            }
 121
 1122            ChangeEntityComponent(entitySingleComponentPayload, scene);
 1123        }
 124
 125        void ChangeEntityComponent(EntitySingleComponentPayload payload, IParcelScene scene)
 126        {
 2127            componentSendHandler.ChangeEntityComponent(payload,scene);
 2128            OnKernelUpdated?.Invoke();
 0129        }
 130
 131        public void AddEntityOnKernel(IDCLEntity entity, IParcelScene scene)
 132        {
 1133            if (scene == null)
 0134                return;
 135
 1136            List<ComponentPayload> list = new List<ComponentPayload>();
 137
 4138            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in scene.componentsManagerLegacy.Ge
 139            {
 1140                ComponentPayload componentPayLoad = new ComponentPayload();
 1141                componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key);
 142
 1143                if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
 144                {
 1145                    TransformComponent entityComponentModel = new TransformComponent();
 146
 1147                    entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transf
 1148                    entityComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation);
 1149                    entityComponentModel.scale = entity.gameObject.transform.lossyScale;
 150
 1151                    componentPayLoad.data = entityComponentModel;
 1152                }
 153                else
 154                {
 0155                    componentPayLoad.data = keyValuePair.Value.GetModel();
 156                }
 157
 1158                list.Add(componentPayLoad);
 159            }
 160
 1161            using (var iterator = scene.componentsManagerLegacy.GetSharedComponents(entity))
 162            {
 1163                while (iterator.MoveNext())
 164                {
 0165                    ComponentPayload componentPayLoad = new ComponentPayload();
 166
 0167                    componentPayLoad.componentId = iterator.Current.GetClassId();
 168
 0169                    if (iterator.Current.GetClassId() == (int) CLASS_ID.NFT_SHAPE)
 170                    {
 0171                        NFTComponent nftComponent = new NFTComponent();
 0172                        NFTShape.Model model = (NFTShape.Model) iterator.Current.GetModel();
 173
 0174                        nftComponent.color = new ColorRepresentation(model.color);
 0175                        nftComponent.assetId = model.assetId;
 0176                        nftComponent.src = model.src;
 0177                        nftComponent.style = model.style;
 178
 0179                        componentPayLoad.data = nftComponent;
 0180                    }
 181                    else
 182                    {
 0183                        componentPayLoad.data = iterator.Current.GetModel();
 184                    }
 185
 0186                    list.Add(componentPayLoad);
 187                }
 1188            }
 189
 1190            SendNewEntityToKernel(scene.sceneData.id, entity.entityId, list.ToArray());
 1191        }
 192
 193        public void EntityTransformReport(IDCLEntity entity, IParcelScene scene)
 194        {
 1195           componentSendHandler.EntityTransformReport(entity,scene);
 1196        }
 197
 198        public void RemoveEntityOnKernel(long entityId, IParcelScene scene)
 199        {
 2200            componentSendHandler.RemoveEntityOnKernel(entityId,scene);
 2201            OnKernelUpdated?.Invoke();
 1202        }
 203
 204        public void StartIsolatedMode(ILand land)
 205        {
 6206            IsolatedConfig config = new IsolatedConfig();
 6207            config.mode = IsolatedMode.BUILDER;
 208
 6209            IsolatedBuilderConfig builderConfig = new IsolatedBuilderConfig();
 210
 6211            builderConfig.sceneId = land.sceneId;
 6212            builderConfig.recreateScene = true;
 6213            builderConfig.killPortableExperiences = true;
 6214            builderConfig.land = land;
 215
 6216            config.payload = builderConfig;
 6217            WebInterface.StartIsolatedMode(config);
 6218        }
 219
 220        public void StopIsolatedMode()
 221        {
 3222            IsolatedConfig config = new IsolatedConfig();
 3223            config.mode = IsolatedMode.BUILDER;
 3224            WebInterface.StopIsolatedMode(config);
 3225        }
 226
 227        public void PublishScene(Dictionary<string, object > filesToDecode, Dictionary<string, object > files, CatalystS
 228        {
 1229            payload.filesToDecode = filesToDecode;
 1230            payload.files = files;
 1231            payload.metadata = metadata;
 1232            payload.pointers = metadata.scene.parcels;
 1233            payload.statelessManifest = statelessManifest;
 1234            payload.reloadSingleScene = publishFromPanel;
 235
 1236            WebInterface.PublishStatefulScene(payload);
 1237        }
 238
 239        private void SendNewEntityToKernel(string sceneId, long entityId, ComponentPayload[] componentsPayload)
 240        {
 1241            componentSendHandler.SendNewEntityToKernel(sceneId,entityId,componentsPayload);
 1242            OnKernelUpdated?.Invoke();
 0243        }
 244
 245        #endregion
 246
 247    }
 248}