Пример #1
0
    public List <int> ReadStateFields()
    {
        List <int> errors = new List <int>();

        stateFunctions.Clear();
        for (int i = 0; i < stateFields.Count; i++)
        {
            StateFunction stateFunction = new StateFunction();

            string gameObjectName = stateFields[i].name.ToString(); // tmp input name format is 'x_input_y' or 'xx_input_y'

            if (Char.IsDigit(gameObjectName[1]))
            {
                stateFunction.setTriggerValue(gameObjectName[9]);
                stateFunction.setTriggerState(int.Parse((gameObjectName[0] - '0').ToString() + (gameObjectName[1] - '0').ToString()));
            }
            else
            {
                stateFunction.setTriggerState(gameObjectName[0] - '0');
                stateFunction.setTriggerValue(gameObjectName[8]);
            }

            Regex regex = new Regex(@"[Qq]\d+\s*(,)\s*[01b]{1}\s*(,)\s*[RLNrln]");

            Match match = regex.Match(stateFields[i].text);

            if (match.Success)
            {
                string trim = stateFields[i].text.Replace(" ", "");
                trim = trim.ToUpper();
                trim = trim.Replace("B", "b");

                string[] inputValues = trim.Split(','); // input format should be 'q0, 0, R' or 'q0,0,R' or 'q10, 0, R'

                if (inputValues[0].Length == 3)
                {
                    stateFunction.setOutputState(int.Parse((inputValues[0][1] - '0').ToString() + (inputValues[0][2] - '0').ToString()));
                }
                else if (inputValues[0].Length == 2)
                {
                    stateFunction.setOutputState(inputValues[0][1] - '0');
                }
                else if (inputValues[0].Length >= 4)
                {
                    stateFunction.setOutputState(17);
                }

                stateFunction.setOutputValue(inputValues[1][0]);
                stateFunction.setAction(inputValues[2][0]);

                stateFunctions.Add(stateFunction);
            }
            else if (stateFields[i].text != "")
            {
                errors.Add(i);
            }
        }
        return(errors);
    }
Пример #2
0
    private StateFunction findStateFunction(char triggerValue, int triggerState)
    {
        StateFunction stateFunction = new StateFunction();

        stateFunction.setOutputState(-1);

        foreach (StateFunction sf in stateFunctions)
        {
            if (sf.getTriggerState() == triggerState && sf.getTriggerValue() == triggerValue)
            {
                return(sf);
            }
        }
        return(stateFunction);
    }