Fix condmulticombine

This commit is contained in:
kijai 2023-10-01 14:10:22 +03:00
parent ca73cb8e8e
commit 69422c9ea9
3 changed files with 42 additions and 36 deletions

View File

@ -112,22 +112,27 @@ class PlotNode:
class ConditioningMultiCombine: class ConditioningMultiCombine:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { return {
"conditioning_1": ("CONDITIONING", ), "required": {
"conditioning_2": ("CONDITIONING", ), "inputcount": ("INT", {"default": 2, "min": 2, "max": 20, "step": 1}),
}} "conditioning_1": ("CONDITIONING", ),
"conditioning_2": ("CONDITIONING", ),
},
}
RETURN_TYPES = ("CONDITIONING",) RETURN_TYPES = ("CONDITIONING", "INT")
RETURN_NAMES = ("combined", "inputcount")
FUNCTION = "combine" FUNCTION = "combine"
CATEGORY = "KJNodes" CATEGORY = "KJNodes"
def combine(self, combine, **kwargs): def combine(self, inputcount, **kwargs):
cond_combine_node = nodes.ConditioningCombine() cond_combine_node = nodes.ConditioningCombine()
cond = kwargs["c1"] cond = kwargs["conditioning_1"]
for c in range(1, combine): for c in range(1, inputcount):
new_cond = kwargs[f"c{c + 1}"] new_cond = kwargs[f"conditioning_{c + 1}"]
cond = cond_combine_node.combine(new_cond, cond)[0] cond = cond_combine_node.combine(new_cond, cond)[0]
return (cond,) return (cond, inputcount,)
class ConditioningSetMaskAndCombine: class ConditioningSetMaskAndCombine:
@classmethod @classmethod

View File

@ -9,22 +9,24 @@ app.registerExtension({
console.log(this.pos[0]) console.log(this.pos[0])
} }
nodeType.prototype.onNodeCreated = function () { nodeType.prototype.onNodeCreated = function () {
this.inputs_offset = nodeData.name.includes("selective")?1:0 //this.inputs_offset = nodeData.name.includes("selective")?1:0
this.cond_type = "CONDITIONING" this.cond_type = "CONDITIONING"
this.addWidget("button", "Add", null, () => { this.inputs_offset = nodeData.name.includes("selective")?1:0
this.addWidget("button", "Update inputs", null, () => {
if (!this.inputs) { if (!this.inputs) {
this.inputs = []; this.inputs = [];
} }
if (this.inputs.length < 20) { const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
const newInputName = `conditioning_${this.inputs.length + 1}`; if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing
this.addInput(newInputName, this.cond_type);
} if(target_number_of_inputs < this.inputs.length){
}); for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--)
this.addWidget("button", "Remove", null, () => { this.removeInput(i)
if (this.inputs.length > 2) { }
const lastInputIndex = this.inputs.length - 1; else{
this.removeInput(lastInputIndex); for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
} this.addInput(`conditioning_${i}`, this.cond_type)
}
}); });
} }
break; break;

View File

@ -150,7 +150,6 @@ app.registerExtension({
} }
this.clone = function () { this.clone = function () {
console.log("CLONE");
const cloned = SetNode.prototype.clone.apply(this); const cloned = SetNode.prototype.clone.apply(this);
cloned.inputs[0].name = '*'; cloned.inputs[0].name = '*';
cloned.inputs[0].type = '*'; cloned.inputs[0].type = '*';
@ -203,9 +202,9 @@ app.registerExtension({
} }
onRemoved() { onRemoved() {
console.log("onRemove"); // console.log("onRemove");
console.log(this); // console.log(this);
console.log(this.flags); // console.log(this.flags);
const allGetters = this.graph._nodes.filter((otherNode) => otherNode.type == "GetNode"); const allGetters = this.graph._nodes.filter((otherNode) => otherNode.type == "GetNode");
allGetters.forEach((otherNode) => { allGetters.forEach((otherNode) => {
if (otherNode.setComboValues) { if (otherNode.setComboValues) {
@ -330,13 +329,13 @@ app.registerExtension({
}; };
this.validateLinks = function() { this.validateLinks = function() {
console.log("validating links"); //console.log("validating links");
if (this.outputs[0].type != '*' && this.outputs[0].links) { if (this.outputs[0].type != '*' && this.outputs[0].links) {
console.log("in"); //console.log("in");
this.outputs[0].links.forEach((linkId) => { this.outputs[0].links.forEach((linkId) => {
const link = node.graph.links[linkId]; const link = node.graph.links[linkId];
if (link && link.type != this.outputs[0].type && link.type != '*') { if (link && link.type != this.outputs[0].type && link.type != '*') {
console.log("removing link"); //console.log("removing link");
node.graph.removeLink(linkId) node.graph.removeLink(linkId)
} }
}) })
@ -369,16 +368,16 @@ app.registerExtension({
if (setter) { if (setter) {
const slot_info = setter.inputs[slot]; const slot_info = setter.inputs[slot];
console.log("slot info"); //console.log("slot info");
console.log(slot_info); //console.log(slot_info);
console.log(this.graph.links); //console.log(this.graph.links);
const link = this.graph.links[ slot_info.link ]; const link = this.graph.links[ slot_info.link ];
console.log("link:"); //console.log("link:");
console.log(link); //console.log(link);
return link; return link;
} else { } else {
console.log(this.widgets[0]); //console.log(this.widgets[0]);
console.log(this.widgets[0].value); //console.log(this.widgets[0].value);
alert("No SetNode found for " + this.widgets[0].value + "(" + this.type + ")"); alert("No SetNode found for " + this.widgets[0].value + "(" + this.type + ")");
throw new Error("No SetNode found for " + this.widgets[0].value + "(" + this.type + ")"); throw new Error("No SetNode found for " + this.widgets[0].value + "(" + this.type + ")");