Example #1
0
        public NodeData AddNode(NodesFactory nodesFactory, string nodeName, string nameSpace, ConstellationScriptData constellationScript)
        {
            var newNode  = nodesFactory.GetNode(nodeName, nameSpace, new UnityConstellationParser());
            var nodeData = new NodeData(newNode);

            foreach (var constellationRule in constellationRules)
            {
                nodeData = constellationRule.NodeAdded(nodeData, newNode, constellationScript);
            }

            nodeData           = constellationScript.AddNode(nodeData);
            nodeData.XPosition = 0;
            nodeData.YPosition = 0;

            return(nodeData);
        }
Example #2
0
        public void UpdateScriptNodes(ConstellationScriptData script, ConstellationScriptData[] constellationScripts, IConstellationFileParser constellationFileParser)
        {
            List <NodeData> nodesToRemove = new List <NodeData>();

            NodesFactory = new NodesFactory(constellationScripts);
            foreach (var node in script.Nodes)
            {
                var nodeObject = NodesFactory.GetNodeSafeMode(node, constellationFileParser);
                foreach (var parsingRule in parsingRules)
                {
                    if (!parsingRule.isNodeValid(node, nodeObject, NodesFactory))
                    {
                        nodesToRemove.Add(node);
                        break;
                    }
                }
            }

            foreach (var node in nodesToRemove)
            {
                script.RemoveNode(node.Guid);
                var replacementNode = NodesFactory.GetNode(node.Name, node.Namespace, new UnityConstellationParser());
                if (replacementNode != null)
                {
                    replacementNode.XPosition = node.XPosition;
                    replacementNode.YPosition = node.YPosition;
                    replacementNode.XSize     = node.SizeX;
                    replacementNode.YSize     = node.SizeY;

                    if (node.ParametersData != null && replacementNode.NodeParameters != null)
                    {
                        if (node.ParametersData.Count == replacementNode.NodeParameters.Count)
                        {
                            for (var i = 0; i < replacementNode.NodeParameters.Count; i++)
                            {
                                replacementNode.NodeParameters[i].Value = new Ray(node.ParametersData[i].Value);
                            }
                        }
                    }


                    if (node.Inputs != null && replacementNode.Inputs != null)
                    {
                        if (node.Inputs.Count >= replacementNode.Inputs.Count)
                        {
                            for (var i = 0; i < replacementNode.Inputs.Count; i++)
                            {
                                replacementNode.Inputs[i].Guid = node.Inputs[i].Guid;
                            }
                        }
                        else
                        {
                            for (var i = 0; i < node.Inputs.Count; i++)
                            {
                                replacementNode.Inputs[i].Guid = node.Inputs[i].Guid;
                            }
                        }
                    }

                    if (node.Outputs != null && replacementNode.Outputs != null)
                    {
                        if (node.Outputs.Count >= replacementNode.Outputs.Count)
                        {
                            for (var i = 0; i < replacementNode.Outputs.Count; i++)
                            {
                                replacementNode.Outputs[i].Guid = node.Outputs[i].Guid;
                            }
                        }
                        else
                        {
                            for (var i = 0; i < node.Outputs.Count; i++)
                            {
                                replacementNode.Outputs[i].Guid = node.Outputs[i].Guid;
                            }
                        }
                    }
                    script.AddNode(new NodeData(replacementNode));
                }
                else
                {
                    script.RemoveNode(node.Guid);
                }
            }

            foreach (var link in script.Links)
            {
                //if()
            }
        }