Exemplo n.º 1
0
        public void UpdateSize(int depth)
        {
            Width = 193;

            if (depth >= 0)
            {
                Height = 200;
                ICompilerCode connection = codeConnections[1];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                scope.sizeDelta = new Vector2(40, Height - 120);
                endConnection.anchoredPosition = new Vector2(0, -Height);
            }

            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);


            var c = CodeUtil.ChangeControlColor(Colors.ControlColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Exemplo n.º 2
0
        string SaveBlock(ICompilerCode code)
        {
            if (code == null)
            {
                return(Saving.CodeScopeBegin.ToString() + Saving.CodeScopeEnd.ToString());
            }

            var str = Saving.CodeScopeBegin.ToString();

            while (code != null)
            {
                str += code.Save();
                if (code.Values.Length == 0)
                {
                    str += SaveValue(null);
                }
                else
                {
                    foreach (var v in code.Values)
                    {
                        str += SaveValue(v);
                    }
                }

                for (int i = 1; i < code.CodeConnections.Length; i++)
                {
                    str += SaveBlock(code.CodeConnections[i]);
                }

                code = code.CodeConnections[0];
            }
            str += Saving.CodeScopeEnd;
            return(str);
        }
Exemplo n.º 3
0
        public void UpdateSize(int depth)
        {
            Width = 0;

            float w1 = 0, w2 = 0;

            for (int i = 0; i < values.Length; i++)
            {
                if (i == 1)
                {
                    w1 = Width;
                }
                else if (i == 2)
                {
                    w2 = Width;
                }

                values[i]?.UpdateSize(0);
                Width += values[i]?.Width ?? CodeUtil.SubWidth;
            }

            text3.anchoredPosition = new Vector2(w2 + 198, 0);
            (valueObjects[1] as RectTransform).anchoredPosition = new Vector2(w1 + 174, 0);
            (valueObjects[2] as RectTransform).anchoredPosition = new Vector2(w2 + 222, 0);

            if (depth >= 0)
            {
                Height = 200;
                ICompilerCode connection = codeConnections[1];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                scope.sizeDelta = new Vector2(40, Height - 120);
                endConnection.anchoredPosition = new Vector2(0, -Height);
            }

            Width          += 224;
            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);


            var c = CodeUtil.ChangeFunctionColor(Colors.ConditionalColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Exemplo n.º 4
0
        public void UpdateSize(int depth)
        {
            Height = 200;
            ICompilerCode connection = codeConnections[0];

            while (connection != null)
            {
                Height    += connection.Height;
                connection = connection.CodeConnections[0];
            }

            scope.sizeDelta = new Vector2(40, Height - 120);
            bottomConnection.anchoredPosition = new Vector2(0, -Height - 80);
        }
Exemplo n.º 5
0
        void CodeConnect(ICompilerCode code)
        {
            if (code != null)
            {
                code.UpdateSize(-1);
                code.Offset.Connect();

                foreach (var v in code.Values)
                {
                    if (v != null)
                    {
                        RecursiveValueConnect(v, true);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static Program RecursiveProgrammer(ICompilerCode initialCode)
        {
            var code        = new List <ICode>();
            var currentCode = initialCode;

            while (currentCode != null)
            {
                var c = currentCode.ConvertToCode();
                if (c != null)
                {
                    code.Add(c);
                }
                currentCode = currentCode.CodeConnections[0];
            }
            return(new Program(code.ToArray()));
        }
Exemplo n.º 7
0
        void MoveCodeConnect(ICompilerCode code)
        {
            if (code != null)
            {
                foreach (var v in code.Values)
                {
                    if (v != null)
                    {
                        RecursiveValueConnect(v, true);
                    }
                }

                for (int i = 1; i < code.CodeConnections.Length; i++)
                {
                    RecursiveCodeConnect(code.CodeConnections[i]);
                }

                RecursiveCodeConnect(code.CodeConnections?[0]);
            }
        }
Exemplo n.º 8
0
        void RecursiveCodeConnect(ICompilerCode code)
        {
            while (code != null)
            {
                code.Offset.Connect();

                foreach (var v in code.Values)
                {
                    if (v != null)
                    {
                        RecursiveValueConnect(v, true);
                    }
                }

                for (int i = 1; i < code.CodeConnections.Length; i++)
                {
                    RecursiveCodeConnect(code.CodeConnections[i]);
                }
                code = code.CodeConnections?[0];
            }
        }
Exemplo n.º 9
0
        public void UpdateSize(int depth)
        {
            Width = 229 - CodeUtil.SubWidth;
            ICompilerValue value = values[0];

            if (value != null)
            {
                value.UpdateSize(0);
                Width += value.Width;
            }
            else
            {
                Width += CodeUtil.SubWidth;
            }


            Height = 200;
            ICompilerCode connection = codeConnections[1];

            while (connection != null)
            {
                connection.UpdateSize(depth + 1);
                Height    += connection.Height;
                connection = connection.CodeConnections[0];
            }

            scope.sizeDelta = new Vector2(40, Height - 120);
            endConnection.anchoredPosition = new Vector2(0, -Height);


            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);


            var c = CodeUtil.ChangeFunctionColor(Colors.ConditionalColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Exemplo n.º 10
0
 public CodeConnection(int index, Transform connectObject, ICompilerCode code)
 {
     this.codeIndex     = index;
     this.connectObject = connectObject;
     this.code          = code;
 }
Exemplo n.º 11
0
        // Subcode and string index end
        int LoadFunctionScopes(SubstringOptimizedString subcode, ICompilerCode currentFunction, SelectableObject obj, int valueEndIndex)
        {
            //print(subcode);

            // CodeConnections: scopeIndex + 1
            int scopeIndex    = 0;
            var totalEndIndex = -1;

            var scopeBeginIndex = subcode.Length > valueEndIndex + 1 ? (subcode[valueEndIndex + 1] == CodeScopeBegin
                        ? valueEndIndex + 1
                        : -1) : -1;

            while (scopeBeginIndex != -1)
            {
                if (scopeIndex != 0)
                {
                    scopeBeginIndex = subcode.Length > 0 ? (subcode[0] == CodeScopeBegin
                                        ? 0
                                        : -1) : -1;
                }

                if (scopeBeginIndex != -1)
                {
                    var scopeEndIndex = -1;
                    var scopeAmount   = 1;

                    for (int i = scopeBeginIndex + 1; i < subcode.Length; i++)
                    {
                        if (subcode[i] == CodeScopeBegin)
                        {
                            scopeAmount++;
                        }
                        else if (subcode[i] == CodeScopeEnd)
                        {
                            scopeAmount--;

                            if (scopeAmount == 0)
                            {
                                scopeEndIndex = i;
                                break;
                            }
                        }
                    }

                    var scopeCode = subcode.Substring(scopeBeginIndex + 1, scopeEndIndex - scopeBeginIndex - 1);
                    //print(scopeCode);

                    LoadFunctions(scopeCode, null, obj, currentFunction, scopeIndex + 1);

                    totalEndIndex += scopeEndIndex;

                    subcode = subcode.Substring(scopeEndIndex + 1);

                    scopeIndex++;
                }
                else
                {
                    break;
                }
            }

            if (totalEndIndex != -1)
            {
                return(totalEndIndex + scopeIndex - 1);
            }

            return(-1);
        }
Exemplo n.º 12
0
        void LoadFunctions(SubstringOptimizedString subcode, ICompilerEvent currentEvent, SelectableObject obj, ICompilerCode currentCode = null, int codeId = 0)
        {
            var           functionScope      = subcode.IndexOf(CodeValueBegin);
            ICompilerCode lastFunctionObject = null;

            while (functionScope != -1)
            {
                var valueScopeAmount = 1;
                var valueEndIndex    = -1;

                for (int i = functionScope + 1; i < subcode.Length; i++)
                {
                    if (subcode[i] == CodeValueBegin)
                    {
                        valueScopeAmount++;
                    }
                    else if (subcode[i] == CodeValueEnd)
                    {
                        valueScopeAmount--;

                        if (valueScopeAmount == 0)
                        {
                            if (subcode.Length > i + 1 && subcode[i + 1] == CodeValueBegin)
                            {
                                // There is still another ()
                                // Eg: (Val1)(Val2)
                            }
                            else                     // if it is the end
                            {
                                valueEndIndex = i;
                                break;
                            }
                        }
                    }
                }

                // Check if code contains equal amount of {}
                if (valueEndIndex == -1)
                {
                    Debug.LogWarning($"{currentEvent as MonoBehaviour} code was corrupted.");
                    return;
                }

                // Create Function
                var functionName = subcode.Substring(0, functionScope).ToString();
                //print(functionName);

                // Broadcast function is only (currently) function with no values, but InputField
                var    functionValueSplit = functionName.IndexOf(FunctionSplit);
                string functionValue      = "";
                if (functionValueSplit != -1)
                {
                    functionValue = functionName.Substring(functionValueSplit + 1);
                    functionName  = functionName.Substring(0, functionValueSplit);
                }

#if UNITY_EDITOR
                if (!CodeIdPrefabs.ContainsKey(functionName))
                {
                    Debug.LogError($"Doesn't Contain {functionName}");
                }
#endif

                var functionObject  = Instantiate(CodeIdPrefabs[functionName], obj.Script.transform);
                var currentFunction = functionObject.GetComponent <ICompilerCode>();

                if (functionValueSplit != -1)
                {
                    if (currentFunction is B_Broadcast bb)
                    {
                        bb.broadcastName.text = functionValue;
                    }
                    else if (currentFunction is B_Comment cc)
                    {
                        cc.inputField.text = functionValue;
                    }
                }

                // Event Offset
                var offset = functionObject.gameObject.AddComponent <BlockOffset>();
                currentFunction.Offset = offset;

                if (lastFunctionObject != null)
                {
                    lastFunctionObject.CodeConnections[0] = currentFunction;
                    offset.Connection = (lastFunctionObject as MonoBehaviour).transform.Find("CodeConnection");
                }
                else
                {
                    if (currentEvent != null)
                    {
                        currentEvent.CodeConnections[0] = currentFunction;
                        offset.Connection = (currentEvent as MonoBehaviour).transform.Find("Scope")
                                            .Find("CodeConnection");
                    }
                    else
                    {
                        currentCode.CodeConnections[codeId] = currentFunction;
                        if (codeId == 1)
                        {
                            offset.Connection = (currentCode as MonoBehaviour).transform.Find("Scope")
                                                .Find("CodeConnection");
                        }
                        else
                        {
                            offset.Connection = (currentCode as MonoBehaviour).transform.Find($"Scope{codeId}")
                                                .Find("CodeConnection");
                        }
                    }
                }

                offset.Connect();

                // Todo: Implement () value creation (LoadValues)
                var valueString = subcode.Substring(functionScope /*+ 1*/, valueEndIndex - functionScope + 1 /*- 1*/);
                if (valueString.Length > 0)
                {
                    LoadValueScopes(valueString, currentFunction);
                }

                // Todo: Implement {}{} function searches (if, if else) (recursion)
                // Function Scopes
                var innerScope = LoadFunctionScopes(subcode, currentFunction, obj, valueEndIndex);
                // Connect innerScope.Variable1? to mainfunction

                // Next Loop:
                if (innerScope != -1)
                {
                    subcode = subcode.Substring(innerScope + 2);
                }
                else
                {
                    subcode = subcode.Substring(valueEndIndex + 1);
                }

                // Next Loop:
                functionScope = subcode.IndexOf(CodeValueBegin);

                lastFunctionObject = currentFunction;
            }
        }
Exemplo n.º 13
0
        public void UpdateSize(int depth)
        {
            /*for (int i = 0; i < values.Length; i++)
             * {
             *  values[i]?.UpdateSize();
             * }
             *
             * for (int i = 1; i < codeConnections.Length; i++)
             * {
             *  codeConnections[i]?.UpdateSize();
             * }*/

            for (int i = 0; i < codeConnections.Length; i++)
            {
                codeTest2[i] = codeConnections[i]?.Transform;
            }

            Width = 260 - CodeUtil.SubWidth;
            ICompilerValue value = values[0];

            if (value != null)
            {
                value.UpdateSize(0);
                Width += value.Width;
                //value = value.Values?.Length > 0 ? value.Values?[0] : null;
            }
            else
            {
                Width += CodeUtil.SubWidth;
            }

            if (depth >= 0)
            {
                var c1 = 0f;
                var c2 = 0f;

                Height = 360;
                ICompilerCode connection = codeConnections[1];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    c1        += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                connection = codeConnections[2];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    c2        += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                scope1.sizeDelta         = new Vector2(40, codeConnections[1] != null ? c1 + 80 : 80);
                scope2.anchoredPosition  = new Vector2(0, codeConnections[1] != null ? -c1 - 240 : -240);
                scope2.sizeDelta         = new Vector2(40, codeConnections[2] != null ? c2 + 40 : 40);
                nextCon.anchoredPosition = new Vector2(0, -Height);
            }

            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);

            var c = CodeUtil.ChangeControlColor(Colors.ControlColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Exemplo n.º 14
0
        void MoveCode(Transform hit, bool left = true)
        {
            var canDropCode = previousConnection == null ||
                              (left ? ((byte)Settings.CodeDropType & 0b01) == 1 : ((byte)Settings.CodeDropType & 0b10) == 1);

            if (CanDelete())
            {
                switch (clonedObjectType)
                {
                case CodeType.Event:
                    CodeDelete(currentClonedObject.GetComponent <ICompilerEvent>());
                    Destroy(currentClonedObject.gameObject);
                    break;

                case CodeType.Function:
                    CodeDelete(currentClonedObject.GetComponent <ICompilerCode>());
                    break;

                case CodeType.Value:
                    ValueDelete(currentClonedObject.GetComponent <ICompilerValues>());
                    break;
                }

                currentClonedObject = null;

                //clickAudioSource.Play();
            }
            else
            {
                switch (clonedObjectType)
                {
                case CodeType.Event:
                    var curEvent = currentClonedObject.GetComponent <ICompilerEvent>();
                    if (hit && !hit.IsChildOf(otherCodeTransform))
                    {
                        var oldEvent = hit.GetComponentInParent <ICompilerEvent>();

                        ICompilerEvent nextCon = oldEvent.NextConnection;
                        oldEvent.NextConnection = curEvent;
                        curEvent.NextConnection = nextCon;

                        curEvent.Offset.Connection = oldEvent.NextConnectionObject;
                        if (curEvent.NextConnection != null)
                        {
                            nextCon.Offset.Connection = curEvent.NextConnectionObject;
                        }

                        currentClonedObject.SetParent(currentScriptObject, false);
                        currentClonedObject = null;
                        ReconnectAll();
                    }
                    else
                    {
                        if (!canDropCode)
                        {
                            var            prevConEvent = (ICompilerEvent)previousConnection;
                            ICompilerEvent nextCon      = prevConEvent.NextConnection;
                            prevConEvent.NextConnection = curEvent;
                            curEvent.NextConnection     = nextCon;

                            curEvent.Offset.Connection = prevConEvent.NextConnectionObject;
                            if (curEvent.NextConnection != null)
                            {
                                nextCon.Offset.Connection = curEvent.NextConnectionObject;
                            }

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                            ReconnectOtherCode();
                        }
                    }

                    break;



                case CodeType.Function:
                    var func = currentClonedObject.GetComponent <ICompilerCode>();

                    var lastCodeInMove = func;
                    var lastFunc       = func.CodeConnections[0];

                    while (lastFunc != null)
                    {
                        lastCodeInMove = lastFunc;
                        lastFunc       = lastFunc.CodeConnections[0];
                    }

                    if (hit)
                    {
                        var connection = hit.GetComponentInParent <ICompilerCodeConnection>();

                        if (connection != null && func != null)
                        {
                            var con = connection.GetCodeConnection(hit).Value;

                            ICompilerCode afterCode = connection.CodeConnections[con.codeIndex];
                            if (afterCode != null)
                            {
                                lastCodeInMove.CodeConnections[0] = afterCode;
                                afterCode.Offset.Connection       = lastCodeInMove.CodeConnectionObjects[0];
                            }
                            connection.CodeConnections[con.codeIndex] = func;
                            func.Offset.Connection = connection.CodeConnectionObjects[con.codeIndex];

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                    }
                    else
                    {
                        if (!canDropCode)
                        {
                            var           prevConCode = (CodeCon)previousConnection;
                            ICompilerCode afterCode   = prevConCode.con.CodeConnections[prevConCode.index];
                            if (afterCode != null)
                            {
                                lastCodeInMove.CodeConnections[0] = afterCode;
                                afterCode.Offset.Connection       = lastCodeInMove.CodeConnectionObjects[0];
                            }

                            prevConCode.con.CodeConnections[prevConCode.index] = func;
                            func.Offset.Connection = prevConCode.con.CodeConnectionObjects[prevConCode.index];

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                            ReconnectOtherCode();
                        }
                    }

                    break;



                case CodeType.Value:
                    var val         = currentClonedObject.GetComponent <ICompilerValue>();
                    var connectPrev = true;

                    if (hit)
                    {
                        var connection = hit.GetComponentInParent <ICompilerValues>();

                        if (connection != null && val != null)
                        {
                            var con = connection.GetValue(hit).Value;

                            ICompilerValue oldValue = connection.Values[con.valueIndex];
                            if (oldValue != null)
                            {
                                connectPrev = true;
                            }
                            else
                            {
                                connection.Values[con.valueIndex] = val;
                                val.Offset.Connection             = con.connectObject;

                                currentClonedObject.SetParent(hit, false);
                                currentClonedObject = null;
                                ReconnectAll();

                                connectPrev = false;
                            }
                        }
                    }

                    if (connectPrev)
                    {
                        if (!canDropCode)
                        {
                            var prevCodeCon = (ValueCon)previousConnection;
                            prevCodeCon.con.Values[prevCodeCon.index] = val;
                            val.Offset.Connection = prevCodeCon.lastCon;

                            currentClonedObject.SetParent(prevCodeCon.lastCon, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                        }
                    }

                    ReconnectOtherCode();

                    break;
                }

                //clickAudioSource.Play();
            }

            //if (hit != null && hit.IsChildOf(otherCodeTransform))
            //ReconnectOtherCode();
        }