public BTreeData(JSON js) { _id = js.ToString("name"); List <BTNodeData> listOfNodes = new List <BTNodeData>(); JSON[] nodeList = js.ToArray <JSON>("bTree"); for (int i = 0; i < nodeList.Length; ++i) { BTNodeData nodeData = BTNodeData.CreateNodeData(nodeList[i]); listOfNodes.Add(nodeData); } JSON[] connectionList = js.ToArray <JSON>("connections"); for (int i = 0; i < connectionList.Length; ++i) { int inNodeId = connectionList[i].ToInt("inNodeId"); int outNodeId = connectionList[i].ToInt("outNodeId"); BTNodeData inNode = listOfNodes[inNodeId]; BTNodeData outNode = listOfNodes[outNodeId]; if (inNode.type == BTNodeData.TYPE.ROOT || inNode.type == BTNodeData.TYPE.DECORATOR) { (inNode as BTDecoratorNodeData).AddChild(outNode); if (inNode.type == BTNodeData.TYPE.ROOT) { _btRootData = outNode; } } else if (inNode.type == BTNodeData.TYPE.COMPOSITE) { (inNode as BTCompositeNodeData).AddChild(outNode); } } }
public BTDecoratorNodeData(JSON js) : base(js, TYPE.DECORATOR) { JSON paramsJS = js.ToJSON("nodeParams"); if (paramsJS.Contains("child")) { JSON childNodeJS = paramsJS.ToJSON("child"); BTNodeData childNode = BTNodeData.CreateNodeData(childNodeJS); if (childNode != null) { AddChild(childNode); } } }
public BTCompositeNodeData(JSON js) : base(js, TYPE.COMPOSITE) { _children = new List <BTNodeData>(); JSON paramsJS = js.ToJSON("nodeParams"); JSON[] childrenJS = paramsJS.ToArray <JSON>("children"); for (int i = 0; i < childrenJS.Length; ++i) { JSON nodeJS = childrenJS[i]; BTNodeData childNode = BTNodeData.CreateNodeData(nodeJS); if (childNode != null) { AddChild(childNode); } } }