예제 #1
0
 public override string VariableOperation(Compiler.Variable var, int value, string op, string selector = "")
 {
     if (op == "=")
     {
         return("scoreboard players set " + GetSelector(var, selector) + " " + value.ToString() + "\n");
     }
     if (op == "+=")
     {
         return("scoreboard players add " + GetSelector(var, selector) + " " + value.ToString() + "\n");
     }
     if (op == "-=")
     {
         return("scoreboard players remove " + GetSelector(var, selector) + " " + value.ToString() + "\n");
     }
     if (op == "*=")
     {
         return("scoreboard players operation " + GetSelector(var, selector) + " *= " + GetSelector(Compiler.GetConstant(value), "") + "\n");
     }
     if (op == "/=")
     {
         return("scoreboard players operation " + GetSelector(var, selector) + " /= " + GetSelector(Compiler.GetConstant(value), "") + "\n");
     }
     if (op == "%=")
     {
         return("scoreboard players operation " + GetSelector(var, selector) + " %= " + GetSelector(Compiler.GetConstant(value), "") + "\n");
     }
     throw new Exception("Unsupported Operator: " + op);
 }
예제 #2
0
 private string GetSelector(Compiler.Variable var1, string selector = "")
 {
     if (var1.entity)
     {
         if (selector != "")
         {
             return(var1.scoreboard().Replace("@s", selector));
         }
         else
         {
             return(var1.scoreboard());
         }
     }
     else
     {
         if (selector.Length > 1)
         {
             throw new Exception("Can not asign " + var1.gameName + " to " + selector);
         }
         else
         {
             return("@e[type=tmbsvalue] " + var1.scoreboard().Split(' ')[0]);
         }
     }
 }
 public override string[] CompareVariable(Compiler.Variable var1, int value, string op, string selector1 = "")
 {
     if (op == "=" || op == "==")
     {
         return(new string[] { "if score " + GetSelector(var1, selector1) + " matches " + value.ToString() + " ", "" });
     }
     else if (op == "<=")
     {
         return(new string[] { "if score " + GetSelector(var1, selector1) + " matches .." + value.ToString() + " ", "" });
     }
     else if (op == "<")
     {
         return(new string[] { "if score " + GetSelector(var1, selector1) + " matches .." + (value - 1).ToString() + " ", "" });
     }
     else if (op == ">=")
     {
         return(new string[] { "if score " + GetSelector(var1, selector1) + " matches " + value.ToString() + ".. ", "" });
     }
     else if (op == ">")
     {
         return(new string[] { "if score " + GetSelector(var1, selector1) + " matches " + (value + 1).ToString() + ".. ", "" });
     }
     else if (op == "!=")
     {
         return(new string[] { "unless score " + GetSelector(var1, selector1) + " matches " + value.ToString() + " ", "" });
     }
     else
     {
         throw new Exception("Unundelled Operation: " + op);
     }
 }
예제 #4
0
 public override string[] CompareVariable(Compiler.Variable var1, int value, string op, string selector1 = "")
 {
     if (op == "=" || op == "==")
     {
         return new string[] { "execute " + GetSelectorEntity(var1, value.ToString(), selector1) + " ~ ~ ~ ", "" }
     }
     ;
     else if (op == "<=")
     {
         return new string[] { "execute " + GetSelectorEntity(var1, ".." + value.ToString(), selector1) + " ~ ~ ~ ", "" }
     }
     ;
     else if (op == ">=")
     {
         return new string[] { "execute " + GetSelectorEntity(var1, value.ToString() + "..", selector1) + " ~ ~ ~ ", "" }
     }
     ;
     else if (op == "<")
     {
         return new string[] { "execute " + GetSelectorEntity(var1, ".." + (value - 1).ToString(), selector1) + " ~ ~ ~ ", "" }
     }
     ;
     else if (op == ">")
     {
         return new string[] { "execute " + GetSelectorEntity(var1, (value + 1).ToString() + "..", selector1) + " ~ ~ ~ ", "" }
     }
     ;
     else
     {
         throw new Exception("Unsupported Operator " + op);
     }
 }
 public override string[] CompareVariable(Compiler.Variable var1, Compiler.Variable var2, string op, string selector1 = "", string selector2 = "")
 {
     if (op == "==")
     {
         op = "=";
     }
     return(new string[] { "if score " + GetSelector(var1, selector1) + " " + op + " " + GetSelector(var2, selector2) + " ", "" });
 }
