diff --git a/core/sockets.py b/core/sockets.py index e164f617af..bc1567da8f 100644 --- a/core/sockets.py +++ b/core/sockets.py @@ -546,7 +546,20 @@ class SvChameleonSocket(NodeSocket, SvSocketCommon): bl_idname = "SvChameleonSocket" bl_label = "Chameleon Socket" - dynamic_color: FloatVectorProperty(default=(0.0, 0.0, 0.0, 0.0), size=4) + dynamic_color: FloatVectorProperty(default=(0.0, 0.0, 0.0, 0.0), size=4, + description="For storing color of other socket via catch_props method") + dynamic_type: StringProperty(default='SvChameleonSocket', + description="For storing type of other socket via catch_props method") + + def catch_props(self): + # should be called during update event of a node for catching its property + other = self.other + if other: + self.dynamic_color = socket_colors[other.bl_idname] + self.dynamic_type = other.bl_idname + else: + self.dynamic_color = (0.0, 0.0, 0.0, 0.0) + self.dynamic_type = self.bl_idname def get_prop_data(self): if self.prop_name: @@ -565,13 +578,6 @@ def sv_get(self, default=sentinel, deepcopy=True): else: return default - def set_color(self): - other = self.other - if other: - self.dynamic_color = socket_colors[other.bl_idname] - else: - self.dynamic_color = (0.0, 0.0, 0.0, 0.0) - def draw_color(self, context, node): return self.dynamic_color diff --git a/nodes/dictionary/dictionary_in.py b/nodes/dictionary/dictionary_in.py index d74380446d..a5f3b5e1ec 100644 --- a/nodes/dictionary/dictionary_in.py +++ b/nodes/dictionary/dictionary_in.py @@ -100,7 +100,7 @@ def sv_init(self, context): def update(self): # Remove unused sockets [self.inputs.remove(sock) for sock in list(self.inputs)[:-1] if not sock.is_linked] - [sock.set_color() for sock in self.inputs if sock.links] + [sock.catch_props() for sock in self.inputs if sock.links] # add property to new socket and add extra empty socket if list(self.inputs)[-1].is_linked and len(self.inputs) < 11: @@ -150,9 +150,9 @@ def process(self): out_dict = SvDict({getattr(self, key): prop for key, prop in zip(keys, props) if prop is not None}) for sock in list(self.inputs)[:-1]: out_dict.inputs[sock.identifier] = { - 'type': sock.other.bl_idname, + 'type': sock.dynamic_type, 'name': getattr(self, sock.prop_name), - 'nest': sock.sv_get()[0].inputs if sock.bl_idname == 'SvDictionarySocket' else None} + 'nest': sock.sv_get()[0].inputs if sock.dynamic_type == 'SvDictionarySocket' else None} out.append(out_dict) self.outputs[0].sv_set(out)