コード例 #1
0
    internal static void createForkNode(Sequence seq, JSONObject jsonObj, IState variables, string nodeId, string key)
    {
        JSONObject node = jsonObj.GetField(nodeId);

        if (!node.HasField(OPTIONS_FIELD))
        {
            throw new Exception("The node " + key + "->" + nodeId + " need a " + OPTIONS_FIELD + " field");
        }

        List <JSONObject> optionsList = node.GetField(OPTIONS_FIELD).list;

        List <Checkable> checkables = new List <Checkable>();

        foreach (JSONObject j in optionsList)
        {
            if (j.HasField(NEXT_FIELD) && j.HasField(CONDITION_FIELD))
            {
                checkables.Add(FormulaFork.Create(j.GetField(CONDITION_FIELD).ToString().Replace("\"", "")));
            }
            else
            {
                throw new Exception("The node " + key + "->" + nodeId + " need a " + NEXT_FIELD + " and " + CONDITION_FIELD + " field");
            }
        }

        SequenceNode newNode = seq[nodeId];

        newNode.Content = MultiFork.Create(checkables);

        if (nodeId == "root")
        {
            seq.Root = newNode;
        }

        int child = 0;

        foreach (JSONObject j in optionsList)
        {
            if (j.HasField(NEXT_FIELD))
            {
                string nextNodeId = j.GetField(NEXT_FIELD).ToString().Replace("\"", "");
                if (nodeId == "root")
                {
                    seq.Root.Childs[child] = seq[nextNodeId];
                }
                else
                {
                    seq[nodeId][child] = seq[nextNodeId];
                }
                createNode(seq, jsonObj, variables, nextNodeId, key);
                child++;
            }
            else
            {
                throw new Exception("The node " + key + "->" + nodeId + " need a " + NEXT_FIELD + " and " + MESSAGE_FIELD + " field");
            }
        }
    }
コード例 #2
0
    internal static void createOptionsNode(Sequence seq, JSONObject jsonObj, IState variables, string nodeId, string key)
    {
        JSONObject node = jsonObj.GetField(nodeId);

        if (!node.HasField(OPTIONS_FIELD))
        {
            throw new Exception("The node " + key + "->" + nodeId + " need a " + OPTIONS_FIELD + " field");
        }

        List <JSONObject> optionsList = node.GetField(OPTIONS_FIELD).list;

        List <Option> options = new List <Option>();

        foreach (JSONObject j in optionsList)
        {
            if (j.HasField(MESSAGE_FIELD))
            {
                Checkable check = null;
                if (j.HasField(CONDITION_FIELD))
                {
                    check = FormulaFork.Create(j.GetField(CONDITION_FIELD).ToString().Replace("\"", ""));
                }
                options.Add(new Option(j.GetField(MESSAGE_FIELD).ToString().Replace("\"", ""), string.Empty, check));
            }
            else
            {
                throw new Exception("The node " + key + "->" + nodeId + " need a " + MESSAGE_FIELD + " field");
            }
        }

        SequenceNode newNode    = seq[nodeId];
        Options      optionsObj = Options.Create(options);

        if (node.HasField(OPTIONS_QUESTION_ID))
        {
            optionsObj.QuestionID = node.GetField(OPTIONS_QUESTION_ID).ToString().Replace("\"", "");
        }

        newNode.Content = optionsObj;

        if (nodeId == "root")
        {
            seq.Root = newNode;
        }

        int child = 0;

        foreach (JSONObject j in optionsList)
        {
            if (j.HasField(NEXT_FIELD) && j.HasField(MESSAGE_FIELD))
            {
                string nextNodeId = j.GetField(NEXT_FIELD).ToString().Replace("\"", "");
                if (nodeId == "root")
                {
                    seq.Root.Childs[child] = seq[nextNodeId];
                }
                else
                {
                    seq[nodeId][child] = seq[nextNodeId];
                }
                createNode(seq, jsonObj, variables, nextNodeId, key);
            }
            child++;
        }
    }