Esempio n. 1
0
        public void Finalize(ActionContext context)
        {
            QuantumConsole console    = context.Console;
            string         serialized = _value as string ?? console.Serialize(_value);

            console.LogToConsole(serialized, _newline);
        }
Esempio n. 2
0
        protected override void OnEnable()
        {
            base.OnEnable();

            QCInstance = (QuantumConsole)target;
            QCInstance.OnStateChange += Repaint;

            FetchSerializedProperties();
        }
        private static ConsoleReplacementResult ReplaceQuantumConsole(QuantumConsole source, out ChirpQuantumConsole chirpQuantumConsole)
        {
            if (source is ChirpQuantumConsole sourceAsChirp)
            {
                chirpQuantumConsole = sourceAsChirp;
                return(ConsoleReplacementResult.AlreadyExists);
            }

            GameObject sourceGameObject = source.gameObject;

            Component[] allComponent   = sourceGameObject.GetComponents <Component>();
            int         componentCount = allComponent.Length;
            int         componentIndex = Array.IndexOf(allComponent, source);


            GameObject          temporaryGameObject     = new GameObject();
            ChirpQuantumConsole temporaryQuantumConsole = temporaryGameObject.AddComponent <ChirpQuantumConsole>();

            EditorUtility.CopySerialized(source, temporaryQuantumConsole);

            if (Application.isPlaying)
            {
                Object.Destroy(source);
            }
            else
            {
                Object.DestroyImmediate(source);
            }

            chirpQuantumConsole = sourceGameObject.AddComponent <ChirpQuantumConsole>();
            EditorUtility.CopySerialized(temporaryQuantumConsole, chirpQuantumConsole);

            var prefabStatus = PrefabUtility.GetPrefabInstanceStatus(sourceGameObject);

            if (prefabStatus == PrefabInstanceStatus.NotAPrefab)
            {
                if (componentIndex != -1 && componentCount - 1 > componentIndex)
                {
                    for (int i = componentCount - 1; i >= componentIndex; i--)
                    {
                        UnityEditorInternal.ComponentUtility.MoveComponentUp(chirpQuantumConsole);
                    }
                }
            }

            if (Application.isPlaying)
            {
                Object.Destroy(temporaryGameObject);
            }
            else
            {
                Object.DestroyImmediate(temporaryGameObject);
            }

            return(ConsoleReplacementResult.Success);
        }
Esempio n. 4
0
    void ListLoadedBlocks()
    {
        string l = "";

        foreach (string key in blocks.Keys)
        {
            l += key + Environment.NewLine;
        }
        QuantumConsole.print(l);
    }
Esempio n. 5
0
        private static IEnumerator <ICommandAction> Generate(IEnumerable <T> choices, Action <T> onSelect, Config config)
        {
            QuantumConsole console = null;
            StringBuilder  builder = new StringBuilder();

            IReadOnlyList <T> choiceList = choices as IReadOnlyList <T> ?? choices.ToList();
            KeyCode           key        = KeyCode.None;
            int choice = 0;

            yield return(new GetContext(ctx => console = ctx.Console));

            ICommandAction DrawRow()
            {
                builder.Clear();
                for (int i = 0; i < choiceList.Count; i++)
                {
                    string item = console.Serialize(choiceList[i]);
                    builder.Append(i == choice
                        ? string.Format(config.ItemFormat, item, 'x').ColorText(config.SelectedColor)
                        : string.Format(config.ItemFormat, item, ' '));

                    if (i != choiceList.Count - 1)
                    {
                        builder.Append(config.Delimiter);
                    }
                }

                return(new Value(builder.ToString()));
            }

            yield return(DrawRow());

            while (key != KeyCode.Return)
            {
                yield return(new GetKey(k => key = k));

                switch (key)
                {
                case KeyCode.LeftArrow: choice--; break;

                case KeyCode.RightArrow: choice++; break;

                case KeyCode.DownArrow: choice++; break;

                case KeyCode.UpArrow: choice--; break;
                }

                choice = (choice + choiceList.Count) % choiceList.Count;
                yield return(new RemoveLog());

                yield return(DrawRow());
            }

            onSelect(choiceList[choice]);
        }
