Exemplo n.º 1
0
    public NodeSelectorPanel(/*, NodeNamespacesData[] customNodes*/)
    {
        var nodes = new List <string>(NodesFactory.GetAllNodes());

        namespaces        = NodesFactory.GetAllNamespaces(nodes.ToArray());
        NodeNamespaceData = new List <NodeNamespacesData>();
    }
        public void InitializeConstellation(ConstellationScriptData[] constellationScripts)
        {
            Entries            = new List <Node <INode> >();
            BrightEntriesInfos = new List <BrightEntryInfos>();
            ExitNodes          = new List <IExitNode>();
            parameters         = new List <IReceiver>();
            if (isInitialized) // do not initialize twice
            {
                return;
            }

            nodesFactory = new NodesFactory(constellationScripts);

            var parametersCounter = 0;
            var entryCounter      = 0;
            var exitCounter       = 0;

            constellation = new Constellation(UnityEngine.JsonUtility.FromJson <ConstellationScriptData>(constellationNodeData.Value.GetString()), nodesFactory, (newNode, node) =>
            {
                if (newNode.NodeType is IExitNode)
                {
                    ExitNodes.Add(newNode.NodeType as IExitNode);
                    if (newNode.NodeType is IBrightExitNode)
                    {
                        (newNode.NodeType as IBrightExitNode).SubscribeReceiver(this, exitCounter);
                    }
                    exitCounter++;
                }

                if (newNode.Name == CoreNodes.Entry.NAME || newNode.Name == CoreNodes.BrightEntry.NAME)
                {
                    if (newNode.Name == CoreNodes.BrightEntry.NAME)
                    {
                        BrightEntriesInfos.Add(new BrightEntryInfos(newNode, entryCounter));
                    }

                    entryCounter++;
                    Entries.Add(newNode);
                }

                if (newNode.NodeType.NodeName() == Parameters.ValueParameter.NAME || newNode.NodeType.NodeName() == Parameters.WordParameter.NAME)
                {
                    parameters.Add(newNode.NodeType as IReceiver);
                }

                if (IsAttribute(node) && NodeParameters[parametersCounter] != null)
                {
                    IParameter nodeParameter = newNode.NodeType as IParameter;
                    if (node.Name != "ObjectParameter" && parametersCounter < NodeParameters.Count)
                    {
                        nodeParameter.SetParameter(NodeParameters[parametersCounter]);
                    }

                    parametersCounter++;
                }
            });
            constellation.Initialize(System.Guid.NewGuid().ToString(), nameParameter.Value.GetString());

            isInitialized = true;
        }
Exemplo n.º 3
0
 public NodeEditorNodes(EditorWindow _editorWindow,
                        NodeConfig _nodeConfig,
                        ConstellationScript _constellationScript,
                        IUndoable _undoable,
                        NodeEditorSelection _nodeEditorSelection,
                        ILinkEditor _linkEditor,
                        IGUI _gui,
                        IVisibleObject _visibleObject,
                        NodeAdded _nodeAdded,
                        NodeRemoved _nodeRemoved,
                        HelpClicked _helpClicked)
 {
     linkEditor          = _linkEditor;
     editorWindow        = _editorWindow;
     Nodes               = new List <NodeView> ();
     nodeConfig          = _nodeConfig;
     constellationScript = _constellationScript;
     isInstance          = constellationScript.IsInstance;
     nodesFactory        = new NodesFactory();
     undoable            = _undoable;
     nodeEditorSelection = _nodeEditorSelection;
     GUI            = _gui;
     visibleObject  = _visibleObject;
     OnNodeAdded   += _nodeAdded;
     OnNodeRemoved += _nodeRemoved;
     OnHelpClicked += _helpClicked;
     SetNodes();
 }
