Browse Source

Merge pull request #179 from Hoikas/sane_sound

Fix Sound Mod Issues.
pull/183/head
Adam Johnson 5 years ago committed by GitHub
parent
commit
e912e1e3ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      korman/operators/op_sound.py
  2. 2
      korman/properties/__init__.py
  3. 43
      korman/properties/modifiers/sound.py
  4. 13
      korman/ui/modifiers/sound.py

3
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):

2
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)

43
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"})
@ -154,6 +140,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 +170,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

13
korman/ui/modifiers/sound.py

@ -40,12 +40,15 @@ 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.prop_search(sound, "sound_data_proxy", bpy.data, "sounds", text="")
row = col.row(align=True)
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
@ -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")

Loading…
Cancel
Save