Example #1
0
    public void Awake()
    {
        String   json = GameManager.instance.loadJSONFile("graph.json");
        JSONList list = JsonUtility.FromJson <JSONList>(json);

        vertices = list.vertices;
    }
Example #2
0
    public void Awake()
    {
        String   json = GameManager.instance.loadJSONFile("graph.json");
        JSONList list = JsonUtility.FromJson <JSONList>(json);

        vertices = list.vertices;

        foreach (Vertex vertex in vertices)
        {
            foreach (int id in vertex.adjacency)
            {
                vertex.edges.Add(new Edge(vertex, vertices[id]));
            }
        }
    }
    private void SaveData()
    {
        List <JSONDictionary> JSONDict = new List <JSONDictionary>();

        foreach (Node currentNode in nodes)
        {
            JSONDictionary thisJSON = new JSONDictionary();
            thisJSON.nodeID           = currentNode.nodeID;
            thisJSON.name             = currentNode.titleString;
            thisJSON.body             = currentNode.bodyString;
            thisJSON.uniqueIDString   = currentNode.uniqueIDString;
            thisJSON.blackboardString = currentNode.blackboardString;
            thisJSON.variableValue    = currentNode.valueBool;
            thisJSON.variableString   = currentNode.variableString;
            thisJSON.position         = currentNode.rect;
            thisJSON.type             = currentNode.type;
            thisJSON.option1          = currentNode.option1String;
            thisJSON.option2          = currentNode.option2String;
            thisJSON.option3          = currentNode.option3String;
            thisJSON.option4          = currentNode.option4String;
            JSONDict.Add(thisJSON);
        }

        List <JSONConnectionDictionary> JSONConnectDict = new List <JSONConnectionDictionary>();

        if (connections.Count != 0)
        {
            foreach (Connection currentConnection in connections)
            {
                JSONConnectionDictionary thisJSON = new JSONConnectionDictionary();
                thisJSON.inPointID    = currentConnection.inPoint.node.nodeID;
                thisJSON.outPointID   = currentConnection.outPoint.node.nodeID;
                thisJSON.outBoolType  = currentConnection.outPoint.boolType;
                thisJSON.optionNumber = currentConnection.outPoint.optionNumber;
                JSONConnectDict.Add(thisJSON);
            }
        }

        JSONList JSONListO = new JSONList();

        JSONListO.dataList       = JSONDict;
        JSONListO.connectionList = JSONConnectDict;

        string dataAsJson = JsonUtility.ToJson(JSONListO);

        File.WriteAllText(filePath, dataAsJson);
    }
Example #4
0
        public void JSON_BuildJSONTree()
        {
            var jsonList = new JSONList
            {
                new BaseItem {Author = "Navid"},
                new BaseItem {Author = "Preety"},
                new BaseItem {Author = "One"},
                new BaseItem {Author = "Two"}
            };

            var list = new List<BaseItem>
            {
                new BaseItem {Author = "Navid"},
                new BaseItem {Author = "Preety"},
            };

            var jsonList2 = JSONList.ToJSONList(list);
            var jsonString2 = jsonList2.ToJSONString();
            Assert.IsTrue(jsonString2.Contains("Navid"));
            var jsonString = jsonList.ToJSONString();
            Assert.IsTrue(jsonString.Contains("Navid"));
        }
Example #5
0
        public void JSON_BuildJSONTree()
        {
            var jsonList = new JSONList
            {
                new BaseListItem {
                    Author = "Navid"
                },
                new BaseListItem {
                    Author = "Preety"
                },
                new BaseListItem {
                    Author = "One"
                },
                new BaseDocument {
                    Author = "Two"
                }
            };

            var list = new List <BaseListItem>
            {
                new BaseListItem {
                    Author = "Navid"
                },
                new BaseListItem {
                    Author = "Preety"
                },
            };

            var jsonList2   = JSONList.ToJSONList(list);
            var jsonString2 = jsonList2.ToJSONString();

            Assert.IsTrue(jsonString2.Contains("Navid"));
            var jsonString = jsonList.ToJSONString();

            Assert.IsTrue(jsonString.Contains("Navid"));
        }
    private void LoadData()
    {
        if (filePath.Length != 0)
        {
            nodes       = new List <Node>();
            connections = new List <Connection>();

            var      fileContent = File.ReadAllBytes(filePath);
            string   dataAsJson  = File.ReadAllText(filePath);
            JSONList JSONListO   = JsonUtility.FromJson <JSONList>(dataAsJson);

            foreach (JSONDictionary currentDict in JSONListO.dataList)
            {
                Node newNode = new Node(new Vector2(currentDict.position.x, currentDict.position.y), 200, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode, currentDict.type);
                newNode.nodeID           = currentDict.nodeID;
                newNode.titleString      = currentDict.name;
                newNode.bodyString       = currentDict.body;
                newNode.uniqueIDString   = currentDict.uniqueIDString;
                newNode.blackboardString = currentDict.blackboardString;
                newNode.valueBool        = currentDict.variableValue;
                newNode.variableString   = currentDict.variableString;
                newNode.type             = currentDict.type;
                newNode.option1String    = currentDict.option1;
                newNode.option2String    = currentDict.option2;
                newNode.option3String    = currentDict.option3;
                newNode.option4String    = currentDict.option4;
                nodes.Add(newNode);
            }

            foreach (JSONConnectionDictionary currentDict in JSONListO.connectionList)
            {
                ConnectionPoint inPoint  = null;
                ConnectionPoint outPoint = null;


                foreach (Node currentNode in nodes)
                {
                    if (currentDict.inPointID == currentNode.nodeID)
                    {
                        inPoint = currentNode.inPoint;
                    }

                    if (currentDict.outPointID == currentNode.nodeID)
                    {
                        if (currentNode.type == "Boolean")
                        {
                            if (currentDict.outBoolType)
                            {
                                outPoint = currentNode.outPoint;
                            }
                            else
                            {
                                outPoint = currentNode.outPoint2;
                            }
                        }
                        else if (currentNode.type == "Multiple Choice")
                        {
                            if (currentDict.optionNumber == 1)
                            {
                                outPoint = currentNode.outPoint;
                            }
                            else if (currentDict.optionNumber == 2)
                            {
                                outPoint = currentNode.outPoint2;
                            }
                            else if (currentDict.optionNumber == 3)
                            {
                                outPoint = currentNode.outPoint3;
                            }
                            else if (currentDict.optionNumber == 4)
                            {
                                outPoint = currentNode.outPoint4;
                            }
                        }



                        else
                        {
                            outPoint = currentNode.outPoint;
                        }
                    }
                }

                if (inPoint != null && outPoint != null)
                {
                    Connection newConnection = new Connection(inPoint, outPoint, OnClickRemoveConnection);
                    connections.Add(newConnection);
                }
            }
        }
    }