Config strictement stricte partout (ruff, mypy --strict, bandit, vulture, import-linter, eslint, stylelint), aucune regle desactivee "pour ne pas casser le build" - l'existant a ete corrige pour la satisfaire plutot que l'inverse. Hooks pre-commit locaux (language: system) bloquants. - Typage mypy --strict propage a tout le moteur (db, screens, auth, core, ai, routes, puis publish/scripts/tests/app.py/build_css.py). - Securite : fuite de handle fichier Windows corrigee dans l'export SCORM (routes/publish/export_scorm.py), CSRF/RNG non-crypto/xAPI documentes (# nosec, # NOSONAR justifies), nouveau db.json_for_script() (echappe "</script>" dans le JSON embarque en <script>, 25 sites). - Architecture : imports circulaires/F811 nettoyes, contrats import-linter respectes, code mort retire (vulture). - Accessibilite : 69 champs de formulaire sans label correctement associe corriges (for/id ou aria-label) sur 11 templates. - ESLint/Stylelint : lot mecanique JS/CSS, regles ajustees puis appliquees (aucune desactivee sans verification individuelle). - Tests : isolation du compte admin partage (nettoyage ponctuel + fixture de teardown automatique en filet de securite), suite complete verte (591 tests Python, 241 tests JS). - SonarQube Community Build self-heberge (Docker + PostgreSQL) : rapport complet analyse point par point, faux positifs documentes. - .gitattributes ajoute (LF force) : core.autocrlf=true sur cette machine faisait echouer ESLint (linebreak-style) via un bug connu de git (checkout "en place" qui ignore l'eol force sur un fichier deja present sur disque - contourne en supprimant puis recreant chaque fichier suivi). djLint (H021, styles inline) volontairement saute pour ce commit - backlog assume, deja documente, traite dans un lot separe. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
import json
|
|
from typing import Any
|
|
|
|
# Widget d'interface "💬 Boîte de dialogue" (voir "🖥️ Interface",
|
|
# templates/scene_edit.html, screens/scenes/add_scene_object.py kind=
|
|
# "dialogue_box") : affiche AUTOMATIQUEMENT, en jeu, la réplique en cours
|
|
# d'un dialogue déclenché par une règle de collision "dialogue" (voir
|
|
# static/js/play/dialogue-box-controller.js) — header (nom du
|
|
# personnage qui parle), corps (texte), pied (bouton "Suivant"),
|
|
# entièrement stylisable par l'auteur.
|
|
DEFAULT_DIALOGUE_BOX_STYLE: dict[str, Any] = {
|
|
"font_family": "inherit",
|
|
"font_size": 14,
|
|
"font_weight": "normal",
|
|
"text_color": "#ffffff",
|
|
"header_bg": "#2f6fed",
|
|
"body_bg": "#1a1d24",
|
|
"footer_bg": "#11141b",
|
|
}
|
|
|
|
FONT_WEIGHT_CHOICES = ["normal", "bold"]
|
|
|
|
|
|
def sanitize_dialogue_box_style(raw_style: Any) -> dict[str, Any]:
|
|
style = dict(DEFAULT_DIALOGUE_BOX_STYLE)
|
|
if not isinstance(raw_style, dict):
|
|
return style
|
|
if isinstance(raw_style.get("font_family"), str) and raw_style["font_family"].strip():
|
|
style["font_family"] = raw_style["font_family"].strip()[:60]
|
|
raw_font_size = raw_style.get("font_size")
|
|
try:
|
|
if raw_font_size is None:
|
|
raise ValueError
|
|
style["font_size"] = max(8, min(48, int(raw_font_size)))
|
|
except (TypeError, ValueError):
|
|
pass
|
|
if raw_style.get("font_weight") in FONT_WEIGHT_CHOICES:
|
|
style["font_weight"] = raw_style["font_weight"]
|
|
for key in ("text_color", "header_bg", "body_bg", "footer_bg"):
|
|
value = raw_style.get(key)
|
|
if isinstance(value, str) and value.strip():
|
|
style[key] = value.strip()[:20]
|
|
return style
|
|
|
|
|
|
def resolve_dialogue_box_style(obj: dict[str, Any]) -> dict[str, Any]:
|
|
raw = (obj.get("attributes") or {}).get("_dialogue_box_style")
|
|
if not raw:
|
|
return dict(DEFAULT_DIALOGUE_BOX_STYLE)
|
|
try:
|
|
parsed = json.loads(raw)
|
|
except (TypeError, ValueError):
|
|
return dict(DEFAULT_DIALOGUE_BOX_STYLE)
|
|
return sanitize_dialogue_box_style(parsed)
|