Esempio n. 6
0
        private static void ConfigureForChirp(MenuCommand command)
        {
            QuantumConsole source = command.context as QuantumConsole;

            if (source == null)
            {
                return;
            }

            ConfigureForChirp(source);
        }
Esempio n. 7
0
        internal static bool VerifyConfiguration(QuantumConsole source, out string message)
        {
            SerializedObject   serializedObject     = new SerializedObject(source);
            SerializedProperty interceptDebugLogger = serializedObject.FindProperty("_interceptDebugLogger");
            SerializedProperty singleton            = serializedObject.FindProperty("_singletonMode");

            s_HelperErrorStringBuilder.Clear();
            s_HelperErrorStringBuilder.AppendLine($"Singleton Mode: {MessageValueCheckOutput(singleton.boolValue, true)}"); s_HelperErrorStringBuilder.AppendLine($"Intercept Debug Messages: {MessageValueCheckOutput(interceptDebugLogger.boolValue, false)}");
            message = s_HelperErrorStringBuilder.ToString();

            return(!interceptDebugLogger.boolValue && singleton.boolValue);
        }
Esempio n. 8
0
        public override void OnInspectorGUI()
        {
            QuantumConsole consoleInstance = FindQuantumConsoleInstance();

            if (consoleInstance == null)
            {
                GUILayout.Label(m_MissingConsoleInstanceContent, Styles.DescriptionLabelWarning);
                using (new GUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Visit Github"))
                    {
                    }
                    if (GUILayout.Button("Open Readme"))
                    {
                    }
                }

                return;
            }

            if (consoleInstance is ChirpQuantumConsole == false)
            {
                GUILayout.Label(m_ConsoleNotConvertedContent, Styles.DescriptionLabelWarning);
                if (GUILayout.Button("Perform Conversion"))
                {
                    consoleInstance = ChirpQuantumConsoleConverter.ConvertQuantumConsole(consoleInstance);
                    ChirpQuantumConsoleConfigurator.ConfigureForChirp(consoleInstance);
                }

                return;
            }

            if (consoleInstance is ChirpQuantumConsole chirpQuantumInstance)
            {
                bool isValid = ChirpQuantumConsoleConfigurator.VerifyConfiguration(chirpQuantumInstance, out string error);

                if (isValid)
                {
                    GUILayout.Label("Console instance has been found and is configured correctly.");
                    GUILayout.Label(error, Styles.DescriptionLabel);
                }
                else
                {
                    GUILayout.Label(m_ConsoleNotConfiguredContent, Styles.DescriptionLabelWarning);
                    GUILayout.Label(error, Styles.DescriptionLabel);
                    if (GUILayout.Button("Configure Automatically"))
                    {
                        ChirpQuantumConsoleConfigurator.ConfigureForChirp(consoleInstance);
                    }
                }
            }
        }
        internal static ChirpQuantumConsole ConvertQuantumConsole(QuantumConsole source)
        {
            ChirpQuantumConsole chirpConsole = null;
            var allQuantumConsoleReferences  = FindAllReferences(source);
            var consoleReplacement           = ReplaceQuantumConsole(source, out chirpConsole);

            ReplaceAllReferences(allQuantumConsoleReferences, chirpConsole);
            var logSelector     = AddLogSelectorComponent(chirpConsole);
            var singletonUpdate = UpdateConsoleSingleton(chirpConsole);

            EditorUtility.DisplayDialog("Chirp: Convert Quantum Console",
                                        $"Quantum console update: {consoleReplacement},\nLog selector creation: {logSelector}\nConsole set to Singleton Mode: {singletonUpdate}", "Ok");
            return(chirpConsole);
        }
Esempio n. 10
0
        new public void Start()
        {
            base.Start();
            Current = this;

            _spawnPoint = transform.position;

            _collider = GetComponent<CapsuleCollider2D>();
            _audio.Source = GetComponent<AudioSource>();
            _console = FindObjectOfType<QuantumConsole>();
            
            _console.OnActivate += () => { _controlsDisabled = true; }; // Disable player controls when console gets activated
            _console.OnDeactivate += () => { _controlsDisabled = false; }; // Enable player controls when console gets closed
        }
