< Summary

Class:DCL.DebugConfigComponent
Assembly:DebugParameters
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/DebugParameters/DebugConfigComponent.cs
Covered lines:0
Uncovered lines:80
Coverable lines:80
Total lines:244
Line coverage:0% (0 of 80)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DebugConfigComponent()0%2100%
Awake()0%6200%
Start()0%12300%
OnCommunicationReadyChangedValue(...)0%12300%
InitConfig()0%12300%
OpenWebBrowser()0%3801900%
OnDestroy()0%2100%
QuitGame()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/DebugParameters/DebugConfigComponent.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Components;
 4using UnityEditor;
 5using UnityEngine;
 6
 7namespace DCL
 8{
 9    public class DebugConfigComponent : MonoBehaviour
 10    {
 11        private static DebugConfigComponent sharedInstance;
 12        public static DebugConfigComponent i
 13        {
 14            get
 15            {
 016                if (sharedInstance == null)
 017                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 018                return sharedInstance;
 19            }
 020            private set => sharedInstance = value;
 21        }
 22
 23        public DebugConfig debugConfig;
 24
 25        public enum DebugPanel
 26        {
 27            Off,
 28            Scene,
 29            Engine
 30        }
 31
 32        public enum BaseUrl
 33        {
 34            LOCAL_HOST,
 35            CUSTOM,
 36        }
 37
 38        public enum Environment
 39        {
 40            USE_DEFAULT_FROM_URL,
 41            LOCAL,
 42            ZONE,
 43            TODAY,
 44            ORG
 45        }
 46
 47        private const string ENGINE_DEBUG_PANEL = "ENGINE_DEBUG_PANEL";
 48        private const string SCENE_DEBUG_PANEL = "SCENE_DEBUG_PANEL";
 49
 50        [Header("General Settings")]
 51        public bool openBrowserWhenStart;
 52        public bool webSocketSSL = false;
 53
 54        [Header("Kernel General Settings")]
 55        public string kernelVersion;
 56        public bool useCustomContentServer = false;
 57
 058        public string customContentServerUrl = "http://localhost:1338/";
 59
 60        [Space(10)]
 61        public BaseUrl baseUrlMode;
 62
 63        public string baseUrlCustom;
 64
 65        [Space(10)]
 66        public Environment environment;
 67
 68        [Tooltip("Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir-
 69        public string realm;
 70
 071        public Vector2 startInCoords = new Vector2(-99, 109);
 72
 73        [Header("Kernel Misc Settings")]
 074        public bool forceLocalComms = true;
 75
 76        public bool allWearables = false;
 77        public bool testWearables = false;
 78        public bool enableTutorial = false;
 79        public bool builderInWorld = false;
 080        public bool soloScene = true;
 81        public bool multithreaded = false;
 82        public DebugPanel debugPanelMode = DebugPanel.Off;
 83
 84        private void Awake()
 85        {
 086            if (sharedInstance == null)
 087                sharedInstance = this;
 88
 089            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 090            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 091            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 092            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 093            DataStore.i.performance.multithreading.Set(multithreaded);
 094            Texture.allowThreadedTextureCreation = multithreaded;
 095        }
 96
 97        private void Start()
 98        {
 099            lock (DataStore.i.wsCommunication.communicationReady)
 100            {
 0101                if (DataStore.i.wsCommunication.communicationReady.Get())
 102                {
 0103                    InitConfig();
 0104                }
 105                else
 106                {
 0107                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 108                }
 0109            }
 0110        }
 111
 112        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 113        {
 0114            if (newState && !prevState)
 0115                InitConfig();
 116
 0117            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0118        }
 119
 120        private void InitConfig()
 121        {
 0122            if (useCustomContentServer)
 123            {
 0124                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0125                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 126            }
 127
 0128            if (openBrowserWhenStart)
 0129                OpenWebBrowser();
 0130        }
 131
 132        private void OpenWebBrowser()
 133        {
 134#if (UNITY_EDITOR || UNITY_STANDALONE)
 0135            string baseUrl = "";
 0136            string debugString = "";
 137
 0138            if (baseUrlMode == BaseUrl.CUSTOM)
 0139                baseUrl = baseUrlCustom;
 140            else
 0141                baseUrl = "http://localhost:3000/?";
 142
 0143            switch (environment)
 144            {
 145                case Environment.USE_DEFAULT_FROM_URL:
 146                    break;
 147                case Environment.LOCAL:
 0148                    debugString = "DEBUG_MODE&";
 0149                    break;
 150                case Environment.ZONE:
 0151                    debugString = "NETWORK=ropsten&";
 0152                    break;
 153                case Environment.TODAY:
 0154                    debugString = "NETWORK=mainnet&";
 0155                    break;
 156                case Environment.ORG:
 0157                    debugString = "NETWORK=mainnet&";
 158                    break;
 159            }
 160
 0161            if (!string.IsNullOrEmpty(kernelVersion))
 162            {
 0163                debugString += $"kernel-version={kernelVersion}&";
 164            }
 165
 0166            if (forceLocalComms)
 167            {
 0168                debugString += "LOCAL_COMMS&";
 169            }
 170
 0171            if (allWearables)
 172            {
 0173                debugString += "ALL_WEARABLES&";
 174            }
 175
 0176            if (testWearables)
 177            {
 0178                debugString += "TEST_WEARABLES&";
 179            }
 180
 0181            if (enableTutorial)
 182            {
 0183                debugString += "RESET_TUTORIAL&";
 184            }
 185
 0186            if (soloScene)
 187            {
 0188                debugString += "LOS=0&";
 189            }
 190
 0191            if (builderInWorld)
 192            {
 0193                debugString += "ENABLE_BUILDER_IN_WORLD&";
 194            }
 195
 0196            if (!string.IsNullOrEmpty(realm))
 197            {
 0198                debugString += $"realm={realm}&";
 199            }
 200
 0201            string debugPanelString = "";
 202
 0203            if (debugPanelMode == DebugPanel.Engine)
 204            {
 0205                debugPanelString = ENGINE_DEBUG_PANEL + "&";
 0206            }
 0207            else if (debugPanelMode == DebugPanel.Scene)
 208            {
 0209                debugPanelString = SCENE_DEBUG_PANEL + "&";
 210            }
 211
 0212            if (!webSocketSSL)
 213            {
 0214                if (baseUrl.Contains("play.decentraland.org"))
 215                {
 0216                    Debug.LogError("play.decentraland.org only works with WebSocket SSL, please change the base URL to p
 0217                    QuitGame();
 0218                    return;
 219                }
 220            }
 221            else
 222            {
 0223                Debug.Log("[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certifica
 224            }
 225
 0226            Application.OpenURL(
 227                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 228#endif
 0229        }
 230
 0231        private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange
 232
 233        private void QuitGame()
 234        {
 235#if UNITY_EDITOR
 236            // Application.Quit() does not work in the editor so
 237            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
 0238            UnityEditor.EditorApplication.isPlaying = false;
 239#else
 240            Application.Quit();
 241#endif
 0242        }
 243    }
 244}