Fix for dialog sound.

This commit is contained in:
Storm Dragon
2025-09-18 15:17:28 -04:00
parent 9996cdc08b
commit 7555429433

View File

@@ -265,7 +265,7 @@ def _play_dialog_sound(entry, dialog_config, sounds):
Args:
entry (dict): Dialog entry that may have a sound
dialog_config (dict): Dialog configuration that may have a default sound
sounds: Sound system for playing audio files
sounds: Sound system (either Sound class instance or dictionary of sounds)
"""
if not sounds:
return
@@ -285,20 +285,25 @@ def _play_dialog_sound(entry, dialog_config, sounds):
if sound_to_play:
try:
# Check if sound exists in the sound system
# Handle both Sound class instances and sound dictionaries
if hasattr(sounds, 'sounds') and sound_to_play in sounds.sounds:
# Sound class instance (like from libstormgames Sound class)
sound_obj = sounds.sounds[sound_to_play]
# Play the sound
channel = sound_obj.play()
# Wait for the sound to finish
sound_duration = sound_obj.get_length()
if sound_duration > 0:
pygame.time.wait(int(sound_duration * 1000)) # Convert to milliseconds
pygame.time.wait(int(sound_duration * 1000))
elif isinstance(sounds, dict) and sound_to_play in sounds:
# Dictionary of pygame sound objects (like from initialize_gui)
sound_obj = sounds[sound_to_play]
channel = sound_obj.play()
sound_duration = sound_obj.get_length()
if sound_duration > 0:
pygame.time.wait(int(sound_duration * 1000))
elif hasattr(sounds, 'play'):
# Try using a play method if available
sounds.play(sound_to_play)
# If we can't get duration, add a small delay
pygame.time.wait(500) # 0.5 second default delay
pygame.time.wait(500) # Default delay if can't get duration
except Exception:
# Sound missing or error - continue silently without crashing
pass