From e14b79c14eca5c0a87507481f51b185711f438da Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Fri, 3 Mar 2023 18:40:50 +0000 Subject: [PATCH] Changed to store resolved prompt in workflow info --- web/extensions/core/dynamicPrompts.js | 8 ++++---- web/scripts/app.js | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web/extensions/core/dynamicPrompts.js b/web/extensions/core/dynamicPrompts.js index 3729cf96..8528201d 100644 --- a/web/extensions/core/dynamicPrompts.js +++ b/web/extensions/core/dynamicPrompts.js @@ -6,9 +6,6 @@ import { app } from "../../scripts/app.js"; app.registerExtension({ name: "Comfy.DynamicPrompts", nodeCreated(node) { - // TODO: Change this to replace the value and restore it after posting - - if (node.widgets) { // Locate dynamic prompt text widgets // Include any widgets with dynamicPrompts set to true, and customtext @@ -17,7 +14,7 @@ app.registerExtension({ ); for (const widget of widgets) { // Override the serialization of the value to resolve dynamic prompts for all widgets supporting it in this node - widget.serializeValue = () => { + widget.serializeValue = (workflowNode, widgetIndex) => { let prompt = widget.value; while (prompt.replace("\\{", "").includes("{") && prompt.replace("\\}", "").includes("}")) { const startIndex = prompt.replace("\\{", "00").indexOf("{"); @@ -32,6 +29,9 @@ app.registerExtension({ prompt = prompt.substring(0, startIndex) + randomOption + prompt.substring(endIndex + 1); } + // Overwrite the value in the serialized workflow pnginfo + workflowNode.widgets_values[widgetIndex] = prompt; + return prompt; }; } diff --git a/web/scripts/app.js b/web/scripts/app.js index c8090df8..071742c9 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -589,9 +589,10 @@ class ComfyApp { // Store all widget values if (widgets) { - for (const widget of widgets) { + for (const i in widgets) { + const widget = widgets[i]; if (!widget.options || widget.options.serialize !== false) { - inputs[widget.name] = widget.serializeValue ? widget.serializeValue() : widget.value; + inputs[widget.name] = widget.serializeValue ? widget.serializeValue(n, i) : widget.value; } } } @@ -619,7 +620,7 @@ class ComfyApp { } else { link = node.getInputLink(i); } - + if (link) { inputs[node.inputs[i].name] = [String(link.origin_id), parseInt(link.origin_slot)]; }