Пример #1
0
 private void CompareNodes(Nodes.Base node1, Nodes.Base node2)
 {
     Assert.That(node1, Is.TypeOf(node2.GetType()));
     Assert.That(node1.Tag, Is.EqualTo(node2.Tag));
     var sca = node1 as Nodes.Scalar;
     if (sca != null)
     {
         Assert.That(sca.Content, Is.EqualTo(((Nodes.Scalar) node2).Content));
         return;
     }
     var seq = node1 as Nodes.Sequence;
     if (seq != null)
     {
         foreach (var p in seq.Content.Zip(((Nodes.Sequence)node2).Content, Tuple.Create))
             this.CompareNodes(p.Item1, p.Item2);
         return;
     }
     var map = node1 as Nodes.Mapping;
     if (map == null)
         return;
     foreach (var p in map.Content.Zip(((Nodes.Mapping)node2).Content, Tuple.Create))
     {
         this.CompareNodes(p.Item1.Key, p.Item2.Key);
         this.CompareNodes(p.Item1.Value, p.Item2.Value);
     }
 }
        public LiteGraph.Node ConvertNodeToLiteGraphNode(Nodes.Node node)
        {
            LiteGraph.Node litegraphNode = new LiteGraph.Node
            {
                title = node.Type,
                type = node.Category + "/" + node.Type,
                id = node.Id,
                panel_id = node.PanelId
            };


            litegraphNode.properties["ObjectType"] = node.GetType().ToString();

            if (node.Position != null)
                litegraphNode.pos = new[] { node.Position.X, node.Position.Y };

            if (node.Size != null)
                litegraphNode.size = new[] { node.Size.Width, node.Size.Height };

            litegraphNode.inputs = new List<LiteGraph.Input>();
            litegraphNode.outputs = new List<LiteGraph.Output>();


            if (node.Inputs != null)
            {
                List<Nodes.Input> orderedInputs = node.Inputs.OrderBy(x => x.SlotIndex).ToList();
                foreach (var input in orderedInputs)
                {
                    litegraphNode.inputs.Add(new LiteGraph.Input
                    {
                        name = input.Name,
                        type = (int)input.Type,
                        link = engine.GetLinkForInput(input)?.Id,
                        isOptional = input.IsOptional
                    });
                }
            }

            if (node.Outputs != null)
            {
                List<Nodes.Output> orderedOutputs = node.Outputs.OrderBy(x => x.SlotIndex).ToList();
                foreach (var output in orderedOutputs)
                {
                    List<Nodes.Link> links = engine.GetLinksForOutput(output);
                    if (links != null)
                    {
                        string[] linksIds = new string[links.Count];
                        for (int i = 0; i < links.Count; i++)
                        {
                            linksIds[i] = links[i].Id;
                        }
                        litegraphNode.outputs.Add(new LiteGraph.Output
                        {
                            name = output.Name,
                            type = (int)output.Type,
                            links = linksIds
                        });
                    }
                    else
                    {
                        litegraphNode.outputs.Add(new LiteGraph.Output
                        {
                            name = output.Name,
                            type = (int)output.Type
                        });
                    }
                }
            }

            if (node.Settings != null && node.Settings.Count > 0)
                litegraphNode.properties["Settings"] = JsonConvert.SerializeObject(node.Settings);


            if (node.Settings.ContainsKey("Name")
                && !string.IsNullOrEmpty(node.Settings["Name"].Value))
                litegraphNode.title += " [" + node.Settings["Name"].Value + "]";

            if (node is PanelNode)
            {
                litegraphNode.title = node.Settings["Name"].Value;
            }



            return litegraphNode;
        }