From ffa0aa3303b4b32acfb8227d567cbc9088e82942 Mon Sep 17 00:00:00 2001 From: skymike03 Date: Thu, 7 Aug 2025 23:21:33 +0200 Subject: [PATCH] test correction bug controles --- .gitignore | 3 +- ports/RGSX/__main__.py | 58 ++++++++++++++++++++++++++++------- ports/RGSX/controls.py | 17 +++++++++- ports/RGSX/controls_mapper.py | 32 +++++++++---------- 4 files changed, 81 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 44fdbcc..3d73f5a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ ports/gamelist.xml *.log *.rar *.zip -.vscode/ \ No newline at end of file +.vscode/ +ports/RGSX.bat \ No newline at end of file diff --git a/ports/RGSX/__main__.py b/ports/RGSX/__main__.py index d9e3c9f..8472fc5 100644 --- a/ports/RGSX/__main__.py +++ b/ports/RGSX/__main__.py @@ -18,8 +18,8 @@ from display import ( ) from language import handle_language_menu_events, _ from network import test_internet, download_rom, is_1fichier_url, download_from_1fichier, check_for_updates -from controls import handle_controls, validate_menu_state, process_key_repeats -from controls_mapper import load_controls_config, map_controls, draw_controls_mapping, ACTIONS +from controls import handle_controls, validate_menu_state, process_key_repeats, get_emergency_controls +from controls_mapper import load_controls_config, save_controls_config, map_controls, draw_controls_mapping, ACTIONS from utils import ( detect_non_pc, load_sources, check_extension_before_download, extract_zip_data, play_random_music, load_accessibility_settings, load_music_config @@ -125,17 +125,48 @@ logger.debug(f"Historique de téléchargement : {len(config.history)} entrées") # Vérification et chargement de la configuration des contrôles config.controls_config = load_controls_config() -# Vérifier si la configuration est vide (pas de fichier ou importation échouée) -if not config.controls_config: - # Si pas de configuration, on commence par les configurer - config.menu_state = "controls_mapping" - config.needs_redraw = True # Forcer le redraw immédiatement - logger.info("Aucune configuration de contrôles disponible, configuration manuelle nécessaire") - logger.debug("Menu initial: mappage des contrôles") +# S'assurer que config.controls_config n'est jamais None +if config.controls_config is None: + config.controls_config = {} + logger.debug("Initialisation de config.controls_config avec un dictionnaire vide") + +# Vérifier si la configuration contient au minimum les contrôles essentiels +essential_controls = ["confirm", "cancel", "up", "down", "left", "right"] +has_essential_controls = all( + config.controls_config and + action in config.controls_config and + config.controls_config[action].get("type") is not None + for action in essential_controls +) + +if not config.controls_config or not has_essential_controls: + # Correction : vérifier si config.controls_config n'est pas None avant d'appeler .keys() + controls_present = list(config.controls_config.keys()) if config.controls_config else [] + logger.warning(f"Configuration des contrôles incomplète ou absente. Contrôles présents: {controls_present}") + + # Essayer d'importer depuis EmulationStation + try: + from es_input_parser import parse_es_input_config + es_config = parse_es_input_config() + if es_config and all(action in es_config for action in essential_controls): + logger.info("Configuration importée depuis EmulationStation avec succès") + config.controls_config = es_config + save_controls_config(es_config) + config.menu_state = "loading" + else: + logger.warning("Import EmulationStation échoué ou incomplet, configuration manuelle nécessaire") + # Ajouter une configuration minimale de secours pour pouvoir naviguer + config.controls_config = get_emergency_controls() + config.menu_state = "controls_mapping" + config.needs_redraw = True + except Exception as e: + logger.error(f"Erreur lors de l'import EmulationStation: {e}") + config.controls_config = get_emergency_controls() + config.menu_state = "controls_mapping" + config.needs_redraw = True else: - # Sinon, chargement normal config.menu_state = "loading" - logger.debug("Menu chargement normal") + logger.debug("Configuration des contrôles valide, chargement normal") # Initialisation du gamepad joystick = None @@ -629,6 +660,11 @@ async def main(): logger.debug("Fichier controls.json existe déjà, passage direct à l'état loading") config.needs_redraw = True else: + # Initialiser config.controls_config avec un dictionnaire vide s'il est None + if config.controls_config is None: + config.controls_config = {} + logger.debug("Initialisation de config.controls_config avec un dictionnaire vide") + # Forcer l'affichage de l'interface de mappage des contrôles action = ACTIONS[0] draw_controls_mapping(screen, action, None, True, 0.0) diff --git a/ports/RGSX/controls.py b/ports/RGSX/controls.py index 9acb898..2340e10 100644 --- a/ports/RGSX/controls.py +++ b/ports/RGSX/controls.py @@ -1139,4 +1139,19 @@ def process_key_repeats(sources, joystick, screen): state["last_repeat_time"] = current_time # Forcer le redessinage - config.needs_redraw = True \ No newline at end of file + config.needs_redraw = True + +def get_emergency_controls(): + """Retourne une configuration de contrôles de secours pour permettre la navigation de base.""" + return { + "confirm": {"type": "key", "key": pygame.K_RETURN}, + "cancel": {"type": "key", "key": pygame.K_ESCAPE}, + "up": {"type": "key", "key": pygame.K_UP}, + "down": {"type": "key", "key": pygame.K_DOWN}, + "left": {"type": "key", "key": pygame.K_LEFT}, + "right": {"type": "key", "key": pygame.K_RIGHT}, + "start": {"type": "key", "key": pygame.K_p}, + # Ajouter aussi les contrôles manette de base si disponible + "confirm_joy": {"type": "button", "button": 0}, # A/Croix + "cancel_joy": {"type": "button", "button": 1}, # B/Rond + } \ No newline at end of file diff --git a/ports/RGSX/controls_mapper.py b/ports/RGSX/controls_mapper.py index 03aa503..a88537c 100644 --- a/ports/RGSX/controls_mapper.py +++ b/ports/RGSX/controls_mapper.py @@ -277,24 +277,22 @@ def load_controls_config(): try: if os.path.exists(CONTROLS_CONFIG_PATH): with open(CONTROLS_CONFIG_PATH, "r") as f: - config = json.load(f) - logger.debug(f"Configuration des contrôles chargée : {config}") - return config + config_data = json.load(f) + logger.debug(f"Configuration des contrôles chargée : {config_data}") + + # Vérifier que la configuration contient les éléments essentiels + essential_controls = ["confirm", "cancel", "up", "down", "left", "right"] + if all(action in config_data for action in essential_controls): + return config_data + else: + logger.warning("Configuration incomplète trouvée dans controls.json") + return {} # Retourner un dictionnaire vide au lieu de None else: - logger.debug("Aucun fichier controls.json trouvé, tentative d'importation depuis EmulationStation") - # Essayer d'importer depuis EmulationStation - from es_input_parser import parse_es_input_config - es_config = parse_es_input_config() - if es_config: - logger.info("Configuration importée depuis EmulationStation") - save_controls_config(es_config) - return es_config - else: - logger.debug("Importation depuis EmulationStation échouée, configuration par défaut") - return {} + logger.debug("Aucun fichier controls.json trouvé") + return {} # Retourner un dictionnaire vide au lieu de None except Exception as e: logger.error(f"Erreur lors du chargement de controls.json : {e}") - return {} + return {} # Retourner un dictionnaire vide au lieu de None def save_controls_config(controls_config): """Enregistre la configuration des contrôles dans controls.json""" @@ -302,9 +300,11 @@ def save_controls_config(controls_config): os.makedirs(os.path.dirname(CONTROLS_CONFIG_PATH), exist_ok=True) with open(CONTROLS_CONFIG_PATH, "w") as f: json.dump(controls_config, f, indent=4) - logger.debug(f"Configuration des contrôles enregistrée : {controls_config}") + logger.info(f"Configuration des contrôles enregistrée avec {len(controls_config)} actions") + logger.debug(f"Contrôles sauvegardés : {list(controls_config.keys())}") except Exception as e: logger.error(f"Erreur lors de l'enregistrement de controls.json : {e}") + raise def get_readable_input_name(event): """Retourne un nom lisible pour une entrée (touche, bouton, axe, hat, ou souris)"""