Sound file error hopefully fixed for pyinstaller.

This commit is contained in:
Storm Dragon
2025-09-13 01:33:16 -04:00
parent 82f1128087
commit 8218d28701
3 changed files with 26 additions and 3 deletions

View File

@@ -95,3 +95,26 @@ def get_level_path(game_dir, level_num):
level_path = os.path.join(base_path, "levels", game_dir, f"{level_num}.json")
return level_path
def get_game_dir_path(game_dir):
"""Get full path to game directory for end.ogg and other game files.
Args:
game_dir (str): Game directory name
Returns:
str: Full path to game directory
"""
if game_dir is None:
raise ValueError("game_dir cannot be None")
# Handle PyInstaller path issues - same logic as get_level_path
if hasattr(sys, "_MEIPASS"):
# Running as PyInstaller executable
base_path = sys._MEIPASS
else:
# Running as script
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, "levels", game_dir)

View File

@@ -9,7 +9,7 @@ from src.pack_sound_system import PackSoundSystem
from src.level import Level
from src.object import Object
from src.player import Player
from src.game_selection import select_game, get_level_path
from src.game_selection import select_game, get_level_path, get_game_dir_path
from src.save_manager import SaveManager
from src.survival_generator import SurvivalGenerator
@@ -446,7 +446,7 @@ class WickedQuest:
totalTime = pygame.time.get_ticks() - self.gameStartTime
if self.player.xPos >= self.currentLevel.rightBoundary:
# Check for end of game scene
gamePath = os.path.dirname(get_level_path(self.currentGame, 1))
gamePath = get_game_dir_path(self.currentGame)
for ext in ['.wav', '.ogg', '.mp3']:
endFile = os.path.join(gamePath, f'end{ext}')
if os.path.exists(endFile):