Browse Source

Adapt sound message node for random sound emitters.

When an emitter is a random sound emitter, then it is no longer possible
to address the individual sounds on that emitter. Instead, you can now
only stop or resume the randomization OR set the volume of the active
sound.
pull/251/head
Adam Johnson 4 years ago
parent
commit
1ccdd2e116
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 45
      korman/nodes/node_messages.py

45
korman/nodes/node_messages.py

@ -733,6 +733,7 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
subtype="PERCENTAGE")
def convert_callback_message(self, exporter, so, msg, target, wait):
assert not self.is_random_sound, "Callbacks are not available for random sounds"
cb = plEventCallbackMsg()
cb.addReceiver(target)
cb.event = kEnd
@ -747,6 +748,33 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
if not soundemit.enabled:
self.raise_error("'{}' is not a valid Sound Emitter".format(self.emitter_object.name))
if self.is_random_sound:
yield from self._convert_random_sound_msg(exporter, so)
else:
yield from self._convert_sound_emitter_msg(exporter, so)
def _convert_random_sound_msg(self, exporter, so):
# Yas, plAnimCmdMsg
msg = plAnimCmdMsg()
msg.addReceiver(exporter.mgr.find_key(plRandomSoundMod, bl=self.emitter_object))
if self.action == "kPlay":
msg.setCmd(plAnimCmdMsg.kContinue, True)
elif self.action == "kStop":
msg.setCmd(plAnimCmdMsg.kStop, True)
elif self.action == "kToggleState":
msg.setCmd(plAnimCmdMsg.kToggleState, True)
if self.volume != "CURRENT":
# No, you are not imagining things...
msg.setCmd(plAnimCmdMsg.kSetSpeed, True)
msg.speed = self.volume_pct / 100.0 if self.volume == "CUSTOM" else 0.0
yield msg
def _convert_sound_emitter_msg(self, exporter, so):
soundemit = self.emitter_object.plasma_modifiers.soundemit
# Always test the specified audible for validity
if self.sound_name and soundemit.sounds.get(self.sound_name, None) is None:
self.raise_error("Invalid Sound '{}' requested from Sound Emitter '{}'".format(self.sound_name, self.emitter_object.name))
@ -787,6 +815,11 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
def draw_buttons(self, context, layout):
layout.prop(self, "emitter_object")
# Random Sound emitters can only control the entire emitter object, not the
# individual sounds.
random = self.is_random_sound
if not random:
if self.emitter_object is not None:
soundemit = self.emitter_object.plasma_modifiers.soundemit
if soundemit.enabled:
@ -797,16 +830,28 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
layout.prop(self, "go_to")
if self.go_to == "TIME":
layout.prop(self, "time")
layout.prop(self, "action")
if self.volume == "CUSTOM":
layout.prop(self, "volume_pct")
if not random:
layout.prop(self, "looping")
layout.prop(self, "volume")
@property
def has_callbacks(self):
return not self.is_random_sound
@classmethod
def _idprop_mapping(cls):
return {"emitter_object": "object_name"}
@property
def is_random_sound(self):
if self.emitter_object is not None:
return self.emitter_object.plasma_modifiers.random_sound.enabled
return False
class PlasmaTimerCallbackMsgNode(PlasmaMessageWithCallbacksNode, bpy.types.Node):
bl_category = "MSG"

Loading…
Cancel
Save