Ejemplo n.º 1
0
    public RihaNode place(RihaNode[] parameters)
    {
        RihaNode par = parameters[parameters.Length - 1];

        RihaNode[] getZero = new RihaNode[] {
            new RihaNode(ValueType.number, 0)
        };
        RihaNode[] getOne = new RihaNode[] {
            new RihaNode(ValueType.number, 1)
        };

        string name = par.get(getZero).GetString();

        RihaNode tileLocation = par.get(getOne);

        Buildable building = GameData.GetBuilding(name);

        if (building != null)
        {
            float x = (float)tileLocation.get(getZero).GetValue();
            float z = (float)tileLocation.get(getOne).GetValue();

            Tile t = GameController.island.GetTileByWorldCoords(x, z);
            GameController.playerController.SetBuilding(building);
            GameController.playerController.Build(t);
            return(new RihaNode(ValueType.boolean, true));
        }
        return(new RihaNode(ValueType.boolean, false));
    }
Ejemplo n.º 2
0
    public RihaNode set(RihaNode[] parameters)
    {
        RihaNode p = parameters[parameters.Length - 1];

        this.value = p.value;
        this.type  = p.GetNodeType();
        return(this);
    }
Ejemplo n.º 3
0
    override protected void Execute()
    {
        RihaNode  variable = this.parameters[0];
        ValueType type     = GetValueType(words[3]);

        variable.SetType(type);

        RihaCompiler.AddToMemory(words[1], variable);
    }
Ejemplo n.º 4
0
    void ExecuteAction(List <string> actions)
    {
        actions.Reverse();
        List <RihaNode> finishedActionsReturns = new List <RihaNode>();

        foreach (string action in actions)
        {
            string[] words    = SplitWords(action).ToArray();
            object   isAction = EvaluateAction(action, words, finishedActionsReturns);
            if (isAction == null)
            {
                RihaNode functionNode = IsFunction(action, words);
                if (functionNode != null)
                {
                    string[]   functions      = words[0].Split('.');
                    string     methodName     = (functionNode.GetNodeType() == ValueType.GLOBAL) ? "GlobalCall" : functions[1].ToLower();
                    MethodInfo functionMethod = functionNode.GetType().GetMethod(methodName);
                    if (functionMethod != null)
                    {
                        object[] parameters;
                        if ((functionNode.GetNodeType() == ValueType.GLOBAL))
                        {
                            parameters = new object[] {
                                functions[1].ToLower(),
                                finishedActionsReturns.ToArray(),
                            };
                        }
                        else
                        {
                            parameters = new object[] {
                                finishedActionsReturns.ToArray(),
                            };
                        }
                        RihaNode returnValue = (RihaNode)functionMethod.Invoke(functionNode, parameters);
                        finishedActionsReturns.Add(returnValue);
                    }
                }
                else
                {
                    MethodInfo actionMethod = this.GetType().GetMethod(words[0].ToLower());
                    if (actionMethod != null)
                    {
                        object[] parameters = new object[] {
                            action,
                            words,
                            finishedActionsReturns.ToArray()
                        };
                        actionMethod.Invoke(this, parameters);
                    }
                }
            }
            else
            {
                finishedActionsReturns.Add(isAction == null ? null : (RihaNode)isAction);
            }
        }
    }
Ejemplo n.º 5
0
    public void import(string action, string[] words, RihaNode[] previuseActionResult)
    {
        //Patern set [varible_key] as [variable_type];
        string setPattern = @"\s*import\s*";

        if (MatchesRegex(action, setPattern))
        {
            RihaNode varible = previuseActionResult[previuseActionResult.Length - 1];
        }
    }
Ejemplo n.º 6
0
    public void size(string action, string[] words, RihaNode[] previuseActionResult)
    {
        string printPattern = @"\s*size\s+of\s*";

        if (MatchesRegex(action, printPattern))
        {
            RihaNode node = previuseActionResult[previuseActionResult.Length - 1];
            codeOutput += node.GetSize() + "\n";
            Debug.Log(node.GetSize());
        }
    }
Ejemplo n.º 7
0
    public void print(string action, string[] words, RihaNode[] previuseActionResult)
    {
        string printPattern = @"\s*print\s*";

        if (MatchesRegex(action, printPattern))
        {
            RihaNode node  = previuseActionResult[previuseActionResult.Length - 1];
            string   value = node.GetString();
            codeOutput += value + "\n";
        }
    }
Ejemplo n.º 8
0
    public RihaNode bigger_than(RihaNode[] parameters)
    {
        bool     ret            = false;
        RihaNode comperisonNode = parameters[parameters.Length - 1];

        if (comperisonNode.GetSize() < GetSize())
        {
            ret = true;
        }
        return(new RihaNode(ValueType.boolean, ret));
    }
Ejemplo n.º 9
0
    public RihaNode equal_type(RihaNode[] parameters)
    {
        bool     ret            = false;
        RihaNode comperisonNode = parameters[parameters.Length - 1];

        if (comperisonNode.GetNodeType() == GetNodeType())
        {
            ret = true;
        }
        return(new RihaNode(ValueType.boolean, ret));
    }
