Browse Source

Fix responder nodes not notifying python nodes

In order for a python script to be notified that a responder attribute
has finished executing, we have to have a callback notify message in the
responder state. Cyan seems to require the artist to do this by hand,
but that seems like such a common operation that we'll add a callback at
the end of every state of any responder linked to a Python node. Cyan's
approach is somewhat more flexible in that you can call back at any
point in the responder, but that seems a bit excessive.
pull/114/head
Adam Johnson 6 years ago
parent
commit
03746ed681
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 19
      korman/nodes/node_responder.py

19
korman/nodes/node_responder.py

@ -103,6 +103,7 @@ class PlasmaResponderNode(PlasmaVersionedNode, bpy.types.Node):
self.states = [] self.states = []
self.parent = respNode self.parent = respNode
self.responder = respMod self.responder = respMod
self.has_pfm = respNode.find_output("keyref") is not None
def convert_states(self, exporter, so): def convert_states(self, exporter, so):
# This could implicitly export more states... # This could implicitly export more states...
@ -269,6 +270,21 @@ class PlasmaResponderStateNode(PlasmaNodeBase, bpy.types.Node):
self._generate_command(exporter, so, stateMgr.responder, commands, i) self._generate_command(exporter, so, stateMgr.responder, commands, i)
commands.save(state) commands.save(state)
# If the responder is linked to a PythonFile node, we need to automatically generate
# the callback message command node...
# YES! This SHOULD indeed be below the command manager save :)
if stateMgr.has_pfm:
pfmNotify = plNotifyMsg()
pfmNotify.BCastFlags |= plMessage.kLocalPropagate
pfmNotify.sender = stateMgr.responder.key
pfmNotify.state = 1.0
pfmNotify.addEvent(proCallbackEventData())
# This command needs to send at the end of the state, so after all waits
# have elapsed. Since waits are serial, we can just take the highest.
lastWait = len(commands.waits) - 1 if commands.waits else -1
state.addCommand(pfmNotify, lastWait)
def _generate_command(self, exporter, so, responder, commandMgr, msgNode, waitOn=-1): def _generate_command(self, exporter, so, responder, commandMgr, msgNode, waitOn=-1):
def prepare_message(exporter, so, responder, commandMgr, waitOn, msg): def prepare_message(exporter, so, responder, commandMgr, waitOn, msg):
idx, command = commandMgr.add_command(self, waitOn) idx, command = commandMgr.add_command(self, waitOn)
@ -290,8 +306,7 @@ class PlasmaResponderStateNode(PlasmaNodeBase, bpy.types.Node):
msg = msgNode.convert_message(exporter, so) msg = msgNode.convert_message(exporter, so)
idx, command = prepare_message(exporter, so, responder, commandMgr, waitOn, msg) idx, command = prepare_message(exporter, so, responder, commandMgr, waitOn, msg)
# If the callback message node is not properly set up for event callbacks, we don't want to if msgNode.has_callbacks:
if msgNode.has_callbacks and msgNode.find_output("msgs"):
childWaitOn = commandMgr.add_wait(idx) childWaitOn = commandMgr.add_wait(idx)
msgNode.convert_callback_message(exporter, so, msg, responder.key, childWaitOn) msgNode.convert_callback_message(exporter, so, msg, responder.key, childWaitOn)
else: else:

Loading…
Cancel
Save