Exemple #1
0
 public Constellation(ConstellationScriptData constellationScriptData,
                      NodesFactory nodesFactory,
                      NodeAdded onNodeAdded = null)
 {
     NodesFactory = nodesFactory;
     SetNodes(constellationScriptData.GetNodes(), onNodeAdded);
     SetLinks(constellationScriptData.GetLinks());
 }
Exemple #2
0
        public void Initialize()
        {
            if (ConstellationData == null && Application.isPlaying)
            {
                this.enabled = false;
                throw new NoConstellationAttached(this);
            }

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

            if (ConstellationComponent.eventSystem == null)
            {
                eventSystem = new ConstellationEventSystem();
            }

            if (NodesFactory.Current == null)
            {
                nodeFactory = new NodesFactory(ConstellationData?.ScriptAssembly?.GetAllScriptData());
            }
            else
            {
                nodeFactory = NodesFactory.Current;
            }

            var nodes = ConstellationData.GetNodes();

            constellation = new Constellation();
            SetNodes(nodes);

            var links = ConstellationData.GetLinks();

            foreach (LinkData link in links)
            {
                var input  = constellation.GetInput(link.Input.Guid);
                var output = constellation.GetOutput(link.Output.Guid);
                if (input != null && output != null)
                {
                    constellation.AddLink(new Link(constellation.GetInput(link.Input.Guid),
                                                   constellation.GetOutput(link.Output.Guid),
                                                   constellation.GetOutput(link.Output.Guid).Type, link.GUID));
                }
            }

            SetUnityObject();
            constellation.Initialize(System.Guid.NewGuid().ToString(), ConstellationData.name);
            if (constellation.GetInjector() is IAwakable)
            {
                constellation.GetInjector().OnAwake();
            }
            isInitialized = true;
        }
Exemple #3
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);
        }
Exemple #4
0
        public void Awake()
        {
            if (ConstellationBehaviour.eventSystem == null)
            {
                eventSystem = new ConstellationEventSystem();
            }

            if (NodesFactory.Current == null)
            {
                nodeFactory = new NodesFactory();
            }
            else
            {
                nodeFactory = NodesFactory.Current;
            }

            if (ConstellationData == null && Application.isPlaying)
            {
                this.enabled = false;
                Debug.LogError("Constellation Error: No Constellation attached to " + this.gameObject);
                return;
            }
            var nodes = ConstellationData.GetNodes();

            Constellation = new Constellation();
            SetNodes(nodes);

            var links = ConstellationData.GetLinks();

            foreach (LinkData link in links)
            {
                Constellation.AddLink(new Link(Constellation.GetInput(link.Input.Guid),
                                               Constellation.GetOutput(link.Output.Guid),
                                               Constellation.GetOutput(link.Output.Guid).Type), "none");
            }
            SetUnityObject();
            SetConstellationEvents();
            foreach (var awakables in Awakables)
            {
                awakables.OnAwake();
            }
        }
Exemple #5
0
        public Constellation(ConstellationScriptData constellationScriptData,
                             NodesFactory nodesFactory,
                             NodeAdded onNodeAdded = null)
        {
            isConstellationInitialized = false;
            NodesFactory = nodesFactory;
            var newAssembly = new List <ConstellationScriptData>();

            if (nodesFactory.GetStaticScripts() == null)
            {
                foreach (var node in constellationScriptData.Nodes)
                {
                    if (node.Namespace == ConstellationNodes.NameSpace.NAME)
                    {
                        newAssembly.Add(UnityEngine.JsonUtility.FromJson <ConstellationScriptData>(node.DiscreteParametersData[1].Value.GetString()));
                    }
                }
                nodesFactory.UpdateConstellationScripts(newAssembly.ToArray());
            }
            SetNodes(constellationScriptData.GetNodes(), onNodeAdded);
            SetLinks(constellationScriptData.GetLinks());
            isConstellationInitialized = true;
        }
Exemple #6
0
        public Constellation(ConstellationScriptData constellationScriptData, NodesFactory nodesFactory, IConstellationFileParser constellationFileParser, NodeAdded onNodeAdded = null)
        {
            fileParser = constellationFileParser;
            isConstellationInitialized = false;
            NodesFactory = nodesFactory;
            var newAssembly = new List <ConstellationScriptData>();

            if (nodesFactory.GetStaticScripts() == null || nodesFactory.GetIsLocalScope())
            {
                foreach (var node in constellationScriptData.Nodes)
                {
                    if (node.Namespace == ConstellationNodes.NameSpace.NAME)
                    {
                        newAssembly.Add(constellationFileParser.ParseConstellationScript(node.DiscreteParametersData[1].Value.GetString()));
                    }
                }
                nodesFactory.UpdateConstellationScripts(newAssembly.ToArray());
                nodesFactory.SetLocalScope();
            }
            SetNodes(constellationScriptData.GetNodes(), onNodeAdded);
            SetLinks(constellationScriptData.GetLinks());
            isConstellationInitialized = true;
        }
Exemple #7
0
 public void UpdateGenericNodeByLinkGUID(ConstellationScriptData constellationScript, NodesFactory nodesFactory, string guid, IConstellationFileParser constellationParser)
 {
     foreach (var constellationRule in constellationRules)
     {
         constellationRule.LinkAdded(constellationScript, nodesFactory, guid, constellationParser);
     }
 }
 public NodesFactory()
 {
     Current = this;
     SetInterfaces();
 }
Exemple #9
0
 public void UpdateGenericNodeByLinkGUID(ConstellationScriptData constellationScript, NodesFactory nodesFactory, string guid)
 {
     foreach (var constellationRule in constellationRules)
     {
         constellationRule.UpdateGenericNodeByLinkGUID(constellationScript, nodesFactory, guid);
     }
 }
Exemple #10
0
 private void Setup()
 {
     Current = this;
     SetConstellationAssembly(scripts);
     SetInterfaces();
 }
Exemple #11
0
 public NodesFactory(ConstellationScriptData[] constellationScript)
 {
     Current = this;
     SetConstellationAssembly(constellationScript);
     SetInterfaces();
 }
Exemple #12
0
 private void Setup()
 {
     Current = this;
     //SetConstellationAssembly();
     SetInterfaces(staticConstellationScripts);
 }
Exemple #13
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()
            }
        }