From d05f12a4b82185b2a1861b63e00f495e6f9423a3 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:42:40 -0500 Subject: [PATCH] Fix image extra output filename --- web/extensions/core/saveImageExtraOutput.js | 36 +++++++++------------ web/lib/litegraph.core.js | 6 +++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/web/extensions/core/saveImageExtraOutput.js b/web/extensions/core/saveImageExtraOutput.js index d0fe1ffcb..cafb0d052 100644 --- a/web/extensions/core/saveImageExtraOutput.js +++ b/web/extensions/core/saveImageExtraOutput.js @@ -1,15 +1,13 @@ import { app } from "../../scripts/app.js"; +import { hook } from "../../scripts/utils.js"; // Use widget values and dates in output filenames -/* app.registerExtension({ name: "Comfy.SaveImageExtraOutput", async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeData.name === "SaveImage") { - const onNodeCreated = nodeType.prototype.onNodeCreated; - - // Simple date formatter + // Simple date formatter const parts = { d: (d) => d.getDate(), M: (d) => d.getMonth() + 1, @@ -18,9 +16,9 @@ app.registerExtension({ s: (d) => d.getSeconds(), }; const format = - Object.keys(parts) - .map((k) => k + k + "?") - .join("|") + "|yyy?y?"; + Object.keys(parts) + .map((k) => k + k + "?") + .join("|") + "|yyy?y?"; function formatDate(text, date) { return text.replace(new RegExp(format, "g"), function (text) { @@ -34,16 +32,16 @@ app.registerExtension({ }); } - // When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R - nodeType.prototype.onNodeCreated = function () { - const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined; + // When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R + hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) { + const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined; const widget = this.widgets.find((w) => w.name === "filename_prefix"); widget.serializeValue = () => { return widget.value.replace(/%([^%]+)%/g, function (match, text) { const split = text.split("."); if (split.length !== 2) { - // Special handling for dates + // Special handling for dates if (split[0].startsWith("date:")) { return formatDate(split[0].substring(5), new Date()); } @@ -83,20 +81,18 @@ app.registerExtension({ }; return r; - }; + }); } else { - // When any other node is created add a property to alias the node - const onNodeCreated = nodeType.prototype.onNodeCreated; - nodeType.prototype.onNodeCreated = function () { - const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined; + // When any other node is created add a property to alias the node + hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) { + const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined; - if (!this.properties || !("Node name for S&R" in this.properties)) { - this.addProperty("Node name for S&R", this.constructor.type, "string"); + if (!this.hasProperty("Node name for S&R")) { + this.addProperty("Node name for S&R", this.type, "string"); } return r; - }; + }); } }, }); -*/ diff --git a/web/lib/litegraph.core.js b/web/lib/litegraph.core.js index bf57fd0d1..1bf617e22 100644 --- a/web/lib/litegraph.core.js +++ b/web/lib/litegraph.core.js @@ -2006,12 +2006,13 @@ const Ne = class { } /** sets the value of a property */ setProperty(t, e) { + var r; if (this.properties || (this.properties = {}), e !== this.properties[t]) { var i = this.properties[t]; if (this.properties[t] = e, this.graph && this.graph._version++, this.onPropertyChanged && this.onPropertyChanged(t, e, i) === !1 && (this.properties[t] = i), this.widgets) for (var n = 0; n < this.widgets.length; ++n) { var s = this.widgets[n]; - if (s && s.options.property == t) { + if (s && ((r = s.options) == null ? void 0 : r.property) == t) { s.value = e; break; } @@ -2452,6 +2453,9 @@ const Ne = class { s[r] = n[r]; return this.properties_info || (this.properties_info = []), this.properties_info.push(s), this.properties || (this.properties = {}), this.properties[t] = e, s; } + hasProperty(t) { + return this.properties != null && t in this.properties; + } /** * add a new output slot to use in this node * @param name