Exemplo n.º 4
0
        public static NodeData AddNode(NodesFactory nodesFactory, string nodeName, string nodeNamespace, ConstellationScriptData constellationScript)
        {
            var newNode = nodesFactory.GetNode(nodeName, nodeNamespace);

            var nodeData    = new NodeData(newNode);
            var genericNode = newNode.NodeType as IGenericNode;

            if (genericNode as IGenericNode != null)
            {
                for (var i = 0; i < newNode.Inputs.Count; i++)
                {
                    var genericOutputsID = genericNode.GetGenericOutputByLinkedInput(i);
                    for (var j = 0; j < genericOutputsID.Length; j++)
                    {
                        nodeData.Outputs[genericOutputsID[j]].Type = UNDEFINED;
                    }
                }
            }

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

            return(nodeData);
        }
Exemplo n.º 5
0
        public static PhpSyntaxTree ParseCode(
            string content,
            PhpParseOptions parseOptions,
            PhpParseOptions scriptParseOptions,
            string fname)
        {
            // TODO: new parser implementation based on Roslyn

            // TODO: file.IsScript ? scriptParseOptions : parseOptions
            var unit = new CodeSourceUnit(
                content, fname, Encoding.UTF8,
                (parseOptions.Kind == SourceCodeKind.Regular) ? Lexer.LexicalStates.INITIAL : Lexer.LexicalStates.ST_IN_SCRIPTING);

            var result = new PhpSyntaxTree(unit);

            var errorSink = new ErrorSink(result);
            var factory   = new NodesFactory(unit);

            //
            unit.Parse(factory, errorSink);

            //
            result.Diagnostics = errorSink.Diagnostics;

            result.Lambdas    = factory.Lambdas.AsImmutableSafe();
            result.Types      = factory.Types.AsImmutableSafe();
            result.Functions  = factory.Functions.AsImmutableSafe();
            result.YieldNodes = factory.YieldNodes.AsImmutableSafe();
            result.Root       = factory.Root;

            //
            return(result);
        }
        public NodeEditorPanel(IGUI _gui,
                               EditorWindow _editorWindow,
                               ConstellationScript _script,
                               IUndoable _undoable,
                               ClipBoard _editorClipBoard,
                               float positionX,
                               float positionY,
                               LinkAdded linkAdded,
                               NodeAdded nodeAdded,
                               NodeRemoved nodeRemoved)
        {
            nodesFactory        = new NodesFactory();
            constellationScript = _script;
            undoable            = _undoable;
            Nodes            = new List <NodeView> ();
            GUI              = _gui;
            EditorWindow     = _editorWindow;
            editorScrollSize = new Vector2(500, 500);
            Background       = AssetDatabase.LoadAssetAtPath(editorPath + "background.png", typeof(Texture2D)) as Texture2D;
            var allNodes = NodesFactory.GetAllNodes();

            nodes           = new string[allNodes.Length];
            editorScrollPos = new Vector2(positionX, positionY);
            for (var i = 0; i < allNodes.Length; i++)
            {
                nodes[i] = allNodes[i];
            }
            OnLinkAdded        += linkAdded;
            OnNodeAdded        += nodeAdded;
            OnNodeRemoved      += nodeRemoved;
            nodeEditorSelection = new NodeEditorSelection(GUI, _editorClipBoard);
        }
