< Summary

Class:EntityInformationController
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/EntityInformationController.cs
Covered lines:90
Uncovered lines:18
Coverable lines:108
Total lines:242
Line coverage:83.3% (90 of 108)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%4.24076.92%
Dispose()0%5.255078.57%
PositionChanged(...)0%220100%
RotationChanged(...)0%330100%
ScaleChanged(...)0%220100%
NameChanged(...)0%220100%
ToggleDetailsInfo()0%110100%
ToggleBasicInfo()0%110100%
StartChangingName()0%2100%
EndChangingName()0%2100%
SetEntity(...)0%3.13077.78%
GetThumbnail(...)0%3.013091.67%
SetThumbnail(...)0%110100%
UpdateEntityName(...)0%330100%
UpdateLimitsInformation(...)0%220100%
Enable()0%110100%
Disable()0%220100%
EntityDeselected()0%9.834028.57%
UpdateInfo(...)0%330100%
UpdateEntitiesSelection(...)0%110100%
SetTransparencyMode(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/EntityInformationController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Models;
 5using System;
 6using UnityEngine;
 7
 8public interface IEntityInformationController
 9{
 10    event Action<Vector3> OnPositionChange;
 11    event Action<Vector3> OnRotationChange;
 12    event Action<Vector3> OnScaleChange;
 13    event Action<BIWEntity, string> OnNameChange;
 14    event Action<BIWEntity> OnSmartItemComponentUpdate;
 15    event Action OnDisable;
 16
 17    void Initialize(IEntityInformationView view);
 18    void Dispose();
 19    void PositionChanged(Vector3 pos);
 20    void RotationChanged(Vector3 rot);
 21    void ScaleChanged(Vector3 scale);
 22    void NameChanged(BIWEntity entity, string name);
 23    void ToggleDetailsInfo();
 24    void ToggleBasicInfo();
 25    void StartChangingName();
 26    void EndChangingName();
 27    void SetEntity(BIWEntity entity, IParcelScene currentScene);
 28    void Enable();
 29    void Disable();
 30    void UpdateInfo(BIWEntity entity);
 31    void UpdateEntitiesSelection(int numberOfSelectedEntities);
 32    void SetTransparencyMode(bool isOn);
 33}
 34
 35public class EntityInformationController : IEntityInformationController
 36{
 37    private const string TRIS_TEXT_FORMAT  = "{0} TRIS";
 38    private const string MATERIALS_TEXT_FORMAT  = "{0} MATERIALS";
 39    private const string TEXTURES_TEXT_FORMAT = "{0} TEXTURES";
 40    private const float TRANSPARENCY_MODE_ALPHA_VALUE = 0.5f;
 41
 42    public event Action<Vector3> OnPositionChange;
 43    public event Action<Vector3> OnRotationChange;
 44    public event Action<Vector3> OnScaleChange;
 45    public event Action<BIWEntity, string> OnNameChange;
 46    public event Action<BIWEntity> OnSmartItemComponentUpdate;
 47    public event Action OnDisable;
 48
 49    internal IEntityInformationView entityInformationView;
 50    internal IParcelScene parcelScene;
 51    internal AssetPromise_Texture loadedThumbnailPromise;
 52    internal bool isChangingName = false;
 53    internal BIWEntity currentEntity;
 54
 55    public void Initialize(IEntityInformationView entityInformationView)
 56    {
 2157        this.entityInformationView = entityInformationView;
 58
 2159        if (entityInformationView.position != null)
 060            entityInformationView.position.OnChanged += PositionChanged;
 61
 2162        if (entityInformationView.rotation != null)
 063            entityInformationView.rotation.OnChanged += RotationChanged;
 64
 2165        if (entityInformationView.scale != null)
 066            entityInformationView.scale.OnChanged += ScaleChanged;
 67
 2168        entityInformationView.OnNameChange += NameChanged;
 2169        entityInformationView.OnStartChangingName += StartChangingName;
 2170        entityInformationView.OnEndChangingName += EndChangingName;
 2171        entityInformationView.OnDisable += Disable;
 2172        entityInformationView.OnUpdateInfo += UpdateInfo;
 2173    }
 74
 75    public void Dispose()
 76    {
 2277        if (entityInformationView == null)
 178            return;
 79
 2180        if (entityInformationView.position != null)
 081            entityInformationView.position.OnChanged -= PositionChanged;
 82
 2183        if (entityInformationView.rotation != null)
 084            entityInformationView.rotation.OnChanged -= RotationChanged;
 85
 2186        if (entityInformationView.scale != null)
 087            entityInformationView.scale.OnChanged -= ScaleChanged;
 88
 2189        entityInformationView.OnNameChange -= NameChanged;
 2190        entityInformationView.OnUpdateInfo -= UpdateInfo;
 2191        entityInformationView.OnStartChangingName -= StartChangingName;
 2192        entityInformationView.OnEndChangingName -= EndChangingName;
 2193        entityInformationView.OnDisable -= Disable;
 2194    }
 95
 296    public void PositionChanged(Vector3 pos) { OnPositionChange?.Invoke(pos); }
 97
 98    public void RotationChanged(Vector3 rot)
 99    {
 1100        currentEntity?.SetRotation(rot);
 1101        OnRotationChange?.Invoke(rot);
 1102    }
 103
 2104    public void ScaleChanged(Vector3 scale) { OnScaleChange?.Invoke(scale); }
 105
 2106    public void NameChanged(BIWEntity entity, string name) { OnNameChange?.Invoke(entity, name); }
 107
 2108    public void ToggleDetailsInfo() { entityInformationView.ToggleDetailsInfo(); }
 109
 2110    public void ToggleBasicInfo() { entityInformationView.ToggleBasicInfo(); }
 111
 0112    public void StartChangingName() { isChangingName = true; }
 113
 0114    public void EndChangingName() { isChangingName = false; }
 115
 116    public void SetEntity(BIWEntity entity, IParcelScene currentScene)
 117    {
 1118        currentEntity = entity;
 1119        EntityDeselected();
 1120        entityInformationView.SetCurrentEntity(entity);
 121
 1122        if (entityInformationView.currentEntity != null)
 123        {
 0124            entity.OnStatusUpdate -= UpdateEntityName;
 0125            entityInformationView.currentEntity.OnStatusUpdate += UpdateEntityName;
 126        }
 127
 1128        parcelScene = currentScene;
 129
 1130        if (entity.HasSmartItemComponent())
 131        {
 0132            entityInformationView.SetSmartItemListViewActive(false);
 133            //TODO: Remove this comment when we implement smart items in builder in world
 134            //if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseComponen
 135            //   entityInformationView.smartItemList.SetSmartItemParameters(entity.GetSmartItemParameters(), ((SmartItem
 0136        }
 137        else
 138        {
 1139            entityInformationView.SetSmartItemListViewActive(false);
 140        }
 141
 1142        entityInformationView.SetEntityThumbnailEnable(false);
 1143        CatalogItem entitySceneObject = entity.GetCatalogItemAssociated();
 1144        GetThumbnail(entitySceneObject);
 1145        UpdateLimitsInformation(entitySceneObject);
 1146        UpdateEntityName(entityInformationView.currentEntity);
 1147        UpdateInfo(entityInformationView.currentEntity);
 1148    }
 149
 150    internal void GetThumbnail(CatalogItem catalogItem)
 151    {
 2152        if (catalogItem == null)
 1153            return;
 154
 1155        var url = catalogItem.thumbnailURL;
 156
 1157        if (string.IsNullOrEmpty(url))
 0158            return;
 159
 1160        var newLoadedThumbnailPromise = new AssetPromise_Texture(url);
 1161        newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail;
 3162        newLoadedThumbnailPromise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error
 1163        AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise);
 1164        AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise);
 1165        loadedThumbnailPromise = newLoadedThumbnailPromise;
 1166    }
 167
 168    internal void SetThumbnail(Asset_Texture texture)
 169    {
 1170        entityInformationView.SetEntityThumbnailEnable(true);
 1171        entityInformationView.SetEntityThumbnailTexture(texture.texture);
 1172    }
 173
 174    internal void UpdateEntityName(BIWEntity entity)
 175    {
 2176        if (entity == null)
 1177            return;
 178
 1179        string currentName = entity.GetDescriptiveName();
 180
 1181        if (!isChangingName)
 1182            entityInformationView.SetNameIFText(currentName);
 1183    }
 184
 185    internal void UpdateLimitsInformation(CatalogItem catalogItem)
 186    {
 3187        if (catalogItem == null)
 188        {
 2189            entityInformationView.SeEntityLimitsText("", "", "");
 2190            return;
 191        }
 192
 1193        string trisText = string.Format(TRIS_TEXT_FORMAT, catalogItem.metrics.triangles);
 1194        string materialText = string.Format(MATERIALS_TEXT_FORMAT, catalogItem.metrics.materials);
 1195        string textureText = string.Format(TEXTURES_TEXT_FORMAT, catalogItem.metrics.textures);
 196
 1197        entityInformationView.SeEntityLimitsText(trisText, materialText, textureText);
 1198    }
 199
 2200    public void Enable() { entityInformationView.SetActive(true); }
 201
 202    public void Disable()
 203    {
 1204        entityInformationView.SetActive(false);
 1205        EntityDeselected();
 1206        entityInformationView.SetCurrentEntity(null);
 1207        OnDisable?.Invoke();
 1208    }
 209
 210    internal void EntityDeselected()
 211    {
 2212        if (entityInformationView.currentEntity == null)
 2213            return;
 214
 0215        var scene = entityInformationView.currentEntity.rootEntity.scene;
 0216        if (scene.componentsManagerLegacy.TryGetBaseComponent(entityInformationView.currentEntity.rootEntity, CLASS_ID_C
 217        {
 0218            SmartItemComponent smartItemComponent = (SmartItemComponent) component;
 0219            OnSmartItemComponentUpdate?.Invoke(entityInformationView.currentEntity);
 220        }
 0221    }
 222
 223    public void UpdateInfo(BIWEntity entity)
 224    {
 2225        if (entity != null && entity.rootEntity.gameObject != null)
 226        {
 1227            Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.rootEntity.gameObject.transfo
 1228            Vector3 currentRotation = entity.rootEntity.gameObject.transform.rotation.eulerAngles;
 1229            Vector3 currentScale = entity.rootEntity.gameObject.transform.lossyScale;
 230
 1231            currentRotation = entity.GetEulerRotation();
 232
 1233            entityInformationView.SetPositionAttribute(positionConverted);
 1234            entityInformationView.SetRotationAttribute(currentRotation);
 1235            entityInformationView.SetScaleAttribute(currentScale);
 236        }
 2237    }
 238
 4239    public void UpdateEntitiesSelection(int numberOfSelectedEntities) { entityInformationView.UpdateEntitiesSelection(nu
 240
 4241    public void SetTransparencyMode(bool isOn) { entityInformationView.SetTransparencyMode(isOn ? TRANSPARENCY_MODE_ALPH
 242}