import json import os # Bibliothèque d'images de fond CraftPix — RÉSERVÉE au rôle admin (voir # core/sprite_gate.py, routes/scenes/scene_object_add.py), même règle que # la bibliothèque de sprites animaux (screens/labels/animal_sprite_library.py) : # licence CraftPix, interdiction de rendre ces images utilisables par un # compte "user". Générée une fois par # scripts/generate_background_manifest.py depuis assets/background// # (pack source, non versionné) vers static/backgrounds// # .png, avec un manifest JSON portant les dimensions RÉELLES # (largeur/hauteur) de chaque image — utilisées comme taille par défaut de # l'objet de scène "fond" posé (voir screens/scenes/add_scene_object.py), # modifiable ensuite comme n'importe quel objet (panneau "Position & taille"). _MANIFEST_PATH = os.path.join( os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "static", "backgrounds", "manifest.json", ) def _load_manifest(): try: with open(_MANIFEST_PATH, encoding="utf-8") as f: return json.load(f) except FileNotFoundError: # Poste de dev sans les images de fond copiées (script pas encore # lancé), ou paquet exporté pour un jeu qui n'utilise aucun fond # CraftPix (voir publish/build_scorm_package.py, à étendre pour # copier sélectivement static/backgrounds/ le jour où un export # utilise ce widget) : aucun fond disponible, pas une erreur. return {} def _build_library(): manifest = _load_manifest() library = {} for pack_slug, pack in manifest.items(): pack_label = pack["label"] for image_name, dims in pack["images"].items(): slug = f"{pack_slug}-{image_name}" library[slug] = { "label": f"{pack_label} — {image_name.replace('_', ' ')}", "url": f"/static/backgrounds/{pack_slug}/{image_name}.png", "width": dims["width"], "height": dims["height"], "pack": pack_slug, "pack_label": pack_label, } return library BACKGROUND_LIBRARY = _build_library()