< Summary

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

Metrics

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

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
 027        private PublishPayload payload = new PublishPayload();
 028        private EntitySingleComponentPayload entitySingleComponentPayload = new EntitySingleComponentPayload();
 29
 30        private IComponentSendHandler componentSendHandler;
 31
 32        private void Awake()
 33        {
 034            componentSendHandler = new LegacyComponentSender();
 035        }
 36
 37        public void SetScene(IBuilderScene builderScene)
 38        {
 039            switch (builderScene.sceneVersion)
 40            {
 41                case IBuilderScene.SceneVersion.LEGACY:
 042                    componentSendHandler = new LegacyComponentSender();
 043                    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();
 61            }
 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        {
 088            if (scene.componentsManagerLegacy.TryGetBaseComponent(entity.rootEntity, CLASS_ID_COMPONENT.SMART_ITEM, out 
 089                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        {
 0101            entitySingleComponentPayload.entityId = entity.rootEntity.entityId;
 0102            entitySingleComponentPayload.componentId = (int) CLASS_ID.LOCKED_ON_EDIT;
 103
 0104            if (scene.componentsManagerLegacy.TryGetSharedComponent(entity.rootEntity, CLASS_ID.LOCKED_ON_EDIT, out ISha
 105            {
 0106                entitySingleComponentPayload.data = ((DCLLockedOnEdit) component).GetModel();
 107            }
 108
 0109            ChangeEntityComponent(entitySingleComponentPayload, scene);
 0110        }
 111
 112        public void ChangedEntityName(BIWEntity entity, IParcelScene scene)
 113        {
 0114            entitySingleComponentPayload.entityId = entity.rootEntity.entityId;
 0115            entitySingleComponentPayload.componentId = (int) CLASS_ID.NAME;
 116
 0117            if (scene.componentsManagerLegacy.TryGetSharedComponent(entity.rootEntity, CLASS_ID.NAME, out ISharedCompone
 118            {
 0119                entitySingleComponentPayload.data = ((DCLName) component).GetModel();
 120            }
 121
 0122            ChangeEntityComponent(entitySingleComponentPayload, scene);
 0123        }
 124
 125        void ChangeEntityComponent(EntitySingleComponentPayload payload, IParcelScene scene)
 126        {
 0127            componentSendHandler.ChangeEntityComponent(payload,scene);
 0128            OnKernelUpdated?.Invoke();
 0129        }
 130
 131        public void AddEntityOnKernel(IDCLEntity entity, IParcelScene scene)
 132        {
 0133            if (scene == null)
 0134                return;
 135
 0136            List<ComponentPayload> list = new List<ComponentPayload>();
 137
 0138            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in scene.componentsManagerLegacy.Ge
 139            {
 0140                ComponentPayload componentPayLoad = new ComponentPayload();
 0141                componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key);
 142
 0143                if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
 144                {
 0145                    TransformComponent entityComponentModel = new TransformComponent();
 146
 0147                    entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transf
 0148                    entityComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation);
 0149                    entityComponentModel.scale = entity.gameObject.transform.lossyScale;
 150
 0151                    componentPayLoad.data = entityComponentModel;
 152                }
 153                else
 154                {
 0155                    componentPayLoad.data = keyValuePair.Value.GetModel();
 156                }
 157
 0158                list.Add(componentPayLoad);
 159            }
 160
 0161            using (var iterator = scene.componentsManagerLegacy.GetSharedComponents(entity))
 162            {
 0163                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;
 180                    }
 181                    else
 182                    {
 0183                        componentPayLoad.data = iterator.Current.GetModel();
 184                    }
 185
 0186                    list.Add(componentPayLoad);
 187                }
 0188            }
 189
 0190            SendNewEntityToKernel(scene.sceneData.sceneNumber, entity.entityId, list.ToArray());
 0191        }
 192
 193        public void EntityTransformReport(IDCLEntity entity, IParcelScene scene)
 194        {
 0195           componentSendHandler.EntityTransformReport(entity,scene);
 0196        }
 197
 198        public void RemoveEntityOnKernel(long entityId, IParcelScene scene)
 199        {
 0200            componentSendHandler.RemoveEntityOnKernel(entityId,scene);
 0201            OnKernelUpdated?.Invoke();
 0202        }
 203
 204        public void StartIsolatedMode(ILand land)
 205        {
 0206            IsolatedConfig config = new IsolatedConfig();
 0207            config.mode = IsolatedMode.BUILDER;
 208
 0209            IsolatedBuilderConfig builderConfig = new IsolatedBuilderConfig();
 210
 211            // We don't use scene id in the client anymore
 212            // builderConfig.sceneId = land.sceneNumber;
 213
 0214            builderConfig.recreateScene = true;
 0215            builderConfig.killPortableExperiences = true;
 0216            builderConfig.land = land;
 217
 0218            config.payload = builderConfig;
 0219            WebInterface.StartIsolatedMode(config);
 0220        }
 221
 222        public void StopIsolatedMode()
 223        {
 0224            IsolatedConfig config = new IsolatedConfig();
 0225            config.mode = IsolatedMode.BUILDER;
 0226            WebInterface.StopIsolatedMode(config);
 0227        }
 228
 229        public void PublishScene(Dictionary<string, object > filesToDecode, Dictionary<string, object > files, CatalystS
 230        {
 0231            payload.filesToDecode = filesToDecode;
 0232            payload.files = files;
 0233            payload.metadata = metadata;
 0234            payload.pointers = metadata.scene.parcels;
 0235            payload.statelessManifest = statelessManifest;
 0236            payload.reloadSingleScene = publishFromPanel;
 237
 0238            WebInterface.PublishStatefulScene(payload);
 0239        }
 240
 241        private void SendNewEntityToKernel(int sceneNumber, long entityId, ComponentPayload[] componentsPayload)
 242        {
 0243            componentSendHandler.SendNewEntityToKernel(sceneNumber, entityId, componentsPayload);
 0244            OnKernelUpdated?.Invoke();
 0245        }
 246
 247        #endregion
 248
 249    }
 250}