Exemplo n.º 7
0
        public void LinkAdded(ConstellationScriptData constellationScript, NodesFactory nodesFactory, string guid, IConstellationFileParser constellationParser)
        {
            var linkedinputID          = 0;
            var linkedOutputID         = 0;
            var connectedNodes         = constellationScript.GetNodesWithLinkGUID(guid, out linkedinputID, out linkedOutputID);
            var outputNode             = connectedNodes[0];
            var inputNode              = connectedNodes[1];
            var inputNodeType          = nodesFactory.GetNode(inputNode, constellationParser).NodeType;
            var outputNodeType         = nodesFactory.GetNode(outputNode, constellationParser).NodeType;
            var inputGenericNodeScript = inputNodeType as IGenericNode;
            var mirrorInputNodeScript  = inputNodeType as IMirrorNode;
            var mirrorOutputNodeScript = outputNodeType as IMirrorNode;

            if (mirrorInputNodeScript != null)
            {
                for (var k = 0; k < inputNode.GetInputs().Length; k++)
                {
                    inputNode.Inputs[k].Type = outputNode.Outputs[linkedOutputID].Type;
                }
            }
            else if (mirrorOutputNodeScript != null)
            {
                for (var k = 0; k < outputNode.GetOutputs().Length; k++)
                {
                    outputNode.Outputs[k].Type = inputNode.Inputs[linkedinputID].Type;
                }
            }
            else
            {
                if (inputGenericNodeScript != null && inputGenericNodeScript.IsGenericInput(linkedinputID))
                {
                    var inputsID = linkedinputID;

                    for (var k = 0; k < inputNode.GetInputs().Length; k++)
                    {
                        if (k == linkedinputID)
                        {
                            inputNode.Inputs[k].Type = outputNode.Outputs[linkedOutputID].Type;
                            break;
                        }
                    }
                    if (inputGenericNodeScript.IsGenericInput(linkedinputID))
                    {
                        var outputID = inputGenericNodeScript.GetGenericOutputByLinkedInput(linkedinputID);
                        for (var k = 0; k < inputNode.GetOutputs().Length; k++)
                        {
                            for (var l = 0; l < outputID.Length; l++)
                            {
                                if (k == outputID[l])
                                {
                                    inputNode.Outputs[k].Type = outputNode.Outputs[linkedOutputID].Type;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static PhpSyntaxTree ParseCode(
            string content,
            PhpParseOptions parseOptions,
            PhpParseOptions scriptParseOptions,
            string fname)
        {
            if (fname == null)
            {
                throw ExceptionUtilities.ArgumentNull(nameof(fname));
            }

            // TODO: new parser implementation based on Roslyn

            // TODO: file.IsScript ? scriptParseOptions : parseOptions
            var unit = new PhpSourceUnit(
                fname,
                SourceText.From(content, Encoding.UTF8),
                encoding: Encoding.UTF8);

            var result = new PhpSyntaxTree(unit);

            var errorSink = new ErrorSink(result);
            var factory   = new NodesFactory(unit, parseOptions.Defines);

            //
            try
            {
                unit.Parse(factory, errorSink,
                           features: GetLanguageFeatures(parseOptions),
                           state: (parseOptions.Kind == SourceCodeKind.Regular) ? Lexer.LexicalStates.INITIAL : Lexer.LexicalStates.ST_IN_SCRIPTING);
            }
            finally
            {
                unit.Close();
            }

            //
            result.Diagnostics = errorSink.Diagnostics;

            result.Lambdas    = factory.Lambdas.AsImmutableSafe();
            result.Types      = factory.Types.AsImmutableSafe();
            result.Functions  = factory.Functions.AsImmutableSafe();
            result.YieldNodes = factory.YieldNodes.AsImmutableSafe();

            if (factory.Root != null)
            {
                result.Root = factory.Root;
            }
            else
            {
                // Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node
                var fullSpan = new Devsense.PHP.Text.Span(0, content.Length);
                result.Root = new GlobalCode(fullSpan, ImmutableArray <Statement> .Empty, unit);
            }

            //
            return(result);
        }
Exemplo n.º 9
0
 public void SetupNamespaceData()
 {
     foreach (var _namespace in namespaces)
     {
         var nodes         = new List <string>(NodesFactory.GetAllNodes());
         var nodeNamespace = new NodeNamespacesData(_namespace, nodes.ToArray());
         NodeNamespaceData.Add(nodeNamespace);
     }
 }
Exemplo n.º 10
0
    public NodeSelectorPanel(ConstellationScriptData[] customNodes)
    {
        var nodes = new List <string>(NodesFactory.GetAllNodesExcludeDiscretes());

        foreach (var customNode in customNodes)
        {
            nodes.Add("Constellation.Custom." + customNode.Name);
        }
        namespaces        = NodesFactory.GetAllNamespaces(nodes.ToArray());
        NodeNamespaceData = new List <NodeNamespacesData>();
    }
Exemplo n.º 11
0
        public bool isNodeValid(NodeData node, Node <INode> nodeObject, NodesFactory nodesFactory)
        {
            if (nodeObject == null)
            {
                return(false);
            }
            else if (node.Inputs.Count != nodeObject.Inputs.Count || node.Outputs.Count != nodeObject.Outputs.Count || node.GetParameters().Length != nodeObject.GetParameters().Length)
            {
                return(false);
            }
            else if (node.Namespace == ConstellationNodes.NameSpace.NAME) // to be done only when the node is edited
            {
                return(false);
            }

            var i = 0;

            if (node.GetParameters().Length != nodeObject.GetParameters().Length)
            {
                return(false);
            }

            foreach (var parameter in node.GetParameters())
            {
                if (parameter.Type != nodeObject.GetParameters()[i].Type)
                {
                    return(false);
                }
                i++;
            }

            i = 0;
            foreach (var input in node.GetInputs())
            {
                if (input.IsBright != nodeObject.Inputs[i].isBright || input.Description != nodeObject.Inputs[i].Description)
                {
                    return(false);
                }
                i++;
            }
            i = 0;
            foreach (var output in node.GetOutputs())
            {
                if (output.IsBright != nodeObject.Outputs[i].IsBright || output.Description != nodeObject.Outputs[i].Description)
                {
                    return(false);
                }
                i++;
            }

            return(true);
        }
Exemplo n.º 12
0
 public void SetupNamespaceData(ConstellationScriptData[] customNodes)
 {
     foreach (var _namespace in namespaces)
     {
         var nodes = new List <string>(NodesFactory.GetAllNodesExcludeDiscretes());
         foreach (var customNode in customNodes)
         {
             nodes.Add("Constellation.Custom." + customNode.Name);
         }
         var nodeNamespace = new NodeNamespacesData(_namespace, nodes.ToArray());
         NodeNamespaceData.Add(nodeNamespace);
     }
 }
Exemplo n.º 13
0
        public NodeSelectorPanel(NodeAdded _onNodeAdded)
        {
            OnNodeAdded  = null;
            OnNodeAdded += _onNodeAdded;
            var nodes = NodesFactory.GetAllNodes();

            namespaces        = NodesFactory.GetAllNamespaces(nodes);
            NodeNamespaceData = new List <NodeNamespacesData> ();
            foreach (var _namespace in namespaces)
            {
                var nodeNamespace = new NodeNamespacesData(_namespace, nodes);
                NodeNamespaceData.Add(nodeNamespace);
            }
        }
Exemplo n.º 14
0
        public void Initialize()
        {
            if (ConstellationData == null && Application.isPlaying)
            {
                this.enabled = false;
                throw new NoConstellationAttached(this);
            }

            if (isInitialized) // do not initialize twice
            {
                return;
            }

            nodeFactory = new NodesFactory(ConstellationData.ScriptAssembly.GetAllStaticScriptData());

            var nodes = ConstellationData.GetNodes();

            constellation = new Constellation(ConstellationData.script,
                                              nodeFactory,
                                              (newNode, node) =>
            {
                var attributesCounter = 0;
                if (IsAttribute(node) && Parameters != null)
                {
                    IParameter nodeParameter = newNode.NodeType as IParameter;
                    if (node.Name != "ObjectParameter" && attributesCounter < Parameters.Count)
                    {
                        nodeParameter.SetParameter(Parameters[attributesCounter].Variable);
                    }
                    else if (attributesCounter < Parameters.Count)
                    {
                        nodeParameter.SetParameter(new Ray().Set(Parameters[attributesCounter].UnityObject as object));
                    }

                    attributesCounter++;
                }
            });

            SetUnityObject();
            constellation.Initialize(System.Guid.NewGuid().ToString(), ConstellationData.name);
            if (constellation.GetInjector() is IAwakable)
            {
                constellation.GetInjector().OnAwake();
            }
            isInitialized = true;
        }
Exemplo n.º 15
0
        public NodeWindow(string _editorPath, ConstellationScript _constellationScript)
        {
            var backgroundTexture = AssetDatabase.LoadAssetAtPath(editorPath + "background.png", typeof(Texture2D)) as Texture2D;

            background          = new NodeEditorBackground(backgroundTexture);
            editorPath          = _editorPath;
            SelectedNodes       = new List <NodeView>();
            Nodes               = new List <NodeView>();
            ConstellationScript = _constellationScript;
            Links               = new LinksView(ConstellationScript);
            NodeFactory         = new NodesFactory(ConstellationScript?.ScriptAssembly?.GetAllScriptData());

            foreach (var node in _constellationScript.GetNodes())
            {
                DisplayNode(node);
            }
        }
Exemplo n.º 16
0
        public NodeEditorPanel(IGUI _gui,
                               EditorWindow _editorWindow,
                               ConstellationScript _script,
                               IUndoable _undoable,
                               ClipBoard _editorClipBoard,
                               float positionX,
                               float positionY,
                               NodeEditorLinks.LinkAdded linkAdded,
                               NodeEditorLinks.LinkRemoved onLinkRemoved,
                               NodeEditorNodes.NodeAdded nodeAdded,
                               NodeEditorNodes.NodeRemoved nodeRemoved,
                               NodeEditorNodes.HelpClicked onHelpClicked,
                               ApplyInstanceChanges applyInstanceChanges,
                               ConstellationScriptData[] _constellationScripts)
        {
            constellationScripts = _constellationScripts;
            constellationScript  = _script;
            undoable             = _undoable;
            GUI              = _gui;
            EditorWindow     = _editorWindow;
            editorScrollSize = new Vector2(500, 500);
            var backgroundTexture = AssetDatabase.LoadAssetAtPath(editorPath + "background.png", typeof(Texture2D)) as Texture2D;

            Background = new NodeEditorBackground(GUI, backgroundTexture);

            var allNodes = NodesFactory.GetAllNodes();

            nodes           = new string[allNodes.Length];
            editorScrollPos = new Vector2(positionX, positionY);

            for (var i = 0; i < allNodes.Length; i++)
            {
                nodes[i] = allNodes[i];
            }
            OnLinkAdded            += linkAdded;
            OnNodeAdded            += nodeAdded;
            OnNodeRemoved          += nodeRemoved;
            OnApplyInstanceChanges += applyInstanceChanges;
            OnHelpClicked          += onHelpClicked;
            OnLinkRemoved          += onLinkRemoved;
            nodeEditorSelection     = new NodeEditorSelection(GUI, _editorClipBoard);
            RequestSetup();
        }
Exemplo n.º 17
0
        public static PhpSyntaxTree ParseCode(
            string content,
            PhpParseOptions parseOptions,
            PhpParseOptions scriptParseOptions,
            string fname)
        {
            // TODO: new parser implementation based on Roslyn

            // TODO: file.IsScript ? scriptParseOptions : parseOptions
            var unit = new CodeSourceUnit(
                content, fname, Encoding.UTF8,
                (parseOptions.Kind == SourceCodeKind.Regular) ? Lexer.LexicalStates.INITIAL : Lexer.LexicalStates.ST_IN_SCRIPTING);

            var result = new PhpSyntaxTree(unit);

            var errorSink = new ErrorSink(result);
            var factory   = new NodesFactory(unit);

            //
            unit.Parse(factory, errorSink);

            //
            result.Diagnostics = errorSink.Diagnostics;

            result.Lambdas    = factory.Lambdas.AsImmutableSafe();
            result.Types      = factory.Types.AsImmutableSafe();
            result.Functions  = factory.Functions.AsImmutableSafe();
            result.YieldNodes = factory.YieldNodes.AsImmutableSafe();

            if (factory.Root != null)
            {
                result.Root = factory.Root;
            }
            else
            {
                // Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node
                var fullSpan = new Devsense.PHP.Text.Span(0, unit.Code.Length);
                result.Root = new GlobalCode(fullSpan, ImmutableArray <Statement> .Empty, unit);
            }

            //
            return(result);
        }
Exemplo n.º 18
0
        public NodeSelectorPanel(NodeAdded _onNodeAdded, NodeNamespacesData[] customNodes)
        {
            OnNodeAdded  = null;
            OnNodeAdded += _onNodeAdded;
            var nodes = new List <string> (NodesFactory.GetAllNodes());

            namespaces        = NodesFactory.GetAllNamespaces(nodes.ToArray());
            NodeNamespaceData = new List <NodeNamespacesData> ();

            foreach (var _namespace in namespaces)
            {
                var nodeNamespace = new NodeNamespacesData(_namespace, nodes.ToArray());
                NodeNamespaceData.Add(nodeNamespace);
            }

            foreach (var node in customNodes)
            {
                NodeNamespaceData.Add(node);
            }
        }
Exemplo n.º 19
0
        public NodeWindow(string _editorPath, ConstellationEditorDataService _constellationEditorData, Vector2 windowSize, Vector2 scrollPosition)
        {
            farNodeX         = windowSize.x;
            farNodeY         = windowSize.y;
            editorScrollSize = new Vector2(farNodeX + 400, farNodeY + 400);
            ScrollPosition   = scrollPosition;
            var backgroundTexture = AssetDatabase.LoadAssetAtPath(editorPath + "background.png", typeof(Texture2D)) as Texture2D;

            background          = new NodeEditorBackground(backgroundTexture);
            editorPath          = _editorPath;
            SelectedNodes       = new List <NodeView>();
            Nodes               = new List <NodeView>();
            EditorData          = _constellationEditorData;
            ConstellationScript = EditorData.Script;
            Links               = new LinksView(ConstellationScript);
            NodeFactory         = new NodesFactory(ConstellationScript.ScriptAssembly.GetAllStaticScriptData());

            foreach (var node in ConstellationScript.GetNodes())
            {
                DisplayNode(node);
            }
        }
Exemplo n.º 20
0
        public bool isNodeValid(NodeData node, Node <INode> nodeObject, NodesFactory nodesFactory)
        {
            var i = 0;

            foreach (var input in node.GetInputs())
            {
                if ((input.Type != nodeObject.Inputs[i].Type && nodeObject.Inputs[i].Type != ConstellationEditorRules.ANY && nodeObject.Inputs[i].Type != ConstellationEditorRules.GENERIC && nodeObject.Inputs[i].Type != ConstellationEditorRules.UNDEFINED))
                {
                    return(false);
                }
                i++;
            }
            i = 0;
            foreach (var output in node.GetOutputs())
            {
                if ((output.Type != nodeObject.Outputs[i].Type && nodeObject.Outputs[i].Type != ConstellationEditorRules.ANY && nodeObject.Outputs[i].Type != ConstellationEditorRules.GENERIC && nodeObject.Outputs[i].Type != ConstellationEditorRules.UNDEFINED))
                {
                    return(false);
                }
                i++;
            }

            return(true);
        }
Exemplo n.º 21
0
        public void UpdateScriptNodes(ConstellationScriptData script, ConstellationScriptData[] constellationScripts)
        {
            List <NodeData> nodesToRemove = new List <NodeData>();

            NodesFactory = new NodesFactory(constellationScripts);
            foreach (var node in script.Nodes)
            {
                var nodeObject = NodesFactory.GetNodeSafeMode(node);
                if (nodeObject == null)
                {
                    nodesToRemove.Add(node);
                }
                else if (node.Inputs.Count != nodeObject.Inputs.Count || node.Outputs.Count != nodeObject.Outputs.Count || node.GetParameters().Length != nodeObject.GetParameters().Length)
                {
                    nodesToRemove.Add(node);
                }
                else
                {
                    var foundDifference = false;
                    var i = 0;
                    foreach (var input in node.GetInputs())
                    {
                        if ((input.Type != nodeObject.Inputs[i].Type && nodeObject.Inputs[i].Type != "Any") || input.IsBright != nodeObject.Inputs[i].isBright)
                        {
                            nodesToRemove.Add(node);
                            foundDifference = true;
                            break;
                        }
                        i++;
                    }

                    if (!foundDifference)
                    {
                        i = 0;
                        foreach (var output in node.GetOutputs())
                        {
                            if ((output.Type != nodeObject.Outputs[i].Type && nodeObject.Outputs[i].Type != "Any") || output.IsBright != nodeObject.Outputs[i].IsWarm)
                            {
                                nodesToRemove.Add(node);
                                break;
                            }
                            i++;
                        }
                    }

                    if (!foundDifference)
                    {
                        i = 0;
                        if (node.GetParameters().Length != nodeObject.GetParameters().Length)
                        {
                            nodesToRemove.Add(node);
                        }

                        foreach (var parameter in node.GetParameters())
                        {
                            if (parameter.Type != nodeObject.GetParameters()[i].Type)
                            {
                                nodesToRemove.Add(node);
                                break;
                            }
                            i++;
                        }
                    }
                }
            }

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

                    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()
            }
        }
Exemplo n.º 22
0
        public void InitializeConstellation(ConstellationScriptData[] constellationScripts, IConstellationFileParser constellationFileParser, bool isLocalScope)
        {
            Entries            = new List <Node <INode> >();
            BrightEntriesInfos = new List <BrightEntryInfos>();
            ExitNodes          = new List <IExitNode>();
            parameters         = new List <IReceiver>();
            if (isInitialized) // do not initialize twice
            {
                return;
            }

            var scriptData = constellationFileParser.ParseConstellationScript(constellationNodeData.Value.GetString());

            if (isLocalScope)
            {
                nodesFactory = new NodesFactory(null);
                var newAssembly = new List <ConstellationScriptData>();
                foreach (var node in scriptData.Nodes)
                {
                    if (node.Namespace == ConstellationNodes.NameSpace.NAME)
                    {
                        newAssembly.Add(constellationFileParser.ParseConstellationScript(node.DiscreteParametersData[1].Value.GetString()));
                    }
                }
                nodesFactory.UpdateConstellationScripts(newAssembly.ToArray());
                nodesFactory.SetLocalScope();
            }
            else
            {
                nodesFactory = new NodesFactory(constellationScripts);
            }

            var parametersCounter = 0;
            var entryCounter      = 0;
            var exitCounter       = 0;

            constellation = new Constellation(scriptData, nodesFactory, constellationFileParser, (newNode, node) =>
            {
                if (newNode.NodeType is IExitNode)
                {
                    ExitNodes.Add(newNode.NodeType as IExitNode);
                    if (newNode.NodeType is IBrightExitNode)
                    {
                        (newNode.NodeType as IBrightExitNode).SubscribeReceiver(this, exitCounter);
                    }
                    exitCounter++;
                }

                if (newNode.Name == CoreNodes.Entry.NAME || newNode.Name == CoreNodes.BrightEntry.NAME)
                {
                    if (newNode.Name == CoreNodes.BrightEntry.NAME)
                    {
                        BrightEntriesInfos.Add(new BrightEntryInfos(newNode, entryCounter));
                    }

                    entryCounter++;
                    Entries.Add(newNode);
                }

                if (newNode.NodeType.NodeName() == Parameters.ValueParameter.NAME || newNode.NodeType.NodeName() == Parameters.WordParameter.NAME)
                {
                    parameters.Add(newNode.NodeType as IReceiver);
                }

                if (IsAttribute(node) && NodeParameters[parametersCounter] != null)
                {
                    IParameter nodeParameter = newNode.NodeType as IParameter;
                    if (nodeParameter.DisplayInConstellation() && parametersCounter < NodeParameters.Count)
                    {
                        nodeParameter.SetParameter(NodeParameters[parametersCounter]);
                    }

                    parametersCounter++;
                }
            });
            constellation.Initialize(System.Guid.NewGuid().ToString(), nameParameter.Value.GetString());

            isInitialized = true;
        }
        public void UpdateScriptNodes(ConstellationScriptData script, ConstellationScriptData[] constellationScripts)
        {
            List <NodeData> nodesToRemove = new List <NodeData>();

            NodesFactory = new NodesFactory(constellationScripts);
            foreach (var node in script.Nodes)
            {
                var nodeObject = NodesFactory.GetNodeSafeMode(node);


                if (nodeObject == null)
                {
                    nodesToRemove.Add(node);
                }
                else if (node.Inputs.Count != nodeObject.Inputs.Count || node.Outputs.Count != nodeObject.Outputs.Count || node.GetParameters().Length != nodeObject.GetParameters().Length)
                {
                    nodesToRemove.Add(node);
                }
                else if (node.Namespace == Constellation.ConstellationNodes.NameSpace.NAME) // to be done only when the node is edited
                {
                    nodesToRemove.Add(node);
                }
                else
                {
                    var foundDifference = false;
                    var i = 0;
                    foreach (var input in node.GetInputs())
                    {
                        if ((input.Type != nodeObject.Inputs[i].Type && nodeObject.Inputs[i].Type != ConstellationEditorRules.ANY && nodeObject.Inputs[i].Type != ConstellationEditorRules.GENERIC && nodeObject.Inputs[i].Type != ConstellationEditorRules.UNDEFINED) || input.IsBright != nodeObject.Inputs[i].isBright || input.Description != nodeObject.Inputs[i].Description)
                        {
                            nodesToRemove.Add(node);
                            foundDifference = true;
                            break;
                        }
                        i++;
                    }

                    if (!foundDifference)
                    {
                        i = 0;
                        foreach (var output in node.GetOutputs())
                        {
                            if ((output.Type != nodeObject.Outputs[i].Type && nodeObject.Outputs[i].Type != ConstellationEditorRules.ANY && nodeObject.Outputs[i].Type != ConstellationEditorRules.GENERIC && nodeObject.Outputs[i].Type != ConstellationEditorRules.UNDEFINED) || output.IsBright != nodeObject.Outputs[i].IsWarm || output.Description != nodeObject.Outputs[i].Description)
                            {
                                nodesToRemove.Add(node);
                                break;
                            }
                            i++;
                        }
                    }

                    if (!foundDifference)
                    {
                        i = 0;
                        if (node.GetParameters().Length != nodeObject.GetParameters().Length)
                        {
                            nodesToRemove.Add(node);
                        }

                        foreach (var parameter in node.GetParameters())
                        {
                            if (parameter.Type != nodeObject.GetParameters()[i].Type)
                            {
                                nodesToRemove.Add(node);
                                break;
                            }
                            i++;
                        }
                    }
                }
            }

            foreach (var node in nodesToRemove)
            {
                script.RemoveNode(node.Guid);
                var replacementNode = NodesFactory.GetNode(node.Name, node.Namespace, null);
                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()
            }
        }
Exemplo n.º 24
0
        public void UpdateScriptNodes(ConstellationScriptData script)
        {
            List <NodeData> nodesToRemove = new List <NodeData>();

            NodesFactory = new NodesFactory();
            try
            {
                foreach (var node in script.Nodes)
                {
                    if (NodesFactory.GetNodeSafeMode(node) == null)
                    {
                        nodesToRemove.Add(node);
                    }
                    else if (node.Inputs.Count != NodesFactory.GetNode(node).Inputs.Count || node.Outputs.Count != NodesFactory.GetNode(node).Outputs.Count)
                    {
                        nodesToRemove.Add(node);
                    }
                }

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

                        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.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);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }