From 2bfe6886c87a514e635f697b621389a7285eba85 Mon Sep 17 00:00:00 2001 From: Barry Downes Date: Sun, 30 Jul 2023 22:47:19 +1000 Subject: [PATCH] Remove dynamicPrompts web extension, as it would interfere with the reimplementation. --- web/extensions/core/dynamicPrompts.js | 48 --------------------------- 1 file changed, 48 deletions(-) delete mode 100644 web/extensions/core/dynamicPrompts.js diff --git a/web/extensions/core/dynamicPrompts.js b/web/extensions/core/dynamicPrompts.js deleted file mode 100644 index 599a9e685..000000000 --- a/web/extensions/core/dynamicPrompts.js +++ /dev/null @@ -1,48 +0,0 @@ -import { app } from "../../scripts/app.js"; - -// Allows for simple dynamic prompt replacement -// Inputs in the format {a|b} will have a random value of a or b chosen when the prompt is queued. - -/* - * Strips C-style line and block comments from a string - */ -function stripComments(str) { - return str.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,''); -} - -app.registerExtension({ - name: "Comfy.DynamicPrompts", - nodeCreated(node) { - if (node.widgets) { - // Locate dynamic prompt text widgets - // Include any widgets with dynamicPrompts set to true, and customtext - const widgets = node.widgets.filter( - (n) => (n.type === "customtext" && n.dynamicPrompts !== false) || n.dynamicPrompts - ); - 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 = (workflowNode, widgetIndex) => { - let prompt = stripComments(widget.value); - while (prompt.replace("\\{", "").includes("{") && prompt.replace("\\}", "").includes("}")) { - const startIndex = prompt.replace("\\{", "00").indexOf("{"); - const endIndex = prompt.replace("\\}", "00").indexOf("}"); - - const optionsString = prompt.substring(startIndex + 1, endIndex); - const options = optionsString.split("|"); - - const randomIndex = Math.floor(Math.random() * options.length); - const randomOption = options[randomIndex]; - - prompt = prompt.substring(0, startIndex) + randomOption + prompt.substring(endIndex + 1); - } - - // Overwrite the value in the serialized workflow pnginfo - if (workflowNode?.widgets_values) - workflowNode.widgets_values[widgetIndex] = prompt; - - return prompt; - }; - } - } - }, -});