Browse Source

Fix interesting empty node socket spawning bugs.

This fixes two bugs with empty node socket spawning:
- The first time an empty is spawned, the link is moved to the last
socket.
- Unlinking a socket in the middle of the group would cause that socket
to be the one that's empty. This isn't bad per-se, but with Responders
being ID-based, it could result in some confusion.
pull/161/head
Adam Johnson 5 years ago
parent
commit
f84a4bd404
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 49
      korman/nodes/node_core.py

49
korman/nodes/node_core.py

@ -300,10 +300,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]
@ -366,27 +388,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)

Loading…
Cancel
Save