Found some differences in how levels are called that required the levels directory be in both _internal and in source directory. This fix hopefully makes them work from a single location.
This commit is contained in:
1 parent
28856d2662
commit
4681dc5a2e
3 files changed
+21
-28
No files matched your search
+17
-24
@@ -7,6 +7,20 @@ from os.path import isdir, join
|
|||||||
from libstormgames import speak, instruction_menu
|
from libstormgames import speak, instruction_menu
|
||||||
|
|
||||||
|
|
||||||
|
def get_levels_base_path():
|
||||||
|
"""Get base path for levels directory, handling PyInstaller paths.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Base path where levels directory is located
|
||||||
|
"""
|
||||||
|
if hasattr(sys, "_MEIPASS"):
|
||||||
|
# Running as PyInstaller executable
|
||||||
|
return sys._MEIPASS
|
||||||
|
else:
|
||||||
|
# Running as script
|
||||||
|
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def get_available_games():
|
def get_available_games():
|
||||||
"""Get list of available game directories in levels folder.
|
"""Get list of available game directories in levels folder.
|
||||||
|
|
||||||
@@ -14,14 +28,7 @@ def get_available_games():
|
|||||||
list: List of game directory names
|
list: List of game directory names
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Handle PyInstaller path issues
|
base_path = get_levels_base_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__)))
|
|
||||||
|
|
||||||
levels_path = os.path.join(base_path, "levels")
|
levels_path = os.path.join(base_path, "levels")
|
||||||
return [d for d in os.listdir(levels_path) if isdir(join(levels_path, d)) and not d.endswith(".md")]
|
return [d for d in os.listdir(levels_path) if isdir(join(levels_path, d)) and not d.endswith(".md")]
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -85,14 +92,7 @@ def get_level_path(game_dir, level_num):
|
|||||||
if game_dir is None:
|
if game_dir is None:
|
||||||
raise ValueError("game_dir cannot be None")
|
raise ValueError("game_dir cannot be None")
|
||||||
|
|
||||||
# Handle PyInstaller path issues
|
base_path = get_levels_base_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__)))
|
|
||||||
|
|
||||||
level_path = os.path.join(base_path, "levels", game_dir, f"{level_num}.json")
|
level_path = os.path.join(base_path, "levels", game_dir, f"{level_num}.json")
|
||||||
return level_path
|
return level_path
|
||||||
|
|
||||||
@@ -109,12 +109,5 @@ def get_game_dir_path(game_dir):
|
|||||||
if game_dir is None:
|
if game_dir is None:
|
||||||
raise ValueError("game_dir cannot be None")
|
raise ValueError("game_dir cannot be None")
|
||||||
|
|
||||||
# Handle PyInstaller path issues - same logic as get_level_path
|
base_path = get_levels_base_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)
|
return os.path.join(base_path, "levels", game_dir)
|
||||||
@@ -4,7 +4,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import copy
|
import copy
|
||||||
from src.game_selection import get_level_path
|
from src.game_selection import get_level_path, get_levels_base_path
|
||||||
|
|
||||||
|
|
||||||
class SurvivalGenerator:
|
class SurvivalGenerator:
|
||||||
@@ -31,7 +31,7 @@ class SurvivalGenerator:
|
|||||||
def loadLevelData(self):
|
def loadLevelData(self):
|
||||||
"""Load all level JSON files from the game pack."""
|
"""Load all level JSON files from the game pack."""
|
||||||
levelFiles = []
|
levelFiles = []
|
||||||
packPath = os.path.join("levels", self.gamePack)
|
packPath = os.path.join(get_levels_base_path(), "levels", self.gamePack)
|
||||||
|
|
||||||
if not os.path.exists(packPath):
|
if not os.path.exists(packPath):
|
||||||
raise FileNotFoundError(f"Game pack '{self.gamePack}' not found")
|
raise FileNotFoundError(f"Game pack '{self.gamePack}' not found")
|
||||||
|
|||||||
+2
-2
@@ -669,9 +669,9 @@ class WickedQuest:
|
|||||||
# Game complete - use gameStartTime for total
|
# Game complete - use gameStartTime for total
|
||||||
totalTime = pygame.time.get_ticks() - self.gameStartTime
|
totalTime = pygame.time.get_ticks() - self.gameStartTime
|
||||||
if self.player.xPos >= self.currentLevel.rightBoundary:
|
if self.player.xPos >= self.currentLevel.rightBoundary:
|
||||||
# Check for end of game scene using relative path like other sounds
|
# Check for end of game scene using unified path resolution
|
||||||
for ext in ['.wav', '.ogg', '.mp3']:
|
for ext in ['.wav', '.ogg', '.mp3']:
|
||||||
endFile = os.path.join("levels", self.currentGame, f'end{ext}')
|
endFile = os.path.join(get_game_dir_path(self.currentGame), f'end{ext}')
|
||||||
if os.path.exists(endFile):
|
if os.path.exists(endFile):
|
||||||
self.get_sounds()['end_scene'] = pygame.mixer.Sound(endFile)
|
self.get_sounds()['end_scene'] = pygame.mixer.Sound(endFile)
|
||||||
cut_scene(self.get_sounds(), 'end_scene')
|
cut_scene(self.get_sounds(), 'end_scene')
|
||||||
|
|||||||
Reference in new issue
Block a user