|
|
|
@ -302,10 +302,32 @@ class PlasmaNodeBase:
|
|
|
|
|
"""Ensures that sockets are linked appropriately and there are enough inputs""" |
|
|
|
|
input_defs, output_defs = self._socket_defs |
|
|
|
|
for defs, sockets in ((input_defs, self.inputs), (output_defs, self.outputs)): |
|
|
|
|
done = set() |
|
|
|
|
|
|
|
|
|
# Need to enumerate by hand because blendsucks has major (crashing) issues if we modify |
|
|
|
|
# this swhizzle while stuff is going down. |
|
|
|
|
self._update_extant_sockets(defs, sockets) |
|
|
|
|
self._update_init_sockets(defs, sockets) |
|
|
|
|
|
|
|
|
|
def _update_init_sockets(self, defs, sockets): |
|
|
|
|
# Create any missing sockets and spawn any required empties. |
|
|
|
|
for alias, options in defs.items(): |
|
|
|
|
working_sockets = [(i, socket) for i, socket in enumerate(sockets) if socket.alias == alias] |
|
|
|
|
if not working_sockets: |
|
|
|
|
self._spawn_socket(alias, options, sockets) |
|
|
|
|
elif options.get("spawn_empty", False): |
|
|
|
|
last_socket_id = next(reversed(working_sockets))[0] |
|
|
|
|
for working_id, working_socket in working_sockets: |
|
|
|
|
if working_id == last_socket_id and working_socket.is_linked: |
|
|
|
|
new_socket_id = len(sockets) |
|
|
|
|
new_socket = self._spawn_socket(alias, options, sockets) |
|
|
|
|
desired_id = last_socket_id + 1 |
|
|
|
|
if new_socket_id != desired_id: |
|
|
|
|
sockets.move(new_socket_id, desired_id) |
|
|
|
|
elif working_id < last_socket_id and not working_socket.is_linked: |
|
|
|
|
# Indices do not update until after the update() function finishes, so |
|
|
|
|
# no need to decrement last_socket_id |
|
|
|
|
sockets.remove(working_socket) |
|
|
|
|
|
|
|
|
|
def _update_extant_sockets(self, defs, sockets): |
|
|
|
|
# Manually enumerate the sockets that are present for their presence and for the |
|
|
|
|
# validity of their links. Can't use a for because we will overrun and crash Blender. |
|
|
|
|
i = 0 |
|
|
|
|
while i < len(sockets): |
|
|
|
|
socket = sockets[i] |
|
|
|
@ -368,27 +390,8 @@ class PlasmaNodeBase:
|
|
|
|
|
pass |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# If this is a spawn empty socket, make sure we have exactly one empty socket |
|
|
|
|
if options.get("spawn_empty", False) and not socket.alias in done: |
|
|
|
|
empty_sockets = [j for j in sockets if j.bl_idname == socket.bl_idname and not j.is_used] |
|
|
|
|
if not empty_sockets: |
|
|
|
|
idx = len(sockets) |
|
|
|
|
dbg = sockets.new(socket.bl_idname, socket.name, socket.alias) |
|
|
|
|
# don't even ask... |
|
|
|
|
new_idx = i + 2 |
|
|
|
|
if idx != new_idx: |
|
|
|
|
sockets.move(idx, new_idx) |
|
|
|
|
else: |
|
|
|
|
while len(empty_sockets) > 1: |
|
|
|
|
sockets.remove(empty_sockets.pop()) |
|
|
|
|
done.add(socket.alias) |
|
|
|
|
|
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
# Create any new sockets |
|
|
|
|
for alias in (j for j in defs if j not in done): |
|
|
|
|
self._spawn_socket(alias, defs[alias], sockets) |
|
|
|
|
|
|
|
|
|
def _whine(self, msg, *args): |
|
|
|
|
if args: |
|
|
|
|
msg = msg.format(*args) |
|
|
|
|