예제 #6
0
        public override string[] CompareVariable(Compiler.Variable var1, Compiler.Variable var2, string op, string selector1 = "", string selector2 = "")
        {
            var    c    = condInv++;
            var    name = "__cond_bedrock__" + c.ToString();
            string def  = Compiler.parseLine(var1.type.ToString().ToLower() + " " + name + " = " + var1.gameName);

            def += Compiler.parseLine(name + " -= " + var2.gameName);
            string[] res = CompareVariable(Compiler.GetVariableByName(name), 0, op, selector1);

            return(new string[] { res[0], res[1] + "\n" + def });
        }
예제 #7
0
        private static string FormatVariable(Compiler.Variable v)
        {
            switch (v.variableType)
            {
            // Escaping to not allow rich text
            case Compiler.VariableTypes.textString: return("<color=#7cbc4f>\"" + EscapeString(v.getString()) + "\"</color>");

            // For ultimate /double/ precision. My eyes are bleeding from this though
            case Compiler.VariableTypes.number: return("<color=#e8a64e>" + v.getNumber().ToString("0." + new string('#', 325)) + "</color>");

            case Compiler.VariableTypes.boolean: return("<color=#de5170>" + v.getBool().ToString() + "</color>");

            default: return("<color=#de5170>None</color>");
            }
        }
예제 #8
0
        static Compiler.Variable[] validParameters(string trimmedPara, Compiler.Function calledFunction, int lineNumber, Compiler.Scope currentScope)
        {
            string[] words = Compiler.WordParser.parseWords(trimmedPara);

            if (words.Length != 0)
            {
                Compiler.Logic[] logicOrder = WordLogic.determineLogicFromWords(words, lineNumber, currentScope);

                List <List <Compiler.Logic> > packedLogics = convertIntoParameterLogic(words, logicOrder, lineNumber);

                if (packedLogics != null)
                {
                    Compiler.Variable[] inputVariables = new Compiler.Variable[packedLogics.Count];

                    for (int i = 0; i < packedLogics.Count; i++)
                    {
                        inputVariables [i] = ValidSumCheck.checkIfValidSum(packedLogics [i].ToArray(), lineNumber);
                    }


                    foreach (Compiler.Variable v in inputVariables)
                    {
                        if (v.variableType == Compiler.VariableTypes.unkown)
                        {
                            ErrorMessage.sendErrorMessage(lineNumber, "one or several of the input parameters to function: " + calledFunction.name + " are corrupt!");
                        }
                    }


                    if (calledFunction.inputParameters.Contains(inputVariables.Length))
                    {
                        return(inputVariables);
                    }
                }
            }

            if (calledFunction.inputParameters.Contains(0))
            {
                return(new Compiler.Variable[0]);
            }

            ErrorMessage.sendErrorMessage(lineNumber, "Amount of parameters does not match Expected!");
            return(new Compiler.Variable[0]);
        }
예제 #9
0
 private string GetSelectorEntity(Compiler.Variable var1, string val, string selector = "")
 {
     if (selector == "")
     {
         return("@s[type=tbmsvalue,scores={" + var1.scoreboard().Split(' ')[0] + "=" + val + "}]");
     }
     else
     {
         if (selector.Contains("]"))
         {
             return(selector.Substring(0, selector.LastIndexOf("]")) +
                    ",scores={" + var1.scoreboard().Replace("@s ", "") + "=" + val + "}]");
         }
         else
         {
             return(selector + "[scores={" + var1.scoreboard().Replace("@s ", "") + "=" + val + "}]");
         }
     }
 }
예제 #10
0
 public abstract string VariableOperation(Compiler.Variable var1, Compiler.Variable var2, string op, string selector1 = "", string selector2 = "");
예제 #11
0
 public override string VariableSetNull(Compiler.Variable var, string selector = "")
 {
     return("scoreboard players reset " + GetSelector(var, selector));
 }
예제 #12
0
 public override string[] CompareVariable(Compiler.Variable var1, int value1, int value2, string selector1 = "")
 {
     return(new string[] { "if score " + GetSelector(var1, selector1) + " matches " + value1.ToString() + ".." + value2.ToString() + " ", "" });
 }
예제 #13
0
 public abstract string[] CompareVariable(Compiler.Variable var1, Compiler.Variable var2, string op, string selector1 = "", string selector2 = "");
예제 #14
0
 public abstract string[] CompareVariable(Compiler.Variable var1, int value1, int value2, string selector1 = "");
