#!/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}")