public ShxmlVariable ShxmlInitVariable(string Name, bool value) // For bools
        {
            ShxmlVariable var = new ShxmlVariable();

            var.Name    = Name;
            var.Type    = 5;
            var.varbool = value;

            Varlist.Add(var);
            return(var);
        }
        public ShxmlVariable ShxmlInitVariable(string Name, float value) // For floats
        {
            ShxmlVariable var = new ShxmlVariable();

            var.Name     = Name;
            var.Type     = 4;
            var.varfloat = value;

            Varlist.Add(var);
            return(var);
        }
        public ShxmlVariable ShxmlInitVariable(string Name, double value) // For doubles
        {
            ShxmlVariable var = new ShxmlVariable();

            var.Name      = Name;
            var.Type      = 3;
            var.vardouble = value;

            Varlist.Add(var);
            return(var);
        }
        public ShxmlVariable ShxmlInitVariable(string Name, char value) // For chars
        {
            ShxmlVariable var = new ShxmlVariable();

            var.Name    = Name;
            var.Type    = 2;
            var.varchar = value;

            Varlist.Add(var);
            return(var);
        }
        public ShxmlVariable ShxmlInitVariable(string Name, string value) // For strings
        {
            ShxmlVariable var = new ShxmlVariable();

            var.Name      = Name;
            var.Type      = 1;
            var.varstring = value;

            Varlist.Add(var);
            return(var);
        }
        public void ShxmlHandleIfStatement(XmlNode token)         // v0.5.6+ (actually functional in v0.6.0)+
        {
            XmlAttributeCollection attributes = token.Attributes; // no attributes but yeahhhhhhhhhhhhhhhhhhhhhhhhh

            if (!token.HasChildNodes)
            {
                ShellCore.ElmThrowException(33); //Empty if statement
            }

            int    count  = 0;
            double result = 0;

            string        x    = null;
            ShxmlVariable svar = new ShxmlVariable();

            OperandList = new List <string>();
            OpList      = new List <char>();
            foreach (XmlAttribute attribute in attributes)
            {
                switch (attribute.Name)
                {
                case "condition":
                case "Condition":
                case "cond":
                case "Cond":
                    x = attribute.Value;
                    char[] thebits = attribute.Value.ToCharArray();

                    // This works because the first operand is after the first part of the string. Thus we get the correct operands.
                    foreach (char bit in thebits)
                    {
                        switch (bit)
                        {
                        case '=':
                        case '!':
                            OpList.Add(bit);
                            continue;
                        }
                        count++;
                    }
                    continue;

                default:
                    ShellCore.ElmThrowException(19);
                    return;
                }
            }

            if (OpList.Count == 0)
            {
                ShellCore.ElmThrowException(41);
            }

            char[] OperatorListA = OpList.ToArray(); // convert to array
            cleancut = x.Split(OperatorListA);

            count = 0; // reset the count

            foreach (string bit2 in cleancut)
            {
                foreach (ShxmlVariable shvar in Varlist)
                {
                    if (cleancut[count] == shvar.Name)
                    {
                        if (shvar.Type == 1)
                        {
                            ShellCore.ElmThrowException(14); // Can't do stuff to strings...yet.
                        }

                        else if (shvar.Type == 5)
                        {
                            ShellCore.ElmThrowException(15); // Can't add booleans.
                        }

                        else
                        {
                            OperandList.Add(Convert.ToString(shvar.vardouble)); // convert it to string
                            count++;
                            continue;
                        }
                    }
                }
                OperandList.Add(bit2);
                count++;
            }

            List <ShxmlVariable> vars  = new List <ShxmlVariable>();
            List <double>        bit3  = new List <double>();
            List <double>        bit3c = new List <double>();

            count = 0; //set count back to 0
            foreach (string bit2 in cleancut)
            {
                string bit2a = bit2.Trim();

                int isVar = 0;
                foreach (ShxmlVariable sxvar in Varlist)
                {
                    if (sxvar.Name == bit2a & bit2a != svar.Name)
                    {
                        isVar = 1;
                        vars.Add(sxvar);
                        bit3.Add(sxvar.vardouble);
                    }
                }
                if (isVar == 0)
                {
                    try
                    {
                        if (bit2a != svar.Name)
                        {
                            double bit2b = Convert.ToDouble(bit2a);
                            bit3.Add(bit2b);
                        }
                    }
                    catch (FormatException)
                    {
                        // error 12 removed from here due to changes in how this works in Shell Development Release
                    }
                }
                isVar = 0;
            }

            // so it's easier
            double[] bit3b = bit3.ToArray();

            ShxmlVariable[] varsb = vars.ToArray(); // local list converted to an array.

            // jesus f*****g christ this code is getting worse!

            foreach (ShxmlVariable varsb2 in varsb)
            {
                bit3c.Add(varsb2.vardouble);
            }

            // this actually parses the stuff
            foreach (double bit3a in bit3b)
            {
                // This is awaiting changes to adding an overload in ShellCore to perform operations on a single int instead of a collection.
                switch (OpList[count])
                {
                case '=':
                    if (bit3a == bit3b[count + 1])
                    {
                        XmlParseScriptNodes(token.ChildNodes);
                    }

                    continue;

                case '!':
                    if (bit3a != bit3b[count + 1])
                    {
                        XmlParseScriptNodes(token.ChildNodes);
                    }
                    continue;
                }
                count++;
            }

            count = 0;

            foreach (ShxmlVariable ShxVar in varsb)
            {
                if (OpList.Count - count > 1)
                {
                    switch (OpList[count])
                    {
                    case '=':
                        if (result == bit3c[count])
                        {
                            XmlParseScriptNodes(token.ChildNodes);
                            return;
                        }
                        count++;
                        continue;

                    case '!':
                        if (result == bit3c[count])
                        {
                            XmlParseScriptNodes(token.ChildNodes);
                            return;
                        }
                        count++;
                        continue;
                    }
                    count++;
                }
            }

            count = 0;
            //return svar;

            return;
        }
