< Summary

Class:HUDFactory
Assembly:HUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/HUDFactory.cs
Covered lines:33
Uncovered lines:5
Coverable lines:38
Total lines:207
Line coverage:86.8% (33 of 38)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HUDFactory()0%2100%
HUDFactory(...)0%110100%
Initialize()0%110100%
Dispose()0%2.262060%
CreateHUD()0%26.0326096.55%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Browser;
 4using DCL.Chat;
 5using DCL.HelpAndSupportHUD;
 6using DCL.ProfanityFiltering;
 7using DCL.Providers;
 8using DCL.SettingsCommon;
 9using DCL.SettingsPanelHUD;
 10using DCL.Social.Chat.Mentions;
 11using DCL.Social.Friends;
 12using SocialFeaturesAnalytics;
 13using System;
 14using System.Collections.Generic;
 15using System.Threading;
 16using static MainScripts.DCL.Controllers.HUD.HUDAssetPath;
 17using Environment = DCL.Environment;
 18using Analytics;
 19using DCL.MyAccount;
 20using DCL.Social.Chat;
 21using DCLServices.CopyPaste.Analytics;
 22using DCLServices.PlacesAPIService;
 23using UnityEngine;
 24using Object = UnityEngine.Object;
 25
 26public class HUDFactory : IHUDFactory
 27{
 28    private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen;
 29    private readonly List<IDisposable> disposableViews;
 30
 31    private Service<IAddressableResourceProvider> assetsProviderService;
 32    private IAddressableResourceProvider assetsProviderRef;
 33
 1034    private IAddressableResourceProvider assetsProvider => assetsProviderRef ??= assetsProviderService.Ref;
 535    private ICopyPasteAnalyticsService copyPasteAnalyticsService => Environment.i.serviceLocator.Get<ICopyPasteAnalytics
 36
 037    protected HUDFactory()
 38    {
 039        disposableViews = new List<IDisposable>();
 040    }
 41
 42742    public HUDFactory(IAddressableResourceProvider assetsProvider)
 43    {
 42744        disposableViews = new List<IDisposable>();
 42745        assetsProviderRef = assetsProvider;
 42746    }
 47
 42548    public void Initialize() { }
 49
 50    public void Dispose()
 51    {
 85052        foreach (IDisposable view in disposableViews)
 053            view.Dispose();
 42554    }
 55
 56    public virtual async UniTask<IHUD> CreateHUD(HUDElementID hudElementId, CancellationToken cancellationToken = defaul
 57    {
 58        switch (hudElementId)
 59        {
 60            case HUDElementID.NONE:
 61                break;
 62            case HUDElementID.MINIMAP:
 163                return new MinimapHUDController(MinimapMetadataController.i,
 64                    new WebInterfaceHomeLocationController(), Environment.i,
 65                    Environment.i.serviceLocator.Get<IPlacesAPIService>(),
 66                    new PlacesAnalytics(), Clipboard.Create(),
 67                    copyPasteAnalyticsService,
 68                    DataStore.i.contentModeration,
 69                    Environment.i.world.state);
 70            case HUDElementID.PROFILE_HUD:
 171                ProfileHUDViewV2 view = Object.Instantiate(Resources.Load<ProfileHUDViewV2>("ProfileHUD_V2"));
 72
 173                var userProfileBridge = new UserProfileWebInterfaceBridge();
 174                var webInterfaceBrowserBridge = new WebInterfaceBrowserBridge();
 75
 176                return new ProfileHUDController(
 77                    view,
 78                    userProfileBridge,
 79                    new SocialAnalytics(
 80                        Environment.i.platform.serviceProviders.analytics,
 81                        userProfileBridge),
 82                    DataStore.i,
 83                    new MyAccountCardController(
 84                        view.MyAccountCardView,
 85                        DataStore.i,
 86                        userProfileBridge,
 87                        Settings.i,
 88                        webInterfaceBrowserBridge),
 89                    webInterfaceBrowserBridge);
 90            case HUDElementID.NOTIFICATION:
 391                return new NotificationHUDController( await CreateHUDView<NotificationHUDView>(VIEW_PATH, cancellationTo
 92            case HUDElementID.SETTINGS_PANEL:
 193                return new SettingsPanelHUDController();
 94            case HUDElementID.TERMS_OF_SERVICE:
 195                return new TermsOfServiceHUDController();
 96            case HUDElementID.FRIENDS:
 197                return new FriendsHUDController(DataStore.i,
 98                    Environment.i.serviceLocator.Get<IFriendsController>(),
 99                    new UserProfileWebInterfaceBridge(),
 100                    new SocialAnalytics(
 101                        Environment.i.platform.serviceProviders.analytics,
 102                        new UserProfileWebInterfaceBridge()),
 103                    Environment.i.serviceLocator.Get<IChatController>(),
 104                    SceneReferences.i.mouseCatcher);
 105            case HUDElementID.WORLD_CHAT_WINDOW:
 1106                return new WorldChatWindowController(
 107                    new UserProfileWebInterfaceBridge(),
 108                    Environment.i.serviceLocator.Get<IFriendsController>(),
 109                    Environment.i.serviceLocator.Get<IChatController>(),
 110                    DataStore.i,
 111                    SceneReferences.i.mouseCatcher,
 112                    new SocialAnalytics(
 113                        Environment.i.platform.serviceProviders.analytics,
 114                        new UserProfileWebInterfaceBridge()),
 115                    Environment.i.serviceLocator.Get<IChannelsFeatureFlagService>(),
 116                    new WebInterfaceBrowserBridge(),
 117                    CommonScriptableObjects.rendererState,
 118                    DataStore.i.mentions,
 119                    Clipboard.Create(),
 120                    copyPasteAnalyticsService);
 121            case HUDElementID.PRIVATE_CHAT_WINDOW:
 1122                return new PrivateChatWindowController(
 123                    DataStore.i,
 124                    new UserProfileWebInterfaceBridge(),
 125                    Environment.i.serviceLocator.Get<IChatController>(),
 126                    Environment.i.serviceLocator.Get<IFriendsController>(),
 127                    new SocialAnalytics(
 128                        Environment.i.platform.serviceProviders.analytics,
 129                        new UserProfileWebInterfaceBridge()),
 130                    SceneReferences.i.mouseCatcher,
 131                    new MemoryChatMentionSuggestionProvider(UserProfileController.i, DataStore.i),
 132                    Clipboard.Create(),
 133                    copyPasteAnalyticsService);
 134            case HUDElementID.PUBLIC_CHAT:
 1135                return new PublicChatWindowController(
 136                    Environment.i.serviceLocator.Get<IChatController>(),
 137                    new UserProfileWebInterfaceBridge(),
 138                    DataStore.i,
 139                    Environment.i.serviceLocator.Get<IProfanityFilter>(),
 140                    SceneReferences.i.mouseCatcher,
 141                    new MemoryChatMentionSuggestionProvider(UserProfileController.i, DataStore.i),
 142                    new SocialAnalytics(
 143                        Environment.i.platform.serviceProviders.analytics,
 144                        new UserProfileWebInterfaceBridge()),
 145                    Clipboard.Create(),
 146                    copyPasteAnalyticsService);
 147            case HUDElementID.CHANNELS_CHAT:
 1148                return new ChatChannelHUDController(
 149                    DataStore.i,
 150                    new UserProfileWebInterfaceBridge(),
 151                    Environment.i.serviceLocator.Get<IChatController>(),
 152                    SceneReferences.i.mouseCatcher,
 153                    new SocialAnalytics(
 154                        Environment.i.platform.serviceProviders.analytics,
 155                        new UserProfileWebInterfaceBridge()),
 156                    Environment.i.serviceLocator.Get<IProfanityFilter>(),
 157                    new MemoryChatMentionSuggestionProvider(UserProfileController.i, DataStore.i),
 158                    Clipboard.Create(),
 159                    copyPasteAnalyticsService);
 160            case HUDElementID.CHANNELS_SEARCH:
 1161                return new SearchChannelsWindowController(
 162                    Environment.i.serviceLocator.Get<IChatController>(),
 163                    SceneReferences.i.mouseCatcher,
 164                    DataStore.i,
 165                    new SocialAnalytics(
 166                        Environment.i.platform.serviceProviders.analytics,
 167                        new UserProfileWebInterfaceBridge()),
 168                    Environment.i.serviceLocator.Get<IChannelsFeatureFlagService>());
 169            case HUDElementID.CHANNELS_CREATE:
 1170                return new CreateChannelWindowController(Environment.i.serviceLocator.Get<IChatController>(), DataStore.
 171            case HUDElementID.CHANNELS_LEAVE_CONFIRMATION:
 1172                return new LeaveChannelConfirmationWindowController(Environment.i.serviceLocator.Get<IChatController>())
 173            case HUDElementID.TASKBAR:
 1174                return new TaskbarHUDController(Environment.i.serviceLocator.Get<IChatController>(), Environment.i.servi
 175            case HUDElementID.OPEN_EXTERNAL_URL_PROMPT:
 1176                return new ExternalUrlPromptHUDController(DataStore.i.rpc.context.restrictedActions);
 177            case HUDElementID.NFT_INFO_DIALOG:
 1178                return new NFTPromptHUDController(DataStore.i.rpc.context.restrictedActions, DataStore.i.common.onOpenNF
 179            case HUDElementID.CONTROLS_HUD:
 1180                return new ControlsHUDController();
 181            case HUDElementID.HELP_AND_SUPPORT_HUD:
 3182                return new HelpAndSupportHUDController(await CreateHUDView<IHelpAndSupportHUDView>(HELP_AND_SUPPORT_HUD,
 183            case HUDElementID.USERS_AROUND_LIST_HUD:
 1184                return new VoiceChatWindowController(
 185                    new UserProfileWebInterfaceBridge(),
 186                    Environment.i.serviceLocator.Get<IFriendsController>(),
 187                    new SocialAnalytics(
 188                        Environment.i.platform.serviceProviders.analytics,
 189                        new UserProfileWebInterfaceBridge()),
 190                    DataStore.i,
 191                    Settings.i,
 192                    SceneReferences.i.mouseCatcher);
 193            case HUDElementID.GRAPHIC_CARD_WARNING:
 1194                return new GraphicCardWarningHUDController();
 195        }
 196
 0197        return null;
 20198    }
 199
 200    public async UniTask<T> CreateHUDView<T>(string assetAddress, CancellationToken cancellationToken = default, string 
 201    {
 202        var view = await assetsProvider.Instantiate<T>(assetAddress, $"_{assetAddress}",  cancellationToken: cancellatio
 203        disposableViews.Add(view);
 204
 205        return view;
 206    }
 207}