Merge pull request 'S6.1: Improve FOV readability, zoom and compact HUD' (#10) from slice/s6-1-fov-zoom-hud into main
This commit was merged in pull request #10.
This commit is contained in:
@@ -0,0 +1,79 @@
|
|||||||
|
# S6.1 — FOV, zoom et HUD compact
|
||||||
|
|
||||||
|
- **Worktree :** `/home/hectelyon/Documents/Projects/ProjetsPersos/DungeonCrawlerWorld/.worktrees/s6-1`
|
||||||
|
- **Spécification :** `.claude/work/dcw-s6-visual-readability/spec.md`, `SLICE-6-1-fov-zoom-hud.md`
|
||||||
|
- **Périmètre :** S6.1 uniquement — aucune modification de DCWASCII, aucun nouvel asset.
|
||||||
|
|
||||||
|
## Livraison
|
||||||
|
|
||||||
|
- Les cellules explorées ont un overlay bleu pâle lisible : `EXPLORED_DIM_COLOR = (0.9, 0.95, 1.0)` (luminance linéaire > 0,55). Les textures restent visibles sous l’overlay.
|
||||||
|
- Les cellules inconnues sont bleu-noir : `UNKNOWN_COLOR = (0.015, 0.025, 0.07)`, distinct des explorées.
|
||||||
|
- `Camera2D.zoom = (2, 2)` dans `Game.tscn`. `Game.TILE_SIZE` et `MapRenderer.TILE_SIZE` restent tous deux à `Vector2i(32, 32)` ; les coordonnées métier et les chemins publics ne changent pas.
|
||||||
|
- HUD réduit : stats et journal en coins, prompt inférieur centré, aide basse compacte. La zone centrale vérifiée (`Rect2(300, 120, 680, 480)`) n’est recouverte par aucun panneau ; l’occupation cumulée est plafonnée par test à 15 % du viewport 1280×720.
|
||||||
|
- `run-visual-check.sh` vérifie désormais aussi les pixels avec un lecteur PNG Python basé uniquement sur la bibliothèque standard (`struct`/`zlib`), sans Pillow ni dépendance externe.
|
||||||
|
|
||||||
|
## TDD
|
||||||
|
|
||||||
|
### RED prouvé avant le changement
|
||||||
|
|
||||||
|
Les nouveaux tests unitaires et E2E ont échoué sur le baseline :
|
||||||
|
|
||||||
|
- zoom : `(1, 1)` reçu au lieu de `(2, 2)` ;
|
||||||
|
- luminance explorée : `0,35`, sous le seuil `0,55` ;
|
||||||
|
- absence de `UNKNOWN_COLOR` / inconnu encore noir ;
|
||||||
|
- les assertions HUD dédiées étaient ajoutées avant l’implémentation.
|
||||||
|
|
||||||
|
### GREEN
|
||||||
|
|
||||||
|
Tests ajoutés/renforcés :
|
||||||
|
|
||||||
|
- couleurs de rendu et seuils de luminance : `tests/unit/test_map_renderer_fog.gd` ;
|
||||||
|
- zoom et invariant `TILE_SIZE=32` : `tests/unit/test_display_layout.gd` ;
|
||||||
|
- rects HUD, aire centrale et taux d’occupation : `tests/unit/test_hud_layout.gd` ;
|
||||||
|
- E2E réel Game : `tests/e2e/test_visual_readability_e2e.gd` ;
|
||||||
|
- contrat E2E FOV mis à jour pour l’inconnu bleu-noir.
|
||||||
|
|
||||||
|
## Vérification finale
|
||||||
|
|
||||||
|
Toutes les commandes suivantes ont réussi avec Godot 4.5 :
|
||||||
|
|
||||||
|
```text
|
||||||
|
/snap/bin/godot4 --headless --path . --import PASS (import propre)
|
||||||
|
git diff --check PASS
|
||||||
|
./scripts/test-unit.sh PASS — 28 tests, 137 assertions
|
||||||
|
./scripts/test-e2e.sh PASS — 11 tests, 127 assertions
|
||||||
|
./scripts/verify.sh PASS — unit + E2E + visual
|
||||||
|
```
|
||||||
|
|
||||||
|
Les runners échouent sur les diagnostics applicatifs Godot `SCRIPT ERROR`, `Parse Error` ou `ERROR:`. Les lignes `xkbcommon: ERROR` concernant Compose/keymap, émises par l’environnement Snap/Xvfb et attendues sur cette machine, sont documentées comme bruit backend et ne sont pas assimilées à une erreur applicative. Les runners terminent avec succès.
|
||||||
|
|
||||||
|
## Capture Xvfb et mesures automatisées
|
||||||
|
|
||||||
|
`./scripts/run-visual-check.sh` a utilisé `xvfb-run --server-args="-screen 0 1280x720x24"` (DISPLAY absent) et a produit :
|
||||||
|
|
||||||
|
- `artifacts/visual-check.png` — PNG valide 1280×720 ;
|
||||||
|
- `artifacts/visual-check-exit.png` — PNG valide 1280×720.
|
||||||
|
|
||||||
|
Mesures de la dernière exécution :
|
||||||
|
|
||||||
|
```text
|
||||||
|
visual-check.png:
|
||||||
|
dungeon_non_black_pixels=488756
|
||||||
|
unknown_pixels=235256
|
||||||
|
unknown_luminance=0.002
|
||||||
|
explored_floor_pixels=4
|
||||||
|
detected_explored_luminance=0.815
|
||||||
|
|
||||||
|
visual-check-exit.png:
|
||||||
|
dungeon_non_black_pixels=488160
|
||||||
|
unknown_pixels=86908
|
||||||
|
unknown_luminance=0.002
|
||||||
|
explored_floor_pixels=141108
|
||||||
|
detected_explored_luminance=0.661
|
||||||
|
```
|
||||||
|
|
||||||
|
Le runner échoue si la zone de donjon est noire, si l’inconnu initial n’est pas bleu-noir, ou si l’overlay exploré mesuré dans la capture de sortie est absent / sous 0,55.
|
||||||
|
|
||||||
|
## Git
|
||||||
|
|
||||||
|
Commit local créé après ce rapport et les vérifications. Aucun push ni PR.
|
||||||
@@ -16,7 +16,7 @@ Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French lab
|
|||||||
|
|
||||||
The project reference viewport is **1280×720**, with canvas-item stretching and a resizable window. Dungeon coordinates remain in the `cell * 32` domain: `MapRenderer.get_cell_rect(cell)` returns the exact 32×32 world rectangle for a cell, and `Game.get_actor_cell_rect(actor_id)` exposes the effective actor image rectangle. Actor sprites are top-left anchored so their complete 32×32 image is contained in their cell before and after movement.
|
The project reference viewport is **1280×720**, with canvas-item stretching and a resizable window. Dungeon coordinates remain in the `cell * 32` domain: `MapRenderer.get_cell_rect(cell)` returns the exact 32×32 world rectangle for a cell, and `Game.get_actor_cell_rect(actor_id)` exposes the effective actor image rectangle. Actor sprites are top-left anchored so their complete 32×32 image is contained in their cell before and after movement.
|
||||||
|
|
||||||
`Camera2D` follows the player after each valid action and is bounded to the map's world rectangle. The public HUD nodes stay below `HUD` (`CanvasLayer`, layer 1), so they remain viewport-anchored rather than moving with the camera.
|
`Camera2D` follows the player after each valid action, uses `zoom = (2, 2)`, and is bounded to the map's world rectangle. Dungeon/domain coordinates and `TILE_SIZE=32` are unchanged. The public HUD nodes stay below `HUD` (`CanvasLayer`, layer 1), so they remain viewport-anchored rather than moving with the camera. Compact corner and bottom panels keep the central play area clear.
|
||||||
|
|
||||||
### S5.1 verification note
|
### S5.1 verification note
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh
|
|||||||
|
|
||||||
Each runner first executes `godot --headless --path . --import`. This generates the ignored `.godot` cache required for global script classes and imported assets, so the commands are reproducible from a newly checked-out worktree. Import failures stop the runner and retain Godot's error output.
|
Each runner first executes `godot --headless --path . --import`. This generates the ignored `.godot` cache required for global script classes and imported assets, so the commands are reproducible from a newly checked-out worktree. Import failures stop the runner and retain Godot's error output.
|
||||||
|
|
||||||
`run-visual-check.sh` runs the actual project twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture.
|
`run-visual-check.sh` runs the actual project twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. The runner measures the dungeon viewport pixels with the Python standard library only (PNG parsing uses `struct`/`zlib`, with no Pillow or other external dependency): an initial blue-black unknown region, a readable explored-tile overlay (luminance ≥ 0.55), and non-black dungeon pixels in both captures. The explored luminance is calculated from the detected captured pixels, not from a pre-render tint constant. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. Godot `SCRIPT ERROR` and `Parse Error` diagnostics fail the check; `xkbcommon: ERROR` Compose/keymap warnings from the Snap/Xvfb environment are expected backend noise and are not treated as application errors. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture.
|
||||||
|
|
||||||
For a direct headless startup check:
|
For a direct headless startup check:
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path .
|
|||||||
|
|
||||||
## Exploration, combat, and HUD
|
## Exploration, combat, and HUD
|
||||||
|
|
||||||
- `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` render dimly; unknown cells are black.
|
- `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` have a pale-blue readable overlay (tint luminance ≥ 0.55); unknown cells are distinguishable blue-black.
|
||||||
- FOV is map-aware: walls and closed doors are visible but block cells behind them.
|
- FOV is map-aware: walls and closed doors are visible but block cells behind them.
|
||||||
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help.
|
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help.
|
||||||
- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. Using stairs sets only `GameState.exit_reached`, logs `stairs_used`, and leaves the player and current map in place.
|
- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. Using stairs sets only `GameState.exit_reached`, logs `stairs_used`, and leaves the player and current map in place.
|
||||||
|
|||||||
+36
-31
@@ -54,6 +54,7 @@ script = ExtResource("3_actor")
|
|||||||
[node name="Enemies" type="Node2D" parent="World"]
|
[node name="Enemies" type="Node2D" parent="World"]
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
zoom = Vector2(2, 2)
|
||||||
position_smoothing_enabled = false
|
position_smoothing_enabled = false
|
||||||
|
|
||||||
[node name="HUD" type="CanvasLayer" parent="."]
|
[node name="HUD" type="CanvasLayer" parent="."]
|
||||||
@@ -74,8 +75,8 @@ layout_mode = 1
|
|||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_left = 12.0
|
offset_left = 12.0
|
||||||
offset_top = 12.0
|
offset_top = 12.0
|
||||||
offset_right = 326.0
|
offset_right = 248.0
|
||||||
offset_bottom = 116.0
|
offset_bottom = 94.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||||
@@ -85,10 +86,10 @@ layout_mode = 1
|
|||||||
anchors_preset = 1
|
anchors_preset = 1
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
offset_left = -344.0
|
offset_left = -256.0
|
||||||
offset_top = 12.0
|
offset_top = 12.0
|
||||||
offset_right = -12.0
|
offset_right = -12.0
|
||||||
offset_bottom = 278.0
|
offset_bottom = 170.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||||
@@ -96,12 +97,14 @@ theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
|||||||
[node name="PromptPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
[node name="PromptPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 10
|
anchors_preset = 10
|
||||||
anchor_right = 1.0
|
anchor_left = 0.5
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 0.5
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 332.0
|
offset_left = -280.0
|
||||||
offset_top = -110.0
|
offset_top = -90.0
|
||||||
offset_right = -332.0
|
offset_right = 280.0
|
||||||
offset_bottom = -62.0
|
offset_bottom = -52.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_styles/panel = SubResource("StyleBox_prompt_panel")
|
theme_override_styles/panel = SubResource("StyleBox_prompt_panel")
|
||||||
@@ -113,7 +116,7 @@ anchor_top = 1.0
|
|||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 12.0
|
offset_left = 12.0
|
||||||
offset_top = -50.0
|
offset_top = -42.0
|
||||||
offset_right = -12.0
|
offset_right = -12.0
|
||||||
offset_bottom = -12.0
|
offset_bottom = -12.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
@@ -124,9 +127,9 @@ theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
|||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_left = 26.0
|
offset_left = 26.0
|
||||||
offset_top = 20.0
|
offset_top = 26.0
|
||||||
offset_right = 312.0
|
offset_right = 236.0
|
||||||
offset_bottom = 44.0
|
offset_bottom = 46.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
||||||
@@ -137,8 +140,8 @@ layout_mode = 1
|
|||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_left = 26.0
|
offset_left = 26.0
|
||||||
offset_top = 48.0
|
offset_top = 48.0
|
||||||
offset_right = 312.0
|
offset_right = 236.0
|
||||||
offset_bottom = 72.0
|
offset_bottom = 68.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_colors/font_color = Color(1, 0.8, 0.7, 1)
|
theme_override_colors/font_color = Color(1, 0.8, 0.7, 1)
|
||||||
@@ -148,9 +151,9 @@ theme_override_font_sizes/font_size = 18
|
|||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_left = 26.0
|
offset_left = 26.0
|
||||||
offset_top = 78.0
|
offset_top = 70.0
|
||||||
offset_right = 312.0
|
offset_right = 236.0
|
||||||
offset_bottom = 100.0
|
offset_bottom = 90.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
|
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
|
||||||
@@ -161,10 +164,10 @@ layout_mode = 1
|
|||||||
anchors_preset = 1
|
anchors_preset = 1
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
offset_left = -330.0
|
offset_left = -244.0
|
||||||
offset_top = 24.0
|
offset_top = 22.0
|
||||||
offset_right = -26.0
|
offset_right = -24.0
|
||||||
offset_bottom = 266.0
|
offset_bottom = 158.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
bbcode_enabled = false
|
bbcode_enabled = false
|
||||||
@@ -175,16 +178,18 @@ theme_override_font_sizes/normal_font_size = 14
|
|||||||
[node name="ContextPromptLabel" type="Label" parent="HUD"]
|
[node name="ContextPromptLabel" type="Label" parent="HUD"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 10
|
anchors_preset = 10
|
||||||
anchor_right = 1.0
|
anchor_left = 0.5
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 0.5
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 348.0
|
offset_left = -266.0
|
||||||
offset_top = -101.0
|
offset_top = -85.0
|
||||||
offset_right = -348.0
|
offset_right = 266.0
|
||||||
offset_bottom = -71.0
|
offset_bottom = -57.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_colors/font_color = Color(1, 0.92, 0.63, 1)
|
theme_override_colors/font_color = Color(1, 0.92, 0.63, 1)
|
||||||
theme_override_font_sizes/font_size = 18
|
theme_override_font_sizes/font_size = 16
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
@@ -195,13 +200,13 @@ anchor_top = 1.0
|
|||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 28.0
|
offset_left = 28.0
|
||||||
offset_top = -43.0
|
offset_top = -37.0
|
||||||
offset_right = -28.0
|
offset_right = -28.0
|
||||||
offset_bottom = -19.0
|
offset_bottom = -17.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
theme_override_colors/font_color = Color(0.82, 0.9, 1, 1)
|
theme_override_colors/font_color = Color(0.82, 0.9, 1, 1)
|
||||||
theme_override_font_sizes/font_size = 16
|
theme_override_font_sizes/font_size = 14
|
||||||
text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E"
|
text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|||||||
Executable
+194
@@ -0,0 +1,194 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate a visual-check PNG and measure the pixels used by its contract.
|
||||||
|
|
||||||
|
This intentionally uses only Python's standard library. Godot writes 8-bit RGB(A)
|
||||||
|
PNG captures, so supporting those non-interlaced PNGs is sufficient and avoids
|
||||||
|
making the visual check depend on Pillow being installed.
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import binascii
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
import zlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
WIDTH = 1280
|
||||||
|
HEIGHT = 720
|
||||||
|
VIEWPORT = (256, 40, 1024, 678)
|
||||||
|
UNKNOWN = (4, 6, 18)
|
||||||
|
|
||||||
|
|
||||||
|
def fail(message: str) -> "NoReturn":
|
||||||
|
raise SystemExit(message)
|
||||||
|
|
||||||
|
|
||||||
|
def read_png(path: Path) -> tuple[int, int, list[bytes]]:
|
||||||
|
try:
|
||||||
|
data = path.read_bytes()
|
||||||
|
except OSError as error:
|
||||||
|
fail(f"cannot read PNG: {error}")
|
||||||
|
if data[:8] != b"\x89PNG\r\n\x1a\n":
|
||||||
|
fail("invalid PNG signature")
|
||||||
|
|
||||||
|
offset = 8
|
||||||
|
header: tuple[int, int, int, int, int, int, int] | None = None
|
||||||
|
compressed = bytearray()
|
||||||
|
saw_iend = False
|
||||||
|
while offset < len(data):
|
||||||
|
if offset + 12 > len(data):
|
||||||
|
fail("truncated PNG chunk")
|
||||||
|
length = struct.unpack_from(">I", data, offset)[0]
|
||||||
|
chunk_end = offset + 12 + length
|
||||||
|
if chunk_end > len(data):
|
||||||
|
fail("truncated PNG chunk data")
|
||||||
|
kind = data[offset + 4 : offset + 8]
|
||||||
|
chunk = data[offset + 8 : offset + 8 + length]
|
||||||
|
expected_crc = struct.unpack_from(">I", data, offset + 8 + length)[0]
|
||||||
|
actual_crc = binascii.crc32(kind + chunk) & 0xFFFFFFFF
|
||||||
|
if actual_crc != expected_crc:
|
||||||
|
fail(f"invalid PNG CRC for {kind.decode('latin1')}")
|
||||||
|
offset = chunk_end
|
||||||
|
|
||||||
|
if kind == b"IHDR":
|
||||||
|
if header is not None or len(chunk) != 13:
|
||||||
|
fail("invalid PNG IHDR")
|
||||||
|
header = struct.unpack(">IIBBBBB", chunk)
|
||||||
|
elif kind == b"IDAT":
|
||||||
|
compressed.extend(chunk)
|
||||||
|
elif kind == b"IEND":
|
||||||
|
if length != 0:
|
||||||
|
fail("invalid PNG IEND")
|
||||||
|
saw_iend = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if header is None or not saw_iend or offset != len(data):
|
||||||
|
fail("incomplete PNG")
|
||||||
|
width, height, depth, color_type, compression, filtering, interlace = header
|
||||||
|
if (width, height) != (WIDTH, HEIGHT):
|
||||||
|
fail(f"expected {WIDTH}x{HEIGHT} PNG, got {width}x{height}")
|
||||||
|
if depth != 8 or color_type not in (2, 6):
|
||||||
|
fail("visual capture must be an 8-bit RGB or RGBA PNG")
|
||||||
|
if (compression, filtering, interlace) != (0, 0, 0):
|
||||||
|
fail("visual capture uses unsupported PNG compression, filter, or interlace")
|
||||||
|
if not compressed:
|
||||||
|
fail("PNG has no image data")
|
||||||
|
return width, height, [bytes(compressed), bytes([color_type])]
|
||||||
|
|
||||||
|
|
||||||
|
def pixels(path: Path):
|
||||||
|
width, height, payload = read_png(path)
|
||||||
|
compressed, color_type = payload
|
||||||
|
channels = 3 if color_type[0] == 2 else 4
|
||||||
|
try:
|
||||||
|
raw = zlib.decompress(compressed)
|
||||||
|
except zlib.error as error:
|
||||||
|
fail(f"invalid PNG image data: {error}")
|
||||||
|
stride = width * channels
|
||||||
|
expected = height * (stride + 1)
|
||||||
|
if len(raw) != expected:
|
||||||
|
fail(f"invalid PNG scanline data: expected {expected} bytes, got {len(raw)}")
|
||||||
|
|
||||||
|
previous = bytearray(stride)
|
||||||
|
offset = 0
|
||||||
|
for _ in range(height):
|
||||||
|
filter_type = raw[offset]
|
||||||
|
offset += 1
|
||||||
|
row = bytearray(raw[offset : offset + stride])
|
||||||
|
offset += stride
|
||||||
|
for index in range(stride):
|
||||||
|
left = row[index - channels] if index >= channels else 0
|
||||||
|
above = previous[index]
|
||||||
|
upper_left = previous[index - channels] if index >= channels else 0
|
||||||
|
if filter_type == 1:
|
||||||
|
row[index] = (row[index] + left) & 255
|
||||||
|
elif filter_type == 2:
|
||||||
|
row[index] = (row[index] + above) & 255
|
||||||
|
elif filter_type == 3:
|
||||||
|
row[index] = (row[index] + (left + above) // 2) & 255
|
||||||
|
elif filter_type == 4:
|
||||||
|
estimate = left + above - upper_left
|
||||||
|
left_distance = abs(estimate - left)
|
||||||
|
above_distance = abs(estimate - above)
|
||||||
|
upper_left_distance = abs(estimate - upper_left)
|
||||||
|
predictor = (
|
||||||
|
left
|
||||||
|
if left_distance <= above_distance and left_distance <= upper_left_distance
|
||||||
|
else above if above_distance <= upper_left_distance else upper_left
|
||||||
|
)
|
||||||
|
row[index] = (row[index] + predictor) & 255
|
||||||
|
elif filter_type != 0:
|
||||||
|
fail(f"unsupported PNG row filter {filter_type}")
|
||||||
|
previous = row
|
||||||
|
yield from (
|
||||||
|
(row[index], row[index + 1], row[index + 2])
|
||||||
|
for index in range(0, stride, channels)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def linear(channel: int) -> float:
|
||||||
|
value = channel / 255.0
|
||||||
|
return value / 12.92 if value <= 0.04045 else ((value + 0.055) / 1.055) ** 2.4
|
||||||
|
|
||||||
|
|
||||||
|
def luminance(rgb: tuple[int, int, int]) -> float:
|
||||||
|
red, green, blue = (linear(channel) for channel in rgb)
|
||||||
|
return 0.2126 * red + 0.7152 * green + 0.0722 * blue
|
||||||
|
|
||||||
|
|
||||||
|
def measure(path: Path) -> None:
|
||||||
|
observed = list(pixels(path))
|
||||||
|
dungeon = (
|
||||||
|
observed[y * WIDTH + x]
|
||||||
|
for y in range(VIEWPORT[1], VIEWPORT[3])
|
||||||
|
for x in range(VIEWPORT[0], VIEWPORT[2])
|
||||||
|
)
|
||||||
|
dungeon_pixels = list(dungeon)
|
||||||
|
non_black = sum(pixel != (0, 0, 0) for pixel in dungeon_pixels)
|
||||||
|
unknown_pixels = [pixel for pixel in dungeon_pixels if pixel == UNKNOWN]
|
||||||
|
explored_pixels = [
|
||||||
|
pixel
|
||||||
|
for pixel in dungeon_pixels
|
||||||
|
if pixel[0] >= 196 and pixel[1] >= 207 and pixel[2] >= 217
|
||||||
|
]
|
||||||
|
if non_black == 0:
|
||||||
|
fail("capture dungeon region is entirely black")
|
||||||
|
|
||||||
|
unknown_luminance = (
|
||||||
|
sum(luminance(pixel) for pixel in unknown_pixels) / len(unknown_pixels)
|
||||||
|
if unknown_pixels
|
||||||
|
else 1.0
|
||||||
|
)
|
||||||
|
if path.name == "visual-check.png":
|
||||||
|
if not unknown_pixels or UNKNOWN[2] <= UNKNOWN[0] or unknown_luminance >= 0.1:
|
||||||
|
fail("unknown fog is not distinguishable blue-black")
|
||||||
|
else:
|
||||||
|
if not explored_pixels:
|
||||||
|
fail("missing explored floor pixels in exit capture")
|
||||||
|
# Measure the RGB values that were actually detected, rather than the
|
||||||
|
# renderer's pre-modulation tint. This catches capture/readback regressions.
|
||||||
|
explored_luminances = [luminance(pixel) for pixel in explored_pixels]
|
||||||
|
explored_luminance = sum(explored_luminances) / len(explored_luminances)
|
||||||
|
if explored_luminance < 0.55:
|
||||||
|
fail(f"detected explored luminance {explored_luminance:.3f} is below 0.55")
|
||||||
|
explored_luminance = (
|
||||||
|
sum(luminance(pixel) for pixel in explored_pixels) / len(explored_pixels)
|
||||||
|
if explored_pixels
|
||||||
|
else 0.0
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
f"visual measurement: {path} "
|
||||||
|
f"dungeon_non_black_pixels={non_black} "
|
||||||
|
f"unknown_pixels={len(unknown_pixels)} unknown_luminance={unknown_luminance:.3f} "
|
||||||
|
f"explored_floor_pixels={len(explored_pixels)} "
|
||||||
|
f"detected_explored_luminance={explored_luminance:.3f}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
fail(f"usage: {Path(sys.argv[0]).name} CAPTURE.png")
|
||||||
|
capture = Path(sys.argv[1])
|
||||||
|
if not capture.is_file() or capture.stat().st_size == 0:
|
||||||
|
fail(f"missing or empty capture {capture}")
|
||||||
|
measure(capture)
|
||||||
@@ -2,7 +2,9 @@ class_name MapRenderer
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
const TILE_SIZE := Vector2i(32, 32)
|
const TILE_SIZE := Vector2i(32, 32)
|
||||||
const EXPLORED_DIM_COLOR := Color(0.35, 0.35, 0.35, 1.0)
|
const EXPLORED_DIM_COLOR := Color(0.9, 0.95, 1.0, 1.0)
|
||||||
|
const EXPLORED_OVERLAY_COLOR := Color(0.9, 0.95, 1.0, 0.85)
|
||||||
|
const UNKNOWN_COLOR := Color(0.015, 0.025, 0.07, 1.0)
|
||||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||||
const TEXTURES := {
|
const TEXTURES := {
|
||||||
GridMapStateType.CellKind.FLOOR: preload("res://assets/dcss/floor.png"),
|
GridMapStateType.CellKind.FLOOR: preload("res://assets/dcss/floor.png"),
|
||||||
@@ -42,7 +44,7 @@ func get_cell_render_color(cell: Vector2i) -> Color:
|
|||||||
&"explored":
|
&"explored":
|
||||||
return EXPLORED_DIM_COLOR
|
return EXPLORED_DIM_COLOR
|
||||||
_:
|
_:
|
||||||
return Color.BLACK
|
return UNKNOWN_COLOR
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
if map == null:
|
if map == null:
|
||||||
@@ -52,7 +54,10 @@ func _draw() -> void:
|
|||||||
var cell := Vector2i(x, y)
|
var cell := Vector2i(x, y)
|
||||||
var tile_rect := get_cell_rect(cell)
|
var tile_rect := get_cell_rect(cell)
|
||||||
var color := get_cell_render_color(cell)
|
var color := get_cell_render_color(cell)
|
||||||
if color == Color.BLACK:
|
if color == UNKNOWN_COLOR:
|
||||||
draw_rect(tile_rect, Color.BLACK)
|
draw_rect(tile_rect, UNKNOWN_COLOR)
|
||||||
|
elif color == EXPLORED_DIM_COLOR:
|
||||||
|
draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false)
|
||||||
|
draw_rect(tile_rect, EXPLORED_OVERLAY_COLOR)
|
||||||
else:
|
else:
|
||||||
draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false, color)
|
draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false, color)
|
||||||
|
|||||||
+16
-32
@@ -44,40 +44,24 @@ run_capture() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_capture() {
|
run_capture "initial" "capture"
|
||||||
local capture_path="$1"
|
run_capture "exit" "capture-exit"
|
||||||
if [[ ! -s "$capture_path" ]]; then
|
# Godot's SCRIPT ERROR / Parse Error diagnostics are actionable application
|
||||||
echo "visual check failed: missing capture $capture_path" >&2
|
# failures. Do not treat unrelated backend diagnostics (for example the
|
||||||
exit 1
|
# expected xkbcommon Compose warnings emitted by some Snap/Xvfb setups) as an
|
||||||
fi
|
# application failure.
|
||||||
if ! python3 - "$capture_path" <<'PY'
|
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
|
||||||
import struct
|
echo "visual check failed: Godot application error; see $log_path" >&2
|
||||||
import sys
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
path = sys.argv[1]
|
measure_capture() {
|
||||||
with open(path, "rb") as capture:
|
local capture_path="$1"
|
||||||
signature = capture.read(8)
|
if ! python3 "$root_dir/scripts/check-visual-capture.py" "$capture_path"; then
|
||||||
length = struct.unpack(">I", capture.read(4))[0]
|
echo "visual check failed: invalid or unreadable capture $capture_path" >&2
|
||||||
kind = capture.read(4)
|
|
||||||
data = capture.read(length)
|
|
||||||
if signature != b"\x89PNG\r\n\x1a\n" or kind != b"IHDR" or len(data) != 13:
|
|
||||||
raise SystemExit("invalid PNG")
|
|
||||||
width, height = struct.unpack(">II", data[:8])
|
|
||||||
if (width, height) != (1280, 720):
|
|
||||||
raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}")
|
|
||||||
print(f"visual capture: {path} ({width}x{height})")
|
|
||||||
PY
|
|
||||||
then
|
|
||||||
echo "visual check failed: capture is not a nonempty valid PNG" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_capture "initial" "capture"
|
measure_capture "$initial_capture_path"
|
||||||
run_capture "exit" "capture-exit"
|
measure_capture "$exit_capture_path"
|
||||||
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
|
|
||||||
echo "visual check failed: Godot reported errors; see $log_path" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
validate_capture "$initial_capture_path"
|
|
||||||
validate_capture "$exit_capture_path"
|
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ func test_real_game_updates_fog_after_public_action_and_preserves_opaque_fov() -
|
|||||||
assert_eq(renderer.get_cell_render_color(Vector2i(2, 9)), Color.WHITE)
|
assert_eq(renderer.get_cell_render_color(Vector2i(2, 9)), Color.WHITE)
|
||||||
assert_false(state.explored_cells.has(Vector2i(10, 9)))
|
assert_false(state.explored_cells.has(Vector2i(10, 9)))
|
||||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(10, 9)), &"unknown")
|
assert_eq(renderer.get_cell_visibility_state(Vector2i(10, 9)), &"unknown")
|
||||||
assert_eq(renderer.get_cell_render_color(Vector2i(10, 9)), Color.BLACK)
|
assert_eq(renderer.get_cell_render_color(Vector2i(10, 9)), renderer.UNKNOWN_COLOR)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
extends GutTest
|
||||||
|
|
||||||
|
const GameScene = preload("res://scenes/Game.tscn")
|
||||||
|
var game: Game
|
||||||
|
|
||||||
|
func before_each() -> void:
|
||||||
|
game = GameScene.instantiate()
|
||||||
|
add_child_autofree(game)
|
||||||
|
await get_tree().process_frame
|
||||||
|
|
||||||
|
func test_real_game_scene_exposes_readable_fov_zoom_and_compact_hud() -> void:
|
||||||
|
var renderer := game.get_node("World/MapRenderer") as MapRenderer
|
||||||
|
var camera := game.get_node("Camera2D") as Camera2D
|
||||||
|
var hud := game.get_node("HUD") as GameHud
|
||||||
|
var results := game.submit_test_action(Vector2i.DOWN)
|
||||||
|
var central_play_area := Rect2(300, 120, 680, 480)
|
||||||
|
|
||||||
|
assert_eq(results[0].kind, &"moved")
|
||||||
|
assert_eq(camera.zoom, Vector2(2.0, 2.0))
|
||||||
|
assert_gte(renderer.get_cell_render_color(Vector2i(8, 2)).get_luminance(), 0.55)
|
||||||
|
assert_eq(renderer.get_cell_render_color(Vector2i(10, 9)), renderer.UNKNOWN_COLOR)
|
||||||
|
for panel_name in [&"StatsPanel", &"LogPanel", &"PromptPanel", &"HelpPanel"]:
|
||||||
|
var panel := hud.get_node("ResponsiveLayout/" + String(panel_name)) as PanelContainer
|
||||||
|
assert_false(panel.get_global_rect().intersects(central_play_area), "%s obscures the central play area" % panel_name)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cjv47hqw8lbv6
|
||||||
@@ -27,11 +27,20 @@ if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
import zlib
|
||||||
|
|
||||||
os.makedirs("artifacts", exist_ok=True)
|
os.makedirs("artifacts", exist_ok=True)
|
||||||
|
width, height = 1280, 720
|
||||||
|
color = (199, 207, 217) if sys.argv[1].endswith("-exit.png") else (4, 6, 18)
|
||||||
|
scanlines = b"".join(b"\x00" + bytes(color) * width for _ in range(height))
|
||||||
|
def chunk(kind, data):
|
||||||
|
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)
|
||||||
|
png = b"\x89PNG\r\n\x1a\n"
|
||||||
|
png += chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0))
|
||||||
|
png += chunk(b"IDAT", zlib.compress(scanlines))
|
||||||
|
png += chunk(b"IEND", b"")
|
||||||
with open(f"artifacts/{sys.argv[1]}", "wb") as capture:
|
with open(f"artifacts/{sys.argv[1]}", "wb") as capture:
|
||||||
capture.write(b"\x89PNG\r\n\x1a\n")
|
capture.write(png)
|
||||||
capture.write(struct.pack(">I4sII5B", 13, b"IHDR", 1280, 720, 8, 2, 0, 0, 0))
|
|
||||||
PY
|
PY
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ func test_camera_tracks_player_after_a_valid_action_and_uses_map_limits() -> voi
|
|||||||
var state := game.get_game_state()
|
var state := game.get_game_state()
|
||||||
|
|
||||||
assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position)
|
assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position)
|
||||||
|
assert_eq(camera.zoom, Vector2(2.0, 2.0))
|
||||||
|
assert_eq(GameType.TILE_SIZE, Vector2i(32, 32))
|
||||||
|
assert_eq(MapRendererType.TILE_SIZE, Vector2i(32, 32))
|
||||||
assert_eq(camera.limit_left, 32)
|
assert_eq(camera.limit_left, 32)
|
||||||
assert_eq(camera.limit_top, 48)
|
assert_eq(camera.limit_top, 48)
|
||||||
assert_eq(camera.limit_right, 416)
|
assert_eq(camera.limit_right, 416)
|
||||||
|
|||||||
@@ -33,3 +33,18 @@ func test_hud_uses_viewport_anchored_panels_with_distinct_stats_and_log_zones()
|
|||||||
assert_true(stats_panel.get_global_rect().encloses(enemy_health.get_global_rect()))
|
assert_true(stats_panel.get_global_rect().encloses(enemy_health.get_global_rect()))
|
||||||
assert_true(log_panel.get_global_rect().encloses(event_log.get_global_rect()))
|
assert_true(log_panel.get_global_rect().encloses(event_log.get_global_rect()))
|
||||||
assert_false(stats_panel.get_global_rect().intersects(log_panel.get_global_rect()))
|
assert_false(stats_panel.get_global_rect().intersects(log_panel.get_global_rect()))
|
||||||
|
|
||||||
|
func test_compact_hud_leaves_a_dominant_unobstructed_central_play_area() -> void:
|
||||||
|
var hud := game.get_node("HUD") as GameHud
|
||||||
|
var stats_panel := hud.get_node("ResponsiveLayout/StatsPanel") as PanelContainer
|
||||||
|
var log_panel := hud.get_node("ResponsiveLayout/LogPanel") as PanelContainer
|
||||||
|
var prompt_panel := hud.get_node("ResponsiveLayout/PromptPanel") as PanelContainer
|
||||||
|
var help_panel := hud.get_node("ResponsiveLayout/HelpPanel") as PanelContainer
|
||||||
|
var panels: Array[PanelContainer] = [stats_panel, log_panel, prompt_panel, help_panel]
|
||||||
|
var occupied_area := 0.0
|
||||||
|
var central_play_area := Rect2(300, 120, 680, 480)
|
||||||
|
for panel in panels:
|
||||||
|
var panel_rect: Rect2 = panel.get_global_rect()
|
||||||
|
occupied_area += panel_rect.get_area()
|
||||||
|
assert_false(panel_rect.intersects(central_play_area), "%s obscures the central play area" % panel.name)
|
||||||
|
assert_lte(occupied_area, float(Game.REFERENCE_VIEWPORT.x * Game.REFERENCE_VIEWPORT.y) * 0.15)
|
||||||
|
|||||||
@@ -18,5 +18,9 @@ func test_game_synchronizes_renderer_visibility_states_after_movement() -> void:
|
|||||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(2, 9)), &"visible")
|
assert_eq(renderer.get_cell_visibility_state(Vector2i(2, 9)), &"visible")
|
||||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(10, 9)), &"unknown")
|
assert_eq(renderer.get_cell_visibility_state(Vector2i(10, 9)), &"unknown")
|
||||||
assert_eq(renderer.get_cell_render_color(Vector2i(8, 2)), renderer.EXPLORED_DIM_COLOR)
|
assert_eq(renderer.get_cell_render_color(Vector2i(8, 2)), renderer.EXPLORED_DIM_COLOR)
|
||||||
|
assert_gte(renderer.EXPLORED_DIM_COLOR.get_luminance(), 0.55)
|
||||||
assert_eq(renderer.get_cell_render_color(Vector2i(2, 9)), Color.WHITE)
|
assert_eq(renderer.get_cell_render_color(Vector2i(2, 9)), Color.WHITE)
|
||||||
assert_eq(renderer.get_cell_render_color(Vector2i(10, 9)), Color.BLACK)
|
assert_eq(renderer.get_cell_render_color(Vector2i(10, 9)), renderer.UNKNOWN_COLOR)
|
||||||
|
assert_ne(renderer.UNKNOWN_COLOR, renderer.EXPLORED_DIM_COLOR)
|
||||||
|
assert_lt(renderer.UNKNOWN_COLOR.get_luminance(), 0.1)
|
||||||
|
assert_gt(renderer.UNKNOWN_COLOR.b, renderer.UNKNOWN_COLOR.r)
|
||||||
|
|||||||
Reference in New Issue
Block a user