Esempio n. 7
0
        public ShxmlVariable ShxmlEvaluateStatement(XmlNode token, int mode = 0)
        {
            int    count  = 0;
            double result = 0;

            XmlAttributeCollection attributes = token.Attributes;
            ShxmlVariable          svar       = new ShxmlVariable();
            string x = null;

            OperandList = new List <string>();
            OpList      = new List <char>();
            foreach (XmlAttribute attribute in attributes)
            {
                switch (attribute.Name)
                {
                case "op":
                case "Op":
                case "operation":
                case "Operation":
                    x = attribute.Value;
                    char[] thebits = attribute.Value.ToCharArray();

                    // This works because the first operand is after the first part of the string. Thus we get the correct operands.
                    foreach (char bit in thebits)
                    {
                        switch (bit)
                        {
                        case '+':
                        case '-':
                        case '*':
                        case '/':
                        case '%':
                            OpList.Add(bit);
                            continue;
                        }
                        count++;
                    }
                    continue;

                case "var":
                case "Var":
                case "variable":
                case "Variable":
                    svar.Name = attribute.Value;
                    svar.Type = 3;     // double by default
                    continue;

                default:
                    ShellCore.ElmThrowException(19);
                    return(svar);
                }
            }

            if (svar.Name == null)
            {
                ShellCore.ElmThrowException(40);
            }

            if (OpList.Count == 0)
            {
                ShellCore.ElmThrowException(41);
            }
            char[] OperatorListA = OpList.ToArray();         // convert to array
            cleancut = x.Split(OperatorListA);

            count = 0;         // reset the count

            foreach (string bit2 in cleancut)
            {
                foreach (ShxmlVariable shvar in Varlist)
                {
                    if (cleancut[count] == shvar.Name)
                    {
                        if (shvar.Type == 1)
                        {
                            ShellCore.ElmThrowException(14);         // Can't do stuff to strings...yet.
                        }

                        else if (shvar.Type == 5)
                        {
                            ShellCore.ElmThrowException(15);         // Can't add booleans.
                        }

                        else
                        {
                            OperandList.Add(Convert.ToString(shvar.vardouble));         // convert it to string
                            count++;
                            continue;
                        }
                    }
                }
                OperandList.Add(bit2);
                count++;
            }



            List <ShxmlVariable> vars  = new List <ShxmlVariable>();
            List <double>        bit3  = new List <double>();
            List <double>        bit3c = new List <double>();

            count = 0;     //set count back to 0
            foreach (string bit2 in cleancut)
            {
                string bit2a = bit2.Trim();

                int isVar = 0;
                foreach (ShxmlVariable sxvar in Varlist)
                {
                    if (sxvar.Name == bit2a & bit2a != svar.Name)
                    {
                        isVar = 1;
                        vars.Add(sxvar);
                        bit3.Add(sxvar.vardouble);
                    }
                }
                if (isVar == 0)
                {
                    try
                    {
                        if (bit2a != svar.Name)
                        {
                            double bit2b = Convert.ToDouble(bit2a);
                            bit3.Add(bit2b);
                        }
                    }
                    catch (FormatException)
                    {
                        // error 12 removed from here due to changes in how this works in Shell Development Release
                    }
                }
                isVar = 0;
            }

            // so it's easier
            double[] bit3b = bit3.ToArray();

            ShxmlVariable[] varsb = vars.ToArray();     // local list converted to an array.

            // jesus f*****g christ this code is getting worse!

            foreach (ShxmlVariable varsb2 in varsb)
            {
                bit3c.Add(varsb2.vardouble);
            }

            // this actually parses the stuff
            foreach (double bit3a in bit3b)
            {
                // This is awaiting changes to adding an overload in ShellCore to perform operations on a single int instead of a collection.
                switch (OpList[count])
                {
                case '+':
                    result = bit3a + bit3b[count + 1];
                    continue;

                case '-':
                    result = bit3a - bit3b[count + 1];
                    continue;

                case '*':
                    result = bit3a * bit3b[count + 1];
                    continue;

                case '/':
                    result = bit3a / bit3b[count + 1];
                    continue;

                case '%':
                    result = bit3a % bit3b[count + 1];
                    continue;
                }
                count++;
            }

            count = 0;

            foreach (ShxmlVariable ShxVar in varsb)
            {
                if (OpList.Count - count > 1)
                {
                    switch (OpList[count])
                    {
                    case '+':
                        result = result + bit3c[count];
                        count++;
                        continue;

                    case '-':
                        result = result - bit3c[count];
                        count++;
                        continue;

                    case '*':
                        result = result * bit3c[count];
                        count++;
                        continue;

                    case '/':
                        result = result / bit3c[count];
                        count++;
                        continue;

                    case '%':
                        result = result % bit3c[count];
                        count++;
                        continue;
                    }
                    count++;
                }
            }

            count = 0;
            //update the main list


            svar.vardouble = result;
            return(svar);
        }
        //TODO: Clean up this function. It blows ass and sucks dick right now.
        public ShxmlVariable ShxmlDeclareVariable(XmlNode node) // Automatically determines the type. Internal?
        {
            ShxmlVariable          xmlvar   = new ShxmlVariable();
            XmlAttributeCollection XmlAttrs = node.Attributes;

            string var_name  = null;
            string var_type  = null;
            string var_value = null;

            foreach (XmlAttribute Attribute in XmlAttrs)
            {
                if (Attribute.Name == "name")
                {
                    var_name = Attribute.Value;
                }

                // get it!
                if (Attribute.Name == "type")
                {
                    var_type = Attribute.Value;
                }

                if (Attribute.Name == "value")
                {
                    var_value = Attribute.Value;
                }
            }


            foreach (ShxmlVariable var in Varlist)
            {
                //Console.WriteLine(var.Name);
                if (var.Name == var_name)
                {
                    //var = null;
                    ShellCore.ElmThrowException(11);
                    return(xmlvar); // silently return if duplicate
                }
            }

            xmlvar.Name = var_name;

            //todo: sometimes for some reason (doubles) it doesn't set the variable
            // split this? -- for function parameters maybe??
            try
            {
                switch (var_type)
                {
                case null:
                    xmlvar.Type = -1;

                    try
                    {
                        xmlvar.Type      = 3;
                        xmlvar.vardouble = Convert.ToDouble(var_value);     // this deliberately triggers an exception
                    }

                    catch (FormatException)   // use an exception handler to set the type
                    {
                        xmlvar.Type      = 1; // ITS A STRING
                        xmlvar.varstring = var_value;
                    }

                    if (xmlvar.Type == -1)
                    {
                        ShellCore.ElmThrowException(5);
                        return(xmlvar);
                    }

                    if (var_value == "true" || var_value == "false")
                    {
                        xmlvar.Type    = 5;
                        xmlvar.varbool = Convert.ToBoolean(var_value);
                    }

                    Varlist.Add(xmlvar);
                    return(xmlvar);

                case "int":
                case "Int":
                    ShxmlInitVariable(var_name, Convert.ToInt32(var_value));
                    return(xmlvar);

                case "str":
                case "Str":
                case "string":
                case "String":
                    //xmlvar.Name = var_name;
                    ShxmlInitVariable(var_name, var_value);
                    return(xmlvar);

                case "letter":
                case "char":
                case "character":
                case "Char":
                case "Character":
                case "Letter":
                    ShxmlInitVariable(var_name, Convert.ToChar(var_value));
                    return(xmlvar);

                case "double":
                case "Double":
                case "number":
                case "Number":
                    ShxmlInitVariable(var_name, Convert.ToDouble(var_value));
                    return(xmlvar);

                case "float":
                case "Float":
                    ShxmlInitVariable(var_name, Convert.ToSingle(var_value));
                    return(xmlvar);

                case "bool":
                case "Bool":
                case "BOOL":
                case "Boolean":
                case "boolean":
                case "truefalse":
                case "true/false":
                case "true false":
                case "falsetrue":
                case "false/true":
                case "false or true":
                case "true or false":
                    ShxmlInitVariable(var_name, Convert.ToBoolean(var_value));
                    return(xmlvar);

                // floats not supported
                default:
                    ShellCore.ElmThrowException(5);
                    return(xmlvar);
                }
            }
            catch (FormatException)
            {
                ShellCore.ElmThrowException(7);
                return(xmlvar);
            }
            //return xmlvar;
        }
