ソースを参照

fix: handle_overlay_detect types

Joseph Brandenburg 1 週間 前
親
コミット
fd9cbe326b
1 ファイル変更、15 行追加、8 行削除
  1. 15 8
      utilities/utilities.py

+ 15 - 8
utilities/utilities.py

@@ -970,6 +970,7 @@ def handle_overlay_detect(node, socket_id, socket_idname, value) -> str:
     root_items_tree = root_tree.interface.items_tree
     # detect if it is in the root tree, if so, handle immediately
     out_value = value
+    # what this recieves is determined by its idname
     socket_type = str
     match socket_idname:
         case "IntSocket" | "UnsignedIntSocket":
@@ -981,14 +982,20 @@ def handle_overlay_detect(node, socket_id, socket_idname, value) -> str:
         for key, interface_item in root_items_tree.items():
             if interface_item.item_type != "SOCKET": continue
             if interface_item.in_out != "INPUT": continue
-            # NOTE this will need to change if overlays extend to other data types
-            if hasattr(interface_item, "default_string"):
-                out_value = socket_type(out_value.replace("$"+key, interface_item.default_string))
-            elif key == value: # TODO this is the wrong way to do this, replace this with parser later
-                if hasattr(interface_item, "default_int"):
-                    out_value = socket_type(interface_item.default_int)
-                elif hasattr(interface_item, "default_float"):
-                    out_value = socket_type(interface_item.default_float)
+            # then what the interface provides is determined by its idname in turn
+            # NOTE I'm not 100% sure checking the socket_type is the right thing to do here
+            match interface_item.bl_socket_idname:
+                case "IntSocket" | "BooleanSocket":
+                    if socket_type in {int, float} and '$'+key == out_value:
+                        # TODO this is the wrong way to do this, replace this with parser later
+                        out_value = socket_type(interface_item.default_int)
+                case "FloatSocket":
+                    if socket_type in {int, float} and '$'+key == out_value:
+                        out_value = socket_type(interface_item.default_float)
+                case "StringSocket":
+                    if socket_type == str:
+                        out_value = socket_type(out_value.replace("$"+key, interface_item.default_string))
+
     else: # since it is not root, we have to tag it.
         mContext.tagged_for_overlay.append((node.signature, socket_id))
     return out_value