Example #1
0
 public PWGraphBuilder NewNode(Type nodeType, Vector2 position, string name, PWGraphCLIAttributes attributes = null)
 {
     if (!nodeType.IsSubclassOf(typeof(PWNode)))
     {
         Debug.Log("[PWGraphBuilder] unknown node type: '" + nodeType + "'");
         return(this);
     }
     commands.Add(PWGraphCLI.GenerateNewNodeCommand(nodeType, name, position, attributes));
     return(this);
 }
Example #2
0
        public static string GenerateNewNodeCommand(Type nodeType, string name, PWGraphCLIAttributes datas = null)
        {
            string cmd = "NewNode " + nodeType.Name + " \"" + name + "\"";

            if (datas != null && datas.Count != 0)
            {
                cmd += " attr=" + PWJson.Generate(datas);
            }

            return(cmd);
        }
Example #3
0
        public void PerlinNoiseWithAttributesToDebugNodeExecution()
        {
            string perlinNodeName   = "perlin";
            var    perlinAttributes = new PWGraphCLIAttributes()
            {
                { "persistance", 2.4f }, { "octaves", 6 }
            };

            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodePerlinNoise2D>(perlinNodeName, perlinAttributes)
                        .Execute()
                        .GetGraph();

            PWNodePerlinNoise2D perlinNode = graph.FindNodeByName(perlinNodeName) as PWNodePerlinNoise2D;

            Assert.That(perlinNode.octaves == 6, "Perlin node octaves expected to be 6 but was " + perlinNode.octaves);
            Assert.That(perlinNode.persistance == 2.4f, "Perlin node persistance expected to be 2.4 but was " + perlinNode.persistance);
        }
Example #4
0
        public static void Export(PWGraph graph, string filePath)
        {
            List <string> commands      = new List <string>();
            List <string> nodeNames     = new List <string>();
            var           nodeToNameMap = new Dictionary <PWNode, string>();

            foreach (var node in graph.nodes)
            {
                var attrs = new PWGraphCLIAttributes();

                //load node attributes
                FieldInfo[] attrFields = node.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                foreach (var field in attrFields)
                {
                    var attributes = field.GetCustomAttributes(false);

                    bool isInput = attributes.Any(a => {
                        return(a.GetType() == typeof(PWInputAttribute));
                    });

                    if (isInput)
                    {
                        continue;
                    }

                    //if the field can't be jsonified, we skip it
                    if (PWJson.allowedJsonTypes.FindIndex(j => j.type == field.FieldType) == -1)
                    {
                        continue;
                    }

                    attrs.Add(field.Name, field.GetValue(node));
                }

                string nodeName = node.name;
                int    i        = 0;

                //unique name generation
                while (nodeNames.Contains(nodeName))
                {
                    nodeName = node.name + i++;
                }

                nodeNames.Add(nodeName);
                nodeToNameMap[node] = nodeName;

                commands.Add(GenerateNewNodeCommand(node.GetType(), nodeName, node.rect.position, attrs));
            }

            foreach (var link in graph.nodeLinkTable.GetLinks())
            {
                if (link.fromNode == null || link.toNode == null)
                {
                    continue;
                }

                var fromName       = nodeToNameMap[link.fromNode];
                var toName         = nodeToNameMap[link.toNode];
                var fromAnchorName = link.fromAnchor.fieldName;
                var toAnchorName   = link.toAnchor.fieldName;

                commands.Add(GenerateLinkAnchorNameCommand(fromName, fromAnchorName, toName, toAnchorName));
            }

            File.WriteAllLines(filePath, commands.ToArray());
        }
Example #5
0
 public PWGraphBuilder NewNode <T>(string name, PWGraphCLIAttributes attributes = null) where T : PWNode
 {
     commands.Add(PWGraphCLI.GenerateNewNodeCommand(typeof(T), name, attributes));
     return(this);
 }