Ejemplo n.º 10
0
    public RihaNode GlobalCall(string method, RihaNode[] par)
    {
        MethodInfo functionMethod = value.GetType().GetMethod(method);

        if (functionMethod != null)
        {
            object[] parameters  = new object[] { par };
            RihaNode returnValue = (RihaNode)functionMethod.Invoke(value, parameters);
            return(returnValue);
        }
        return(null);
    }
Ejemplo n.º 11
0
    public RihaNode less_than(RihaNode[] parameters)
    {
        bool     ret            = false;
        RihaNode comperisonNode = parameters[parameters.Length - 1];

        if (comperisonNode.GetSize() > GetSize())
        {
            ret = true;
        }
        Debug.Log(ret);
        return(new RihaNode(ValueType.boolean, ret));
    }
Ejemplo n.º 12
0
    public void set(string action, string[] words, RihaNode[] previuseActionResult)
    {
        //Patern set [varible_key] as [variable_type];
        string setPattern = @"\s*set\s+\w+\s+as\s+\w+\s*";

        if (MatchesRegex(action, setPattern))
        {
            RihaNode  varible = previuseActionResult[previuseActionResult.Length - 1];
            ValueType type    = GetValueType(words[3]);
            varible.SetType(type);
            variableMemory.Add(words[1], varible);
        }
    }
Ejemplo n.º 13
0
    public void add(string action, string[] words, RihaNode[] previuseActionResult)
    {
        string addPattern = @"\s*add\s+to\s+\w+\s*";

        if (MatchesRegex(action, addPattern))
        {
            string variableKey = words[2];
            if (variableMemory.ContainsKey(variableKey))
            {
                RihaNode varibale = variableMemory[variableKey];
                varibale.Add(previuseActionResult[previuseActionResult.Length - 1]);
            }
        }
    }
Ejemplo n.º 14
0
 public void Add(RihaNode addNode)
 {
     if (type == ValueType.number)
     {
         float add      = addNode.GetNodeType() == ValueType.number ? RihaNode.GetNumeric(addNode.GetValue()) : 0;
         float newValue = RihaNode.GetNumeric(value) + add;
         value = newValue.ToString();
     }
     else if (type == ValueType.text)
     {
         value += addNode.GetString();
     }
     else if (type == ValueType.array)
     {
         ((List <RihaNode>)value).Add(addNode);
     }
 }
Ejemplo n.º 15
0
    public void scope(string action, string[] words, RihaNode[] previuseActionResult)
    {
        string setPattern = @"\s*scope\s+\w+\s*";

        if (MatchesRegex(action, setPattern))
        {
            RihaNode  value = previuseActionResult[previuseActionResult.Length - 1];
            ScopeType type  = GetScopeType(words[1]);
            if (type == ScopeType.check && value.GetNodeType() == ValueType.boolean || type == ScopeType.loop && value.GetNodeType() == ValueType.number)
            {
                scopes.Add(new RihaScope()
                {
                    type      = type,
                    parameter = value,
                    startLine = lineNumber
                });
            }
        }
    }
Ejemplo n.º 16
0
    object EvaluateAction(string action, string[] words, List <RihaNode> pevActions)
    {
        // Is number:
        float n;
        bool  isNumeric = float.TryParse(action, out n);

        if (isNumeric)
        {
            return(new RihaNode(ValueType.number, n));
        }


        if (words.Length == 1)
        {
            if (words[0] == "GLOBAL")
            {
                if (globals.ContainsKey(pevActions.Last().GetString()))
                {
                    return(globals[pevActions.Last().GetString()]);
                }
            }
            //Is boolean
            else if (words[0].ToLower() == "true")
            {
                return(new RihaNode(ValueType.boolean, true));
            }
            else if (words[0].ToLower() == "false")
            {
                return(new RihaNode(ValueType.boolean, false));
            }
            else if (words[0].ToLower() == "null")
            {
                return(new RihaNode(ValueType.tmp, null));
            }
            // NULL
        }

        //Is varibale
        if (variableMemory.ContainsKey(words[0]))
        {
            return(variableMemory[words[0]]);
        }

        //Is array
        string        arrayPattern = @"\[.*\]";
        List <string> arrayGroups  = GroupMatch(action, arrayPattern);

        if (arrayGroups != null)
        {
            string          arrayless = arrayGroups[0].Substring(1, arrayGroups[0].Length - 2);
            string[]        elements  = arrayless.Split(',');
            List <RihaNode> array     = new List <RihaNode>();
            foreach (string element in elements)
            {
                string[] elementWords = SplitWords(element).ToArray();
                RihaNode variable     = (RihaNode)EvaluateAction(element, elementWords, null);
                array.Add(variable);
            }
            return(new RihaNode(ValueType.array, array));
        }

        //Is text:
        string        textPattern = @"\"".*?\""";
        List <string> textGroups  = GroupMatch(action, textPattern);

        if (textGroups != null)
        {
            string qouteless = textGroups[0].Substring(1, textGroups[0].Length - 2);
            return(new RihaNode(ValueType.text, qouteless));
        }


        return(null);
    }
Ejemplo n.º 17
0
 public static void AddToMemory(string key, RihaNode value)
 {
     RihaCompiler.variableMemory.Add(key, value);
 }