From 915fc58e213b5e266ca212d260a15b4627e4920d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 24 Feb 2020 23:33:40 -0500 Subject: [PATCH 1/2] Fix #178. This adds a button for packaging/exporting sound files to either the zip or the game directory. --- korman/properties/__init__.py | 2 ++ korman/properties/modifiers/sound.py | 21 ++++++++++++++++++++- korman/ui/modifiers/sound.py | 9 ++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/korman/properties/__init__.py b/korman/properties/__init__.py index 741a519..fa3b5e4 100644 --- a/korman/properties/__init__.py +++ b/korman/properties/__init__.py @@ -21,6 +21,7 @@ from .prop_lamp import * from . import modifiers from .prop_object import * from .prop_scene import * +from .prop_sound import * from .prop_text import * from .prop_texture import * from .prop_world import * @@ -33,6 +34,7 @@ def register(): bpy.types.Object.plasma_net = bpy.props.PointerProperty(type=PlasmaNet) bpy.types.Object.plasma_object = bpy.props.PointerProperty(type=PlasmaObject) bpy.types.Scene.plasma_scene = bpy.props.PointerProperty(type=PlasmaScene) + bpy.types.Sound.plasma_sound = bpy.props.PointerProperty(type=PlasmaSound) bpy.types.Text.plasma_text = bpy.props.PointerProperty(type=PlasmaText) bpy.types.Texture.plasma_layer = bpy.props.PointerProperty(type=PlasmaLayer) bpy.types.World.plasma_age = bpy.props.PointerProperty(type=PlasmaAge) diff --git a/korman/properties/modifiers/sound.py b/korman/properties/modifiers/sound.py index ec4482b..bacfe5c 100644 --- a/korman/properties/modifiers/sound.py +++ b/korman/properties/modifiers/sound.py @@ -154,6 +154,24 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): fade_in = PointerProperty(type=PlasmaSfxFade, options=set()) fade_out = PointerProperty(type=PlasmaSfxFade, options=set()) + def _get_package_value(self): + if self.sound is not None: + self.package_value = self.sound.plasma_sound.package + return self.package_value + + def _set_package_value(self, value): + if self.sound is not None: + self.sound.plasma_sound.package = value + + # This is really a property of the sound itself, not of this particular emitter instance. + # However, to prevent weird UI inconsistencies where the button might be missing or change + # states when clearing the sound pointer, we'll cache the actual value here. + package = BoolProperty(name="Export", + description="Package this file in the age export", + get=_get_package_value, set=_set_package_value, + options=set()) + package_value = BoolProperty(options={"HIDDEN", "SKIP_SAVE"}) + @property def channel_override(self): if self.is_stereo and len(self.channel) == 1: @@ -166,7 +184,8 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): length = dataSize / header.avgBytesPerSec # HAX: Ensure that the sound file is copied to game, if applicable. - exporter.output.add_sfx(self._sound) + if self._sound.plasma_sound.package: + exporter.output.add_sfx(self._sound) # There is some bug in the MOUL code that causes a crash if this does not match the expected # result. There's no sense in debugging that though--the user should never specify diff --git a/korman/ui/modifiers/sound.py b/korman/ui/modifiers/sound.py index e51b383..af5020a 100644 --- a/korman/ui/modifiers/sound.py +++ b/korman/ui/modifiers/sound.py @@ -40,8 +40,11 @@ def soundemit(modifier, layout, context): except: pass else: + split = layout.split(percentage=0.75) + col = split.column() + # Sound datablock picker - row = layout.row(align=True) + row = col.row(align=True) row.prop_search(sound, "sound_data_proxy", bpy.data, "sounds", text="") open_op = row.operator("sound.plasma_open", icon="FILESEL", text="") open_op.data_path = repr(sound) @@ -55,6 +58,10 @@ def soundemit(modifier, layout, context): else: row.operator_menu_enum("sound.plasma_unpack", "method", icon="PACKAGE", text="") + col = split.column() + col.enabled = data is not None + col.prop(sound, "package", text="Export") + # If an invalid sound data block is spec'd, let them know about it. if data and not sound.is_valid: layout.label(text="Invalid sound specified", icon="ERROR") From 34a945e86c212b39a01ae423bd7965877d47738d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 24 Feb 2020 23:40:41 -0500 Subject: [PATCH 2/2] Remove sound datablock name proxy hack. The commentary about PointerProps and update callbacks appears to be incorrect. Maybe it was broken in a beta release of Blender 2.79? Works fine in Blender 2.79b. --- korman/operators/op_sound.py | 3 +-- korman/properties/modifiers/sound.py | 22 ++++------------------ korman/ui/modifiers/sound.py | 4 ++-- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/korman/operators/op_sound.py b/korman/operators/op_sound.py index c61981b..911a562 100644 --- a/korman/operators/op_sound.py +++ b/korman/operators/op_sound.py @@ -44,9 +44,8 @@ class PlasmaSoundOpenOperator(SoundOperator, bpy.types.Operator): sound = bpy.data.sounds.load(self.filepath) # Now do the stanky leg^H^H^H^H^H^H^H^H^H^H deed and put the sound on the mod - # NOTE: must use the name so that the mod can receive update callbacks dest = eval(self.data_path) - setattr(dest, self.sound_property, sound.name) + setattr(dest, self.sound_property, sound) return {"FINISHED"} def invoke(self, context, event): diff --git a/korman/properties/modifiers/sound.py b/korman/properties/modifiers/sound.py index bacfe5c..04c70e1 100644 --- a/korman/properties/modifiers/sound.py +++ b/korman/properties/modifiers/sound.py @@ -39,16 +39,8 @@ class PlasmaSfxFade(bpy.types.PropertyGroup): class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): - def _get_name_proxy(self): - if self.sound is not None: - return self.sound.name - return "" - - def _set_name_proxy(self, value): - self.sound = bpy.data.sounds.get(value, None) - - # This is the actual pointer update callback - if not self.sound: + def _update_sound(self, value): + if not value: self.name = "[Empty]" return @@ -73,14 +65,8 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): enabled = BoolProperty(name="Enabled", default=True, options=set()) sound = PointerProperty(name="Sound", description="Sound Datablock", - type=bpy.types.Sound) - - # This is needed because pointer properties do not seem to allow update CBs... Bug? - sound_data_proxy = StringProperty(name="Sound", - description="Name of sound datablock", - get=_get_name_proxy, - set=_set_name_proxy, - options=set()) + type=bpy.types.Sound, + update=_update_sound) is_stereo = BoolProperty(default=True, options={"HIDDEN"}) is_valid = BoolProperty(default=False, options={"HIDDEN"}) diff --git a/korman/ui/modifiers/sound.py b/korman/ui/modifiers/sound.py index af5020a..f80fae6 100644 --- a/korman/ui/modifiers/sound.py +++ b/korman/ui/modifiers/sound.py @@ -45,10 +45,10 @@ def soundemit(modifier, layout, context): # Sound datablock picker row = col.row(align=True) - row.prop_search(sound, "sound_data_proxy", bpy.data, "sounds", text="") + row.prop(sound, "sound", text="") open_op = row.operator("sound.plasma_open", icon="FILESEL", text="") open_op.data_path = repr(sound) - open_op.sound_property = "sound_data_proxy" + open_op.sound_property = "sound" # Pack/Unpack data = sound.sound