< 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:247
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%4202000%
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;
 80        public bool enableProceduralSkybox = false;
 081        public bool soloScene = true;
 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        }
 94
 95        private void Start()
 96        {
 097            lock (DataStore.i.wsCommunication.communicationReady)
 98            {
 099                if (DataStore.i.wsCommunication.communicationReady.Get())
 100                {
 0101                    InitConfig();
 0102                }
 103                else
 104                {
 0105                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 106                }
 0107            }
 0108        }
 109
 110        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 111        {
 0112            if (newState && !prevState)
 0113                InitConfig();
 114
 0115            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0116        }
 117
 118        private void InitConfig()
 119        {
 0120            if (useCustomContentServer)
 121            {
 0122                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0123                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 124            }
 125
 0126            if (openBrowserWhenStart)
 0127                OpenWebBrowser();
 0128        }
 129
 130        private void OpenWebBrowser()
 131        {
 132#if (UNITY_EDITOR || UNITY_STANDALONE)
 0133            string baseUrl = "";
 0134            string debugString = "";
 135
 0136            if (baseUrlMode == BaseUrl.CUSTOM)
 0137                baseUrl = baseUrlCustom;
 138            else
 0139                baseUrl = "http://localhost:3000/?";
 140
 0141            switch (environment)
 142            {
 143                case Environment.USE_DEFAULT_FROM_URL:
 144                    break;
 145                case Environment.LOCAL:
 0146                    debugString = "DEBUG_MODE&";
 0147                    break;
 148                case Environment.ZONE:
 0149                    debugString = "NETWORK=ropsten&";
 0150                    break;
 151                case Environment.TODAY:
 0152                    debugString = "NETWORK=mainnet&";
 0153                    break;
 154                case Environment.ORG:
 0155                    debugString = "NETWORK=mainnet&";
 156                    break;
 157            }
 158
 0159            if (!string.IsNullOrEmpty(kernelVersion))
 160            {
 0161                debugString += $"kernel-version={kernelVersion}&";
 162            }
 163
 0164            if (forceLocalComms)
 165            {
 0166                debugString += "LOCAL_COMMS&";
 167            }
 168
 0169            if (allWearables)
 170            {
 0171                debugString += "ALL_WEARABLES&";
 172            }
 173
 0174            if (testWearables)
 175            {
 0176                debugString += "TEST_WEARABLES&";
 177            }
 178
 0179            if (enableTutorial)
 180            {
 0181                debugString += "RESET_TUTORIAL&";
 182            }
 183
 0184            if (soloScene)
 185            {
 0186                debugString += "LOS=0&";
 187            }
 188
 0189            if (builderInWorld)
 190            {
 0191                debugString += "ENABLE_BUILDER_IN_WORLD&";
 192            }
 193
 0194            if (enableProceduralSkybox)
 195            {
 0196                debugString += "ENABLE_PROCEDURAL_SKYBOX&";
 197            }
 198
 0199            if (!string.IsNullOrEmpty(realm))
 200            {
 0201                debugString += $"realm={realm}&";
 202            }
 203
 0204            string debugPanelString = "";
 205
 0206            if (debugPanelMode == DebugPanel.Engine)
 207            {
 0208                debugPanelString = ENGINE_DEBUG_PANEL + "&";
 0209            }
 0210            else if (debugPanelMode == DebugPanel.Scene)
 211            {
 0212                debugPanelString = SCENE_DEBUG_PANEL + "&";
 213            }
 214
 0215            if (!webSocketSSL)
 216            {
 0217                if (baseUrl.Contains("play.decentraland.org"))
 218                {
 0219                    Debug.LogError("play.decentraland.org only works with WebSocket SSL, please change the base URL to p
 0220                    QuitGame();
 0221                    return;
 222                }
 223            }
 224            else
 225            {
 0226                Debug.Log("[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certifica
 227            }
 228
 0229            Application.OpenURL(
 230                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 231#endif
 0232        }
 233
 0234        private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange
 235
 236        private void QuitGame()
 237        {
 238#if UNITY_EDITOR
 239            // Application.Quit() does not work in the editor so
 240            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
 0241            UnityEditor.EditorApplication.isPlaying = false;
 242#else
 243            Application.Quit();
 244#endif
 0245        }
 246    }
 247}