Skip to content

Commit

Permalink
add catching type of other socket for chameleon socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Durman committed Jan 10, 2020
1 parent 5822f97 commit 79e0f8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions nodes/dictionary/dictionary_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 79e0f8f

Please sign in to comment.