//  FIXME: Generic export when recieves ignore field parameters
        // Add attribute like IgnoreExport or similar
        // For linked types do similar
        public override string ExportData(NodeGraphData data, List <Type> referenceTypes)
        {
            JSONObject exportJSON = new JSONObject();

            JSONObject graph = new JSONObject();

            JSONArray graphNodesReferences = new JSONArray();

            referenceTypes.Add(typeof(Node));
            referenceTypes.Add(typeof(NodeGraph));
            referenceTypes.Add(typeof(NodePort));

            graph.Add("type", new JSONString(data.graph.GetType().AssemblyQualifiedName));
            graph.Add("name", new JSONString(data.graph.name));
            graph.Add("id", new JSONNumber(data.graph.GetHashCode()));
            NodeGraph g = data.graph;

            graph = (JSONObject)SimpleJSONExtension.ToJSON(g, graph, new List <string>()
            {
                "sceneVariables"
            }, referenceTypes);

            JSONArray connections = new JSONArray();

            for (int c = 0; c < data.connections.Count; c++)
            {
                JSONObject connection = new JSONObject();
                connection.Add("port1ID", data.connections[c].port1ID);
                connection.Add("port2ID", data.connections[c].port2ID);
                connections.Add(connection);
            }

            JSONArray nodes = new JSONArray();

            for (int n = 0; n < data.nodes.Count; n++)
            {
                Node       node     = data.nodes[n].node;
                JSONObject nodeJSON = new JSONObject();
                nodeJSON.Add("name", node.name);
                nodeJSON.Add("type", node.GetType().AssemblyQualifiedName);
                nodeJSON.Add("position", node.position);
                nodeJSON.Add("id", node.GetHashCode());

                JSONArray nodePorts = new JSONArray();

                for (int np = 0; np < data.nodes[n].ports.Count; np++)
                {
                    NodePort port = data.nodes[n].ports[np].port;

                    JSONObject nodePortJSON = new JSONObject();
                    nodePortJSON.Add("name", port.fieldName);
                    nodePortJSON.Add("id", port.GetHashCode());
                    nodePortJSON.Add("dynamic", port.IsDynamic);
                    nodePortJSON.Add("valueType", port.ValueType.AssemblyQualifiedName);
                    nodePortJSON.Add("typeConstraint", (int)port.typeConstraint);
                    nodePortJSON.Add("connectionType", (int)port.connectionType);
                    nodePortJSON.Add("direction", (int)port.direction);

                    nodePorts.Add(nodePortJSON);
                }

                nodeJSON.Add("ports", nodePorts);

                nodeJSON = (JSONObject)SimpleJSONExtension.ToJSON(node, nodeJSON, new List <string>(), referenceTypes);

                nodes.Add(nodeJSON);
            }

            exportJSON.Add("graph", graph);
            exportJSON.Add("connections", connections);
            exportJSON.Add("nodes", nodes);

            return(exportJSON.ToString());
        }
Example #2
0
 public NodePortData(NodeData nodeData, NodePort nodePort)
 {
     port   = nodePort;
     portID = nodePort.GetHashCode();
     node   = nodeData;
 }