Image de fond de scène + caméra qui suit le personnage, fps d'animation cohérent
Trois retours utilisateur : - fps d'idle/interagir/touches supplémentaires alignés sur celui de la marche (8 i/s partout, était 4 pour idle — perçu comme "les autres animations sont lentes à côté de la marche"). - Nouveau menu "🏞️ Images de fond" dans "Objets de cette scène" : pose un objet kind="fond" à la taille RÉELLE de l'image choisie (pack CraftPix intégré en galerie, admin seulement — licence, voir core/sprite_gate.py), derrière tout le reste, insensible au clic. - Si ce fond dépasse la scène, elle devient le "monde" : .playScreen. playScene est désormais le viewport (overflow:hidden, taille fixe), .sceneWorld le monde à l'intérieur — la caméra centre le premier personnage trouvé, bornée pour ne jamais montrer au-delà des bords (voir personnage-controller.js::forgeUpdateSceneCamera). Le personnage peut désormais se déplacer sur tout le monde, pas seulement le petit cadre visible (clampSceneObjectPosition, actions.js). Un jeu sans fond XXL garde un comportement strictement identique à avant (monde == scène, transform vide). Bibliothèque générée une fois par scripts/generate_background_manifest.py (assets/background/, non versionné, licence CraftPix) vers static/backgrounds/ (committé), même patron que generate_animal_sprite_manifest.py. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
5891c82c62
commit
9199897784
@@ -67,6 +67,11 @@ from .labels.animal_sprite_library import ADMIN_SPRITE_LIBRARY
|
||||
SPRITE_LIBRARY = {**PUBLIC_SPRITE_LIBRARY, **ADMIN_SPRITE_LIBRARY}
|
||||
ADMIN_ONLY_CHARACTER_SLUGS = set(ADMIN_SPRITE_LIBRARY)
|
||||
from .labels.sprite_gallery import sprite_gallery_families
|
||||
from .labels.background_library import BACKGROUND_LIBRARY
|
||||
# Un seul pack aujourd'hui, licence CraftPix — tout BACKGROUND_LIBRARY est
|
||||
# admin-only (voir core/sprite_gate.py::forbid_admin_only_background),
|
||||
# jamais de version "publique" comme pour les personnages Kenney.
|
||||
ADMIN_ONLY_BACKGROUND_SLUGS = set(BACKGROUND_LIBRARY)
|
||||
from .rendering.list_used_forge_characters import list_used_forge_characters
|
||||
|
||||
from .flow.constants import (
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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>/
|
||||
# (pack source, non versionné) vers static/backgrounds/<pack_slug>/
|
||||
# <image>.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()
|
||||
@@ -5,20 +5,27 @@ import db
|
||||
from .ensure_scene_schema import ensure_scene_schema
|
||||
|
||||
_DEFAULT_PERSONNAGE_DATA = {"source": "forge", "forge_character": "male-adventurer"}
|
||||
_KINDS = {"personnage", "decor"}
|
||||
_KINDS = {"personnage", "decor", "fond"}
|
||||
|
||||
|
||||
def add_scene_object(slug, scene_id, kind="personnage", forge_character=None):
|
||||
def add_scene_object(slug, scene_id, kind="personnage", forge_character=None, background_slug=None):
|
||||
"""Pose un nouvel objet sur une scène (voir ensure_scene_schema.py).
|
||||
kind="personnage" : attributes._personnage_data, MÊME structure/mêmes
|
||||
fonctions resolve_personnage_* que le widget "personnage" de l'éditeur
|
||||
document (screens/rendering/personnage_data.py) — un objet de scène
|
||||
"personnage" partage donc directement la bibliothèque Forge et le
|
||||
système d'animation déjà écrits. kind="decor" : une simple image fixe
|
||||
(attributes.src), pas d'animation."""
|
||||
(attributes.src), pas d'animation. kind="fond" : même image fixe que
|
||||
"decor" (render_scene_object.py ne les distingue pas au rendu), mais
|
||||
posée en dessous de tout le reste (z_index très négatif, voir
|
||||
static/style.css .sceneBackground) et à la taille RÉELLE de l'image
|
||||
choisie (voir screens/labels/background_library.py) par défaut — une
|
||||
image plus grande que la scène devient alors le "monde" que la caméra
|
||||
suit en défilant (voir static/js/play/personnage-controller.js)."""
|
||||
ensure_scene_schema(slug)
|
||||
kind = kind if kind in _KINDS else "personnage"
|
||||
attributes = {}
|
||||
width = height = None
|
||||
if kind == "personnage":
|
||||
data = dict(_DEFAULT_PERSONNAGE_DATA)
|
||||
if forge_character:
|
||||
@@ -27,15 +34,30 @@ def add_scene_object(slug, scene_id, kind="personnage", forge_character=None):
|
||||
if forge_character in PUBLIC_SPRITE_LIBRARY or forge_character in ADMIN_SPRITE_LIBRARY:
|
||||
data["forge_character"] = forge_character
|
||||
attributes["_personnage_data"] = json.dumps(data)
|
||||
elif kind == "fond" and background_slug:
|
||||
from ..labels.background_library import BACKGROUND_LIBRARY
|
||||
background = BACKGROUND_LIBRARY.get(background_slug)
|
||||
if background:
|
||||
attributes["src"] = background["url"]
|
||||
width, height = background["width"], background["height"]
|
||||
conn = db.connect(slug)
|
||||
max_z = conn.execute(
|
||||
"SELECT MAX(z_index) AS m FROM _scene_objects WHERE scene_id = ?", (scene_id,)
|
||||
).fetchone()["m"]
|
||||
conn.execute(
|
||||
"""INSERT INTO _scene_objects (scene_id, kind, attributes, z_index)
|
||||
VALUES (?, ?, ?, ?)""",
|
||||
(scene_id, kind, json.dumps(attributes), (max_z or 0) + 1),
|
||||
)
|
||||
if kind == "fond":
|
||||
z_index = -1000
|
||||
else:
|
||||
max_z = conn.execute(
|
||||
"SELECT MAX(z_index) AS m FROM _scene_objects WHERE scene_id = ?", (scene_id,)
|
||||
).fetchone()["m"]
|
||||
z_index = (max_z or 0) + 1
|
||||
cols = ["scene_id", "kind", "attributes", "z_index"]
|
||||
values = [scene_id, kind, json.dumps(attributes), z_index]
|
||||
if width is not None:
|
||||
# x=0/y=0 (jamais le défaut 100/100, voir ensure_scene_schema.py) :
|
||||
# un fond commence au coin haut-gauche de la scène/du monde, pas
|
||||
# décalé arbitrairement comme un objet ordinaire.
|
||||
cols += ["width", "height", "x", "y"]
|
||||
values += [width, height, 0, 0]
|
||||
placeholders = ", ".join(["?"] * len(values))
|
||||
conn.execute(f"INSERT INTO _scene_objects ({', '.join(cols)}) VALUES ({placeholders})", values)
|
||||
object_id = conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -46,5 +46,12 @@ def render_scene_object(obj):
|
||||
f'data-anim-target="{obj["id"]}" data-personnage="1" style="{style}"{src_attr}>')
|
||||
src = (obj.get("attributes") or {}).get("src", "")
|
||||
src_attr = f' src="{html_lib.escape(src)}"' if src else ""
|
||||
return (f'<img class="sceneObjectSprite" data-object-id="{obj["id"]}" data-element-id="{obj["id"]}" '
|
||||
# "fond" (voir add_scene_object.py) : même image fixe que "decor",
|
||||
# seule la classe change — .sceneBackground (static/style.css) la
|
||||
# rend insensible au clic (pointer-events:none), pour qu'elle ne
|
||||
# bloque jamais un clic destiné à un objet posé par-dessus, même
|
||||
# étendue sur tout le "monde" (voir personnage-controller.js, la
|
||||
# caméra qui la suit en défilant).
|
||||
css_class = "sceneObjectSprite sceneBackground" if obj["kind"] == "fond" else "sceneObjectSprite"
|
||||
return (f'<img class="{css_class}" data-object-id="{obj["id"]}" data-element-id="{obj["id"]}" '
|
||||
f'data-anim-target="{obj["id"]}" style="{style}"{src_attr}>')
|
||||
|
||||
Reference in New Issue
Block a user