< Summary

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

Metrics

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

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
 026    public DCLName() { model = new Model(); }
 27
 28    private string oldName;
 29
 030    public override int GetClassId() { return (int) CLASS_ID.NAME; }
 31
 32    public override IEnumerator ApplyChanges(BaseModel newModel)
 33    {
 034        Model modelToApply = (Model) newModel;
 35
 036        model = modelToApply;
 37
 038        foreach (IDCLEntity entity in attachedEntities)
 39        {
 040            entity.OnNameChange?.Invoke(modelToApply);
 41        }
 42
 43#if UNITY_EDITOR
 044        foreach (IDCLEntity decentralandEntity in this.attachedEntities)
 45        {
 046            if (!string.IsNullOrEmpty(oldName))
 047                decentralandEntity.gameObject.name.Replace(oldName, "");
 48
 049            decentralandEntity.gameObject.name += $"-{modelToApply.value}";
 50        }
 51#endif
 052        oldName = modelToApply.value;
 053        return null;
 54    }
 55
 56    public void SetNewName(string value)
 57    {
 058        Model newModel = new Model();
 059        newModel.value = value;
 060        UpdateFromModel(newModel);
 061    }
 62}