test correction bug controles
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,4 +9,5 @@ ports/gamelist.xml
|
|||||||
*.log
|
*.log
|
||||||
*.rar
|
*.rar
|
||||||
*.zip
|
*.zip
|
||||||
.vscode/
|
.vscode/
|
||||||
|
ports/RGSX.bat
|
||||||
@@ -18,8 +18,8 @@ from display import (
|
|||||||
)
|
)
|
||||||
from language import handle_language_menu_events, _
|
from language import handle_language_menu_events, _
|
||||||
from network import test_internet, download_rom, is_1fichier_url, download_from_1fichier, check_for_updates
|
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 import handle_controls, validate_menu_state, process_key_repeats, get_emergency_controls
|
||||||
from controls_mapper import load_controls_config, map_controls, draw_controls_mapping, ACTIONS
|
from controls_mapper import load_controls_config, save_controls_config, map_controls, draw_controls_mapping, ACTIONS
|
||||||
from utils import (
|
from utils import (
|
||||||
detect_non_pc, load_sources, check_extension_before_download, extract_zip_data,
|
detect_non_pc, load_sources, check_extension_before_download, extract_zip_data,
|
||||||
play_random_music, load_accessibility_settings, load_music_config
|
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
|
# Vérification et chargement de la configuration des contrôles
|
||||||
config.controls_config = load_controls_config()
|
config.controls_config = load_controls_config()
|
||||||
|
|
||||||
# Vérifier si la configuration est vide (pas de fichier ou importation échouée)
|
# S'assurer que config.controls_config n'est jamais None
|
||||||
if not config.controls_config:
|
if config.controls_config is None:
|
||||||
# Si pas de configuration, on commence par les configurer
|
config.controls_config = {}
|
||||||
config.menu_state = "controls_mapping"
|
logger.debug("Initialisation de config.controls_config avec un dictionnaire vide")
|
||||||
config.needs_redraw = True # Forcer le redraw immédiatement
|
|
||||||
logger.info("Aucune configuration de contrôles disponible, configuration manuelle nécessaire")
|
# Vérifier si la configuration contient au minimum les contrôles essentiels
|
||||||
logger.debug("Menu initial: mappage des contrôles")
|
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:
|
else:
|
||||||
# Sinon, chargement normal
|
|
||||||
config.menu_state = "loading"
|
config.menu_state = "loading"
|
||||||
logger.debug("Menu chargement normal")
|
logger.debug("Configuration des contrôles valide, chargement normal")
|
||||||
|
|
||||||
# Initialisation du gamepad
|
# Initialisation du gamepad
|
||||||
joystick = None
|
joystick = None
|
||||||
@@ -629,6 +660,11 @@ async def main():
|
|||||||
logger.debug("Fichier controls.json existe déjà, passage direct à l'état loading")
|
logger.debug("Fichier controls.json existe déjà, passage direct à l'état loading")
|
||||||
config.needs_redraw = True
|
config.needs_redraw = True
|
||||||
else:
|
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
|
# Forcer l'affichage de l'interface de mappage des contrôles
|
||||||
action = ACTIONS[0]
|
action = ACTIONS[0]
|
||||||
draw_controls_mapping(screen, action, None, True, 0.0)
|
draw_controls_mapping(screen, action, None, True, 0.0)
|
||||||
|
|||||||
@@ -1139,4 +1139,19 @@ def process_key_repeats(sources, joystick, screen):
|
|||||||
state["last_repeat_time"] = current_time
|
state["last_repeat_time"] = current_time
|
||||||
|
|
||||||
# Forcer le redessinage
|
# Forcer le redessinage
|
||||||
config.needs_redraw = True
|
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
|
||||||
|
}
|
||||||
@@ -277,24 +277,22 @@ def load_controls_config():
|
|||||||
try:
|
try:
|
||||||
if os.path.exists(CONTROLS_CONFIG_PATH):
|
if os.path.exists(CONTROLS_CONFIG_PATH):
|
||||||
with open(CONTROLS_CONFIG_PATH, "r") as f:
|
with open(CONTROLS_CONFIG_PATH, "r") as f:
|
||||||
config = json.load(f)
|
config_data = json.load(f)
|
||||||
logger.debug(f"Configuration des contrôles chargée : {config}")
|
logger.debug(f"Configuration des contrôles chargée : {config_data}")
|
||||||
return config
|
|
||||||
|
# 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:
|
else:
|
||||||
logger.debug("Aucun fichier controls.json trouvé, tentative d'importation depuis EmulationStation")
|
logger.debug("Aucun fichier controls.json trouvé")
|
||||||
# Essayer d'importer depuis EmulationStation
|
return {} # Retourner un dictionnaire vide au lieu de None
|
||||||
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 {}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Erreur lors du chargement de controls.json : {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):
|
def save_controls_config(controls_config):
|
||||||
"""Enregistre la configuration des contrôles dans controls.json"""
|
"""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)
|
os.makedirs(os.path.dirname(CONTROLS_CONFIG_PATH), exist_ok=True)
|
||||||
with open(CONTROLS_CONFIG_PATH, "w") as f:
|
with open(CONTROLS_CONFIG_PATH, "w") as f:
|
||||||
json.dump(controls_config, f, indent=4)
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Erreur lors de l'enregistrement de controls.json : {e}")
|
logger.error(f"Erreur lors de l'enregistrement de controls.json : {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
def get_readable_input_name(event):
|
def get_readable_input_name(event):
|
||||||
"""Retourne un nom lisible pour une entrée (touche, bouton, axe, hat, ou souris)"""
|
"""Retourne un nom lisible pour une entrée (touche, bouton, axe, hat, ou souris)"""
|
||||||
|
|||||||
Reference in New Issue
Block a user