Esempio n. 9
-1
        public ShxmlVariable ShxmlPerformOperation(XmlNode token, int mode = 0)
        {
            ShxmlVariable svar = ShxmlEvaluateStatement(token);

            Varlist.Add(svar);
            return(svar);
        }
Esempio n. 10
-1
        public void ShxmlConsoleInput(XmlNode Token)
        {
            string        text = "";
            int           posx = -0xd15ea5e;
            int           posy = -0xd15ea5e;
            char          chr  = ' ';
            ShxmlVariable svar = new ShxmlVariable(); //TODO: Clean up the code.

            svar.Name = "ddddddddddddddddddddddddddddddddddddddddddddddddddd";
            XmlAttributeCollection attributes = Token.Attributes;

            foreach (XmlAttribute attribute in attributes)
            {
                switch (attribute.Name)
                {
                case "text":
                    text = attribute.Value;
                    continue;

                case "posx":
                    try
                    {
                        posx = Convert.ToInt32(attribute.Value);
                    }

                    catch (FormatException)
                    {
                        ShellCore.ElmThrowException(16);
                    }

                    if (posx == -0xd15ea5e)
                    {
                        ShellCore.ElmThrowException(18);
                    }
                    continue;

                case "posy":
                    try
                    {
                        posy = Convert.ToInt32(attribute.Value);
                    }

                    catch (FormatException)
                    {
                        ShellCore.ElmThrowException(17);
                    }

                    if (posx == -0xd15ea5e)
                    {
                        ShellCore.ElmThrowException(18);
                    }

                    continue;

                case "char":
                    try
                    {
                        chr = Convert.ToChar(attribute.Value);
                    }
                    catch (FormatException)
                    {
                        ShellCore.ElmThrowException(20);
                    }

                    continue;

                case "variable":
                case "var":

                    svar.Name = attribute.Value;

                    if (svar.Name == "")
                    {
                        ShellCore.ElmThrowException(21);
                    }

                    svar.Type = 1;     // string


                    continue;
                }
            }

            if (svar.Name == "ddddddddddddddddddddddddddddddddddddddddddddddddddd")
            {
                ShellCore.ElmThrowException(22); // exception 22 - no variable
            }

            if (posx != -0xd15ea5e & posy != 0xd15ea5e)
            {
                UiSetCursorPosition(posx, posy); // set the cursor position if it is not a default value
            }

            Console.Write($"{text} {chr}");
            svar.varstring = Console.ReadLine();
            Varlist.Add(svar); // add it to the global master variable listash
        }