From dc1557e71d3dc087e8fd76f5d730a7b515d0699f Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 9 Sep 2025 03:03:22 -0400 Subject: [PATCH] Oops, forgot to add some files in the last push. Rest of the sound changes. --- src/pack_sound_system.py | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/pack_sound_system.py diff --git a/src/pack_sound_system.py b/src/pack_sound_system.py new file mode 100644 index 0000000..0df1ea3 --- /dev/null +++ b/src/pack_sound_system.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""Pack-specific sound system for Wicked Quest. + +Provides hierarchical sound loading that checks pack-specific sounds first, +then falls back to generic sounds, without modifying libstormgames. +""" + +import os +import pygame +from libstormgames.sound import Sound + + +class PackSoundSystem(dict): + """Sound system with hierarchical pack-specific loading.""" + + def __init__(self, originalSounds, soundDir="sounds/", levelPackName=None): + """Initialize pack-specific sound system. + + Args: + originalSounds (dict): Original sound dictionary from initialize_gui + soundDir (str): Base sound directory + levelPackName (str): Name of level pack for pack-specific sounds + """ + # Initialize dict with original sounds + super().__init__(originalSounds) + + self.soundDir = soundDir + self.levelPackName = levelPackName + + # Load pack-specific sounds if pack name provided + if levelPackName: + self._load_pack_sounds() + + def _load_pack_sounds(self): + """Load pack-specific sounds from sounds/[pack_name]/ directory.""" + packSoundDir = os.path.join(self.soundDir, self.levelPackName) + if not os.path.exists(packSoundDir): + return + + try: + for dirPath, _, fileNames in os.walk(packSoundDir): + relPath = os.path.relpath(dirPath, packSoundDir) + + for fileName in fileNames: + if fileName.lower().endswith(('.ogg', '.wav')): + fullPath = os.path.join(dirPath, fileName) + baseName = os.path.splitext(fileName)[0] + + # Create sound key same as base system + soundKey = baseName if relPath == '.' else os.path.join(relPath, baseName).replace('\\', '/') + # Add/override sound in the main dictionary + self[soundKey] = pygame.mixer.Sound(fullPath) + + except Exception as e: + print(f"Error loading pack sounds: {e}") +