|
142 | 142 |
|
143 | 143 | ctrl_shift_v_paste_connect_unselected_outputs: false, //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes |
144 | 144 |
|
| 145 | + // if true, all newly created nodes/links will use string UUIDs for their id fields instead of integers. |
| 146 | + // use this if you must have node IDs that are unique across all graphs and subgraphs. |
| 147 | + use_uuids: false, |
| 148 | + |
145 | 149 | /** |
146 | 150 | * Register a node class so it can be listed when the user wants to create a new one |
147 | 151 | * @method registerNodeType |
|
601 | 605 | return target; |
602 | 606 | }, |
603 | 607 |
|
| 608 | + /* |
| 609 | + * https://gist.github.com/jed/982883?permalink_comment_id=852670#gistcomment-852670 |
| 610 | + */ |
| 611 | + uuidv4: function() { |
| 612 | + return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,a=>(a^Math.random()*16>>a/4).toString(16)); |
| 613 | + }, |
| 614 | + |
604 | 615 | /** |
605 | 616 | * Returns if the types of two slots are compatible (taking into account wildcards, etc) |
606 | 617 | * @method isValidConnection |
|
1405 | 1416 | console.warn( |
1406 | 1417 | "LiteGraph: there is already a node with this ID, changing it" |
1407 | 1418 | ); |
1408 | | - node.id = ++this.last_node_id; |
| 1419 | + if (LiteGraph.use_uuids) { |
| 1420 | + node.id = LiteGraph.uuidv4(); |
| 1421 | + } |
| 1422 | + else { |
| 1423 | + node.id = ++this.last_node_id; |
| 1424 | + } |
1409 | 1425 | } |
1410 | 1426 |
|
1411 | 1427 | if (this._nodes.length >= LiteGraph.MAX_NUMBER_OF_NODES) { |
1412 | 1428 | throw "LiteGraph: max number of nodes in a graph reached"; |
1413 | 1429 | } |
1414 | 1430 |
|
1415 | 1431 | //give him an id |
1416 | | - if (node.id == null || node.id == -1) { |
1417 | | - node.id = ++this.last_node_id; |
1418 | | - } else if (this.last_node_id < node.id) { |
1419 | | - this.last_node_id = node.id; |
| 1432 | + if (LiteGraph.use_uuids) { |
| 1433 | + if (node.id == null || node.id == -1) |
| 1434 | + node.id = LiteGraph.uuidv4(); |
| 1435 | + } |
| 1436 | + else { |
| 1437 | + if (node.id == null || node.id == -1) { |
| 1438 | + node.id = ++this.last_node_id; |
| 1439 | + } else if (this.last_node_id < node.id) { |
| 1440 | + this.last_node_id = node.id; |
| 1441 | + } |
1420 | 1442 | } |
1421 | 1443 |
|
1422 | 1444 | node.graph = this; |
|
2412 | 2434 | enumerable: true |
2413 | 2435 | }); |
2414 | 2436 |
|
2415 | | - this.id = -1; //not know till not added |
| 2437 | + if (LiteGraph.use_uuids) { |
| 2438 | + this.id = LiteGraph.uuidv4(); |
| 2439 | + } |
| 2440 | + else { |
| 2441 | + this.id = -1; //not know till not added |
| 2442 | + } |
2416 | 2443 | this.type = null; |
2417 | 2444 |
|
2418 | 2445 | //inputs available: array of inputs |
|
2626 | 2653 | } |
2627 | 2654 |
|
2628 | 2655 | delete data["id"]; |
| 2656 | + |
| 2657 | + if (LiteGraph.use_uuids) { |
| 2658 | + data["id"] = LiteGraph.uuidv4() |
| 2659 | + } |
| 2660 | + |
2629 | 2661 | //remove links |
2630 | 2662 | node.configure(data); |
2631 | 2663 |
|
|
4264 | 4296 | break; |
4265 | 4297 | } |
4266 | 4298 | } |
| 4299 | + |
| 4300 | + var nextId |
| 4301 | + if (LiteGraph.use_uuids) |
| 4302 | + nextId = LiteGraph.uuidv4(); |
| 4303 | + else |
| 4304 | + nextId = ++this.graph.last_link_id; |
4267 | 4305 |
|
4268 | 4306 | //create link class |
4269 | 4307 | link_info = new LLink( |
4270 | | - ++this.graph.last_link_id, |
| 4308 | + nextId, |
4271 | 4309 | input.type || output.type, |
4272 | 4310 | this.id, |
4273 | 4311 | slot, |
@@ -7071,19 +7109,21 @@ LGraphNode.prototype.executeAction = function(action) |
7071 | 7109 | var selected_nodes_array = []; |
7072 | 7110 | for (var i in this.selected_nodes) { |
7073 | 7111 | var node = this.selected_nodes[i]; |
| 7112 | + if (node.clonable === false) |
| 7113 | + continue; |
7074 | 7114 | node._relative_id = index; |
7075 | 7115 | selected_nodes_array.push(node); |
7076 | 7116 | index += 1; |
7077 | 7117 | } |
7078 | 7118 |
|
7079 | 7119 | for (var i = 0; i < selected_nodes_array.length; ++i) { |
7080 | 7120 | var node = selected_nodes_array[i]; |
7081 | | - var cloned = node.clone(); |
7082 | | - if(!cloned) |
7083 | | - { |
7084 | | - console.warn("node type not found: " + node.type ); |
7085 | | - continue; |
7086 | | - } |
| 7121 | + var cloned = node.clone(); |
| 7122 | + if(!cloned) |
| 7123 | + { |
| 7124 | + console.warn("node type not found: " + node.type ); |
| 7125 | + continue; |
| 7126 | + } |
7087 | 7127 | clipboard_info.nodes.push(cloned.serialize()); |
7088 | 7128 | if (node.inputs && node.inputs.length) { |
7089 | 7129 | for (var j = 0; j < node.inputs.length; ++j) { |
@@ -12947,7 +12987,7 @@ LGraphNode.prototype.executeAction = function(action) |
12947 | 12987 | var newSelected = {}; |
12948 | 12988 |
|
12949 | 12989 | var fApplyMultiNode = function(node){ |
12950 | | - if (node.clonable == false) { |
| 12990 | + if (node.clonable === false) { |
12951 | 12991 | return; |
12952 | 12992 | } |
12953 | 12993 | var newnode = node.clone(); |
|
0 commit comments