فهرست منبع

NodeGroupUpdate finally works as intended

I swear if I have to make another pass at this issue once I make this commit...
Joseph Brandenburg 6 ماه پیش
والد
کامیت
6754e64d6a
2فایلهای تغییر یافته به همراه40 افزوده شده و 38 حذف شده
  1. 29 33
      base_definitions.py
  2. 11 5
      utilities.py

+ 29 - 33
base_definitions.py

@@ -392,42 +392,35 @@ def node_group_update(node, force = False):
 
         reorder_me_input = []; input_index = 0
         reorder_me_output = []; output_index = 0
+
+        def update_group_sockets(interface_item, is_input):
+            socket_map = socket_map_in if is_input else socket_map_out
+            socket_collection = node.inputs if is_input else node.outputs
+            counter = input_index if is_input else output_index
+            reorder_collection = reorder_me_input if is_input else reorder_me_output
+            if socket_map:
+                if item.identifier in socket_map.keys():
+                    socket = relink_socket_map_add_socket(node, socket_collection, item)
+                    do_relink(node, socket, socket_map, item.in_out)
+                else:
+                    for has_socket in socket_collection:
+                        if has_socket.bl_idname == item.socket_type and \
+                            has_socket.name == item.name:
+                            reorder_collection.append((has_socket, counter))
+                            break
+                    else:
+                        socket = relink_socket_map_add_socket(node, socket_collection, item)
+            else:
+                socket = relink_socket_map_add_socket(node, socket_collection, item)
+            counter += 1
+
         for item in node.node_tree.interface.items_tree:
             if item.item_type != "SOCKET": continue
             if (item.in_out == 'INPUT' and update_input):
-                if socket_map_in:
-                    if item.identifier in socket_map_in.keys():
-                        socket = relink_socket_map_add_socket(node, node.inputs, item)
-                        do_relink(node, socket, socket_map_in)
-                    else:
-                        for has_socket in node.inputs:
-                            if has_socket.bl_idname == item.socket_type and \
-                                has_socket.name == item.name:
-                                reorder_me_input.append((has_socket, input_index))
-                                break
-                        else:
-                            socket = relink_socket_map_add_socket(node, node.inputs, item)
-                else:
-                    socket = relink_socket_map_add_socket(node, node.inputs, item)
-                input_index += 1
-
+                update_group_sockets(item, True)
             if (item.in_out == 'OUTPUT' and update_output):
-                if socket_map_out:
-                    if item.identifier in socket_map_out.keys():
-                        socket = relink_socket_map_add_socket(node, node.outputs, item)
-                        do_relink(node, socket, socket_map_out)
-                    else:
-                        for has_socket in node.outputs:
-                            if has_socket.bl_idname == item.socket_type and \
-                                has_socket.name == item.name:
-                                reorder_me_output.append((has_socket, output_index))
-                                break
-                        else:
-                            socket = relink_socket_map_add_socket(node, node.outputs, item)
-                else:
-                    socket = relink_socket_map_add_socket(node, node.outputs, item)
-                output_index += 1
-        
+                update_group_sockets(item, False)
+
         both_reorders = zip([reorder_me_input, reorder_me_output], [node.inputs, node.outputs])
         for reorder_task, collection in both_reorders:
             for socket, position in reorder_task:
@@ -435,7 +428,10 @@ def node_group_update(node, force = False):
                     if s.identifier == socket.identifier: break
                 else:
                     prRed(f"WARN: could not reorder socket {socket.name}")
-                collection.move(i, position)
+                to_index = position
+                if (not socket.is_output) and node.bl_idname == "MantisSchemaGroup":
+                    to_index+=1
+                collection.move(i, to_index)
 
         # at this point there is no wildcard socket
         if socket_map_in and '__extend__' in socket_map_in.keys():

+ 11 - 5
utilities.py

@@ -161,16 +161,22 @@ def do_relink(node, s, map, in_out='INPUT', parent_name = ''):
                 # then move it up and delete the other link.
                 # this also needs to modify the interface of the node tree.
             if isinstance(sub_val, NodeSocket):
+                l = None
                 if in_out =='INPUT':
-                    node.id_data.links.new(input=sub_val, output=s)
+                    l = node.id_data.links.new(input=sub_val, output=s)
                 else:
-                    node.id_data.links.new(input=s, output=sub_val)
+                    l = node.id_data.links.new(input=s, output=sub_val)
+                if l is None:
+                    raise RuntimeError("Could not create link")
             elif isinstance(sub_val, Node):
+                l = None
                 # this happens when it is a NodeReroute
-                if in_out =='INPUT':
-                    node.id_data.links.new(input=sub_val.outputs[0], output=s)
+                if not s.is_output:
+                    l = node.id_data.links.new(input=sub_val.outputs[0], output=s)
                 else:
-                    node.id_data.links.new(input=s, output=sub_val.inputs[0])
+                    l = node.id_data.links.new(input=s, output=sub_val.inputs[0])
+                if l is None:
+                    raise RuntimeError("Could not create link")
             else:
                 raise RuntimeError("Unhandled case in do_relink()")
     elif get_string != "__extend__":