< Summary

Class:DCL.Chat.HUD.PoolPrivateChatEntryFactory
Assembly:PrivateChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PoolPrivateChatEntryFactory.cs
Covered lines:1
Uncovered lines:17
Coverable lines:18
Total lines:56
Line coverage:5.5% (1 of 18)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PoolPrivateChatEntryFactory()0%110100%
CreateDateSeparator()0%2100%
Create(...)0%2100%
Destroy(...)0%6200%
GetPool()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PoolPrivateChatEntryFactory.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4namespace DCL.Chat.HUD
 5{
 6    [CreateAssetMenu(fileName = "PoolPrivateChatEntryFactory", menuName = "DCL/Social/PoolPrivateChatEntryFactory")]
 7    public class PoolPrivateChatEntryFactory : ScriptableObject, IChatEntryFactory
 8    {
 9        private const string POOL_NAME_PREFIX = "ChatDateSeparators_";
 10        private const int PRE_INSTANTIATED_ENTRIES = 30;
 11
 12        [SerializeField] private PoolChatEntryFactory factory;
 13        [SerializeField] private DateSeparatorEntry separatorEntryPrefab;
 14
 115        private readonly Dictionary<ChatEntry, PoolableObject> pooledObjects =
 16            new Dictionary<ChatEntry, PoolableObject>();
 17
 18        public DateSeparatorEntry CreateDateSeparator()
 19        {
 020            var pool = GetPool();
 021            var pooledObj = pool.Get();
 022            var entry = pooledObj.gameObject.GetComponent<DateSeparatorEntry>();
 023            pooledObjects[entry] = pooledObj;
 024            return entry;
 25        }
 26
 027        public ChatEntry Create(ChatEntryModel model) => factory.Create(model);
 28
 29        public void Destroy(ChatEntry entry)
 30        {
 031            if (pooledObjects.TryGetValue(entry, out var pooledObj))
 32            {
 033                pooledObj.Release();
 034                pooledObjects.Remove(entry);
 35            }
 36
 037            factory.Destroy(entry);
 038        }
 39
 40        private Pool GetPool()
 41        {
 042            var poolId = POOL_NAME_PREFIX + GetInstanceID();
 043            var entryPool = PoolManager.i.GetPool(poolId);
 044            if (entryPool != null) return entryPool;
 45
 046            entryPool = PoolManager.i.AddPool(
 47                poolId,
 48                Instantiate(separatorEntryPrefab).gameObject,
 49                maxPrewarmCount: PRE_INSTANTIATED_ENTRIES,
 50                isPersistent: true);
 051            entryPool.ForcePrewarm();
 52
 053            return entryPool;
 54        }
 55    }
 56}