From 55c6bb330b0487a3b2a13752cefe8369f1c1a699 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 3 Sep 2026 17:28:03 +0200 Subject: [PATCH] =?UTF-8?q?Contr=C3=B4le=20direct=20de=20la=20taille=20de?= =?UTF-8?q?=20la=20cam=C3=A9ra=20(Largeur=20=C3=97=20Hauteur,=20toujours?= =?UTF-8?q?=20modifiable)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remplace le bouton conditionnel "Agrandir la caméra à la zone visible" (n'apparaissait que si un fond dépassait déjà la scène) par deux champs "Caméra (px)" TOUJOURS visibles, pré-remplis avec scene_width/ scene_height actuels — demande explicite : "l'écran de l'éditeur a une taille fixe, la caméra a la même taille, c'est tout", un réglage direct plutôt qu'une suggestion automatique liée à la taille d'un fond. Co-Authored-By: Claude Sonnet 5 --- static/js/scenes/scene-editor.js | 18 ++++++++++-------- templates/scene_edit.html | 24 +++++++++++++++--------- tests/test_scene_edit_view.py | 19 ++++++++++++++----- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/static/js/scenes/scene-editor.js b/static/js/scenes/scene-editor.js index 9fe057dc..3110058d 100644 --- a/static/js/scenes/scene-editor.js +++ b/static/js/scenes/scene-editor.js @@ -20,14 +20,16 @@ function addSceneObject(kind, forgeCharacter, backgroundSlug) { form.requestSubmit(); } -// "📐 Agrandir la caméra à la zone visible" (voir templates/scene_edit.html) : -// fait de tout le "monde" affiché par l'éditeur (voir world_width/ -// world_height, routes/scenes/scene_edit_view.py — la taille réelle -// d'un "fond" plus grand que la scène nominale) la scène/caméra -// elle-même — recharge la page ensuite, SCENE_WIDTH/SCENE_HEIGHT et le -// cadre "🎥 Champ de la caméra" doivent tous deux refléter la nouvelle -// taille, plus simple qu'une mise à jour partielle en JS. -function expandCameraToWorld(width, height) { +// Taille de la caméra (voir "🎮 Jeu 2D" en haut de templates/ +// scene_edit.html) — TOUJOURS modifiable ici, directement en pixels +// (demande explicite : "l'écran de l'éditeur a une taille fixe, la +// caméra a la même taille, c'est tout") : recharge la page une fois +// appliqué, SCENE_WIDTH/SCENE_HEIGHT et le cadre "🎥 Champ de la caméra" +// éventuel doivent tous deux refléter la nouvelle taille, plus simple +// qu'une mise à jour partielle en JS. +function applyCameraSize() { + var wEl = document.getElementById('scene-camera-w'), hEl = document.getElementById('scene-camera-h'); + var width = parseInt(wEl.value, 10) || 1, height = parseInt(hEl.value, 10) || 1; fetch("/game/" + GAME_SLUG + "/screens/" + SCREEN_ID + "/scene-size", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ width: width, height: height }), diff --git a/templates/scene_edit.html b/templates/scene_edit.html index fefc770c..c5d51b7e 100644 --- a/templates/scene_edit.html +++ b/templates/scene_edit.html @@ -30,15 +30,21 @@ demande de l'utilisateur, en prévision d'un éditeur dédié aux scènes 2D (collision/périmètre -> action), pas encore construit. -->

- 🎮 Jeu 2D — scène à taille fixe ({{ screen.scene_width }}×{{ screen.scene_height }} px). - {% if world_width > screen.scene_width or world_height > screen.scene_height %} - - - {% endif %} + 🎮 Jeu 2D — scène à taille fixe. + + + + +

diff --git a/tests/test_scene_edit_view.py b/tests/test_scene_edit_view.py index b653fd93..8a1e0781 100644 --- a/tests/test_scene_edit_view.py +++ b/tests/test_scene_edit_view.py @@ -214,6 +214,12 @@ def test_scene_edit_view_world_matches_scene_when_no_oversized_fond(client, tmp_ html = client.get(f"/game/{slug}/screens/{screen_id}/edit").get_data(as_text=True) assert 'id="canvas" style="width:960px; height:540px;' in html assert "sceneCameraFrame" not in html + # "Caméra (px)" : TOUJOURS modifiable, même sans fond qui dépasse + # (demande explicite : "l'écran de l'éditeur a une taille fixe, la + # caméra a la même taille, c'est tout" — un réglage direct, pas + # seulement suggéré automatiquement). + assert 'id="scene-camera-w" class="input is-small" style="width:80px;" min="1" value="960"' in html + assert 'id="scene-camera-h" class="input is-small" style="width:80px;" min="1" value="540"' in html def test_scene_edit_view_expands_world_for_an_oversized_fond(client, tmp_game_slug_cleanup): @@ -242,9 +248,9 @@ def test_scene_edit_view_world_bounds_are_used_for_drag_clamping(client, tmp_gam def test_set_scene_size_updates_screen_dimensions(tmp_game_slug_cleanup): - """"📐 Agrandir la caméra à la zone visible" (voir templates/ - scene_edit.html) : fait du "monde" affiché la scène/caméra - elle-même — jusqu'ici fixée à la création et jamais modifiable.""" + """"Caméra (px)" (voir templates/scene_edit.html) : jusqu'ici + scene_width/scene_height n'étaient fixées qu'à la création de + l'écran, jamais modifiables ensuite.""" slug = tmp_game_slug_cleanup(db.create_game("pytest_scene_size")) screen_id = screens.create_screen(slug, "Scène 1", kind="jeu_2d") screens.set_scene_size(slug, screen_id, 1920, 1080) @@ -262,9 +268,12 @@ def test_screen_set_scene_size_route_persists_and_reflects_in_editor(client, tmp assert resp.get_json() == {"ok": True} html = client.get(f"/game/{slug}/screens/{screen_id}/edit").get_data(as_text=True) assert 'id="canvas" style="width:1920px; height:1080px;' in html - # La scène nominale == le monde désormais -> plus de repère caméra ni de bouton. + # La scène nominale == le monde désormais -> plus de repère caméra. assert "sceneCameraFrame" not in html - assert "Agrandir la caméra" not in html + # Les champs "Caméra (px)" restent TOUJOURS visibles (pas conditionnels), + # pré-remplis avec la nouvelle taille. + assert 'id="scene-camera-w" class="input is-small" style="width:80px;" min="1" value="1920"' in html + assert 'id="scene-camera-h" class="input is-small" style="width:80px;" min="1" value="1080"' in html def test_screen_set_scene_size_route_rejects_invalid_dimensions(client, tmp_game_slug_cleanup):