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>
49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
import json
|
|
from typing import Any
|
|
|
|
from ..labels.animal_sprite_library import ADMIN_SPRITE_LIBRARY
|
|
from ..labels.sprite_library import PUBLIC_SPRITE_LIBRARY
|
|
|
|
# Résolution RUNTIME (jeu jouable) : le catalogue COMPLET, quel que soit le
|
|
# rôle du créateur — voir le plan "Bibliothèque de sprites animaux
|
|
# CraftPix" (aucun filtrage par rôle au runtime, seulement à la galerie de
|
|
# l'éditeur/l'écriture, voir routes/screens/screen_edit.py et
|
|
# routes/elements/element_add.py).
|
|
_SPRITE_LIBRARY = {**PUBLIC_SPRITE_LIBRARY, **ADMIN_SPRITE_LIBRARY}
|
|
|
|
_DEFAULT_PERSONNAGE_DATA = {"source": "forge", "forge_character": "male-adventurer"}
|
|
|
|
|
|
def resolve_personnage_data(el: dict[str, Any]) -> dict[str, Any]:
|
|
"""Décode attributes._personnage_data (voir set_personnage_data.py) en
|
|
dict Python, jamais None — un attribut absent/corrompu retombe sur le
|
|
défaut posé à la création (default_style_for_widget.py)."""
|
|
raw = (el.get("attributes") or {}).get("_personnage_data")
|
|
if not raw:
|
|
return dict(_DEFAULT_PERSONNAGE_DATA)
|
|
try:
|
|
data = json.loads(raw)
|
|
except (TypeError, ValueError):
|
|
return dict(_DEFAULT_PERSONNAGE_DATA)
|
|
return data if isinstance(data, dict) else dict(_DEFAULT_PERSONNAGE_DATA)
|
|
|
|
|
|
def resolve_personnage_animations(el: dict[str, Any]) -> dict[str, list[str]]:
|
|
"""{nom_animation: [urls...]} pour cet élément personnage, quelle que
|
|
soit sa source — Forge (SPRITE_LIBRARY) ou sprites propres au créateur
|
|
(ses propres frames importées, voir personnage-panel.js)."""
|
|
data = resolve_personnage_data(el)
|
|
if data.get("source") == "custom":
|
|
return data.get("animations") or {}
|
|
character = _SPRITE_LIBRARY.get(data.get("forge_character") or "")
|
|
return character["animations"] if character else {}
|
|
|
|
|
|
def resolve_personnage_idle_frame(el: dict[str, Any]) -> str:
|
|
"""Première image de l'animation "idle" (ou, à défaut, de la première
|
|
animation disponible) — utilisée pour le rendu serveur ET l'aperçu
|
|
animé de l'éditeur, jamais vide tant qu'au moins une frame existe."""
|
|
animations = resolve_personnage_animations(el)
|
|
frames = animations.get("idle") or (next(iter(animations.values())) if animations else None)
|
|
return frames[0] if frames else ""
|