Fix importing a node with an invalid number of outputs.

This commit is contained in:
GogoVega 2024-06-15 11:39:25 +02:00
parent 39d8386e43
commit e5db6661c3
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -1937,32 +1937,30 @@ RED.nodes = (function() {
newNode._config.x = node.x; newNode._config.x = node.x;
newNode._config.y = node.y; newNode._config.y = node.y;
if (node.hasOwnProperty("inputs")) { if (node.hasOwnProperty("inputs") && def.defaults.hasOwnProperty("inputs")) {
newNode._config.inputs = JSON.stringify(node.inputs); newNode._config.inputs = JSON.stringify(node.inputs);
newNode.inputs = node.inputs; newNode.inputs = parseInt(node.inputs, 10);
} else { } else {
newNode.inputs = def.inputs; newNode.inputs = def.inputs;
} }
if (node.hasOwnProperty("outputs")) { if (node.hasOwnProperty("outputs") && def.defaults.hasOwnProperty("outputs")) {
newNode._config.outputs = JSON.stringify(node.outputs); newNode._config.outputs = JSON.stringify(node.outputs);
newNode.outputs = node.outputs; newNode.outputs = parseInt(node.outputs, 10);
} else { } else {
newNode.outputs = def.outputs; newNode.outputs = def.outputs;
} }
if (newNode.wires.length > newNode.outputs) {
if (!def.defaults.hasOwnProperty("outputs") || !isNaN(parseInt(newNode.outputs))) {
// The node declares outputs in its defaults, but has not got a valid value // The node declares outputs in its defaults, but has not got a valid value
// Defer to the length of the wires array // Defer to the length of the wires array
if (isNaN(newNode.outputs)) {
newNode.outputs = newNode.wires.length; newNode.outputs = newNode.wires.length;
} else { } else if (newNode.wires.length > newNode.outputs) {
// If 'wires' is longer than outputs, clip wires // If 'wires' is longer than outputs, clip wires
console.log("Warning: node.wires longer than node.outputs - trimming wires:", node.id, " wires:", node.wires.length, " outputs:", node.outputs); console.log("Warning: node.wires longer than node.outputs - trimming wires:", node.id, " wires:", node.wires.length, " outputs:", node.outputs);
// TODO: Pas dans l'autre sens ? // TODO: Pas dans l'autre sens ?
newNode.wires = newNode.wires.slice(0, newNode.outputs); newNode.wires = newNode.wires.slice(0, newNode.outputs);
} }
}
// Copy node user properties // Copy node user properties
for (const d in def.defaults) { for (const d in def.defaults) {