Files
Forge-Engine/tests/test_scene_objects.py
T
williamandClaude Sonnet 5 559331f9cf
Build and deploy / test-python (push) Successful in 10m59s
Build and deploy / test-js (push) Successful in 1m27s
Build and deploy / build-and-push (push) Skipped
Build and deploy / deploy (push) Skipped
Enrichit les declencheurs/actions de scene (clic/survol/affichage, surbrillance/video/son/visibilite/indication/attendre) et fiabilise la pose d'un fond/decor importe
- Ajoute clic/survol/affichage-ecran comme declencheurs, et surbrillance,
  video, son, visibilite, indication, attendre comme actions, utilisables
  aussi bien par l'editeur manuel (menu lateral Objets/Ecran) que par
  Ruby (IA), avec blocs deplacables/supprimables dans une chaine.
- Corrige plusieurs variantes du bug "impossible de poser un objet hors
  du champ de la camera" (troncature du chainage d'actions a 4 maillons,
  fond importe pose a 128x128 au lieu de sa taille reelle, decalage du
  fond au vrai glisser-depose, redimensionnement manuel jamais propage
  au monde).
- Ajoute un vrai glisser-depose depuis la galerie vers la scene, la
  gestion complete de "Mes assets" (sous-sections Fonds/Decors/Sons/
  Videos, suppression, reclassement fond<->decor sans re-upload).
- Ajoute l'upload de son (limite 3 min) et de video (MP4 uniquement,
  limite 5 min), avec validation de la duree reelle du fichier, et une
  replique audio optionnelle dans une bulle de dialogue.
- Fixe la taille de pose d'un objet/decor importe a 200x200 avec une
  boite de collision de 150x150.
- Filtre le selecteur de fichier des actions son/video par type reel.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-12 00:28:46 +02:00

