< Summary

Class:EntityInformationController
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Scripts/Common/EntityInformationController.cs
Covered lines:94
Uncovered lines:11
Coverable lines:105
Total lines:238
Line coverage:89.5% (94 of 105)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%440100%
Dispose()0%440100%
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%8.744033.33%
UpdateInfo(...)0%330100%
UpdateEntitiesSelection(...)0%110100%
SetTransparencyMode(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/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    {
 4757        this.entityInformationView = entityInformationView;
 58
 4759        if (entityInformationView.position != null)
 2660            entityInformationView.position.OnChanged += PositionChanged;
 61
 4762        if (entityInformationView.rotation != null)
 2663            entityInformationView.rotation.OnChanged += RotationChanged;
 64
 4765        if (entityInformationView.scale != null)
 2666            entityInformationView.scale.OnChanged += ScaleChanged;
 67
 4768        entityInformationView.OnNameChange += NameChanged;
 4769        entityInformationView.OnStartChangingName += StartChangingName;
 4770        entityInformationView.OnEndChangingName += EndChangingName;
 4771        entityInformationView.OnDisable += Disable;
 4772        entityInformationView.OnUpdateInfo += UpdateInfo;
 4773    }
 74
 75    public void Dispose()
 76    {
 4777        if (entityInformationView.position != null)
 2678            entityInformationView.position.OnChanged -= PositionChanged;
 79
 4780        if (entityInformationView.rotation != null)
 2681            entityInformationView.rotation.OnChanged -= RotationChanged;
 82
 4783        if (entityInformationView.scale != null)
 2684            entityInformationView.scale.OnChanged -= ScaleChanged;
 85
 4786        entityInformationView.OnNameChange -= NameChanged;
 4787        entityInformationView.OnUpdateInfo -= UpdateInfo;
 4788        entityInformationView.OnStartChangingName -= StartChangingName;
 4789        entityInformationView.OnEndChangingName -= EndChangingName;
 4790        entityInformationView.OnDisable -= Disable;
 4791    }
 92
 293    public void PositionChanged(Vector3 pos) { OnPositionChange?.Invoke(pos); }
 94
 95    public void RotationChanged(Vector3 rot)
 96    {
 197        currentEntity?.SetRotation(rot);
 198        OnRotationChange?.Invoke(rot);
 199    }
 100
 2101    public void ScaleChanged(Vector3 scale) { OnScaleChange?.Invoke(scale); }
 102
 2103    public void NameChanged(BIWEntity entity, string name) { OnNameChange?.Invoke(entity, name); }
 104
 2105    public void ToggleDetailsInfo() { entityInformationView.ToggleDetailsInfo(); }
 106
 2107    public void ToggleBasicInfo() { entityInformationView.ToggleBasicInfo(); }
 108
 0109    public void StartChangingName() { isChangingName = true; }
 110
 0111    public void EndChangingName() { isChangingName = false; }
 112
 113    public void SetEntity(BIWEntity entity, IParcelScene currentScene)
 114    {
 1115        currentEntity = entity;
 1116        EntityDeselected();
 1117        entityInformationView.SetCurrentEntity(entity);
 118
 1119        if (entityInformationView.currentEntity != null)
 120        {
 0121            entity.OnStatusUpdate -= UpdateEntityName;
 0122            entityInformationView.currentEntity.OnStatusUpdate += UpdateEntityName;
 123        }
 124
 1125        parcelScene = currentScene;
 126
 1127        if (entity.HasSmartItemComponent())
 128        {
 0129            entityInformationView.SetSmartItemListViewActive(false);
 130            //TODO: Remove this comment when we implement smart items in builder in world
 131            //if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseComponen
 132            //   entityInformationView.smartItemList.SetSmartItemParameters(entity.GetSmartItemParameters(), ((SmartItem
 0133        }
 134        else
 135        {
 1136            entityInformationView.SetSmartItemListViewActive(false);
 137        }
 138
 1139        entityInformationView.SetEntityThumbnailEnable(false);
 1140        CatalogItem entitySceneObject = entity.GetCatalogItemAssociated();
 1141        GetThumbnail(entitySceneObject);
 1142        UpdateLimitsInformation(entitySceneObject);
 1143        UpdateEntityName(entityInformationView.currentEntity);
 1144        UpdateInfo(entityInformationView.currentEntity);
 1145    }
 146
 147    internal void GetThumbnail(CatalogItem catalogItem)
 148    {
 2149        if (catalogItem == null)
 1150            return;
 151
 1152        var url = catalogItem.thumbnailURL;
 153
 1154        if (string.IsNullOrEmpty(url))
 0155            return;
 156
 1157        var newLoadedThumbnailPromise = new AssetPromise_Texture(url);
 1158        newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail;
 1159        newLoadedThumbnailPromise.OnFailEvent += x => { Debug.Log($"Error downloading: {url}"); };
 1160        AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise);
 1161        AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise);
 1162        loadedThumbnailPromise = newLoadedThumbnailPromise;
 1163    }
 164
 165    internal void SetThumbnail(Asset_Texture texture)
 166    {
 1167        entityInformationView.SetEntityThumbnailEnable(true);
 1168        entityInformationView.SetEntityThumbnailTexture(texture.texture);
 1169    }
 170
 171    internal void UpdateEntityName(BIWEntity entity)
 172    {
 2173        if (entity == null)
 1174            return;
 175
 1176        string currentName = entity.GetDescriptiveName();
 177
 1178        if (!isChangingName)
 1179            entityInformationView.SetNameIFText(currentName);
 1180    }
 181
 182    internal void UpdateLimitsInformation(CatalogItem catalogItem)
 183    {
 3184        if (catalogItem == null)
 185        {
 2186            entityInformationView.SeEntityLimitsText("", "", "");
 2187            return;
 188        }
 189
 1190        string trisText = string.Format(TRIS_TEXT_FORMAT, catalogItem.metrics.triangles);
 1191        string materialText = string.Format(MATERIALS_TEXT_FORMAT, catalogItem.metrics.materials);
 1192        string textureText = string.Format(TEXTURES_TEXT_FORMAT, catalogItem.metrics.textures);
 193
 1194        entityInformationView.SeEntityLimitsText(trisText, materialText, textureText);
 1195    }
 196
 2197    public void Enable() { entityInformationView.SetActive(true); }
 198
 199    public void Disable()
 200    {
 1201        entityInformationView.SetActive(false);
 1202        EntityDeselected();
 1203        entityInformationView.SetCurrentEntity(null);
 1204        OnDisable?.Invoke();
 1205    }
 206
 207    internal void EntityDeselected()
 208    {
 2209        if (entityInformationView.currentEntity == null)
 2210            return;
 211
 0212        if (entityInformationView.currentEntity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntit
 213        {
 0214            SmartItemComponent smartItemComponent = (SmartItemComponent) component;
 0215            OnSmartItemComponentUpdate?.Invoke(entityInformationView.currentEntity);
 216        }
 0217    }
 218
 219    public void UpdateInfo(BIWEntity entity)
 220    {
 2221        if (entity != null && entity.rootEntity.gameObject != null)
 222        {
 1223            Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.rootEntity.gameObject.transfo
 1224            Vector3 currentRotation = entity.rootEntity.gameObject.transform.rotation.eulerAngles;
 1225            Vector3 currentScale = entity.rootEntity.gameObject.transform.lossyScale;
 226
 1227            currentRotation = entity.GetEulerRotation();
 228
 1229            entityInformationView.SetPositionAttribute(positionConverted);
 1230            entityInformationView.SetRotationAttribute(currentRotation);
 1231            entityInformationView.SetScaleAttribute(currentScale);
 232        }
 2233    }
 234
 4235    public void UpdateEntitiesSelection(int numberOfSelectedEntities) { entityInformationView.UpdateEntitiesSelection(nu
 236
 4237    public void SetTransparencyMode(bool isOn) { entityInformationView.SetTransparencyMode(isOn ? TRANSPARENCY_MODE_ALPH
 238}