예제 #15
0
 public Constant(double value)
 {
     variable         = Compiler.GetConstant(value);
     this.valueDouble = value;
     isFloat          = true;
 }
예제 #16
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > -1)
            {
                if (Functions != null)
                {
                    listBox2.Items.Clear();
                    richTextBox1.Text  = "";
                    richTextBox1.Text += listBox1.SelectedItem.ToString() + "\n";
                    foreach (Compiler.Function f in Functions[listBox1.SelectedItem.ToString()])
                    {
                        foreach (var arg in f.args)
                        {
                            listBox2.Items.Add(arg.name + " : " + arg.GetTypeString());
                        }
                        if (Functions[listBox1.SelectedItem.ToString()].Count > 1)
                        {
                            listBox2.Items.Add("==========================");
                        }
                        richTextBox1.Text += f.desc + "\n==========================\n";
                        richTextBox1.Text += $"lazy: {f.lazy.ToString()} adj: {f?.package}\nattributes: {(f?.attributes.Count > 0 ? f?.attributes.Aggregate((x, y) => (x + ", " + y)):"")}\n\n";
                        foreach (string line in f.file.parsed)
                        {
                            richTextBox1.Text += line + "\n";
                        }
                        richTextBox1.Text += "\n==========================\n";
                    }
                }
                if (Structures != null)
                {
                    listBox2.Items.Clear();
                    Compiler.Structure f = Structures[listBox1.SelectedItem.ToString()];
                    foreach (var arg in f.fields)
                    {
                        listBox2.Items.Add(arg.name + " : " + arg.GetTypeString());
                    }
                    richTextBox1.Text = $"attributes: {(f.attributes.Count > 0 ? f.attributes.Aggregate((x, y) => (x + ", " + y)):"")}";
                }
                if (Variables != null)
                {
                    listBox2.Items.Clear();
                    Compiler.Variable f = Variables[listBox1.SelectedItem.ToString()];
                    richTextBox1.Text = f.gameName + ": " + f.GetTypeString() + " entity:" + f.entity.ToString() + $"\nattributes: {(f.attributes.Count>0?f.attributes.Aggregate((x, y) => (x + ", " + y)):"")}";
                }
                if (Enums != null)
                {
                    listBox2.Items.Clear();
                    List <string> f = Enums[listBox1.SelectedItem.ToString()].Values();

                    foreach (var arg in f)
                    {
                        listBox2.Items.Add(arg);
                    }
                }
                if (Tags != null)
                {
                    listBox2.Items.Clear();
                    List <string> f = Tags[listBox1.SelectedItem.ToString()].values;

                    foreach (var arg in f)
                    {
                        listBox2.Items.Add(arg);
                    }
                }
                if (names != null)
                {
                    listBox2.Items.Clear();
                    listBox2.Items.Add(listBox1.SelectedItem.ToString());
                    richTextBox1.Text = listBox1.SelectedItem.ToString();
                }
                if (Predicates != null)
                {
                    listBox2.Items.Clear();
                    foreach (var v in Predicates[listBox1.SelectedItem.ToString()])
                    {
                        richTextBox1.Text += v.baseFile.content + "\n===================\n";
                    }
                }
            }
        }
예제 #17
0
 public abstract string VariableSetNull(Compiler.Variable var, string selector = "");
예제 #18
0
 public override string[] CompareVariable(Compiler.Variable var1, int value1, int value2, string selector1 = "")
 {
     return(new string[] { "execute " + GetSelectorEntity(var1, value1.ToString() + ".." + value2.ToString(), selector1) + " ~ ~ ~ ", "" });
 }
예제 #19
0
 public abstract string VariableOperation(Compiler.Variable var, int value, string op, string selector = "");
예제 #20
0
 public Variable(Compiler.Variable variable)
 {
     this.variable = variable;
 }
예제 #21
0
 public override string VariableOperation(Compiler.Variable var1, Compiler.Variable var2, string op, string selector1 = "", string selector2 = "")
 {
     return("scoreboard players operation " + GetSelector(var1, selector1) + " " + op + " " + GetSelector(var2, selector2) + "\n");
 }
예제 #22
0
 public Constant(int value)
 {
     variable      = Compiler.GetConstant(value);
     this.valueInt = value;
     isFloat       = false;
 }
예제 #23
0
 public void SetPrintPopupValue(Compiler.Variable valueToPrint)
 {
     thePrintText.text = FormatVariable(valueToPrint);
     ResizeToFit(thePrintText, bubbleRect);
 }