Esempio n. 11
0
    void SetHotbarSlot(int slot, string item)
    {
        int _s = Mathf.Clamp(slot, 1, 10);

        if (ItemList.instance.items.TryGetValue(item, out Item _i))
        {
            HotbarItems[_s - 1] = _i;
            UpdateHotbar();
            UpdateHeldItem();
            QuantumConsole.print($"Successfully set slot {_s} to '{item}'");
        }
        else
        {
            QuantumConsole.print("Cannot set hotbar slot, chosen item doesn't exist.");
        }
    }
Esempio n. 12
0
        internal static void ConfigureForChirp(QuantumConsole source)
        {
            SerializedObject   serializedObject     = new SerializedObject(source);
            SerializedProperty interceptDebugLogger = serializedObject.FindProperty("_interceptDebugLogger");

            interceptDebugLogger.boolValue = false;

            SerializedProperty singleton = serializedObject.FindProperty("_singletonMode");

            singleton.boolValue = true;

            serializedObject.ApplyModifiedProperties();

            EditorUtility.DisplayDialog("Chirp Logger: Configure Quantum Console",
                                        "Quantum Console has been configured to work along Chirp Logging Framework.\nSingleton Mode: TRUE\nIntercept Debug Logger: FALSE",
                                        "Close");
        }
        private void BindToConsoleInstance()
        {
            if (!_consoleInstance)
            {
                _consoleInstance = FindObjectOfType <QuantumConsole>();
            }
            if (_consoleInstance)
            {
                _consoleInstance.OnActivate   += BlockInput;
                _consoleInstance.OnDeactivate += UnblockInput;

                _blocked = _consoleInstance.IsActive;
            }
            else
            {
                UnblockInput();
            }
        }
        private static ConsolePropertyUpdateResult UpdateConsoleSingleton(QuantumConsole consoleInstance)
        {
            if (consoleInstance == null)
            {
                return(ConsolePropertyUpdateResult.UnableToUpdate);
            }

            SerializedObject   serializedObject = new SerializedObject(consoleInstance);
            SerializedProperty singleton        = serializedObject.FindProperty("_singletonMode");

            if (singleton.boolValue == true)
            {
                return(ConsolePropertyUpdateResult.Updated);
            }
            singleton.boolValue = true;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();

            return(ConsolePropertyUpdateResult.Success);
        }
        private static void ConvertQuantumConsole(MenuCommand command)
        {
            QuantumConsole source = command.context as QuantumConsole;

            if (source == null)
            {
                return;
            }

            source = ConvertQuantumConsole(source);

                        #if CHIRP
            if (EditorUtility.DisplayDialog("Chirp Logging Framework Integration",
                                            $"It appears you have the Chirp Logging Framework enabled in your project. Would you like to configure the console for it?",
                                            "Yes", "Not Now"))
            {
                ChirpQuantumConsoleConfigurator.ConfigureForChirp(source);
            }
                        #endif
        }
        private static SerializedProperty[] FindAllReferences(QuantumConsole source)
        {
            // already replaced
            if (source is ChirpQuantumConsole)
            {
                return(Array.Empty <SerializedProperty>());
            }

            List <SerializedProperty> output = new List <SerializedProperty>();

            Component[] allComponents = source.GetComponentsInChildren <Component>();
            foreach (var component in allComponents)
            {
                if (component == source)
                {
                    continue;
                }

                SerializedObject   so       = new SerializedObject(component);
                SerializedProperty iterator = so.GetIterator();
                while (iterator.Next(true))
                {
                    if (iterator.propertyType != SerializedPropertyType.ObjectReference)
                    {
                        continue;
                    }

                    if (iterator.objectReferenceValue != source)
                    {
                        continue;
                    }

                    output.Add(iterator.Copy());
                }
            }

            return(output.ToArray());
        }
        private static void ReplaceAllReferences(IEnumerable <SerializedProperty> referenceList, QuantumConsole target)
        {
            if (referenceList == null || target == null)
            {
                return;
            }

            foreach (var pointer in referenceList)
            {
                pointer.objectReferenceValue = target;
                pointer.serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }
        }