public bool HasEdge(Edge edge) { var serializedEdge = new SerializedEdge { Input = edge.input.node.viewDataKey, Output = edge.output.node.viewDataKey, InputPort = edge.input.viewDataKey, OutputPort = edge.output.viewDataKey }; return(Edges.Any(edge1 => edge1.Input == serializedEdge.Input && edge1.Output == serializedEdge.Output && edge1.InputPort == serializedEdge.InputPort && edge1.OutputPort == serializedEdge.OutputPort)); }
public void AddEdge(Edge edge) { var serializedEdge = new SerializedEdge { Input = edge.input.node.viewDataKey, Output = edge.output.node.viewDataKey, InputPort = edge.input.viewDataKey, OutputPort = edge.output.viewDataKey, InputCapacity = edge.input.capacity, OutputCapacity = edge.output.capacity }; AddEdge(serializedEdge); }
public bool OnSelectEntry(SearcherItem selectedEntry, Vector2 mousePosition) { if (selectedEntry == null || ((selectedEntry as SearchNodeItem).NodeEntry.Type == null && (selectedEntry as SearchNodeItem).NodeEntry.Node == null)) { return(false); } var nodeEntry = (selectedEntry as SearchNodeItem).NodeEntry; var windowMousePosition = editorWindow.rootVisualElement.ChangeCoordinatesTo(editorWindow.rootVisualElement.parent, mousePosition); var graphMousePosition = editorView.GraphView.contentViewContainer.WorldToLocal(windowMousePosition); SerializedNode node; if (nodeEntry.Node != null) { node = nodeEntry.Node; node.DrawState.Position.position = graphMousePosition; } else { var nodeType = nodeEntry.Type; node = new SerializedNode(nodeType, new Rect(graphMousePosition, EditorView.DefaultNodeSize)); } editorView.DlogObject.RegisterCompleteObjectUndo("Add " + node.Type); editorView.DlogObject.DlogGraph.AddNode(node); if (ConnectedPort != null) { if (nodeEntry.Node == null) { node.BuildNode(editorView, null); } var edge = new SerializedEdge { Output = ConnectedPort.node.viewDataKey, Input = node.GUID, OutputPort = ConnectedPort.viewDataKey, InputPort = node.PortData[nodeEntry.CompatiblePortIndex], OutputCapacity = ConnectedPort.capacity, InputCapacity = nodeEntry.Capacity.Value }; editorView.DlogObject.DlogGraph.AddEdge(edge); } return(true); }
public void AddEdge(SerializedEdge edge) { if (edge.InputCapacity == Port.Capacity.Single) { // Remove all edges with the same port var temp = new List <SerializedEdge>(); temp.AddRange(edges.Where(edge1 => edge1.InputPort == edge.InputPort)); temp.ForEach(RemoveEdge); } if (edge.OutputCapacity == Port.Capacity.Single) { // Remove all edges with the same port var temp = new List <SerializedEdge>(); temp.AddRange(edges.Where(edge1 => edge1.OutputPort == edge.OutputPort)); temp.ForEach(RemoveEdge); } edges.Add(edge); addedEdges.Add(edge); }
private void AddEdge(SerializedEdge edge) { edges.Add(edge); }
public void Paste(CopyPasteData copyPasteData, List <SerializedNode> remappedNodes, List <SerializedEdge> remappedEdges) { var nodeGuidMap = new Dictionary <string, string>(); var portGuidMap = new Dictionary <string, string>(); foreach (var node in copyPasteData.Nodes) { var oldGuid = node.GUID; var newGuid = Guid.NewGuid().ToString(); node.GUID = newGuid; nodeGuidMap[oldGuid] = newGuid; for (var i = 0; i < node.PortData.Count; i++) { var newPortGuid = Guid.NewGuid().ToString(); var oldPortGuid = node.PortData[i]; portGuidMap[oldPortGuid] = newPortGuid; node.PortData[i] = newPortGuid; } // Ugly magic to change dynamic port guid data if (node.Type == typeof(SelfNode).FullName) { var data = JObject.Parse(node.NodeData); var lines = JsonConvert.DeserializeObject <List <LineDataSelf> >(data.Value <string>("lines")); foreach (var currLine in lines) { currLine.PortGuidA = portGuidMap[currLine.PortGuidA]; currLine.PortGuidB = portGuidMap[currLine.PortGuidB]; } data["lines"] = new JValue(JsonConvert.SerializeObject(lines)); node.NodeData = data.ToString(Formatting.None); } else if (node.Type == typeof(NpcNode).FullName) { var data = JObject.Parse(node.NodeData); var lines = JsonConvert.DeserializeObject <List <LineDataNpc> >(data.Value <string>("lines")); foreach (var currLine in lines) { currLine.PortGuidA = portGuidMap[currLine.PortGuidA]; currLine.PortGuidB = portGuidMap[currLine.PortGuidB]; currLine.PortGuidC = portGuidMap[currLine.PortGuidC]; } data["lines"] = new JValue(JsonConvert.SerializeObject(lines)); node.NodeData = data.ToString(Formatting.None); } // offset the pasted node slightly so it's not on top of the original one var drawState = node.DrawState; var position = drawState.Position; position.x += 30; position.y += 30; drawState.Position = position; node.DrawState = drawState; remappedNodes.Add(node); AddNode(node); // add the node to the pasted node list pastedNodes.Add(node); } foreach (var edge in copyPasteData.Edges) { if ((nodeGuidMap.ContainsKey(edge.Input) && nodeGuidMap.ContainsKey(edge.Output)) && (portGuidMap.ContainsKey(edge.InputPort) && portGuidMap.ContainsKey(edge.OutputPort))) { var remappedOutputGuid = nodeGuidMap.ContainsKey(edge.Output) ? nodeGuidMap[edge.Output] : edge.Output; var remappedInputGuid = nodeGuidMap.ContainsKey(edge.Input) ? nodeGuidMap[edge.Input] : edge.Input; var remappedOutputPortGuid = portGuidMap.ContainsKey(edge.OutputPort) ? portGuidMap[edge.OutputPort] : edge.OutputPort; var remappedInputPortGuid = portGuidMap.ContainsKey(edge.InputPort) ? portGuidMap[edge.InputPort] : edge.InputPort; var remappedEdge = new SerializedEdge { Input = remappedInputGuid, Output = remappedOutputGuid, InputPort = remappedInputPortGuid, OutputPort = remappedOutputPortGuid, InputCapacity = edge.InputCapacity, OutputCapacity = edge.OutputCapacity }; remappedEdges.Add(remappedEdge); AddEdge(remappedEdge); } } }
public void RemoveEdge(SerializedEdge edge) { edges.Remove(edge); removedEdges.Add(edge); }