Bibliothèque de sprites animaux CraftPix (2/3) : export .zip sélectif
Corrige aussi un import cassé du commit précédent : screens/__init__.py importe déjà screens.rendering.list_used_forge_characters (nécessaire à screens.ADMIN_ONLY_CHARACTER_SLUGS/la galerie filtrée), mais ce fichier n'avait pas été inclus dans ce commit — screens/ ne s'importait plus en l'état. Corrigé ici, dans le même commit que sa seule vraie utilisation. publish/build_package.py copiait jusqu'ici static/characters/ dans SON INTÉGRALITÉ pour CHAQUE jeu exporté (.zip), sans filtrage — avec la bibliothèque d'animaux (~2,1 Go), ça aurait gonflé chaque export du poids de toute la bibliothèque, même un jeu qui n'utilise aucun animal. screens.list_used_forge_characters(slug) (nouveau) parcourt tous les écrans du jeu (écrans-modèles compris, même patron que full_game_payload.py) et renvoie l'ensemble des personnages Forge réellement référencés. _copy_engine_sources()/_copy_characters() copient désormais : le rangement plat Kenney (petit, comme avant) + toujours static/characters/animals/manifest.json (nécessaire à l'IMPORT de screens/labels/animal_sprite_library.py dans le paquet exporté, sinon le jeu exporté ne démarre plus) + UNIQUEMENT les dossiers animal/variante réellement utilisés par CE jeu. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
449c36fd5d
commit
a27d08c6b0
@@ -14,6 +14,7 @@ import tempfile
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
import db
|
import db
|
||||||
|
import screens
|
||||||
|
|
||||||
from . import vendor_runtime
|
from . import vendor_runtime
|
||||||
|
|
||||||
@@ -28,7 +29,54 @@ _STATIC_ITEMS = ["style.css", "csrf_fetch.js", "icons", "branding", "vendor/font
|
|||||||
_SLUG_PLACEHOLDER = "_SLUG_PLACEHOLDER"
|
_SLUG_PLACEHOLDER = "_SLUG_PLACEHOLDER"
|
||||||
|
|
||||||
|
|
||||||
def _copy_engine_sources(staging_dir):
|
def _copy_characters(static_dir, used_forge_characters):
|
||||||
|
"""`static/characters/` contient 2 rangements bien distincts (voir le
|
||||||
|
plan "Bibliothèque de sprites animaux CraftPix") : le rangement plat
|
||||||
|
Kenney (`<slug>/*.png`, CC0, ~6 Mo, toujours copié comme avant) et
|
||||||
|
`animals/<animal>/<NN>/` (CraftPix, ~1,5-2 Go pour les 210 variantes)
|
||||||
|
— celui-ci copié SÉLECTIVEMENT, seulement les dossiers (animal, NN)
|
||||||
|
correspondant aux personnages `animal-<animal>-<NN>` réellement
|
||||||
|
utilisés par CE jeu (used_forge_characters), pour ne pas gonfler
|
||||||
|
CHAQUE .zip exporté du poids de toute la bibliothèque. manifest.json
|
||||||
|
est toujours copié : screens/labels/animal_sprite_library.py le lit à
|
||||||
|
l'import, sans lui `screens` (copié intégralement juste après) ne
|
||||||
|
s'importerait plus dans le paquet exporté."""
|
||||||
|
src_root = os.path.join(_BASE_DIR, "static", "characters")
|
||||||
|
dst_root = os.path.join(static_dir, "characters")
|
||||||
|
for name in os.listdir(src_root):
|
||||||
|
if name == "animals":
|
||||||
|
continue
|
||||||
|
src = os.path.join(src_root, name)
|
||||||
|
dst = os.path.join(dst_root, name)
|
||||||
|
if os.path.isdir(src):
|
||||||
|
shutil.copytree(src, dst)
|
||||||
|
else:
|
||||||
|
os.makedirs(dst_root, exist_ok=True)
|
||||||
|
shutil.copy2(src, dst)
|
||||||
|
|
||||||
|
animals_src_root = os.path.join(src_root, "animals")
|
||||||
|
if not os.path.isdir(animals_src_root):
|
||||||
|
return
|
||||||
|
animals_dst_root = os.path.join(dst_root, "animals")
|
||||||
|
os.makedirs(animals_dst_root, exist_ok=True)
|
||||||
|
shutil.copy2(os.path.join(animals_src_root, "manifest.json"), os.path.join(animals_dst_root, "manifest.json"))
|
||||||
|
used_variants = set()
|
||||||
|
for slug in used_forge_characters:
|
||||||
|
# slug = "animal-<animal>-<NN>" (voir screens/labels/animal_sprite_library.py) ;
|
||||||
|
# ignore silencieusement tout ce qui ne colle pas à ce format —
|
||||||
|
# un personnage Kenney (déjà copié ci-dessus) n'a pas ce préfixe.
|
||||||
|
if not slug.startswith("animal-"):
|
||||||
|
continue
|
||||||
|
animal, _, nn = slug[len("animal-"):].rpartition("-")
|
||||||
|
if animal:
|
||||||
|
used_variants.add((animal, nn))
|
||||||
|
for animal, nn in used_variants:
|
||||||
|
src = os.path.join(animals_src_root, animal, nn)
|
||||||
|
if os.path.isdir(src):
|
||||||
|
shutil.copytree(src, os.path.join(animals_dst_root, animal, nn))
|
||||||
|
|
||||||
|
|
||||||
|
def _copy_engine_sources(staging_dir, slug):
|
||||||
"""Copie la partie du moteur nécessaire au mode jouable SEUL (jamais
|
"""Copie la partie du moteur nécessaire au mode jouable SEUL (jamais
|
||||||
l'éditeur ni l'authentification — voir le constat d'exploration dans
|
l'éditeur ni l'authentification — voir le constat d'exploration dans
|
||||||
le plan : screens/ et db/ sont déjà totalement découplés de auth//
|
le plan : screens/ et db/ sont déjà totalement découplés de auth//
|
||||||
@@ -48,7 +96,11 @@ def _copy_engine_sources(staging_dir):
|
|||||||
shutil.copy2(os.path.join(_BASE_DIR, "templates", "play.html"), os.path.join(templates_dir, "play.html"))
|
shutil.copy2(os.path.join(_BASE_DIR, "templates", "play.html"), os.path.join(templates_dir, "play.html"))
|
||||||
|
|
||||||
static_dir = os.path.join(staging_dir, "static")
|
static_dir = os.path.join(staging_dir, "static")
|
||||||
|
used_forge_characters = screens.list_used_forge_characters(slug)
|
||||||
for item in _STATIC_ITEMS:
|
for item in _STATIC_ITEMS:
|
||||||
|
if item == "characters":
|
||||||
|
_copy_characters(static_dir, used_forge_characters)
|
||||||
|
continue
|
||||||
src = os.path.join(_BASE_DIR, "static", item)
|
src = os.path.join(_BASE_DIR, "static", item)
|
||||||
dst = os.path.join(static_dir, item)
|
dst = os.path.join(static_dir, item)
|
||||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
@@ -100,7 +152,7 @@ def build_game_zip(slug):
|
|||||||
try:
|
try:
|
||||||
shutil.copytree(python_dir, os.path.join(staging_dir, "python-embed"))
|
shutil.copytree(python_dir, os.path.join(staging_dir, "python-embed"))
|
||||||
shutil.copytree(pylibs_dir, os.path.join(staging_dir, "python-embed", "pylibs"))
|
shutil.copytree(pylibs_dir, os.path.join(staging_dir, "python-embed", "pylibs"))
|
||||||
_copy_engine_sources(staging_dir)
|
_copy_engine_sources(staging_dir, slug)
|
||||||
_copy_game_data(staging_dir, slug)
|
_copy_game_data(staging_dir, slug)
|
||||||
_write_player_app(staging_dir, slug)
|
_write_player_app(staging_dir, slug)
|
||||||
_write_run_bat(staging_dir)
|
_write_run_bat(staging_dir)
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
from ..screens_repo.list_screens import list_screens
|
||||||
|
from ..elements.list_elements import list_elements
|
||||||
|
from ..scenes.list_scene_objects import list_scene_objects
|
||||||
|
from .personnage_data import resolve_personnage_data
|
||||||
|
|
||||||
|
|
||||||
|
def list_used_forge_characters(slug):
|
||||||
|
"""Ensemble des slugs SPRITE_LIBRARY (screens.SPRITE_LIBRARY)
|
||||||
|
réellement référencés par CE jeu — tous écrans, écrans-modèles compris
|
||||||
|
(même patron que full_game_payload.py : un personnage peut vivre dans
|
||||||
|
un écran-modèle d'élément réutilisable). Utilisé par
|
||||||
|
publish/build_package.py pour ne copier dans le .zip exporté que les
|
||||||
|
dossiers static/characters/animals/<animal>/<NN>/ réellement utilisés
|
||||||
|
par CE jeu, plutôt que les ~52 000 fichiers de toute la bibliothèque
|
||||||
|
(voir le plan "Bibliothèque de sprites animaux CraftPix")."""
|
||||||
|
used = set()
|
||||||
|
for s in list_screens(slug, include_templates=True):
|
||||||
|
for el in list_elements(slug, s["id"]):
|
||||||
|
if el.get("widget") == "personnage":
|
||||||
|
data = resolve_personnage_data(el)
|
||||||
|
if data.get("source") == "forge" and data.get("forge_character"):
|
||||||
|
used.add(data["forge_character"])
|
||||||
|
for o in list_scene_objects(slug, s["id"]):
|
||||||
|
if o.get("kind") == "personnage":
|
||||||
|
data = resolve_personnage_data(o)
|
||||||
|
if data.get("source") == "forge" and data.get("forge_character"):
|
||||||
|
used.add(data["forge_character"])
|
||||||
|
return used
|
||||||
Reference in New Issue
Block a user