Count tags on parent subgraphs as being on child nodes and ignore tags

on reroutes
This commit is contained in:
space-nuko
2023-05-25 17:05:54 -05:00
parent e6b446079a
commit d70f430383
5 changed files with 3277 additions and 3270 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -34,7 +34,7 @@ import { basename, capitalize, download, graphToGraphVis, jsonToJsObject, prompt
import { tick } from "svelte";
import { type SvelteComponentDev } from "svelte/internal";
import { get, writable, type Writable } from "svelte/store";
import ComfyPromptSerializer, { isActiveBackendNode, UpstreamNodeLocator } from "./ComfyPromptSerializer";
import ComfyPromptSerializer, { isActiveBackendNode, nodeHasTag, UpstreamNodeLocator } from "./ComfyPromptSerializer";
import DanbooruTags from "$lib/DanbooruTags";
import { deserializeTemplateFromSVG, type SerializedComfyBoxTemplate } from "$lib/ComfyBoxTemplate";
import templateState from "$lib/stores/templateState";
@@ -924,10 +924,7 @@ export default class ComfyApp {
const thumbnails = []
for (const node of workflow.graph.iterateNodesInOrderRecursive()) {
if (node.mode !== NodeMode.ALWAYS
|| (tag != null
&& Array.isArray(node.properties.tags)
&& node.properties.tags.indexOf(tag) === -1))
if (node.mode !== NodeMode.ALWAYS || (tag != null && !nodeHasTag(node, tag)))
continue;
if ("getPromptThumbnails" in node) {

View File

@@ -4,21 +4,42 @@ import type ComfyGraphNode from "$lib/nodes/ComfyGraphNode";
import { GraphInput, GraphOutput, LGraph, LGraphNode, LLink, NodeMode, Subgraph, type SlotIndex } from "@litegraph-ts/core";
import type { SerializedPrompt, SerializedPromptInput, SerializedPromptInputsForNode, SerializedPromptInputsAll, SerializedPromptInputs } from "./ComfyApp";
import type IComfyInputSlot from "$lib/IComfyInputSlot";
import { Reroute } from "@litegraph-ts/nodes-basic";
import { ComfyReroute } from "$lib/nodes";
function hasTag(node: LGraphNode, tag: string): boolean {
return "tags" in node.properties && node.properties.tags.indexOf(tag) !== -1
function isReroute(node: LGraphNode): boolean {
return node.is(Reroute) || node.is(ComfyReroute)
}
function isGraphInputOutput(node: LGraphNode): boolean {
return node.is(GraphInput) || node.is(GraphOutput)
}
export function nodeHasTag(node: LGraphNode, tag: string): boolean {
// Ignore tags on reroutes since they're just movable wires and it defeats
// the convenience gains to have to set tags for all them
if (isReroute(node))
return true;
while (node != null) {
if ("tags" in node.properties) {
if (node.properties.tags.indexOf(tag) !== -1)
return true;
}
// Count parent subgraphs having the tag also.
node = node.graph?._subgraph_node;
}
return false;
}
export function isActiveNode(node: LGraphNode, tag: string | null = null): boolean {
if (!node)
return false;
// Check tags but not on graph inputs/outputs
if (!isGraphInputOutput(node) && (tag && !hasTag(node, tag))) {
if (!isGraphInputOutput(node) && (tag && !nodeHasTag(node, tag))) {
console.debug("Skipping tagged node", tag, node.properties.tags, node)
return false;
}

View File

@@ -2,6 +2,7 @@ import type { ComfyWidgetNode } from "$lib/nodes/widgets";
import { BuiltInSlotType, LiteGraph, NodeMode, type ITextWidget, type IToggleWidget, type SlotLayout } from "@litegraph-ts/core";
import { get } from "svelte/store";
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
import { nodeHasTag } from "$lib/components/ComfyPromptSerializer";
export interface ComfySetNodeModeActionProperties extends ComfyGraphNodeProperties {
targetTags: string,
@@ -52,7 +53,7 @@ export default class ComfySetNodeModeAction extends ComfyGraphNode {
for (const node of this.graph._nodes) {
if ("tags" in node.properties) {
const comfyNode = node as ComfyGraphNode;
const hasTag = tags.some(t => comfyNode.properties.tags.indexOf(t) != -1);
const hasTag = tags.some(t => nodeHasTag(comfyNode, t));
if (hasTag) {
let newMode: NodeMode;
if (enabled) {

View File

@@ -2,6 +2,7 @@ import { type DragItemID } from "$lib/stores/layoutStates";
import { BuiltInSlotType, LiteGraph, NodeMode, type ITextWidget, type IToggleWidget, type PropertyLayout, type SlotLayout } from "@litegraph-ts/core";
import { get } from "svelte/store";
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
import { nodeHasTag } from "$lib/components/ComfyPromptSerializer";
export type TagAction = {
tag: string,
@@ -68,7 +69,7 @@ export default class ComfySetNodeModeAdvancedAction extends ComfyGraphNode {
for (const node of this.graph.iterateNodesInOrderRecursive()) {
if ("tags" in node.properties) {
const comfyNode = node as ComfyGraphNode;
const hasTag = comfyNode.properties.tags.indexOf(action.tag) != -1;
const hasTag = nodeHasTag(comfyNode, action.tag);
if (hasTag) {
let newMode: NodeMode;