"deploy/git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "693e4db5012ca2361f6a284e29eb30cb8345461f"
Commit eed4f62c authored by space-nuko's avatar space-nuko
Browse files

Add comment support to dynamic prompts nodes

parent 29c50954
...@@ -3,6 +3,13 @@ import { app } from "../../scripts/app.js"; ...@@ -3,6 +3,13 @@ import { app } from "../../scripts/app.js";
// Allows for simple dynamic prompt replacement // 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. // 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({ app.registerExtension({
name: "Comfy.DynamicPrompts", name: "Comfy.DynamicPrompts",
nodeCreated(node) { nodeCreated(node) {
...@@ -15,7 +22,7 @@ app.registerExtension({ ...@@ -15,7 +22,7 @@ app.registerExtension({
for (const widget of widgets) { for (const widget of widgets) {
// Override the serialization of the value to resolve dynamic prompts for all widgets supporting it in this node // Override the serialization of the value to resolve dynamic prompts for all widgets supporting it in this node
widget.serializeValue = (workflowNode, widgetIndex) => { widget.serializeValue = (workflowNode, widgetIndex) => {
let prompt = widget.value; let prompt = stripComments(widget.value);
while (prompt.replace("\\{", "").includes("{") && prompt.replace("\\}", "").includes("}")) { while (prompt.replace("\\{", "").includes("{") && prompt.replace("\\}", "").includes("}")) {
const startIndex = prompt.replace("\\{", "00").indexOf("{"); const startIndex = prompt.replace("\\{", "00").indexOf("{");
const endIndex = prompt.replace("\\}", "00").indexOf("}"); const endIndex = prompt.replace("\\}", "00").indexOf("}");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment