/// <summary> /// Removes a sequence element from the graph, by repointing incoming references to the ones referenced by outgoing items on this export. This is a very basic utility, only use it for items with one input and potentially multiple outputs. /// </summary> /// <param name="elementToSkip">Th sequence object to skip</param> /// <param name="outboundLinkIdx">The 0-indexed outbound link that should be attached the preceding entry element, as if this one had fired that link.</param> public static void SkipSequenceElement(ExportEntry elementToSkip, string outboundLinkName = null, int outboundLinkIdx = -1) { if (outboundLinkIdx == -1 && outboundLinkName == null) { throw new Exception(@"SkipSequenceElement() must have an outboundLinkName or an outboundLinkIdx!"); } if (outboundLinkIdx == -1) { var outboundLinkNames = KismetHelper.GetOutboundLinkNames(elementToSkip); outboundLinkIdx = outboundLinkNames.IndexOf(outboundLinkName); } // List of outbound link elements on the specified item we want to skip. These will be placed into the inbound item Debug.WriteLine($@"Attempting to skip {elementToSkip.UIndex} in {elementToSkip.FileRef.FilePath}"); var outboundLinkLists = SeqTools.GetOutboundLinksOfNode(elementToSkip); var inboundToSkippedNode = SeqTools.FindOutboundConnectionsToNode(elementToSkip, SeqTools.GetAllSequenceElements(elementToSkip).OfType <ExportEntry>()); var newTargetNodes = outboundLinkLists[outboundLinkIdx]; foreach (var preNode in inboundToSkippedNode) { // For every node that links to the one we want to skip... var preNodeLinks = GetOutboundLinksOfNode(preNode); foreach (var ol in preNodeLinks) { var numRemoved = ol.RemoveAll(x => x.LinkedOp == elementToSkip); if (numRemoved > 0) { // At least one was removed. Repoint it ol.AddRange(newTargetNodes); } } WriteOutboundLinksToNode(preNode, preNodeLinks); } }