Browse Source

More work on Responder callbacks...

pull/10/head
Adam Johnson 10 years ago
parent
commit
54e324e360
  1. 57
      korman/nodes/node_messages.py
  2. 10
      korman/nodes/node_responder.py

57
korman/nodes/node_messages.py

@ -27,12 +27,18 @@ class PlasmaMessageSocket(PlasmaMessageSocketBase, bpy.types.NodeSocket):
pass pass
class PlasmaMessageNode(PlasmaNodeBase): class PlasmaMessageNode(PlasmaNodeVariableInput):
@property @property
def has_callbacks(self): def has_callbacks(self):
"""This message has callbacks that can be waited on by a Responder""" """This message has callbacks that can be waited on by a Responder"""
return False return False
def init(self, context):
self.inputs.new("PlasmaMessageSocket", "Sender", "sender")
def update(self):
self.ensure_sockets("PlasmaMessageSocket", "Sender", "sender")
class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node): class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node):
bl_category = "MSG" bl_category = "MSG"
@ -103,8 +109,12 @@ class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node):
description="Frame number at which the loop ends", description="Frame number at which the loop ends",
min=0) min=0)
def init(self, context): event = EnumProperty(name="Callback",
self.inputs.new("PlasmaMessageSocket", "Sender", "sender") description="Event upon which to callback the Responder",
items=[("kEnd", "End", "When the action ends"),
("NONE", "(None)", "Don't notify the Responder at all"),
("kStop", "Stop", "When the action is stopped by a message")],
default="kEnd")
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
layout.prop(self, "anim_type") layout.prop(self, "anim_type")
@ -138,7 +148,16 @@ class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node):
layout.prop(self, "loop_begin") layout.prop(self, "loop_begin")
layout.prop(self, "loop_end") layout.prop(self, "loop_end")
def convert_message(self, exporter, tree, so, respKey, wait): layout.prop(self, "event")
def convert_callback_message(self, exporter, tree, so, msg, target, wait):
cb = plEventCallbackMsg()
cb.addReceiver(target)
cb.event = globals()[self.event]
cb.user = wait
msg.addCallback(cb)
def convert_message(self, exporter, tree, so):
msg = plAnimCmdMsg() msg = plAnimCmdMsg()
# We're either sending this off to an AGMasterMod or a LayerAnim # We're either sending this off to an AGMasterMod or a LayerAnim
@ -188,6 +207,10 @@ class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node):
# Whew, this was crazy # Whew, this was crazy
return msg return msg
@property
def has_callbacks(self):
return self.event != "NONE"
class PlasmaOneShotMsgNode(PlasmaMessageNode, bpy.types.Node): class PlasmaOneShotMsgNode(PlasmaMessageNode, bpy.types.Node):
bl_category = "MSG" bl_category = "MSG"
@ -206,6 +229,8 @@ class PlasmaOneShotMsgNode(PlasmaMessageNode, bpy.types.Node):
animation = StringProperty(name="Animation", animation = StringProperty(name="Animation",
description="Name of the animation the avatar should execute") description="Name of the animation the avatar should execute")
marker = StringProperty(name="Marker",
description="Name of the marker specifying when to notify the Responder")
drivable = BoolProperty(name="Drivable", drivable = BoolProperty(name="Drivable",
description="Player retains control of the avatar during the OneShot", description="Player retains control of the avatar during the OneShot",
default=False) default=False)
@ -213,19 +238,17 @@ class PlasmaOneShotMsgNode(PlasmaMessageNode, bpy.types.Node):
description="Player can reverse the OneShot", description="Player can reverse the OneShot",
default=False) default=False)
def init(self, context): def convert_callback_message(self, exporter, tree, so, msg, target, wait):
self.inputs.new("PlasmaOneShotMsgSocket", "Sender", "sender") msg.addCallback(self.marker, target, wait)
def convert_message(self, exporter, tree, so, respKey, wait): def convert_message(self, exporter, tree, so):
msg = plOneShotMsg() msg = plOneShotMsg()
msg.addReceiver(self.get_key(exporter, tree, so)) msg.addReceiver(self.get_key(exporter, tree, so))
cb = self.find_input_socket("sender")
if cb.marker:
msg.addCallback(cb.marker, respKey, wait)
return msg return msg
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
layout.prop(self, "animation", text="Anim") layout.prop(self, "animation", text="Anim")
layout.prop(self, "marker")
row = layout.row() row = layout.row()
row.prop(self, "drivable") row.prop(self, "drivable")
row.prop(self, "reversable") row.prop(self, "reversable")
@ -254,19 +277,15 @@ class PlasmaOneShotMsgNode(PlasmaMessageNode, bpy.types.Node):
@property @property
def has_callbacks(self): def has_callbacks(self):
cb = self.find_input_socket("sender") return bool(self.marker)
return bool(cb.marker)
class PlasmaOneShotMsgSocket(PlasmaMessageSocketBase, bpy.types.NodeSocket): class PlasmaOneShotCallbackSocket(PlasmaMessageSocketBase, bpy.types.NodeSocket):
marker = StringProperty(name="Marker", marker = StringProperty(name="Marker",
description="Name of the marker specifying the time to send a callback message") description="Marker specifying the time at which to send a callback to this Responder")
def draw(self, context, layout, node, text): def draw(self, context, layout, node, text):
if self.is_linked: layout.prop(self, "marker")
layout.prop(self, "marker")
else:
layout.label(text)
class PlasmaFootstepSoundMsgNode(PlasmaMessageNode, bpy.types.Node): class PlasmaFootstepSoundMsgNode(PlasmaMessageNode, bpy.types.Node):
@ -285,7 +304,7 @@ class PlasmaFootstepSoundMsgNode(PlasmaMessageNode, bpy.types.Node):
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
layout.prop(self, "surface") layout.prop(self, "surface")
def convert_message(self, exporter, tree, so, respKey, wait): def convert_message(self, exporter, tree, so):
msg = plArmatureEffectStateMsg() msg = plArmatureEffectStateMsg()
msg.surface = footstep_surface_ids[self.surface] msg.surface = footstep_surface_ids[self.surface]
return msg return msg

10
korman/nodes/node_responder.py

@ -180,18 +180,18 @@ class PlasmaResponderCommandNode(PlasmaNodeBase, bpy.types.Node):
if msgNode is not None: if msgNode is not None:
idx, command = commandMgr.add_command(self, waitOn) idx, command = commandMgr.add_command(self, waitOn)
# Finally, convert our message...
msg = msgNode.convert_message(exporter, tree, so)
self._finalize_message(exporter, responder, msg)
# If we have child commands, we need to make sure that we support chaining this message as a callback # If we have child commands, we need to make sure that we support chaining this message as a callback
# If not, we'll export our children and tell them to not actually wait on us. # If not, we'll export our children and tell them to not actually wait on us.
haveChildren = self.find_output("trigger", "PlasmaResponderCommandNode") is not None haveChildren = self.find_output("trigger", "PlasmaResponderCommandNode") is not None
if haveChildren and msgNode.has_callbacks: if haveChildren and msgNode.has_callbacks:
childWaitOn = commandMgr.add_wait(idx) childWaitOn = commandMgr.add_wait(idx)
msgNode.convert_callback_message(exporter, tree, so, msg, responder.key, childWaitOn)
else: else:
childWaitOn = -1 childWaitOn = -1
# Finally, convert our message...
msg = msgNode.convert_message(exporter, tree, so, responder.key, childWaitOn)
self._finalize_message(exporter, responder, msg)
command.msg = msg command.msg = msg
else: else:
childWaitOn = -1 childWaitOn = -1

Loading…
Cancel
Save