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. 41
      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) 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 # 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) dest = eval(self.data_path)
setattr(dest, self.sound_property, sound.name) setattr(dest, self.sound_property, sound)
return {"FINISHED"} return {"FINISHED"}
def invoke(self, context, event): def invoke(self, context, event):

2
korman/properties/__init__.py

@ -21,6 +21,7 @@ from .prop_lamp import *
from . import modifiers from . import modifiers
from .prop_object import * from .prop_object import *
from .prop_scene import * from .prop_scene import *
from .prop_sound import *
from .prop_text import * from .prop_text import *
from .prop_texture import * from .prop_texture import *
from .prop_world 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_net = bpy.props.PointerProperty(type=PlasmaNet)
bpy.types.Object.plasma_object = bpy.props.PointerProperty(type=PlasmaObject) bpy.types.Object.plasma_object = bpy.props.PointerProperty(type=PlasmaObject)
bpy.types.Scene.plasma_scene = bpy.props.PointerProperty(type=PlasmaScene) 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.Text.plasma_text = bpy.props.PointerProperty(type=PlasmaText)
bpy.types.Texture.plasma_layer = bpy.props.PointerProperty(type=PlasmaLayer) bpy.types.Texture.plasma_layer = bpy.props.PointerProperty(type=PlasmaLayer)
bpy.types.World.plasma_age = bpy.props.PointerProperty(type=PlasmaAge) bpy.types.World.plasma_age = bpy.props.PointerProperty(type=PlasmaAge)

41
korman/properties/modifiers/sound.py

@ -39,16 +39,8 @@ class PlasmaSfxFade(bpy.types.PropertyGroup):
class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup):
def _get_name_proxy(self): def _update_sound(self, value):
if self.sound is not None: if not value:
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:
self.name = "[Empty]" self.name = "[Empty]"
return return
@ -73,14 +65,8 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup):
enabled = BoolProperty(name="Enabled", default=True, options=set()) enabled = BoolProperty(name="Enabled", default=True, options=set())
sound = PointerProperty(name="Sound", sound = PointerProperty(name="Sound",
description="Sound Datablock", description="Sound Datablock",
type=bpy.types.Sound) type=bpy.types.Sound,
update=_update_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())
is_stereo = BoolProperty(default=True, options={"HIDDEN"}) is_stereo = BoolProperty(default=True, options={"HIDDEN"})
is_valid = BoolProperty(default=False, 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_in = PointerProperty(type=PlasmaSfxFade, options=set())
fade_out = 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 @property
def channel_override(self): def channel_override(self):
if self.is_stereo and len(self.channel) == 1: if self.is_stereo and len(self.channel) == 1:
@ -166,6 +170,7 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup):
length = dataSize / header.avgBytesPerSec length = dataSize / header.avgBytesPerSec
# HAX: Ensure that the sound file is copied to game, if applicable. # HAX: Ensure that the sound file is copied to game, if applicable.
if self._sound.plasma_sound.package:
exporter.output.add_sfx(self._sound) 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 # There is some bug in the MOUL code that causes a crash if this does not match the expected

13
korman/ui/modifiers/sound.py

@ -40,12 +40,15 @@ def soundemit(modifier, layout, context):
except: except:
pass pass
else: else:
split = layout.split(percentage=0.75)
col = split.column()
# Sound datablock picker # Sound datablock picker
row = layout.row(align=True) 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 = row.operator("sound.plasma_open", icon="FILESEL", text="")
open_op.data_path = repr(sound) open_op.data_path = repr(sound)
open_op.sound_property = "sound_data_proxy" open_op.sound_property = "sound"
# Pack/Unpack # Pack/Unpack
data = sound.sound data = sound.sound
@ -55,6 +58,10 @@ def soundemit(modifier, layout, context):
else: else:
row.operator_menu_enum("sound.plasma_unpack", "method", icon="PACKAGE", text="") 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 an invalid sound data block is spec'd, let them know about it.
if data and not sound.is_valid: if data and not sound.is_valid:
layout.label(text="Invalid sound specified", icon="ERROR") layout.label(text="Invalid sound specified", icon="ERROR")

Loading…
Cancel
Save