from .constants import QUEST_STATUS_CHOICES, QUEST_SPEAKER_CHOICES _MAX_LINES_PER_COLUMN = 200 def sanitize_quest_dialogues(raw_dialogues): """Une réplique = {speaker: 'joueur'|'pnj', text: '...'} — une colonne par statut de quête (voir QUEST_STATUS_CHOICES), la même forme que resolve_collision_rules.sanitize_collision_rules : rejette tout élément invalide plutôt que de lever, ne garde jamais un texte vide.""" result = {status: [] for status in QUEST_STATUS_CHOICES} if not isinstance(raw_dialogues, dict): return result for status in QUEST_STATUS_CHOICES: raw_lines = raw_dialogues.get(status) if not isinstance(raw_lines, list): continue cleaned = [] for raw_line in raw_lines[:_MAX_LINES_PER_COLUMN]: if not isinstance(raw_line, dict): continue speaker = raw_line.get("speaker") text = raw_line.get("text") if speaker not in QUEST_SPEAKER_CHOICES: continue if not isinstance(text, str) or not text.strip(): continue cleaned.append({"speaker": speaker, "text": text.strip()}) result[status] = cleaned return result