Count tags on parent subgraphs as being on child nodes and ignore tags
on reroutes
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,7 @@ import { basename, capitalize, download, graphToGraphVis, jsonToJsObject, prompt
|
|||||||
import { tick } from "svelte";
|
import { tick } from "svelte";
|
||||||
import { type SvelteComponentDev } from "svelte/internal";
|
import { type SvelteComponentDev } from "svelte/internal";
|
||||||
import { get, writable, type Writable } from "svelte/store";
|
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 DanbooruTags from "$lib/DanbooruTags";
|
||||||
import { deserializeTemplateFromSVG, type SerializedComfyBoxTemplate } from "$lib/ComfyBoxTemplate";
|
import { deserializeTemplateFromSVG, type SerializedComfyBoxTemplate } from "$lib/ComfyBoxTemplate";
|
||||||
import templateState from "$lib/stores/templateState";
|
import templateState from "$lib/stores/templateState";
|
||||||
@@ -924,10 +924,7 @@ export default class ComfyApp {
|
|||||||
|
|
||||||
const thumbnails = []
|
const thumbnails = []
|
||||||
for (const node of workflow.graph.iterateNodesInOrderRecursive()) {
|
for (const node of workflow.graph.iterateNodesInOrderRecursive()) {
|
||||||
if (node.mode !== NodeMode.ALWAYS
|
if (node.mode !== NodeMode.ALWAYS || (tag != null && !nodeHasTag(node, tag)))
|
||||||
|| (tag != null
|
|
||||||
&& Array.isArray(node.properties.tags)
|
|
||||||
&& node.properties.tags.indexOf(tag) === -1))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ("getPromptThumbnails" in node) {
|
if ("getPromptThumbnails" in node) {
|
||||||
|
|||||||
@@ -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 { GraphInput, GraphOutput, LGraph, LGraphNode, LLink, NodeMode, Subgraph, type SlotIndex } from "@litegraph-ts/core";
|
||||||
import type { SerializedPrompt, SerializedPromptInput, SerializedPromptInputsForNode, SerializedPromptInputsAll, SerializedPromptInputs } from "./ComfyApp";
|
import type { SerializedPrompt, SerializedPromptInput, SerializedPromptInputsForNode, SerializedPromptInputsAll, SerializedPromptInputs } from "./ComfyApp";
|
||||||
import type IComfyInputSlot from "$lib/IComfyInputSlot";
|
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 {
|
function isReroute(node: LGraphNode): boolean {
|
||||||
return "tags" in node.properties && node.properties.tags.indexOf(tag) !== -1
|
return node.is(Reroute) || node.is(ComfyReroute)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGraphInputOutput(node: LGraphNode): boolean {
|
function isGraphInputOutput(node: LGraphNode): boolean {
|
||||||
return node.is(GraphInput) || node.is(GraphOutput)
|
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 {
|
export function isActiveNode(node: LGraphNode, tag: string | null = null): boolean {
|
||||||
if (!node)
|
if (!node)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check tags but not on graph inputs/outputs
|
// 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)
|
console.debug("Skipping tagged node", tag, node.properties.tags, node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { BuiltInSlotType, LiteGraph, NodeMode, type ITextWidget, type IToggleWidget, type SlotLayout } from "@litegraph-ts/core";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
|
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
|
||||||
|
import { nodeHasTag } from "$lib/components/ComfyPromptSerializer";
|
||||||
|
|
||||||
export interface ComfySetNodeModeActionProperties extends ComfyGraphNodeProperties {
|
export interface ComfySetNodeModeActionProperties extends ComfyGraphNodeProperties {
|
||||||
targetTags: string,
|
targetTags: string,
|
||||||
@@ -52,7 +53,7 @@ export default class ComfySetNodeModeAction extends ComfyGraphNode {
|
|||||||
for (const node of this.graph._nodes) {
|
for (const node of this.graph._nodes) {
|
||||||
if ("tags" in node.properties) {
|
if ("tags" in node.properties) {
|
||||||
const comfyNode = node as ComfyGraphNode;
|
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) {
|
if (hasTag) {
|
||||||
let newMode: NodeMode;
|
let newMode: NodeMode;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
|||||||
@@ -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 { BuiltInSlotType, LiteGraph, NodeMode, type ITextWidget, type IToggleWidget, type PropertyLayout, type SlotLayout } from "@litegraph-ts/core";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
|
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
|
||||||
|
import { nodeHasTag } from "$lib/components/ComfyPromptSerializer";
|
||||||
|
|
||||||
export type TagAction = {
|
export type TagAction = {
|
||||||
tag: string,
|
tag: string,
|
||||||
@@ -68,7 +69,7 @@ export default class ComfySetNodeModeAdvancedAction extends ComfyGraphNode {
|
|||||||
for (const node of this.graph.iterateNodesInOrderRecursive()) {
|
for (const node of this.graph.iterateNodesInOrderRecursive()) {
|
||||||
if ("tags" in node.properties) {
|
if ("tags" in node.properties) {
|
||||||
const comfyNode = node as ComfyGraphNode;
|
const comfyNode = node as ComfyGraphNode;
|
||||||
const hasTag = comfyNode.properties.tags.indexOf(action.tag) != -1;
|
const hasTag = nodeHasTag(comfyNode, action.tag);
|
||||||
|
|
||||||
if (hasTag) {
|
if (hasTag) {
|
||||||
let newMode: NodeMode;
|
let newMode: NodeMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user