< Summary

Class:PlacesAndEventsCardsFactory
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsCardsFactory.cs
Covered lines:23
Uncovered lines:0
Coverable lines:23
Total lines:100
Line coverage:100% (23 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetCardsPoolLazy(...)0%220100%
CreateConfiguredEventCard(...)0%110100%
CreateConfiguredPlaceCard(...)0%110100%
GetPlaceCardTemplateHiddenLazy(...)0%110100%
GetEventCardTemplateHiddenLazy(...)0%110100%
GetCardTemplateHiddenLazy[TCardView](...)0%220100%
CreatePlacesCards(...)0%110100%
CreateEventsCards(...)0%110100%
CreateModelsListFromAPI[TModel, TInfo](...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsCardsFactory.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using static HotScenesController;
 6using Object = UnityEngine.Object;
 7
 8public static class PlacesAndEventsCardsFactory
 9{
 10    internal const string EVENT_CARD_MODAL_ID = "EventCard_Modal";
 11    internal const string PLACE_CARD_MODAL_ID = "PlaceCard_Modal";
 12
 13    /// <summary>
 14    /// Creates and configures a pool for cards.
 15    /// </summary>
 16    /// <param name="pool">Pool to configure.</param>
 17    /// <param name="poolName">Name of the pool.</param>
 18    /// <param name="cardPrefab">Card prefab to use by the pool.</param>
 19    /// <param name="maxPrewarmCount">Max number of pre-created cards.</param>
 20    public static Pool GetCardsPoolLazy(string poolName, BaseComponentView cardPrefab, int maxPrewarmCount)
 21    {
 17122        Pool pool = PoolManager.i.GetPool(poolName);
 23
 17124        if (pool != null)
 16225            return pool;
 26
 927        pool = PoolManager.i.AddPool(poolName, Object.Instantiate(cardPrefab).gameObject, maxPrewarmCount: maxPrewarmCou
 928        pool.ForcePrewarm();
 29
 930        return pool;
 31    }
 32
 33    public static EventCardComponentView CreateConfiguredEventCard(Pool pool, EventCardComponentModel eventInfo, Action<
 2434        EventsCardsConfigurator.Configure(pool.Get<EventCardComponentView>(), eventInfo, OnEventInfoClicked, OnEventJump
 35
 36    public static PlaceCardComponentView CreateConfiguredPlaceCard(Pool pool, PlaceCardComponentModel placeInfo, Action<
 3837        PlacesCardsConfigurator.Configure(pool.Get<PlaceCardComponentView>(), placeInfo, OnPlaceInfoClicked, OnPlaceJump
 38
 39    /// <summary>
 40    /// Instantiates (if does not already exists) a place card modal from the given prefab.
 41    /// </summary>
 42    /// <param name="placeCardModalPrefab">Prefab to instantiate.</param>
 43    /// <returns>An instance of a place card modal.</returns>
 44    public static PlaceCardComponentView GetPlaceCardTemplateHiddenLazy(PlaceCardComponentView placeCardModalPrefab) =>
 13845        GetCardTemplateHiddenLazy(placeCardModalPrefab, PLACE_CARD_MODAL_ID);
 46
 47    /// <summary>
 48    /// Instantiates (if does not already exists) a event card modal from the given prefab.
 49    /// </summary>
 50    /// <param name="eventCardModalPrefab">Prefab to instantiate.</param>
 51    /// <returns>An instance of a event card modal.</returns>
 52    public static EventCardComponentView GetEventCardTemplateHiddenLazy(EventCardComponentView eventCardModalPrefab) =>
 10953        GetCardTemplateHiddenLazy(eventCardModalPrefab, EVENT_CARD_MODAL_ID);
 54
 55    private static TCardView GetCardTemplateHiddenLazy<TCardView>(TCardView modalPrefab, string cardModalId) where TCard
 56    {
 57        TCardView modal;
 58
 24759        GameObject existingModal = GameObject.Find(cardModalId);
 60
 24761        if (existingModal != null)
 20562            modal = existingModal.GetComponent<TCardView>();
 63        else
 64        {
 4265            modal = Object.Instantiate(modalPrefab);
 4266            modal.name = cardModalId;
 67        }
 68
 24769        modal.Hide(true);
 70
 24771        return modal;
 72    }
 73
 74    /// <summary>
 75    /// Returns a place card model from the given API data.
 76    /// </summary>
 77    /// <param name="filteredPlaces">Data received from the API.</param>
 78    /// <returns>A place card model.</returns>
 79    public static List<PlaceCardComponentModel> CreatePlacesCards(List<HotSceneInfo> filteredPlaces) =>
 780        CreateModelsListFromAPI<PlaceCardComponentModel, HotSceneInfo>(filteredPlaces, PlacesCardsConfigurator.Configure
 81
 82    /// <summary>
 83    /// Returns a event card model from the given API data.
 84    /// </summary>
 85    /// <param name="filteredEvents">Data received from the API.</param>
 86    /// <returns>An event card model.</returns>
 87    public static List<EventCardComponentModel> CreateEventsCards(List<EventFromAPIModel> filteredEvents) =>
 1488        CreateModelsListFromAPI<EventCardComponentModel, EventFromAPIModel>(filteredEvents, EventsCardsConfigurator.Conf
 89
 90    private static List<TModel> CreateModelsListFromAPI<TModel, TInfo>(List<TInfo> filteredAPIModels, Func<TModel, TInfo
 91        where TModel: BaseComponentModel, new()
 92    {
 2193        List<TModel> loadedCards = new List<TModel>();
 94
 7495        foreach (TInfo filteredCardInfo in filteredAPIModels)
 1696            loadedCards.Add(configureModelByApiData(new TModel(), filteredCardInfo));
 97
 2198        return loadedCards;
 99    }
 100}