From 4923a78d7cf1d53f082ee9cab9a7fe0f60e2394c Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:44:02 -0500 Subject: [PATCH] Improvement for finding nodes with missing tags --- src/lib/ComfyGraphCanvas.ts | 21 +++-- src/lib/components/ComfyGraphErrorList.svelte | 80 +++++++++++++++---- 2 files changed, 82 insertions(+), 19 deletions(-) diff --git a/src/lib/ComfyGraphCanvas.ts b/src/lib/ComfyGraphCanvas.ts index 220d85e..ac04293 100644 --- a/src/lib/ComfyGraphCanvas.ts +++ b/src/lib/ComfyGraphCanvas.ts @@ -25,7 +25,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas { activeErrors?: ComfyGraphErrors = null; blinkError: ComfyGraphErrorLocation | null = null; blinkErrorTime: number = 0; - highlightNodeAndInput: [LGraphNode, number] | null = null; + highlightNodeAndInput: [LGraphNode, number | null] | null = null; get comfyGraph(): ComfyGraph | null { return this.graph as ComfyGraph; @@ -133,6 +133,15 @@ export default class ComfyGraphCanvas extends LGraphCanvas { else if (isHighlightedNode) { color = "cyan"; thickness = 2 + + // Blink node if no input highlighted + if (this.highlightNodeAndInput[1] == null) { + if (this.blinkErrorTime > 0) { + if ((Math.floor(this.blinkErrorTime / 2)) % 2 === 0) { + color = null; + } + } + } } else if (ss.currentHoveredNodes.has(node.id)) { color = "lightblue"; @@ -172,9 +181,11 @@ export default class ComfyGraphCanvas extends LGraphCanvas { } if (draw) { const [node, inputSlot] = this.highlightNodeAndInput; - ctx.lineWidth = 2; - ctx.strokeStyle = color; - this.highlightNodeInput(node, inputSlot, ctx); + if (inputSlot != null) { + ctx.lineWidth = 2; + ctx.strokeStyle = color; + this.highlightNodeInput(node, inputSlot, ctx); + } } } } @@ -733,7 +744,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas { this.selectNode(node); } - jumpToNodeAndInput(node: LGraphNode, slotIndex: number) { + jumpToNodeAndInput(node: LGraphNode, slotIndex: number | null) { this.jumpToNode(node); this.highlightNodeAndInput = [node, slotIndex]; this.blinkErrorTime = 20; diff --git a/src/lib/components/ComfyGraphErrorList.svelte b/src/lib/components/ComfyGraphErrorList.svelte index f8a669b..3822ec7 100644 --- a/src/lib/components/ComfyGraphErrorList.svelte +++ b/src/lib/components/ComfyGraphErrorList.svelte @@ -5,15 +5,35 @@ import uiState from '$lib/stores/uiState'; import type { ComfyNodeDefInputType } from "$lib/ComfyNodeDef"; import type { INodeInputSlot, LGraphNode, LLink, Subgraph } from "@litegraph-ts/core"; - import { UpstreamNodeLocator, getUpstreamLink } from "./ComfyPromptSerializer"; + import { UpstreamNodeLocator, getUpstreamLink, nodeHasTag } from "./ComfyPromptSerializer"; import JsonView from "./JsonView.svelte"; export let app: ComfyApp; export let errors: ComfyGraphErrors; + let missingTag = null; + let nodeToJumpTo = null; + let inputSlotToHighlight = null; + let _errors = null + + $: if (_errors != errors) { + _errors = errors; + if (errors.errors[0]) { + jumpToError(errors.errors[0]) + } + } + function closeList() { app.lCanvas.clearErrors(); $uiState.activeError = null; + clearState() + } + + function clearState() { + _errors = null; + missingTag = null; + nodeToJumpTo = null; + inputSlotToHighlight = null; } function getParentNode(error: ComfyGraphErrorLocation): Subgraph | null { @@ -24,11 +44,19 @@ return node.graph._subgraph_node } - function canJumpToDisconnectedInput(error: ComfyGraphErrorLocation): boolean { - return error.errorType === ComfyNodeErrorType.RequiredInputMissing && error.input != null; + function jumpToFoundNode() { + if (nodeToJumpTo == null) { + return + } + + app.lCanvas.jumpToNodeAndInput(nodeToJumpTo, inputSlotToHighlight); } - function jumpToDisconnectedInput(error: ComfyGraphErrorLocation) { + function detectDisconnected(error: ComfyGraphErrorLocation) { + missingTag = null; + nodeToJumpTo = null; + inputSlotToHighlight = null; + if (error.errorType !== ComfyNodeErrorType.RequiredInputMissing || error.input == null) { return } @@ -44,19 +72,32 @@ const tag: string | null = error.queueEntry.extraData.extra_pnginfo.comfyBoxPrompt.subgraphs[0]; const test = (node: LGraphNode, currentLink: LLink) => { + if (!nodeHasTag(node, tag, true)) + return true; + const [nextGraph, nextLink, nextInputSlot, nextNode] = getUpstreamLink(node, currentLink) return nextLink == null; }; const nodeLocator = new UpstreamNodeLocator(test) - const [_, foundLink, foundInputSlot, foundPrevNode] = nodeLocator.locateUpstream(node, inputIndex, tag); + const [foundNode, foundLink, foundInputSlot, foundPrevNode] = nodeLocator.locateUpstream(node, inputIndex, null); if (foundInputSlot != null && foundPrevNode != null) { - app.lCanvas.jumpToNodeAndInput(foundPrevNode, foundInputSlot); + if (!nodeHasTag(foundNode, tag, true)) { + nodeToJumpTo = foundNode + missingTag = tag; + inputSlotToHighlight = null; + } + else { + nodeToJumpTo = foundPrevNode; + inputSlotToHighlight = foundInputSlot; + } } } function jumpToError(error: ComfyGraphErrorLocation) { app.lCanvas.jumpToError(error); + + detectDisconnected(error); } function getInputTypeName(type: ComfyNodeDefInputType) { @@ -91,26 +132,37 @@