Ejemplo n.º 1
0
    /// <summary>
    /// Sets a variable.
    /// </summary>
    /// <param name="nounAndVar"></param>
    static public void Set(string[] nounAndVar)
    {
        string _noun      = nounAndVar[0]; // variable name (key)
        string _var       = nounAndVar[1]; // variable value (value)
        double _varDouble = GlobalInputParser.EvaluateMathExpression(_var);

        // Limit variables to only one digit, for simplicity.
        if (_noun.Length > 1)
        {
            ConsoleResponseHandling.instance.ThrowError(ConsoleResponseHandling.ErrorType.OnlyOneDigitVariablesAllowed);
            return;
        }

        // If dictionary doesn't contains the key: add it. Else: replace it.
        if (!instance.localVariables.ContainsKey(_noun))
        {
            instance.localVariables.Add(_noun, _varDouble);
        }
        else
        {
            instance.localVariables[_noun] = _varDouble;
        }

        // See Dictionary in Inspector (doesn't account for variable replacements, it is jsut for simple debugging)
        instance.localVariableKeys.Add(_noun);
        instance.localVariableValues.Add(_varDouble);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Calculates mathematical expression. Variables are allowed.
    /// </summary>
    /// <param name="nounAndVar"></param>
    static public void Calc(string[] nounAndVar)
    {
        string _noun = nounAndVar[0]; // Mathematical Expression
        // Iterates through every char of _noun (expression). If a letter is found, it searches if it is a local variable, throws error if not. Finally, it does the calculation.
        List <string> expressionParsed = new List <string>();

        foreach (char c in _noun)
        {
            if (char.IsLetter(c))
            {
                if (instance.localVariables.ContainsKey(c.ToString()))
                {
                    expressionParsed.Add(instance.localVariables[c.ToString()].ToString());
                }
                else
                {
                    ConsoleResponseHandling.instance.ThrowError(ConsoleResponseHandling.ErrorType.LocalVariableNotFound);
                    return;
                }
            }
            else
            {
                expressionParsed.Add(c.ToString());
            }
        }
        string joinedExpression = string.Join("", expressionParsed.ToArray());
        string result           = GlobalInputParser.EvaluateMathExpression(joinedExpression).ToString();

        CanvasLogicInGame.instance.SetOutput(result);
    }
Ejemplo n.º 3
0
    private void CallCommand(string _action, string _object = null, string _noun = null, string _var = null)
    {
        // Setting first char of every string to upper (except _var)
        _action = GlobalInputParser.SetFirstCharToUpper(_action);
        _object = GlobalInputParser.SetFirstCharToUpper(_object);
        _noun   = GlobalInputParser.SetFirstCharToUpper(_noun);

        string[] NounAndVar = { _noun, _var };

        try {
            if (_object == null)
            {
                InvokeStringMethod(_action, "Console", NounAndVar);
            }
            else
            {
                InvokeStringMethod(_action, _object, NounAndVar);
            }
        } catch {
            ConsoleResponseHandling.instance.ThrowError(ConsoleResponseHandling.ErrorType.InvalidCommand);
            return;
        }
        ConsoleResponseHandling.instance.ThrowResponse(ConsoleResponseHandling.ResponseType.Done);
        //Debug.Log(_object + " | " + _action + " | " + _noun + " | " + _var);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Changes background or text color of console.
    /// </summary>
    /// <param name="nounAndVar"></param>
    static public void Change(string[] nounAndVar)
    {
        string _noun = nounAndVar[0];
        string _var  = nounAndVar[1];

        switch (_noun)
        {
        case "Bg":
            CanvasLogicInGame.instance.ChangeUIColor(GlobalInputParser.StringToColor(_var), true);
            break;

        case "Text":
            CanvasLogicInGame.instance.ChangeUIColor(GlobalInputParser.StringToColor(_var), false);
            break;

        case "Help":
            CanvasLogicInGame.instance.SetOutput("To change the colors of the console background or text, you must follow this structure: console change bg/text <hexadecimal-color>");
            break;

        default:
            ConsoleResponseHandling.instance.ThrowError(ConsoleResponseHandling.ErrorType.InvalidCommand);
            return;
        }
    }