< Summary

Class:DCLName
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/BuilderInWorld/DCLName.cs
Covered lines:15
Uncovered lines:2
Coverable lines:17
Total lines:62
Line coverage:88.2% (15 of 17)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetDataFromJSON(...)0%2100%
DCLName()0%110100%
GetClassId()0%110100%
ApplyChanges(...)0%5.015092.86%
SetNewName(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/BuilderInWorld/DCLName.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Models;
 5using System.Collections;
 6using System.Collections.Generic;
 7using DCL.Helpers;
 8using UnityEngine;
 9
 10/// <summary>
 11/// This component is a descriptive name of the Entity. In the BuilderInWorld you can give an entity a descriptive name 
 12/// Builder in World send a message to kernel to change the value of this component in order to assign a descriptive nam
 13/// </summary>
 14public class DCLName : BaseDisposable
 15{
 16    [System.Serializable]
 17    public class Model : BaseModel
 18    {
 19        public string value;
 20        //TODO: This value is used for builder to manage the smart items, when the builder is no longer active we should
 21        public string builderValue;
 22
 023        public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 24    }
 25
 6026    public DCLName() { model = new Model(); }
 27
 28    private string oldName;
 29
 7730    public override int GetClassId() { return (int) CLASS_ID.NAME; }
 31
 32    public override IEnumerator ApplyChanges(BaseModel newModel)
 33    {
 2034        Model modelToApply = (Model) newModel;
 35
 2036        model = modelToApply;
 37
 7238        foreach (IDCLEntity entity in attachedEntities)
 39        {
 1640            entity.OnNameChange?.Invoke(modelToApply);
 41        }
 42
 43#if UNITY_EDITOR
 7244        foreach (IDCLEntity decentralandEntity in this.attachedEntities)
 45        {
 1646            if (!string.IsNullOrEmpty(oldName))
 047                decentralandEntity.gameObject.name.Replace(oldName, "");
 48
 1649            decentralandEntity.gameObject.name += $"-{modelToApply.value}";
 50        }
 51#endif
 2052        oldName = modelToApply.value;
 2053        return null;
 54    }
 55
 56    public void SetNewName(string value)
 57    {
 2058        Model newModel = new Model();
 2059        newModel.value = value;
 2060        UpdateFromModel(newModel);
 2061    }
 62}