From 48cf28c7d0cc1455926c72cf88a91580c06dd89b Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:06:18 +0300 Subject: [PATCH] fix JoinStringMulti --- web/js/jsnodes.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/web/js/jsnodes.js b/web/js/jsnodes.js index 8442843..68df804 100644 --- a/web/js/jsnodes.js +++ b/web/js/jsnodes.js @@ -151,27 +151,29 @@ app.registerExtension({ break; case "JoinStringMulti": + const originalOnNodeCreated = nodeType.prototype.onNodeCreated || function() {}; nodeType.prototype.onNodeCreated = function () { - this._type = "STRING" - this.inputs_offset = nodeData.name.includes("selective")?1:0 - this.addWidget("button", "Update inputs", null, () => { - if (!this.inputs) { - this.inputs = []; - } - const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"]; - if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing - - if(target_number_of_inputs < this.inputs.length){ - for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--) - this.removeInput(i) + originalOnNodeCreated.apply(this, arguments); + + this._type = "STRING"; + this.inputs_offset = nodeData.name.includes("selective") ? 1 : 0; + this.addWidget("button", "Update inputs", null, () => { + if (!this.inputs) { + this.inputs = []; } - else{ - for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i) - this.addInput(`string_${i}`, this._type) - } - }); - } - break; + const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"]; + if (target_number_of_inputs === this.inputs.length) return; // already set, do nothing + + if (target_number_of_inputs < this.inputs.length) { + for (let i = this.inputs.length; i >= this.inputs_offset + target_number_of_inputs; i--) + this.removeInput(i); + } else { + for (let i = this.inputs.length + 1 - this.inputs_offset; i <= target_number_of_inputs; ++i) + this.addInput(`string_${i}`, this._type); + } + }); + } + break; case "SoundReactive": nodeType.prototype.onNodeCreated = function () { let audioContext;