< Summary

Class:DCL.StickersController
Assembly:StickersController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/StickersController/StickersController.cs
Covered lines:16
Uncovered lines:18
Coverable lines:34
Total lines:88
Line coverage:47% (16 of 34)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:6
Method coverage:66.6% (4 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
StickersController()0%110100%
Awake()0%110100%
PlaySticker(...)0%2100%
PlaySticker(...)0%34.367017.65%
ToggleHideArea(...)0%2100%
ConfigurePools()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/StickersController/StickersController.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL
 6{
 7    public class StickersController : MonoBehaviour
 8    {
 9        private const int POOL_PREWARM_COUNT = 10;
 65710        private Dictionary<string, Pool> pools = new Dictionary<string, Pool>();
 11        private StickersFactory stickersFactory;
 12        private bool isInHideArea;
 13
 14        private void Awake()
 15        {
 63416            stickersFactory = Resources.Load<StickersFactory>("StickersFactory");
 17
 63418            ConfigurePools();
 63419        }
 20
 21        public void PlaySticker(string id)
 22        {
 023            PlaySticker(id, transform.position, Vector3.zero, true);
 024        }
 25
 26        /// <summary>
 27        /// Play a sticker
 28        /// </summary>
 29        /// <param name="id"></param>
 30        /// <param name="position"> if following transform, position must be an offset from the target. Otherwise, it's 
 31        /// <param name="direction"></param>
 32        /// <param name="followTransform"></param>
 33        public void PlaySticker(string id, Vector3 position, Vector3 direction, bool followTransform, int renderingLayer
 34        {
 2235            if (stickersFactory == null || !stickersFactory.TryGet(id, out GameObject prefab) || isInHideArea)
 036                return;
 37
 38            // TODO(Brian): Mock this system properly through our service locators or plugin system
 2239            if (DCL.Configuration.EnvironmentSettings.RUNNING_TESTS)
 2240                return;
 41
 042            PoolableObject sticker = pools[id].Get();
 043            GameObject stickerGo = sticker.gameObject;
 044            sticker.gameObject.layer = renderingLayer;
 045            stickerGo.transform.position = position;
 046            stickerGo.transform.rotation = Quaternion.Euler(prefab.transform.rotation.eulerAngles + direction);
 47
 048            ReleaseParticlesOnFinish releaser = stickerGo.GetOrCreateComponent<ReleaseParticlesOnFinish>();
 049            if (releaser != null)
 050                releaser.Initialize(sticker);
 51
 052            if (followTransform)
 53            {
 054                FollowObject stickerFollow = stickerGo.GetOrCreateComponent<FollowObject>();
 055                stickerFollow.target = transform;
 056                stickerFollow.offset = stickerGo.transform.position - transform.position;
 57            }
 058        }
 59
 60        public void ToggleHideArea(bool entered)
 61        {
 062            isInHideArea = entered;
 063        }
 64
 65        internal void ConfigurePools()
 66        {
 63467            List<StickersFactory.StickerFactoryEntry> stickers = stickersFactory.GetStickersList();
 68
 1394869            foreach (StickersFactory.StickerFactoryEntry stricker in stickers)
 70            {
 634071                string nameID = $"Sticker {stricker.id}";
 634072                Pool pool = PoolManager.i.GetPool(nameID);
 634073                if (pool == null)
 74                {
 400075                    pool = PoolManager.i.AddPool(
 76                        nameID,
 77                        Instantiate(stricker.stickerPrefab),
 78                        maxPrewarmCount: POOL_PREWARM_COUNT,
 79                        isPersistent: true);
 80
 400081                    pool.ForcePrewarm();
 82                }
 83
 634084                pools.Add(stricker.id, pool);
 85            }
 63486        }
 87    }
 88}