Work on fixing the path read for scores.
This commit is contained in:
		
							
								
								
									
										48
									
								
								menu.py
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								menu.py
									
									
									
									
									
								
							| @@ -22,7 +22,7 @@ from inspect import isfunction | ||||
| from .speech import messagebox, Speech | ||||
| from .sound import adjust_master_volume, adjust_bgm_volume, adjust_sfx_volume, play_bgm | ||||
| from .display import display_text | ||||
| from .services import PathService | ||||
| from .services import PathService, ConfigService | ||||
|  | ||||
| def game_menu(sounds, playCallback=None, *customOptions): | ||||
|     """Display and handle the main game menu with standard and custom options. | ||||
| @@ -314,8 +314,33 @@ def has_high_scores(): | ||||
|         bool: True if at least one high score exists, False otherwise | ||||
|     """ | ||||
|     try: | ||||
|         # Get PathService to access game name | ||||
|         pathService = PathService.get_instance() | ||||
|         gameName = pathService.gameName | ||||
|          | ||||
|         # Ensure path service is properly initialized | ||||
|         if not pathService.gamePath: | ||||
|             pathService.initialize(gameName) | ||||
|          | ||||
|         # Get the config file path | ||||
|         configPath = os.path.join(pathService.gamePath, "config.ini") | ||||
|          | ||||
|         # If config file doesn't exist, there are no scores | ||||
|         if not os.path.exists(configPath): | ||||
|             return False | ||||
|              | ||||
|         # Ensure config service is properly connected to path service | ||||
|         configService = ConfigService.get_instance() | ||||
|         configService.set_game_info(gameName, pathService) | ||||
|          | ||||
|         # Create scoreboard using the properly initialized services | ||||
|         from .scoreboard import Scoreboard | ||||
|         board = Scoreboard() | ||||
|         board = Scoreboard(0, configService) | ||||
|          | ||||
|         # Force a read of local config to ensure fresh data | ||||
|         configService.read_local_config() | ||||
|          | ||||
|         # Get high scores | ||||
|         scores = board.get_high_scores() | ||||
|          | ||||
|         # Check if any score is greater than zero | ||||
| @@ -327,7 +352,7 @@ def has_high_scores(): | ||||
| def high_scores(): | ||||
|     """Display high scores for the current game. | ||||
|      | ||||
|     Reads the high scores from Scoreboard and displays them in order. | ||||
|     Reads the high scores from Scoreboard class. | ||||
|     Shows the game name at the top followed by the available scores. | ||||
|     """ | ||||
|     try: | ||||
| @@ -335,9 +360,22 @@ def high_scores(): | ||||
|         pathService = PathService.get_instance() | ||||
|         gameName = pathService.gameName | ||||
|          | ||||
|         # Create Scoreboard instance and get high scores | ||||
|         # Ensure path service is properly initialized | ||||
|         if not pathService.gamePath: | ||||
|             pathService.initialize(gameName) | ||||
|          | ||||
|         # Ensure config service is properly connected to path service | ||||
|         configService = ConfigService.get_instance() | ||||
|         configService.set_game_info(gameName, pathService) | ||||
|          | ||||
|         # Create scoreboard using the properly initialized services | ||||
|         from .scoreboard import Scoreboard | ||||
|         board = Scoreboard() | ||||
|         board = Scoreboard(0, configService) | ||||
|          | ||||
|         # Force a read of local config to ensure fresh data | ||||
|         configService.read_local_config() | ||||
|          | ||||
|         # Get high scores | ||||
|         scores = board.get_high_scores() | ||||
|          | ||||
|         # Filter out scores with zero points | ||||
|   | ||||
		Reference in New Issue
	
	Block a user