185 lines
9.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Objets de scène (_scene_objects) — fondations de l'éditeur de scène 2D
(écrans "jeu_2d", voir screens/screens_repo/ensure_schema.py). Positions
en PIXELS fixes (pas des %, voir ensure_scene_schema.py). kind="personnage"
réutilise TELLE QUELLE la structure _personnage_data et les fonctions
resolve_personnage_* déjà écrites pour le widget "personnage" de
l'éditeur document (Phase 8) — même bibliothèque Forge, même moteur
d'animation côté client, juste une autre table de stockage."""
import db
import screens
def _create_jeu2d_game(tmp_game_slug_cleanup, name="pytest_scene_test"):
slug = tmp_game_slug_cleanup(db.create_game(name))
screen_id = screens.create_screen(slug, "Scène 1", kind="jeu_2d")
return slug, screen_id
def test_scene_object_defaults_to_forge_personnage(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id)
obj = screens.get_scene_object(slug, obj_id)
assert obj["kind"] == "personnage"
assert obj["attributes"]["_personnage_data"]
data = screens.resolve_personnage_data(obj)
assert data["source"] == "forge"
assert data["forge_character"] in screens.SPRITE_LIBRARY
def test_add_scene_object_with_specific_forge_character(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="personnage", forge_character="zombie")
obj = screens.get_scene_object(slug, obj_id)
assert screens.resolve_personnage_data(obj)["forge_character"] == "zombie"
def test_add_decor_scene_object(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="decor")
obj = screens.get_scene_object(slug, obj_id)
assert obj["kind"] == "decor"
def test_add_decor_scene_object_with_an_image_defaults_to_200x200_with_a_150x150_collision_box(tmp_game_slug_cleanup):
"""Demande explicite : un objet/décor posé depuis "Mes assets" doit
toujours démarrer à 200×200 (jamais la taille réelle, souvent bien
plus grande, ni le défaut 128×128 du schéma), avec une boîte de
collision plus petite (150×150, centrée) pour rester proche de la
silhouette réelle."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="decor", image_url="/assets/1/photo.png")
obj = screens.get_scene_object(slug, obj_id)
assert (obj["width"], obj["height"]) == (200, 200)
collision = screens.resolve_collision_settings(obj)
assert (collision["width"], collision["height"]) == (150, 150)
def test_add_decor_scene_object_with_an_image_ignores_real_image_dimensions(tmp_game_slug_cleanup):
"""Contrairement à "fond" (voir add_scene_object.py), un "decor" ne
doit JAMAIS être posé à la taille réelle de l'image importée — même
quand elle est connue (image_width/image_height fournis)."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(
slug, screen_id, kind="decor", image_url="/assets/1/photo.png",
image_width=5504, image_height=3072,
)
obj = screens.get_scene_object(slug, obj_id)
assert (obj["width"], obj["height"]) == (200, 200)
def test_scene_object_geometry_is_pixels_not_percent(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id)
screens.update_scene_object_geometry(slug, obj_id, x=320, y=200, width=128, height=128)
obj = screens.get_scene_object(slug, obj_id)
assert (obj["x"], obj["y"], obj["width"], obj["height"]) == (320, 200, 128, 128)
def test_list_scene_objects_ordered_by_z_index(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
first = screens.add_scene_object(slug, screen_id)
second = screens.add_scene_object(slug, screen_id)
objs = screens.list_scene_objects(slug, screen_id)
assert [o["id"] for o in objs] == [first, second]
def test_swap_scene_object_forge_character(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, forge_character="male-adventurer")
screens.set_scene_object_personnage_data(slug, obj_id, {"source": "forge", "forge_character": "robot"})
obj = screens.get_scene_object(slug, obj_id)
assert screens.resolve_personnage_data(obj)["forge_character"] == "robot"
def test_render_scene_object_shows_idle_frame_pixel_positioned(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, forge_character="zombie")
screens.update_scene_object_geometry(slug, obj_id, x=50, y=60, width=64, height=64)
obj = screens.get_scene_object(slug, obj_id)
html = screens.render_scene_object(obj)
assert "/static/characters/zombie/idle.png" in html
assert "left:50" in html and "top:60" in html
assert f'data-object-id="{obj_id}"' in html
assert 'data-personnage="1"' in html
def test_render_scene_object_alt_uses_the_authored_name_rgaa(tmp_game_slug_cleanup):
"""RGAA/WCAG 1.1.1 : le nom donné par l'auteur (panneau "ℹ️
Informations") sert d'alternative textuelle — jamais aucun attribut
alt du tout n'était généré avant."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, forge_character="zombie")
screens.set_scene_object_name(slug, obj_id, "Zombie du hangar")
obj = screens.get_scene_object(slug, obj_id)
html = screens.render_scene_object(obj)
assert 'alt="Zombie du hangar"' in html
def test_render_scene_object_alt_is_empty_when_unnamed_rgaa(tmp_game_slug_cleanup):
"""alt="" (décoratif) plutôt qu'aucun attribut du tout quand l'auteur
n'a pas nommé l'objet."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, forge_character="zombie")
obj = screens.get_scene_object(slug, obj_id)
html = screens.render_scene_object(obj)
assert 'alt=""' in html
def test_render_scene_object_fond_alt_is_always_empty_rgaa(tmp_game_slug_cleanup):
"""Un "fond" est toujours décoratif — alt="" même s'il est nommé."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="fond", background_slug="foret")
screens.set_scene_object_name(slug, obj_id, "Grand décor de fond")
obj = screens.get_scene_object(slug, obj_id)
html = screens.render_scene_object(obj)
assert 'alt=""' in html
def test_add_scene_object_with_explicit_position_uses_it_instead_of_the_default(tmp_game_slug_cleanup):
"""Vrai glisser-déposer depuis la galerie (demande explicite :
"n'importe où sur la scène") — x/y explicites remplacent le défaut
100/100 posé par le schéma (voir ensure_scene_schema.py)."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="decor", x=250, y=340)
obj = screens.get_scene_object(slug, obj_id)
assert obj["x"] == 250
assert obj["y"] == 340
def test_add_scene_object_without_position_still_defaults_to_100_100(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="decor")
obj = screens.get_scene_object(slug, obj_id)
assert obj["x"] == 100
assert obj["y"] == 100
def test_add_scene_object_fond_with_explicit_position_overrides_the_top_left_default(tmp_game_slug_cleanup):
"""Un "fond" reste au coin haut-gauche (0,0) SANS position explicite
(comportement inchangé), mais un glisser-déposer précis doit pouvoir
le positionner ailleurs si le créateur le demande explicitement."""
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="fond", background_slug="foret", x=50, y=60)
obj = screens.get_scene_object(slug, obj_id)
assert obj["x"] == 50
assert obj["y"] == 60
def test_add_scene_object_fond_without_position_still_defaults_to_top_left(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id, kind="fond", background_slug="foret")
obj = screens.get_scene_object(slug, obj_id)
assert obj["x"] == 0
assert obj["y"] == 0
def test_delete_scene_object_cleans_up_referencing_flow_nodes(tmp_game_slug_cleanup):
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
obj_id = screens.add_scene_object(slug, screen_id)
node_id = screens.add_flow_node(
slug, screen_id, node_type="action", action_type="jouer_animation_sprite",
target_object_id=obj_id, data_value='{"animation":"idle","fps":8,"loop":true}',
)
screens.delete_scene_object(slug, obj_id)
assert screens.get_flow_node(slug, node_id) is None