Some minor cleanup.

This commit is contained in:
Storm Dragon
2025-03-21 20:54:13 -04:00
parent cb69189c8e
commit 87d0764156
16 changed files with 193 additions and 193 deletions

View File

@@ -8,7 +8,7 @@ from libstormgames import speak
def get_available_games():
"""Get list of available game directories in levels folder.
Returns:
list: List of game directory names
"""
@@ -19,11 +19,11 @@ def get_available_games():
def selection_menu(sounds, *options):
"""Display level selection menu.
Args:
sounds (dict): Dictionary of loaded sound effects
*options: Variable number of menu options
Returns:
str: Selected option or None if cancelled
"""
@@ -31,53 +31,53 @@ def selection_menu(sounds, *options):
pygame.mixer.stop()
i = 0
j = -1
# Clear any pending events
pygame.event.clear()
speak("Select an adventure")
time.sleep(1.0)
while loop:
if i != j:
speak(options[i])
j = i
pygame.event.pump()
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return None
if event.key == pygame.K_DOWN and i < len(options) - 1:
i = i + 1
try:
sounds['menu-move'].play()
except:
pass
if event.key == pygame.K_UP and i > 0:
i = i - 1
try:
sounds['menu-move'].play()
except:
pass
if event.key == pygame.K_HOME and i != 0:
i = 0
try:
sounds['menu-move'].play()
except:
pass
if event.key == pygame.K_END and i != len(options) - 1:
i = len(options) - 1
try:
sounds['menu-move'].play()
except:
pass
if event.key == pygame.K_RETURN:
try:
sounds['menu-select'].play()
@@ -87,48 +87,48 @@ def selection_menu(sounds, *options):
return options[i]
elif event.type == pygame.QUIT:
return None
pygame.event.pump()
event = pygame.event.clear()
time.sleep(0.001)
def select_game(sounds):
"""Display game selection menu and return chosen game.
Args:
sounds (dict): Dictionary of loaded sound effects
Returns:
str: Selected game directory name or None if cancelled
"""
availableGames = get_available_games()
if not availableGames:
speak("No games found in levels directory!")
return None
# Convert directory names to display names (replace underscores with spaces)
menuOptions = [game.replace("_", " ") for game in availableGames]
choice = selection_menu(sounds, *menuOptions)
if choice is None:
return None
# Convert display name back to directory name if needed
gameDir = choice.replace(" ", "_")
if gameDir not in availableGames:
gameDir = choice # Use original if conversion doesn't match
return gameDir
def get_level_path(gameDir, levelNum):
"""Get full path to level JSON file.
Args:
gameDir (str): Game directory name
levelNum (int): Level number
Returns:
str: Full path to level JSON file
"""