Jelajahi Sumber

fix: socket UI update fails for multi-prop sockets

Joseph Brandenburg 6 bulan lalu
induk
melakukan
d2d6ed5d8a
2 mengubah file dengan 32 tambahan dan 16 penghapusan
  1. 32 14
      base_definitions.py
  2. 0 2
      socket_definitions.py

+ 32 - 14
base_definitions.py

@@ -737,6 +737,25 @@ class MantisNode:
         for out in self.outputs.values():
             out.flush_links()
     
+    def update_socket_value(self, blender_property, value) -> bool:
+        change_handled=False
+        if self.node_type == 'LINK':
+            for b_ob in self.bObject:
+                try:
+                    setattr(b_ob, blender_property, value)
+                    change_handled=True
+                except Exception as e:
+                    print("Failed to update mantis socket because of %s" % e,
+                            "Updating tree instead.")
+        else:
+            try:
+                setattr(self.bObject, blender_property, value)
+                change_handled=True
+            except Exception as e:
+                print("Failed to update mantis socket because of %s" % e,
+                        "Updating tree instead.")
+        return change_handled
+
     def ui_modify_socket(self, ui_socket, socket_name=None) -> bool:
         """ Handle changes in the node's UI. Updates the rig if possible."""
         # Always update the node's data
@@ -751,22 +770,21 @@ class MantisNode:
                     f" {ui_socket.node.name} in tree {ui_socket.node.id_data.name}.")
         for s_template in self.socket_templates:
             if s_template.name==ui_socket.name:
+                change_handled = True
                 if not s_template.blender_property: return False
-                if self.node_type == 'LINK':
-                    for b_ob in self.bObject:
+                elif isinstance(s_template.blender_property, str):
+                    change_handled &= self.update_socket_value(
+                        s_template.blender_property, value)
+                else: # it is a tuple
+                    for i, prop in enumerate(s_template.blender_property):
                         try:
-                            setattr(b_ob, s_template.blender_property, value)
-                            change_handled=True
-                        except Exception as e:
-                            print("Failed to update mantis socket because of %s" % e,
-                                  "Updating tree instead.")
-                else:
-                    try:
-                        setattr(self.bObject, s_template.blender_property, value)
-                        change_handled=True
-                    except Exception as e:
-                        print("Failed to update mantis socket because of %s" % e,
-                                "Updating tree instead.")
+                            change_handled &= self.update_socket_value(
+                                prop, value[i])
+                        except IndexError:
+                            prRed(f"{ui_socket.name} does not have enough values to unpack"
+                                  " to update the Mantis tree. Please report this as a bug.")
+                            change_handled=False
+                break # we don't have to look through any more socket templates
         return change_handled
     
     # the goal here is to tag the node as unprepared

+ 0 - 2
socket_definitions.py

@@ -277,9 +277,7 @@ def default_update(ui_socket, context, do_execute=True):
                 if isinstance(mantis_node, SimpleInputNode):
                     node_updated = socket_update(mantis_node, ui_socket)
                     for l in mantis_node.outputs[ui_socket.name].links:
-                        print (l.to_node, l.to_socket)
                         node_updated = node_updated and socket_update(l.to_node, ui_socket, l.to_socket)
-                        print (node_updated)
                 else:
                     node_updated = socket_update(mantis_node, ui_socket)
                 # execute the tree if even one node didn't update