From a875b7c6f7dccc6ee8173099d2eaa31a479bc672 Mon Sep 17 00:00:00 2001 From: apirrone Date: Sun, 6 Apr 2025 12:39:42 +0200 Subject: [PATCH] cleaning up --- mini_bdx_runtime/mini_bdx_runtime/sounds.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mini_bdx_runtime/mini_bdx_runtime/sounds.py b/mini_bdx_runtime/mini_bdx_runtime/sounds.py index d9fa4a5..6eae7ba 100644 --- a/mini_bdx_runtime/mini_bdx_runtime/sounds.py +++ b/mini_bdx_runtime/mini_bdx_runtime/sounds.py @@ -10,15 +10,18 @@ class Sounds: pygame.mixer.music.set_volume(volume) self.sounds = {} self.ok = True - - for file in os.listdir(sound_directory): - if file.endswith(".wav"): - sound_path = os.path.join(sound_directory, file) - try: - self.sounds[file] = pygame.mixer.Sound(sound_path) - print(f"Loaded: {file}") - except pygame.error as e: - print(f"Failed to load {file}: {e}") + try: + for file in os.listdir(sound_directory): + if file.endswith(".wav"): + sound_path = os.path.join(sound_directory, file) + try: + self.sounds[file] = pygame.mixer.Sound(sound_path) + print(f"Loaded: {file}") + except pygame.error as e: + print(f"Failed to load {file}: {e}") + except FileNotFoundError: + print(f"Directory {sound_directory} not found.") + self.ok = False if len(self.sounds) == 0: print("No sound files found in the directory.") self.ok = False