< Summary

Class:DCL.StickersController
Assembly:StickersController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/StickersController/StickersController.cs
Covered lines:18
Uncovered lines:15
Coverable lines:33
Total lines:87
Line coverage:54.5% (18 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
StickersController()0%110100%
Awake()0%110100%
PlaySticker(...)0%2100%
PlaySticker(...)0%33.287018.75%
ToggleHideArea(...)0%110100%
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;
 76210        private Dictionary<string, Pool> pools = new Dictionary<string, Pool>();
 11        private StickersFactory stickersFactory;
 12        private bool isInHideArea;
 13
 14        private void Awake()
 15        {
 73816            stickersFactory = Resources.Load<StickersFactory>("StickersFactory");
 17
 73818            ConfigurePools();
 73819        }
 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)
 34        {
 2135            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
 2139            if (DCL.Configuration.EnvironmentSettings.RUNNING_TESTS)
 2140                return;
 41
 042            PoolableObject sticker = pools[id].Get();
 043            GameObject stickerGo = sticker.gameObject;
 044            stickerGo.transform.position = position;
 045            stickerGo.transform.rotation = Quaternion.Euler(prefab.transform.rotation.eulerAngles + direction);
 46
 047            ReleaseParticlesOnFinish releaser = stickerGo.GetOrCreateComponent<ReleaseParticlesOnFinish>();
 048            if (releaser != null)
 049                releaser.Initialize(sticker);
 50
 051            if (followTransform)
 52            {
 053                FollowObject stickerFollow = stickerGo.GetOrCreateComponent<FollowObject>();
 054                stickerFollow.target = transform;
 055                stickerFollow.offset = stickerGo.transform.position - transform.position;
 56            }
 057        }
 58
 59        public void ToggleHideArea(bool entered)
 60        {
 161            isInHideArea = entered;
 162        }
 63
 64        internal void ConfigurePools()
 65        {
 73866            List<StickersFactory.StickerFactoryEntry> stickers = stickersFactory.GetStickersList();
 67
 1328468            foreach (StickersFactory.StickerFactoryEntry stricker in stickers)
 69            {
 590470                string nameID = $"Sticker {stricker.id}";
 590471                Pool pool = PoolManager.i.GetPool(nameID);
 590472                if (pool == null)
 73                {
 391274                    pool = PoolManager.i.AddPool(
 75                        nameID,
 76                        Instantiate(stricker.stickerPrefab),
 77                        maxPrewarmCount: POOL_PREWARM_COUNT,
 78                        isPersistent: true);
 79
 391280                    pool.ForcePrewarm();
 81                }
 82
 590483                pools.Add(stricker.id, pool);
 84            }
 73885        }
 86    }
 87}