Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc9b5898a3 | ||
|
|
67efd9dc67 | ||
|
|
b5eaf0ef4f | ||
|
|
673c1c1257 | ||
|
|
4919369dba | ||
|
|
b5e520a682 | ||
|
|
df1451a45a | ||
|
|
97cb295f05 | ||
|
|
a834c9fb4f | ||
|
|
d1f16eee4d | ||
|
|
7798909c0b | ||
|
|
6eef939905 | ||
|
|
6aa91f3500 | ||
|
|
c16f648ce8 | ||
|
|
b0ce464a38 | ||
|
|
a8e59544ff | ||
|
|
b469c6decb | ||
|
|
e501dbccc6 | ||
|
|
5679ed3008 | ||
|
|
502492ffc0 | ||
|
|
7c2c08e180 | ||
|
|
929e5a394c | ||
|
|
515cf72594 | ||
|
|
68db197773 | ||
|
|
33acf27ced | ||
|
|
3be49f0277 |
@@ -1,3 +1,5 @@
|
||||
.godot/
|
||||
*.import
|
||||
artifacts/
|
||||
|
||||
.claude/
|
||||
|
||||
@@ -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.
|
||||
@@ -0,0 +1,71 @@
|
||||
# S6.2 — Carte démo 30×20, porte guidée et coffre ouvrable
|
||||
|
||||
- **Worktree :** `/home/hectelyon/Documents/Projects/ProjetsPersos/DungeonCrawlerWorld/.worktrees/s6-2`
|
||||
- **Spécification :** `.claude/work/dcw-s6-visual-readability/spec.md`, `SLICE-6-2-demo-map.md`
|
||||
- **Périmètre :** carte de démonstration, interactions porte/coffre/escalier et leurs tests. Aucun loot, inventaire, niveau supplémentaire ou asset nouveau.
|
||||
|
||||
## Livraison
|
||||
|
||||
- La carte initiale est une grille **30×20** de salles et couloirs. Le joueur commence en `(4, 12)`, devant la porte fermée `(4, 11)` ; le coffre est en `(4, 7)`, et l'escalier en `(18, 4)`.
|
||||
- Un coffre fermé est maintenant non praticable et opaque. Tenter d'y entrer renvoie donc `blocked`, sans tour ennemi.
|
||||
- `GameState.get_context_target()` et `InteractionResolver` partagent `InteractionResolver.TARGET_OFFSETS`. La priorité est : sortie déjà atteinte, escalier sous le joueur, coffre (sous le joueur ou dans l'ordre des offsets), porte, puis aucune interaction.
|
||||
- `Espace` et `E` ouvrent un coffre ciblé : `CHEST` devient `FLOOR`, le résultat est `chest_opened` avec le texte exact `You open the chest.`, l'exploration/FOV est recalculée et une seule réponse ennemie normale au plus est ajoutée.
|
||||
- Le HUD affiche exactement `Espace — Ouvrir le coffre` tant que le coffre est la cible de contexte. La documentation décrit aussi le comportement et l'absence volontaire de loot/inventaire.
|
||||
- Le parcours réel E2E utilise des `InputEvent` : porte (`E`, en conservant ainsi une preuve du binding alternatif), blocage sur coffre fermé, coffre (`Espace`, avec assertion explicite de `chest_opened` puis `FLOOR`), puis escalier (Espace).
|
||||
|
||||
## Couverture TDD
|
||||
|
||||
### RED historique reconstruit et durable
|
||||
|
||||
La preuve RED manquante a été reconstruite sur le baseline **`b5eaf0e`**, dans un worktree détaché, avant tout changement de production. Le test minimal crée une case `CHEST` adjacente et exige que `state.try_interact()` retourne `results[0].kind == &"chest_opened"`. Il échoue bien (statut 1) avec :
|
||||
|
||||
```text
|
||||
[STRING_NAME(nothing_to_interact)] expected to equal [STRING_NAME(chest_opened)]
|
||||
```
|
||||
|
||||
La source exacte et le journal GUT assaini sont versionnés ici afin que cette preuve reste consultable :
|
||||
|
||||
- `tdd-red-chest-contract-b5eaf0e.gd` ;
|
||||
- `tdd-red-chest-contract-b5eaf0e.txt`.
|
||||
|
||||
`./scripts/test-unit.sh` ne découvre volontairement que `res://tests/unit`; la reconstruction temporaire a donc été exécutée directement avec GUT et `-gdir=res://tests/tdd_red`, comme indiqué dans le journal. Le test GREEN permanent correspondant est `tests/unit/test_chest_interaction.gd`.
|
||||
|
||||
Les tests ajoutés couvrent les conditions des micro-tâches :
|
||||
|
||||
- M1 : dimensions 30×20, spawn et positions/route porte-coffre-escalier (`test_demo_map.gd`) ;
|
||||
- M2 : coffre fermé non praticable et mouvement bloqué sans réponse ennemie (`test_chest_interaction.gd`) ;
|
||||
- M3 : texte et durée du prompt coffre (`test_hud_chest_prompt.gd`) ;
|
||||
- M4 : `chest_opened`, texte exact, remplacement par sol, FOV et unique réponse ennemie (`test_chest_interaction.gd`) ;
|
||||
- M5 : scène `Game.tscn` et événements clavier réels pour le parcours intégral (`test_demo_map_chest_e2e.gd`) ; `E` reste vérifié sur la porte et `Espace` ouvre explicitement le coffre avec les assertions `chest_opened` et `FLOOR`.
|
||||
|
||||
`test_combat_hud_e2e.gd` rétablit les invariants de régression retirés lors de l'adaptation 30×20 : mur et porte bloqués sans tour ennemi, cellule joueur inchangée, dégâts/HP joueur et feedback visuel, messages du journal, HP et résumé de combat avant/après coup, puis suppression de la cible et résumé final après défaite.
|
||||
|
||||
Les tests existants adaptés à l'extension 30×20 conservent leurs invariants fonctionnels (combat, audio, FOV, caméra, HUD, porte et escalier) sans dépendre de l'ancien layout 12×10.
|
||||
|
||||
## Vérification finale
|
||||
|
||||
Exécutée avec Godot **4.5.0** (`/snap/bin/godot4`) :
|
||||
|
||||
```text
|
||||
./scripts/test-unit.sh PASS — 33 tests, 163 assertions
|
||||
./scripts/test-e2e.sh PASS — 12 tests, 147 assertions
|
||||
./scripts/run-visual-check.sh PASS — Xvfb, deux captures PNG 1280×720
|
||||
./scripts/verify.sh PASS — unit + E2E + visual
|
||||
|
||||
git diff --check PASS
|
||||
```
|
||||
|
||||
Le contrôle visuel Xvfb a produit et validé les captures ignorées `artifacts/visual-check.png` et `artifacts/visual-check-exit.png` :
|
||||
|
||||
```text
|
||||
initial : dungeon_non_black_pixels=489308, unknown_pixels=366972,
|
||||
unknown_luminance=0.002
|
||||
sortie : dungeon_non_black_pixels=488516, unknown_pixels=196792,
|
||||
unknown_luminance=0.002, detected_explored_luminance=0.815
|
||||
```
|
||||
|
||||
Les avertissements de ressources UID de GUT, `ObjectDB instances leaked at exit`, et les messages `xkbcommon` Compose de Snap/Xvfb sont des diagnostics préexistants/de l'environnement. Ils ne sont pas des `SCRIPT ERROR` ou `Parse Error`; aucune suite ne les a traités comme une erreur applicative.
|
||||
|
||||
## Git
|
||||
|
||||
Rapport finalisé avant le commit local S6.2. Aucun push ni PR.
|
||||
@@ -0,0 +1,23 @@
|
||||
# Historical RED reconstruction source
|
||||
#
|
||||
# Executed unchanged in a detached worktree at b5eaf0e with:
|
||||
# /snap/bin/godot4 --headless --path . -s res://addons/gut/gut_cmdln.gd \
|
||||
# -gdir=res://tests/tdd_red -gexit
|
||||
#
|
||||
# It is preserved as S6.2 TDD evidence rather than placed under tests/, because
|
||||
# its assertion intentionally fails before chest interaction is implemented.
|
||||
extends GutTest
|
||||
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
|
||||
func test_interacting_with_a_chest_reports_chest_opened() -> void:
|
||||
var chest := Vector2i(3, 2)
|
||||
var map := GridMapState.new(Vector2i(9, 7), GridMapState.CellKind.FLOOR)
|
||||
map.set_cell(chest, GridMapState.CellKind.CHEST)
|
||||
var state := GameState.new(map, ActorState.new(&"player", Vector2i(3, 3), 12, 3), {})
|
||||
|
||||
var results := state.try_interact()
|
||||
|
||||
assert_eq(results[0].kind, &"chest_opened")
|
||||
@@ -0,0 +1,43 @@
|
||||
S6.2 historical TDD RED reconstruction
|
||||
=======================================
|
||||
|
||||
Baseline revision: b5eaf0e
|
||||
Detached worktree: /home/hectelyon/Documents/Projects/ProjetsPersos/DungeonCrawlerWorld/.worktrees/s6-2-chest-red-b5eaf0e
|
||||
Test source preserved beside this log as tdd-red-chest-contract-b5eaf0e.gd.
|
||||
|
||||
Command (run from the detached b5eaf0e worktree):
|
||||
/snap/bin/godot4 --headless --path . -s res://addons/gut/gut_cmdln.gd \
|
||||
-gdir=res://tests/tdd_red -gexit
|
||||
|
||||
Exit status: 1 (expected RED)
|
||||
|
||||
Relevant sanitized GUT output:
|
||||
|
||||
res://tests/tdd_red/test_chest_contract_red.gd
|
||||
* test_interacting_with_a_chest_reports_chest_opened
|
||||
[Failed]: [STRING_NAME(nothing_to_interact)] expected to equal [STRING_NAME(chest_opened)]:
|
||||
at line 15
|
||||
0/1 passed.
|
||||
|
||||
==============================================
|
||||
= Run Summary
|
||||
==============================================
|
||||
|
||||
res://tests/tdd_red/test_chest_contract_red.gd
|
||||
- test_interacting_with_a_chest_reports_chest_opened
|
||||
[Failed]: [STRING_NAME(nothing_to_interact)] expected to equal [STRING_NAME(chest_opened)]:
|
||||
at line 15
|
||||
|
||||
Totals
|
||||
------
|
||||
Scripts 1
|
||||
Tests 1
|
||||
Passing Tests none
|
||||
Failing Tests 1
|
||||
Asserts 0/1
|
||||
|
||||
---- 1 failing tests ----
|
||||
|
||||
Note: ./scripts/test-unit.sh intentionally targets res://tests/unit only, so it
|
||||
cannot execute this temporary res://tests/tdd_red reconstruction. The direct
|
||||
GUT command above is therefore the authoritative RED command.
|
||||
@@ -10,7 +10,17 @@ Godot 4.2+ is required (verified with Godot 4.5). GUT **9.5.0** is vendored and
|
||||
"${GODOT_BIN:-$(command -v godot4 || command -v godot)}" --path .
|
||||
```
|
||||
|
||||
Use WASD / arrow keys (and QEZC diagonals). `Game.submit_test_action(Vector2i)` is the deterministic public E2E seam and follows the same action processor as keyboard input.
|
||||
Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French labels `Déplacer : ZQSD / Flèches` and `Interagir : Espace ou E`; both **Space** and **E** are bound to `interact`. `Game.submit_test_action(Vector2i)` and `Game.submit_test_interact()` are deterministic public E2E seams and follow the same processors as keyboard input. Interacting with an adjacent closed door opens it into floor space, logs the action, refreshes FOV, and gives living enemies exactly one normal response. A closed chest is likewise non-walkable; interacting with it replaces it with floor, logs `chest_opened` as `You open the chest.`, refreshes FOV, and gives at most one normal enemy response. It deliberately grants no loot or inventory item. Interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. Interacting while standing on stairs logs `stairs_used`, sets the demonstration exit state, and gives living enemies exactly one normal response.
|
||||
|
||||
## Display, grid, and camera
|
||||
|
||||
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, 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
|
||||
|
||||
The S5.1 contract—1280×720 reference viewport, actor rectangle, and camera behavior—is covered by the dedicated tests and visual capture check. This note records coverage only; it does not assert an execution result.
|
||||
|
||||
## Optional ASCII audio layout
|
||||
|
||||
@@ -50,7 +60,9 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh
|
||||
GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh
|
||||
```
|
||||
|
||||
`run-visual-check.sh` runs the actual project with `--capture`, waits for it to render, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a nonempty valid PNG. It chooses `xvfb-run` 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.
|
||||
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`. 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:
|
||||
|
||||
@@ -60,15 +72,35 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path .
|
||||
|
||||
## 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.
|
||||
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state.
|
||||
- `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()`: stairs under the player take priority and read `Espace — Descendre l’escalier`; otherwise an adjacent closed chest reads `Espace — Ouvrir le coffre` before an adjacent closed door can read `Espace — Ouvrir la porte`; 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.
|
||||
- Every `melee` and `enemy_melee` result is routed to its actor view; the sprite's persistent red tint makes received damage visible.
|
||||
|
||||
## Exports
|
||||
|
||||
Install the matching Godot export templates, then configure/export the project in the Godot editor for **Linux/X11** or **Windows Desktop**. Linux builds may be tested on a Linux host with the resulting executable. Windows exports can be produced from Linux when the export templates are installed, but this project does **not** claim that a Windows export has been tested on Windows.
|
||||
Install the Godot 4.5 export templates matching the editor/runtime, then open `project.godot` in the Godot editor and use **Project → Export**.
|
||||
|
||||
### Linux/X11
|
||||
|
||||
1. Add or select a **Linux/X11** preset.
|
||||
2. Choose an output path such as `build/linux/DungeonCrawlerWorld.x86_64` and click **Export Project**.
|
||||
3. On Linux, make the binary executable if necessary, then launch it:
|
||||
|
||||
```bash
|
||||
chmod +x build/linux/DungeonCrawlerWorld.x86_64
|
||||
./build/linux/DungeonCrawlerWorld.x86_64
|
||||
```
|
||||
|
||||
### Windows Desktop
|
||||
|
||||
1. Add or select a **Windows Desktop** preset.
|
||||
2. Choose an output path such as `build/windows/DungeonCrawlerWorld.exe` and click **Export Project**.
|
||||
3. Distribute the exported `.exe` with its generated `.pck` file when Godot produces one.
|
||||
|
||||
Windows exports can be produced from Linux when the matching templates are installed, but this project does **not** claim that a Windows export has been tested on Windows.
|
||||
|
||||
## Limits
|
||||
|
||||
This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets.
|
||||
This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets. Reaching the stairs is a demonstration-only exit: it sets `exit_reached` and displays `Sortie atteinte — prochain étage bientôt disponible`; **no next level is generated or loaded**, and the current player and map remain unchanged.
|
||||
|
||||
@@ -16,3 +16,13 @@ The S4 prototype may discover admitted audio filenames under the configured ASCI
|
||||
## Verification coverage
|
||||
|
||||
Unit and E2E coverage create both a structurally nominal WAV and a truncated/invalid WAV in the external layout. They assert discovery remains diagnostic-only, neither file is playable through the public API, and combat still resolves normally. The README now states that discovery does not promise readability or playback.
|
||||
|
||||
## S5.1 RED evidence reconstruction
|
||||
|
||||
On base `515cf72`, a test referencing `Game.REFERENCE_VIEWPORT` produced:
|
||||
|
||||
```text
|
||||
SCRIPT ERROR: Parse Error: Cannot find member REFERENCE_VIEWPORT in base Game
|
||||
```
|
||||
|
||||
The runner exited with status `1`.
|
||||
|
||||
+7
-4
@@ -7,10 +7,12 @@ config/name="Dungeon Crawler World"
|
||||
run/main_scene="res://scenes/Game.tscn"
|
||||
|
||||
[display]
|
||||
window/size/viewport_width=640
|
||||
window/size/viewport_height=480
|
||||
window/size/window_width_override=640
|
||||
window/size/window_height_override=480
|
||||
window/size/viewport_width=1280
|
||||
window/size/viewport_height=720
|
||||
window/size/window_width_override=1280
|
||||
window/size/window_height_override=720
|
||||
window/size/resizable=true
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
[rendering]
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
@@ -22,6 +24,7 @@ textures/canvas_textures/default_texture_filter=0
|
||||
enabled=PackedStringArray("res://addons/gut/plugin.cfg")
|
||||
|
||||
[input]
|
||||
interact={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":32),Object(InputEventKey,"physical_keycode":69)]}
|
||||
move_north={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":87),Object(InputEventKey,"physical_keycode":4194320)]}
|
||||
move_south={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":83),Object(InputEventKey,"physical_keycode":4194322)]}
|
||||
move_west={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":65),Object(InputEventKey,"physical_keycode":4194319)]}
|
||||
|
||||
+164
-18
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=6 format=3]
|
||||
[gd_scene load_steps=8 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/game/game.gd" id="1_game"]
|
||||
[ext_resource type="Script" path="res://scripts/presentation/map_renderer.gd" id="2_map"]
|
||||
@@ -7,6 +7,34 @@
|
||||
[ext_resource type="Texture2D" path="res://assets/dcss/player.png" id="5_player"]
|
||||
[ext_resource type="Script" path="res://scripts/infrastructure/audio_library.gd" id="6_audio"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_hud_panel"]
|
||||
bg_color = Color(0.035, 0.055, 0.09, 0.9)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.25, 0.48, 0.62, 0.9)
|
||||
corner_radius_top_left = 6
|
||||
corner_radius_top_right = 6
|
||||
corner_radius_bottom_right = 6
|
||||
corner_radius_bottom_left = 6
|
||||
content_margin_left = 12.0
|
||||
content_margin_top = 8.0
|
||||
content_margin_right = 12.0
|
||||
content_margin_bottom = 8.0
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_prompt_panel"]
|
||||
bg_color = Color(0.08, 0.12, 0.16, 0.94)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.82, 0.66, 0.25, 0.95)
|
||||
corner_radius_top_left = 6
|
||||
corner_radius_top_right = 6
|
||||
corner_radius_bottom_right = 6
|
||||
corner_radius_bottom_left = 6
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_game")
|
||||
|
||||
@@ -26,41 +54,159 @@ script = ExtResource("3_actor")
|
||||
[node name="Enemies" type="Node2D" parent="World"]
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(320, 240)
|
||||
zoom = Vector2(2, 2)
|
||||
position_smoothing_enabled = false
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="."]
|
||||
layer = 1
|
||||
script = ExtResource("4_hud")
|
||||
|
||||
[node name="PlayerHealthLabel" type="Label" parent="HUD"]
|
||||
[node name="ResponsiveLayout" type="Control" parent="HUD"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="StatsPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 12.0
|
||||
offset_top = 10.0
|
||||
offset_right = 220.0
|
||||
offset_bottom = 35.0
|
||||
offset_top = 12.0
|
||||
offset_right = 248.0
|
||||
offset_bottom = 94.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="LogPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -256.0
|
||||
offset_top = 12.0
|
||||
offset_right = -12.0
|
||||
offset_bottom = 170.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="PromptPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -280.0
|
||||
offset_top = -90.0
|
||||
offset_right = 280.0
|
||||
offset_bottom = -52.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_prompt_panel")
|
||||
|
||||
[node name="HelpPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 12.0
|
||||
offset_top = -42.0
|
||||
offset_right = -12.0
|
||||
offset_bottom = -12.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="PlayerHealthLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 26.0
|
||||
offset_right = 236.0
|
||||
offset_bottom = 46.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="EnemyHealthLabel" type="Label" parent="HUD"]
|
||||
offset_left = 12.0
|
||||
offset_top = 35.0
|
||||
offset_right = 240.0
|
||||
offset_bottom = 60.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 48.0
|
||||
offset_right = 236.0
|
||||
offset_bottom = 68.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.8, 0.7, 1)
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="CombatSummaryLabel" type="Label" parent="HUD"]
|
||||
offset_left = 12.0
|
||||
offset_top = 60.0
|
||||
offset_right = 300.0
|
||||
offset_bottom = 85.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 70.0
|
||||
offset_right = 236.0
|
||||
offset_bottom = 90.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
|
||||
theme_override_font_sizes/font_size = 16
|
||||
|
||||
[node name="EventLog" type="RichTextLabel" parent="HUD"]
|
||||
offset_left = 410.0
|
||||
offset_top = 285.0
|
||||
offset_right = 630.0
|
||||
offset_bottom = 470.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -244.0
|
||||
offset_top = 22.0
|
||||
offset_right = -24.0
|
||||
offset_bottom = 158.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
bbcode_enabled = false
|
||||
fit_content = false
|
||||
theme_override_colors/default_color = Color(1, 1, 0.8, 1)
|
||||
theme_override_font_sizes/normal_font_size = 14
|
||||
|
||||
[node name="ContextPromptLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -266.0
|
||||
offset_top = -85.0
|
||||
offset_right = 266.0
|
||||
offset_bottom = -57.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.92, 0.63, 1)
|
||||
theme_override_font_sizes/font_size = 16
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="HelpLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 28.0
|
||||
offset_top = -37.0
|
||||
offset_right = -28.0
|
||||
offset_bottom = -17.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(0.82, 0.9, 1, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E"
|
||||
horizontal_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,12 +2,14 @@ class_name GameState
|
||||
extends RefCounted
|
||||
|
||||
const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd")
|
||||
const InteractionResolverType = preload("res://scripts/domain/interaction_resolver.gd")
|
||||
|
||||
var player: ActorState
|
||||
var enemies: Dictionary[StringName, ActorState]
|
||||
var map: GridMapState
|
||||
var visible_cells: Dictionary[Vector2i, bool] = {}
|
||||
var explored_cells: Dictionary[Vector2i, bool] = {}
|
||||
var exit_reached := false
|
||||
|
||||
func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionary[StringName, ActorState]) -> void:
|
||||
map = new_map
|
||||
@@ -15,11 +17,30 @@ func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionar
|
||||
enemies = new_enemies
|
||||
update_exploration()
|
||||
|
||||
func get_context_target() -> StringName:
|
||||
if exit_reached:
|
||||
return &"exit_reached"
|
||||
if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS:
|
||||
return &"stairs"
|
||||
for direction in InteractionResolverType.TARGET_OFFSETS:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CHEST:
|
||||
return &"chest"
|
||||
for direction in InteractionResolverType.TARGET_OFFSETS:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CLOSED_DOOR:
|
||||
return &"closed_door"
|
||||
return &""
|
||||
|
||||
func try_player_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
var results := TurnResolverType.resolve_player_action(self, direction)
|
||||
update_exploration()
|
||||
return results
|
||||
|
||||
func try_interact() -> Array[TurnResult]:
|
||||
var results := InteractionResolverType.resolve(self)
|
||||
if results[0].kind != &"nothing_to_interact":
|
||||
update_exploration()
|
||||
return results
|
||||
|
||||
func compute_visible_cells(game_map: GridMapState, origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]:
|
||||
var visible: Dictionary[Vector2i, bool] = {}
|
||||
for y in range(origin.y - radius, origin.y + radius + 1):
|
||||
|
||||
@@ -25,8 +25,8 @@ func is_inside(cell: Vector2i) -> bool:
|
||||
|
||||
func is_walkable(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
return kind == CellKind.FLOOR or kind == CellKind.CHEST or kind == CellKind.STAIRS
|
||||
return kind == CellKind.FLOOR or kind == CellKind.STAIRS
|
||||
|
||||
func is_opaque(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
return kind == CellKind.WALL or kind == CellKind.CLOSED_DOOR
|
||||
return kind == CellKind.WALL or kind == CellKind.CLOSED_DOOR or kind == CellKind.CHEST
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
class_name InteractionResolver
|
||||
extends RefCounted
|
||||
|
||||
const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd")
|
||||
const TurnResultType = preload("res://scripts/domain/turn_result.gd")
|
||||
|
||||
const TARGET_OFFSETS: Array[Vector2i] = [
|
||||
Vector2i.ZERO,
|
||||
Vector2i.UP,
|
||||
Vector2i.RIGHT,
|
||||
Vector2i.DOWN,
|
||||
Vector2i.LEFT,
|
||||
Vector2i(1, -1),
|
||||
Vector2i(1, 1),
|
||||
Vector2i(-1, 1),
|
||||
Vector2i(-1, -1),
|
||||
]
|
||||
|
||||
static func resolve(state: GameState) -> Array[TurnResult]:
|
||||
var results: Array[TurnResult] = []
|
||||
if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS and not state.exit_reached:
|
||||
state.exit_reached = true
|
||||
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var chest_cell := _find_cell_of_kind(state, GridMapState.CellKind.CHEST)
|
||||
if chest_cell.x >= 0:
|
||||
state.map.set_cell(chest_cell, GridMapState.CellKind.FLOOR)
|
||||
results.append(TurnResultType.new(state.player.id, &"chest_opened", state.player.cell, chest_cell, &"", 0, "You open the chest."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var door_cell := _find_cell_of_kind(state, GridMapState.CellKind.CLOSED_DOOR)
|
||||
if door_cell.x >= 0:
|
||||
state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR)
|
||||
results.append(TurnResultType.new(state.player.id, &"door_opened", state.player.cell, door_cell, &"", 0, "You open the door."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
results.append(TurnResultType.new(state.player.id, &"nothing_to_interact", state.player.cell, state.player.cell, &"", 0, "Nothing to interact with."))
|
||||
return results
|
||||
|
||||
static func _find_cell_of_kind(state: GameState, kind: GridMapState.CellKind) -> Vector2i:
|
||||
for offset in TARGET_OFFSETS:
|
||||
var cell := state.player.cell + offset
|
||||
if state.map.get_cell(cell) == kind:
|
||||
return cell
|
||||
return Vector2i(-1, -1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bhmjqespb8gnp
|
||||
@@ -17,7 +17,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra
|
||||
state.enemies.erase(enemy.id)
|
||||
results.append(TurnResultType.new(enemy.id, &"enemy_defeated", enemy.cell, enemy.cell, player.id, 0, "The goblin is defeated."))
|
||||
else:
|
||||
_append_enemy_response(state, results)
|
||||
append_enemy_response(state, results)
|
||||
return results
|
||||
if not state.map.is_walkable(destination):
|
||||
results.append(TurnResultType.new(player.id, &"blocked", player.cell, destination, &"", 0, "Your way is blocked."))
|
||||
@@ -25,7 +25,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra
|
||||
var from: Vector2i = player.cell
|
||||
player.cell = destination
|
||||
results.append(TurnResultType.new(player.id, &"moved", from, destination, &"", 0, "You move to (%d, %d)." % [destination.x, destination.y]))
|
||||
_append_enemy_response(state, results)
|
||||
append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState:
|
||||
@@ -34,7 +34,7 @@ static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState:
|
||||
return enemy
|
||||
return null
|
||||
|
||||
static func _append_enemy_response(state: GameState, results: Array[TurnResult]) -> void:
|
||||
static func append_enemy_response(state: GameState, results: Array[TurnResult]) -> void:
|
||||
for enemy: ActorState in state.enemies.values():
|
||||
var delta: Vector2i = state.player.cell - enemy.cell
|
||||
if abs(delta.x) + abs(delta.y) == 1:
|
||||
|
||||
+103
-26
@@ -1,6 +1,7 @@
|
||||
class_name Game
|
||||
extends Node2D
|
||||
|
||||
const REFERENCE_VIEWPORT := Vector2i(1280, 720)
|
||||
const TILE_SIZE := Vector2i(32, 32)
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
@@ -9,60 +10,111 @@ const ActorViewType = preload("res://scripts/presentation/actor_view.gd")
|
||||
@onready var map_renderer: MapRenderer = $World/MapRenderer
|
||||
@onready var player_view: ActorView = $World/Player
|
||||
@onready var enemies: Node2D = $World/Enemies
|
||||
@onready var camera: Camera2D = $Camera2D
|
||||
@onready var hud: GameHud = $HUD
|
||||
@onready var audio_library = $AudioLibrary
|
||||
var game_state: GameState
|
||||
var enemy_views: Dictionary[StringName, ActorView] = {}
|
||||
var last_turn_results: Array[TurnResult] = []
|
||||
|
||||
func _ready() -> void:
|
||||
game_state = _create_initial_state()
|
||||
map_renderer.set_map(game_state.map)
|
||||
_sync_map_renderer_visibility()
|
||||
player_view.set_actor(game_state.player)
|
||||
_configure_camera()
|
||||
_sync_enemy_views()
|
||||
hud.refresh(game_state)
|
||||
audio_library.set_ambience_context("exploration")
|
||||
if "--capture" in OS.get_cmdline_user_args():
|
||||
_capture_visual_check()
|
||||
var capture_mode := _get_capture_mode()
|
||||
if not capture_mode.is_empty():
|
||||
_capture_visual_check(capture_mode)
|
||||
|
||||
func _capture_visual_check() -> void:
|
||||
func _get_capture_mode() -> String:
|
||||
var arguments := OS.get_cmdline_user_args()
|
||||
if "--capture-exit" in arguments:
|
||||
return "exit"
|
||||
if "--capture" in arguments:
|
||||
return "initial"
|
||||
return ""
|
||||
|
||||
func _capture_visual_check(capture_mode: String) -> void:
|
||||
if capture_mode == "exit":
|
||||
_prepare_exit_capture_state()
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await RenderingServer.frame_post_draw
|
||||
var capture_path := ProjectSettings.globalize_path("res://artifacts/visual-check.png")
|
||||
var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png"
|
||||
var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename)
|
||||
DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir())
|
||||
var image := get_viewport().get_texture().get_image()
|
||||
var result := image.save_png(capture_path)
|
||||
get_tree().quit(0 if result == OK else 1)
|
||||
|
||||
func _prepare_exit_capture_state() -> void:
|
||||
game_state.map.set_cell(Vector2i(4, 10), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = Vector2i(18, 4)
|
||||
_process_interact()
|
||||
_sync_camera_to_player()
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"move_north"):
|
||||
_process_action(Vector2i.UP)
|
||||
if event.is_action_pressed(&"interact"):
|
||||
last_turn_results = submit_test_interact()
|
||||
elif event.is_action_pressed(&"move_north"):
|
||||
last_turn_results = _process_action(Vector2i.UP)
|
||||
elif event.is_action_pressed(&"move_south"):
|
||||
_process_action(Vector2i.DOWN)
|
||||
last_turn_results = _process_action(Vector2i.DOWN)
|
||||
elif event.is_action_pressed(&"move_west"):
|
||||
_process_action(Vector2i.LEFT)
|
||||
last_turn_results = _process_action(Vector2i.LEFT)
|
||||
elif event.is_action_pressed(&"move_east"):
|
||||
_process_action(Vector2i.RIGHT)
|
||||
last_turn_results = _process_action(Vector2i.RIGHT)
|
||||
elif event.is_action_pressed(&"move_northwest"):
|
||||
_process_action(Vector2i(-1, -1))
|
||||
last_turn_results = _process_action(Vector2i(-1, -1))
|
||||
elif event.is_action_pressed(&"move_northeast"):
|
||||
_process_action(Vector2i(1, -1))
|
||||
last_turn_results = _process_action(Vector2i(1, -1))
|
||||
elif event.is_action_pressed(&"move_southwest"):
|
||||
_process_action(Vector2i(-1, 1))
|
||||
last_turn_results = _process_action(Vector2i(-1, 1))
|
||||
elif event.is_action_pressed(&"move_southeast"):
|
||||
_process_action(Vector2i(1, 1))
|
||||
last_turn_results = _process_action(Vector2i(1, 1))
|
||||
|
||||
func submit_test_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
return _process_action(direction)
|
||||
|
||||
func submit_test_interact() -> Array[TurnResult]:
|
||||
return _process_interact()
|
||||
|
||||
func get_game_state() -> GameState:
|
||||
return game_state
|
||||
|
||||
func get_actor_cell_rect(actor_id: StringName) -> Rect2:
|
||||
if actor_id == &"player":
|
||||
return player_view.get_cell_rect()
|
||||
if enemy_views.has(actor_id):
|
||||
return enemy_views[actor_id].get_cell_rect()
|
||||
return Rect2()
|
||||
|
||||
func _process_interact() -> Array[TurnResult]:
|
||||
if game_state.get_context_target() == &"exit_reached":
|
||||
return _refresh_hud_for_context()
|
||||
var results := game_state.try_interact()
|
||||
_sync_map_renderer_visibility()
|
||||
player_view.refresh()
|
||||
_sync_enemy_views()
|
||||
_show_damage_feedback(results)
|
||||
_dispatch_audio(results)
|
||||
hud.refresh(game_state, results)
|
||||
return results
|
||||
|
||||
func _refresh_hud_for_context() -> Array[TurnResult]:
|
||||
hud.refresh(game_state)
|
||||
return []
|
||||
|
||||
func _process_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
var results := game_state.try_player_action(direction)
|
||||
_sync_map_renderer_visibility()
|
||||
player_view.refresh()
|
||||
_sync_camera_to_player()
|
||||
_sync_enemy_views()
|
||||
_show_damage_feedback(results)
|
||||
_dispatch_audio(results)
|
||||
@@ -89,21 +141,46 @@ func _show_damage_feedback(results: Array[TurnResult]) -> void:
|
||||
player_view.show_damage(result.damage)
|
||||
|
||||
func _create_initial_state() -> GameState:
|
||||
var map := GridMapStateType.new(Vector2i(12, 10), GridMapStateType.CellKind.FLOOR)
|
||||
for x in range(map.size.x):
|
||||
map.set_cell(Vector2i(x, 0), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(x, map.size.y - 1), GridMapStateType.CellKind.WALL)
|
||||
for y in range(map.size.y):
|
||||
map.set_cell(Vector2i(0, y), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(map.size.x - 1, y), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(1, 2), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
map.set_cell(Vector2i(8, 3), GridMapStateType.CellKind.CHEST)
|
||||
map.set_cell(Vector2i(9, 7), GridMapStateType.CellKind.STAIRS)
|
||||
var player := ActorStateType.new(&"player", Vector2i(2, 2), 12, 3)
|
||||
var goblin := ActorStateType.new(&"goblin", Vector2i(4, 2), 6, 2)
|
||||
var map := GridMapStateType.new(Vector2i(30, 20), GridMapStateType.CellKind.WALL)
|
||||
_carve_room(map, Rect2i(2, 12, 6, 5))
|
||||
_carve_room(map, Rect2i(2, 4, 7, 7))
|
||||
_carve_room(map, Rect2i(10, 2, 10, 6))
|
||||
_carve_room(map, Rect2i(21, 5, 7, 8))
|
||||
_carve_vertical_corridor(map, 4, 10, 12)
|
||||
_carve_horizontal_corridor(map, 8, 10, 6)
|
||||
_carve_horizontal_corridor(map, 18, 21, 6)
|
||||
_carve_vertical_corridor(map, 18, 4, 6)
|
||||
map.set_cell(Vector2i(4, 11), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.CHEST)
|
||||
map.set_cell(Vector2i(18, 4), GridMapStateType.CellKind.STAIRS)
|
||||
var player := ActorStateType.new(&"player", Vector2i(4, 12), 12, 3)
|
||||
var goblin := ActorStateType.new(&"goblin", Vector2i(24, 8), 6, 2)
|
||||
return GameStateType.new(map, player, {&"goblin": goblin})
|
||||
|
||||
func _carve_room(map: GridMapState, room: Rect2i) -> void:
|
||||
for y in range(room.position.y, room.end.y):
|
||||
for x in range(room.position.x, room.end.x):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_horizontal_corridor(map: GridMapState, from_x: int, to_x: int, y: int) -> void:
|
||||
for x in range(from_x, to_x + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_vertical_corridor(map: GridMapState, x: int, from_y: int, to_y: int) -> void:
|
||||
for y in range(from_y, to_y + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _configure_camera() -> void:
|
||||
var map_size := game_state.map.size * TILE_SIZE
|
||||
camera.limit_left = $World.position.x
|
||||
camera.limit_top = $World.position.y
|
||||
camera.limit_right = $World.position.x + map_size.x
|
||||
camera.limit_bottom = $World.position.y + map_size.y
|
||||
_sync_camera_to_player()
|
||||
|
||||
func _sync_camera_to_player() -> void:
|
||||
camera.position = $World.position + Vector2(game_state.player.cell * TILE_SIZE)
|
||||
|
||||
func _sync_map_renderer_visibility() -> void:
|
||||
map_renderer.set_visibility(game_state.visible_cells, game_state.explored_cells)
|
||||
|
||||
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$root_dir"
|
||||
|
||||
GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}"
|
||||
if [[ ! -x "$GODOT_BIN" ]]; then
|
||||
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
|
||||
fi
|
||||
: "${GODOT_BIN:?Set GODOT_BIN or install godot4/godot}"
|
||||
|
||||
"$GODOT_BIN" --headless --path . --import
|
||||
@@ -6,6 +6,13 @@ const DAMAGE_MODULATE := Color(1.0, 0.45, 0.45, 1.0)
|
||||
var actor: ActorState
|
||||
var last_damage := 0
|
||||
|
||||
func _init() -> void:
|
||||
centered = false
|
||||
|
||||
func get_cell_rect() -> Rect2:
|
||||
var local_image_rect := get_rect()
|
||||
return Rect2(position + local_image_rect.position, local_image_rect.size)
|
||||
|
||||
func set_actor(new_actor: ActorState) -> void:
|
||||
actor = new_actor
|
||||
refresh()
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
class_name GameHud
|
||||
extends CanvasLayer
|
||||
|
||||
const DOOR_PROMPT := "Espace — Ouvrir la porte"
|
||||
const CHEST_PROMPT := "Espace — Ouvrir le coffre"
|
||||
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
|
||||
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
|
||||
|
||||
@onready var player_health_label: Label = $PlayerHealthLabel
|
||||
@onready var enemy_health_label: Label = $EnemyHealthLabel
|
||||
@onready var combat_summary_label: Label = $CombatSummaryLabel
|
||||
@onready var event_log: RichTextLabel = $EventLog
|
||||
@onready var context_prompt_label: Label = $ContextPromptLabel
|
||||
var combat_summary := ""
|
||||
var _state: GameState
|
||||
|
||||
func refresh(state: GameState, results: Array[TurnResult] = []) -> void:
|
||||
_state = state
|
||||
player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points]
|
||||
if state.enemies.has(&"goblin"):
|
||||
var goblin: ActorState = state.enemies[&"goblin"]
|
||||
@@ -17,5 +25,21 @@ func refresh(state: GameState, results: Array[TurnResult] = []) -> void:
|
||||
enemy_health_label.text = "No active target"
|
||||
combat_summary = "No active target"
|
||||
combat_summary_label.text = combat_summary
|
||||
context_prompt_label.text = get_context_prompt()
|
||||
for result in results:
|
||||
event_log.append_text(result.message + "\n")
|
||||
|
||||
func get_context_prompt() -> String:
|
||||
if _state == null:
|
||||
return ""
|
||||
match _state.get_context_target():
|
||||
&"chest":
|
||||
return CHEST_PROMPT
|
||||
&"closed_door":
|
||||
return DOOR_PROMPT
|
||||
&"stairs":
|
||||
return STAIRS_PROMPT
|
||||
&"exit_reached":
|
||||
return EXIT_REACHED_PROMPT
|
||||
_:
|
||||
return ""
|
||||
|
||||
@@ -2,7 +2,9 @@ class_name MapRenderer
|
||||
extends Node2D
|
||||
|
||||
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 TEXTURES := {
|
||||
GridMapStateType.CellKind.FLOOR: preload("res://assets/dcss/floor.png"),
|
||||
@@ -16,6 +18,9 @@ var map: GridMapState
|
||||
var _visible_cells: Dictionary[Vector2i, bool] = {}
|
||||
var _explored_cells: Dictionary[Vector2i, bool] = {}
|
||||
|
||||
func get_cell_rect(cell: Vector2i) -> Rect2:
|
||||
return Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE))
|
||||
|
||||
func set_map(new_map: GridMapState) -> void:
|
||||
map = new_map
|
||||
queue_redraw()
|
||||
@@ -39,7 +44,7 @@ func get_cell_render_color(cell: Vector2i) -> Color:
|
||||
&"explored":
|
||||
return EXPLORED_DIM_COLOR
|
||||
_:
|
||||
return Color.BLACK
|
||||
return UNKNOWN_COLOR
|
||||
|
||||
func _draw() -> void:
|
||||
if map == null:
|
||||
@@ -47,9 +52,12 @@ func _draw() -> void:
|
||||
for y in range(map.size.y):
|
||||
for x in range(map.size.x):
|
||||
var cell := Vector2i(x, y)
|
||||
var tile_rect := Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE))
|
||||
var tile_rect := get_cell_rect(cell)
|
||||
var color := get_cell_render_color(cell)
|
||||
if color == Color.BLACK:
|
||||
draw_rect(tile_rect, Color.BLACK)
|
||||
if color == UNKNOWN_COLOR:
|
||||
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:
|
||||
draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false, color)
|
||||
|
||||
+38
-37
@@ -12,55 +12,56 @@ if [[ -z "$GODOT_BIN" ]]; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
"$root_dir/scripts/godot-import.sh"
|
||||
|
||||
mkdir -p artifacts
|
||||
log_path="artifacts/visual-check.log"
|
||||
capture_path="artifacts/visual-check.png"
|
||||
rm -f "$capture_path"
|
||||
initial_capture_path="artifacts/visual-check.png"
|
||||
exit_capture_path="artifacts/visual-check-exit.png"
|
||||
rm -f "$initial_capture_path" "$exit_capture_path"
|
||||
: > "$log_path"
|
||||
|
||||
runner=()
|
||||
if [[ -z "${DISPLAY:-}" ]]; then
|
||||
if command -v xvfb-run >/dev/null 2>&1; then
|
||||
runner=(xvfb-run --auto-servernum --server-args="-screen 0 640x480x24")
|
||||
runner=(xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24")
|
||||
else
|
||||
echo "visual check unavailable: DISPLAY is unset and xvfb-run is not installed" | tee "$log_path" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
set +e
|
||||
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
if (( status != 0 )); then
|
||||
echo "visual check failed: Godot exited with status $status; see $log_path" >&2
|
||||
exit "$status"
|
||||
fi
|
||||
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
|
||||
if [[ ! -s "$capture_path" ]]; then
|
||||
echo "visual check failed: missing capture $capture_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! python3 - "$capture_path" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
run_capture() {
|
||||
local label="$1"
|
||||
local capture_argument="$2"
|
||||
set +e
|
||||
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1
|
||||
local status=$?
|
||||
set -e
|
||||
if (( status != 0 )); then
|
||||
echo "visual check failed: $label capture Godot exited with status $status; see $log_path" >&2
|
||||
exit "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
path = sys.argv[1]
|
||||
with open(path, "rb") as capture:
|
||||
signature = capture.read(8)
|
||||
length = struct.unpack(">I", capture.read(4))[0]
|
||||
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 == 0 or height == 0:
|
||||
raise SystemExit("empty PNG")
|
||||
print(f"visual capture: {path} ({width}x{height})")
|
||||
PY
|
||||
then
|
||||
echo "visual check failed: capture is not a nonempty valid PNG" >&2
|
||||
run_capture "initial" "capture"
|
||||
run_capture "exit" "capture-exit"
|
||||
# Godot's SCRIPT ERROR / Parse Error diagnostics are actionable application
|
||||
# failures. Do not treat unrelated backend diagnostics (for example the
|
||||
# expected xkbcommon Compose warnings emitted by some Snap/Xvfb setups) as an
|
||||
# application failure.
|
||||
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
|
||||
echo "visual check failed: Godot application error; see $log_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
measure_capture() {
|
||||
local capture_path="$1"
|
||||
if ! python3 "$root_dir/scripts/check-visual-capture.py" "$capture_path"; then
|
||||
echo "visual check failed: invalid or unreadable capture $capture_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
measure_capture "$initial_capture_path"
|
||||
measure_capture "$exit_capture_path"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
"$script_dir/godot-import.sh"
|
||||
|
||||
GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}"
|
||||
if [[ ! -x "$GODOT_BIN" ]]; then
|
||||
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
"$script_dir/godot-import.sh"
|
||||
|
||||
GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}"
|
||||
if [[ ! -x "$GODOT_BIN" ]]; then
|
||||
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
|
||||
|
||||
@@ -9,27 +9,26 @@ func before_each() -> void:
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_configured_input_event_uses_the_same_action_path_as_submit_test_action() -> void:
|
||||
var state := game.get_game_state()
|
||||
var input_event := InputEventKey.new()
|
||||
input_event.physical_keycode = KEY_DOWN
|
||||
input_event.pressed = true
|
||||
game._unhandled_input(input_event)
|
||||
|
||||
assert_eq(game.get_game_state().player.cell, Vector2i(2, 3))
|
||||
assert_eq(game.get_node("HUD/EventLog").get_parsed_text(), "You move to (2, 3).\nThe goblin moves.\n")
|
||||
assert_eq(state.player.cell, Vector2i(4, 13))
|
||||
assert_eq(game.get_node("HUD/EventLog").get_parsed_text(), "You move to (4, 13).\nThe goblin moves.\n")
|
||||
|
||||
var submitted_game := GameScene.instantiate() as Game
|
||||
add_child_autofree(submitted_game)
|
||||
await get_tree().process_frame
|
||||
var test_results := submitted_game.submit_test_action(Vector2i.DOWN)
|
||||
|
||||
assert_eq(submitted_game.get_game_state().player.cell, Vector2i(2, 3))
|
||||
assert_eq(submitted_game.get_game_state().player.cell, Vector2i(4, 13))
|
||||
assert_eq(test_results.size(), 2)
|
||||
assert_eq(test_results[0].kind, &"moved")
|
||||
assert_eq(test_results[0].from_cell, Vector2i(2, 2))
|
||||
assert_eq(test_results[0].to_cell, Vector2i(2, 3))
|
||||
assert_eq(test_results[0].from_cell, Vector2i(4, 12))
|
||||
assert_eq(test_results[0].to_cell, Vector2i(4, 13))
|
||||
assert_eq(test_results[1].kind, &"enemy_moved")
|
||||
assert_eq(test_results[1].from_cell, Vector2i(4, 2))
|
||||
assert_eq(test_results[1].to_cell, Vector2i(3, 2))
|
||||
|
||||
func test_real_game_scene_completes_walking_combat_and_defeat_route() -> void:
|
||||
assert_not_null(game.get_node_or_null("World/MapRenderer"))
|
||||
@@ -47,22 +46,30 @@ func test_real_game_scene_completes_walking_combat_and_defeat_route() -> void:
|
||||
var enemy_view := game.get_node("World/Enemies/Goblin") as ActorView
|
||||
assert_eq(hud.combat_summary, "Target: Goblin HP: 6/6")
|
||||
assert_eq(hud.combat_summary_label.text, "Target: Goblin HP: 6/6")
|
||||
|
||||
# The new spawn is beside a wall and a closed door; neither consumes a turn.
|
||||
var start := state.player.cell
|
||||
var wall := game.submit_test_action(Vector2i.LEFT)
|
||||
var wall := game.submit_test_action(Vector2i(-1, -1))
|
||||
assert_eq(wall.size(), 1)
|
||||
assert_eq(wall[0].kind, &"blocked")
|
||||
assert_eq(state.player.cell, start)
|
||||
var door := game.submit_test_action(Vector2i.UP)
|
||||
assert_eq(door.size(), 1)
|
||||
assert_eq(door[0].kind, &"blocked")
|
||||
assert_eq(state.player.cell, start)
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "blocked")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "Your way is blocked.")
|
||||
|
||||
# Move the existing goblin onto the adapted combat lane after the map assertions.
|
||||
state.enemies[&"goblin"].cell = start + Vector2i(2, 0)
|
||||
var movement := game.submit_test_action(Vector2i.RIGHT)
|
||||
assert_eq(movement[0].kind, &"moved")
|
||||
assert_eq(state.player.cell, start + Vector2i.RIGHT)
|
||||
assert_eq(movement[1].kind, &"enemy_melee")
|
||||
assert_eq(player_view.last_damage, 2)
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "You move")
|
||||
assert_string_contains(game.get_node("HUD/PlayerHealthLabel").text, "10/12")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "You move to (5, 12).")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "The goblin hits you for 2.")
|
||||
|
||||
var first_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
assert_eq(first_melee[0].kind, &"melee")
|
||||
assert_eq(first_melee[1].kind, &"enemy_melee")
|
||||
@@ -72,6 +79,7 @@ func test_real_game_scene_completes_walking_combat_and_defeat_route() -> void:
|
||||
assert_eq(hud.combat_summary, "Target: Goblin HP: 3/6")
|
||||
assert_eq(hud.combat_summary_label.text, "Target: Goblin HP: 3/6")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "You strike the goblin for 3.")
|
||||
|
||||
var lethal_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
assert_eq(lethal_melee[0].kind, &"melee")
|
||||
assert_eq(lethal_melee[1].kind, &"enemy_defeated")
|
||||
@@ -82,4 +90,4 @@ func test_real_game_scene_completes_walking_combat_and_defeat_route() -> void:
|
||||
assert_eq(game.get_node("HUD/EnemyHealthLabel").text, "No active target")
|
||||
assert_eq(hud.combat_summary, "No active target")
|
||||
assert_eq(hud.combat_summary_label.text, "No active target")
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "defeated")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "The goblin is defeated.")
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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_input_opens_door_then_chest_and_preserves_stairs_route() -> void:
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
state.enemies.erase(&"goblin")
|
||||
|
||||
assert_eq(state.map.size, Vector2i(30, 20))
|
||||
assert_eq(prompt_label.text, "Espace — Ouvrir la porte")
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(game.last_turn_results[0].kind, &"door_opened")
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 11)), GridMapState.CellKind.FLOOR)
|
||||
|
||||
for keycode in [KEY_UP, KEY_UP, KEY_UP, KEY_UP]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
assert_eq(state.player.cell, Vector2i(4, 8))
|
||||
assert_eq(prompt_label.text, "Espace — Ouvrir le coffre")
|
||||
game._unhandled_input(_key_event(KEY_UP))
|
||||
assert_eq(state.player.cell, Vector2i(4, 8))
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 7)), GridMapState.CellKind.CHEST)
|
||||
assert_string_contains(event_log.get_parsed_text(), "Your way is blocked.")
|
||||
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
assert_eq(game.last_turn_results[0].kind, &"chest_opened")
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 7)), GridMapState.CellKind.FLOOR)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the chest.")
|
||||
game._unhandled_input(_key_event(KEY_UP))
|
||||
assert_eq(state.player.cell, Vector2i(4, 7))
|
||||
|
||||
for keycode in [KEY_UP, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_UP, KEY_UP]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
assert_true(state.exit_reached)
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://dtkblrbmeb1u6
|
||||
@@ -0,0 +1,32 @@
|
||||
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_keyboard_movement_keeps_actor_in_cell_and_updates_camera_without_moving_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 CanvasLayer
|
||||
var state := game.get_game_state()
|
||||
var player_health_label := game.get_node("HUD/PlayerHealthLabel") as Label
|
||||
var hud_screen_position: Vector2 = player_health_label.get_global_rect().position
|
||||
var start_cell := state.player.cell
|
||||
|
||||
assert_eq(Game.REFERENCE_VIEWPORT, Vector2i(1280, 720))
|
||||
assert_true(renderer.get_cell_rect(start_cell).encloses(game.get_actor_cell_rect(&"player")))
|
||||
|
||||
var keyboard_event := InputEventKey.new()
|
||||
keyboard_event.physical_keycode = KEY_DOWN
|
||||
keyboard_event.pressed = true
|
||||
game._unhandled_input(keyboard_event)
|
||||
|
||||
assert_eq(state.player.cell, start_cell + Vector2i.DOWN)
|
||||
assert_true(renderer.get_cell_rect(state.player.cell).encloses(game.get_actor_cell_rect(&"player")))
|
||||
assert_eq(camera.position, game.get_node("World").position + Vector2(state.player.cell * Game.TILE_SIZE))
|
||||
assert_eq(hud.layer, 1)
|
||||
assert_eq(game.get_node("HUD/PlayerHealthLabel").get_global_rect().position, hud_screen_position)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c28a5drwhxg56
|
||||
@@ -0,0 +1,50 @@
|
||||
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_input_map_binds_space_and_e_to_interact() -> void:
|
||||
assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_SPACE)))
|
||||
assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_E)))
|
||||
|
||||
func test_real_game_keyboard_space_and_test_seam_open_door_then_allow_walking_through_it() -> void:
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
var door_cell := Vector2i(4, 11)
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
|
||||
assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
assert_eq(prompt_label.text, "")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the door.")
|
||||
|
||||
var move_results := game.submit_test_action(Vector2i.UP)
|
||||
assert_eq(move_results[0].kind, &"moved")
|
||||
assert_eq(state.player.cell, door_cell)
|
||||
|
||||
var submitted_game := GameScene.instantiate() as Game
|
||||
add_child_autofree(submitted_game)
|
||||
await get_tree().process_frame
|
||||
var submitted_results: Array[TurnResult] = submitted_game.submit_test_interact()
|
||||
assert_eq(submitted_results[0].kind, &"door_opened")
|
||||
assert_eq(submitted_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
|
||||
var e_game := GameScene.instantiate() as Game
|
||||
add_child_autofree(e_game)
|
||||
await get_tree().process_frame
|
||||
e_game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(e_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxsgdgfxa8ke3
|
||||
@@ -0,0 +1,48 @@
|
||||
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_input_event_completes_door_to_stairs_exit_without_replacing_the_current_map() -> void:
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
var initial_map := state.map
|
||||
var initial_map_size := state.map.size
|
||||
state.enemies.erase(&"goblin")
|
||||
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 11)), GridMapState.CellKind.FLOOR)
|
||||
for keycode in [KEY_UP, KEY_UP, KEY_UP, KEY_UP]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
assert_eq(state.player.cell, Vector2i(4, 8))
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
for keycode in [KEY_UP, KEY_UP, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_UP, KEY_UP]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the door.")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
assert_same(state.map, initial_map)
|
||||
assert_eq(state.map.size, initial_map_size)
|
||||
assert_eq(state.map.get_cell(Vector2i(18, 4)), GridMapState.CellKind.STAIRS)
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://c1iiybjl4f1bi
|
||||
@@ -11,21 +11,22 @@ func before_each() -> void:
|
||||
func test_real_game_updates_fog_after_public_action_and_preserves_opaque_fov() -> void:
|
||||
var renderer := game.get_node("World/MapRenderer") as MapRenderer
|
||||
var state := game.get_game_state()
|
||||
var opaque_obstacle := Vector2i(1, 2)
|
||||
var cell_behind_obstacle := Vector2i(0, 2)
|
||||
var opaque_obstacle := Vector2i(4, 11)
|
||||
var cell_behind_obstacle := Vector2i(4, 10)
|
||||
assert_true(state.visible_cells.has(opaque_obstacle))
|
||||
assert_false(state.visible_cells.has(cell_behind_obstacle))
|
||||
|
||||
var results := game.submit_test_action(Vector2i.DOWN)
|
||||
game.submit_test_interact()
|
||||
var results := game.submit_test_action(Vector2i.UP)
|
||||
|
||||
assert_eq(results[0].kind, &"moved")
|
||||
assert_true(state.explored_cells.has(Vector2i(8, 2)))
|
||||
assert_false(state.visible_cells.has(Vector2i(8, 2)))
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(8, 2)), &"explored")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(8, 2)), renderer.EXPLORED_DIM_COLOR)
|
||||
assert_true(state.visible_cells.has(Vector2i(2, 9)))
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(2, 9)), &"visible")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(2, 9)), Color.WHITE)
|
||||
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_render_color(Vector2i(10, 9)), Color.BLACK)
|
||||
assert_true(state.explored_cells.has(Vector2i(1, 12)))
|
||||
assert_false(state.visible_cells.has(Vector2i(1, 12)))
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(1, 12)), &"explored")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(1, 12)), renderer.EXPLORED_DIM_COLOR)
|
||||
assert_true(state.visible_cells.has(Vector2i(4, 17)))
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(4, 17)), &"visible")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(4, 17)), Color.WHITE)
|
||||
assert_false(state.explored_cells.has(Vector2i(29, 19)))
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(29, 19)), &"unknown")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(29, 19)), renderer.UNKNOWN_COLOR)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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_exposes_door_and_stairs_prompts_with_help_and_event_log() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
var help_label := game.get_node("HUD/HelpLabel") as Label
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
|
||||
assert_eq(prompt_label.text, "Espace — Ouvrir la porte")
|
||||
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
|
||||
assert_string_contains(help_label.text, "Interagir : Espace ou E")
|
||||
|
||||
var interact_event := InputEventKey.new()
|
||||
interact_event.keycode = KEY_SPACE
|
||||
interact_event.physical_keycode = KEY_SPACE
|
||||
interact_event.pressed = true
|
||||
game._unhandled_input(interact_event)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 11)), GridMapState.CellKind.FLOOR)
|
||||
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
var stairs_results := game.submit_test_interact()
|
||||
assert_eq(stairs_results[0].kind, &"stairs_used")
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
|
||||
var results := game.submit_test_action(Vector2i.LEFT)
|
||||
assert_eq(results[0].kind, &"moved")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You move to")
|
||||
@@ -0,0 +1 @@
|
||||
uid://buopjv13wyxnx
|
||||
@@ -28,6 +28,8 @@ func after_each() -> void:
|
||||
func test_real_game_resolves_combat_with_empty_audio_home() -> void:
|
||||
var audio = game.get_node("AudioLibrary")
|
||||
|
||||
var state := game.get_game_state()
|
||||
state.enemies[&"goblin"].cell = state.player.cell + Vector2i(2, 0)
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
var first_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
var lethal_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
@@ -58,6 +60,8 @@ func test_external_nominal_and_invalid_wavs_do_not_affect_combat() -> void:
|
||||
invalid_file.store_string("truncated WAV")
|
||||
invalid_file.close()
|
||||
|
||||
var state := game.get_game_state()
|
||||
state.enemies[&"goblin"].cell = state.player.cell + Vector2i(2, 0)
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
var first_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
var lethal_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
|
||||
@@ -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(4, 12)).get_luminance(), 0.55)
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(29, 19)), 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
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
tmp_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp_dir"' EXIT
|
||||
project_dir="$tmp_dir/project"
|
||||
cp -a "$root_dir" "$project_dir"
|
||||
rm -rf "$project_dir/.git" "$project_dir/.godot" "$project_dir/artifacts"
|
||||
|
||||
fake_godot="$tmp_dir/godot4"
|
||||
cat > "$fake_godot" <<'FAKE_GODOT'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
printf '%s\n' "$*" >> "$FAKE_GODOT_LOG"
|
||||
if [[ " $* " == *" --import "* ]]; then
|
||||
printf '%s\n' "fake import output" >&2
|
||||
exit "${FAKE_IMPORT_STATUS:-0}"
|
||||
fi
|
||||
if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then
|
||||
if [[ " $* " == *" --capture-exit "* ]]; then
|
||||
capture_name="visual-check-exit.png"
|
||||
else
|
||||
capture_name="visual-check.png"
|
||||
fi
|
||||
python3 - "$capture_name" <<'PY'
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
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:
|
||||
capture.write(png)
|
||||
PY
|
||||
fi
|
||||
exit 0
|
||||
FAKE_GODOT
|
||||
chmod +x "$fake_godot"
|
||||
|
||||
assert_import_precedes_run() {
|
||||
local runner="$1"
|
||||
local log="$tmp_dir/${runner}.log"
|
||||
FAKE_GODOT_LOG="$log" GODOT_BIN="$fake_godot" DISPLAY=:99 "$project_dir/scripts/$runner"
|
||||
local first_line
|
||||
first_line="$(head -n 1 "$log")"
|
||||
[[ "$first_line" == *"--headless"* && "$first_line" == *"--import"* ]] || {
|
||||
echo "$runner did not invoke headless import before its runner command" >&2
|
||||
return 1
|
||||
}
|
||||
[[ "$(wc -l < "$log")" -ge 2 ]] || {
|
||||
echo "$runner did not invoke its runner command after importing" >&2
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
assert_import_precedes_run test-unit.sh
|
||||
assert_import_precedes_run test-e2e.sh
|
||||
assert_import_precedes_run run-visual-check.sh
|
||||
|
||||
failure_log="$tmp_dir/import-failure.log"
|
||||
set +e
|
||||
failure_output="$(FAKE_GODOT_LOG="$failure_log" FAKE_IMPORT_STATUS=42 GODOT_BIN="$fake_godot" "$project_dir/scripts/test-unit.sh" 2>&1)"
|
||||
failure_status=$?
|
||||
set -e
|
||||
[[ "$failure_status" -eq 42 ]] || {
|
||||
echo "test-unit.sh did not return the import failure status" >&2
|
||||
exit 1
|
||||
}
|
||||
[[ "$failure_output" == *"fake import output"* ]] || {
|
||||
echo "test-unit.sh did not preserve import error output" >&2
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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_actor_render_rect_is_contained_in_its_grid_cell_before_and_after_movement() -> void:
|
||||
var renderer := game.get_node("World/MapRenderer") as MapRenderer
|
||||
var player_view := game.get_node("World/Player") as ActorView
|
||||
var state := game.get_game_state()
|
||||
|
||||
assert_true(renderer.get_cell_rect(state.player.cell).encloses(player_view.get_cell_rect()))
|
||||
|
||||
game.submit_test_action(Vector2i.DOWN)
|
||||
|
||||
assert_true(renderer.get_cell_rect(state.player.cell).encloses(player_view.get_cell_rect()))
|
||||
@@ -0,0 +1 @@
|
||||
uid://bqgnlfyvec5v7
|
||||
@@ -0,0 +1,49 @@
|
||||
extends GutTest
|
||||
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
|
||||
func _state_with_chest(chest: Vector2i, player: Vector2i = Vector2i(3, 3)) -> GameState:
|
||||
var map := GridMapState.new(Vector2i(9, 7), GridMapState.CellKind.FLOOR)
|
||||
map.set_cell(chest, GridMapState.CellKind.CHEST)
|
||||
return GameState.new(map, ActorState.new(&"player", player, 12, 3), {&"goblin": ActorState.new(&"goblin", Vector2i(7, 3), 6, 2)})
|
||||
|
||||
func test_closed_chest_is_not_walkable_and_movement_is_blocked_without_an_enemy_turn() -> void:
|
||||
var state := _state_with_chest(Vector2i(4, 3))
|
||||
|
||||
var results := state.try_player_action(Vector2i.RIGHT)
|
||||
|
||||
assert_false(state.map.is_walkable(Vector2i(4, 3)))
|
||||
assert_eq(results.size(), 1)
|
||||
assert_eq(results[0].kind, &"blocked")
|
||||
assert_eq(state.player.cell, Vector2i(3, 3))
|
||||
|
||||
func test_chest_is_the_context_target_before_doors_but_stairs_keep_priority() -> void:
|
||||
var state := _state_with_chest(Vector2i(3, 2))
|
||||
state.map.set_cell(Vector2i(4, 3), GridMapState.CellKind.CLOSED_DOOR)
|
||||
assert_eq(state.get_context_target(), &"chest")
|
||||
|
||||
state.map.set_cell(state.player.cell, GridMapState.CellKind.STAIRS)
|
||||
assert_eq(state.get_context_target(), &"stairs")
|
||||
|
||||
func test_opening_chest_replaces_it_with_floor_refreshes_fov_and_gets_one_enemy_response() -> void:
|
||||
var chest := Vector2i(3, 2)
|
||||
var revealed := Vector2i(3, 1)
|
||||
var state := _state_with_chest(chest)
|
||||
state.map.set_cell(revealed, GridMapState.CellKind.FLOOR)
|
||||
assert_false(state.visible_cells.has(revealed))
|
||||
|
||||
var results := state.try_interact()
|
||||
var enemy_response_count := 0
|
||||
for result in results:
|
||||
if String(result.kind).begins_with("enemy_"):
|
||||
enemy_response_count += 1
|
||||
|
||||
assert_eq(results[0].kind, &"chest_opened")
|
||||
assert_eq(results[0].message, "You open the chest.")
|
||||
assert_eq(results[0].to_cell, chest)
|
||||
assert_eq(state.map.get_cell(chest), GridMapState.CellKind.FLOOR)
|
||||
assert_true(state.map.is_walkable(chest))
|
||||
assert_true(state.visible_cells.has(revealed))
|
||||
assert_eq(enemy_response_count, 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b13pnjogahauk
|
||||
@@ -12,6 +12,8 @@ func test_combat_routes_damage_feedback_and_exposes_current_target_summary() ->
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var player_view := game.get_node("World/Player") as ActorView
|
||||
var enemy_view := game.get_node("World/Enemies/Goblin") as ActorView
|
||||
var state := game.get_game_state()
|
||||
state.enemies[&"goblin"].cell = state.player.cell + Vector2i(2, 0)
|
||||
|
||||
assert_eq(hud.combat_summary, "Target: Goblin HP: 6/6")
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_initial_demo_map_is_30_by_20_with_a_known_door_chest_and_stairs_route() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var state := game.get_game_state()
|
||||
|
||||
assert_eq(state.map.size, Vector2i(30, 20))
|
||||
assert_eq(state.player.cell, Vector2i(4, 12))
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 11)), GridMapState.CellKind.CLOSED_DOOR)
|
||||
assert_eq(state.map.get_cell(Vector2i(4, 7)), GridMapState.CellKind.CHEST)
|
||||
assert_eq(state.map.get_cell(Vector2i(18, 4)), GridMapState.CellKind.STAIRS)
|
||||
for cell in [Vector2i(4, 10), Vector2i(4, 8), Vector2i(4, 6), Vector2i(10, 4), Vector2i(17, 4)]:
|
||||
assert_true(state.map.is_walkable(cell), "Expected the demo route to include %s." % cell)
|
||||
@@ -0,0 +1 @@
|
||||
uid://v5xlp310damm
|
||||
@@ -0,0 +1,40 @@
|
||||
extends GutTest
|
||||
|
||||
const GameType = preload("res://scripts/game/game.gd")
|
||||
const MapRendererType = preload("res://scripts/presentation/map_renderer.gd")
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_reference_viewport_and_project_window_settings_are_1280_by_720() -> void:
|
||||
assert_eq(GameType.REFERENCE_VIEWPORT, Vector2i(1280, 720))
|
||||
assert_eq(ProjectSettings.get_setting("display/window/size/viewport_width"), 1280)
|
||||
assert_eq(ProjectSettings.get_setting("display/window/size/viewport_height"), 720)
|
||||
assert_eq(ProjectSettings.get_setting("display/window/size/window_width_override"), 1280)
|
||||
assert_eq(ProjectSettings.get_setting("display/window/size/window_height_override"), 720)
|
||||
assert_eq(ProjectSettings.get_setting("display/window/size/resizable"), true)
|
||||
assert_eq(ProjectSettings.get_setting("display/window/stretch/mode"), "canvas_items")
|
||||
|
||||
func test_map_renderer_returns_the_contract_cell_rectangle() -> void:
|
||||
var renderer := MapRendererType.new()
|
||||
add_child_autofree(renderer)
|
||||
|
||||
assert_eq(renderer.get_cell_rect(Vector2i(2, 3)), Rect2(64, 96, 32, 32))
|
||||
|
||||
func test_camera_tracks_player_after_a_valid_action_and_uses_map_limits() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var camera := game.get_node("Camera2D") as Camera2D
|
||||
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.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_top, 48)
|
||||
assert_eq(camera.limit_right, 992)
|
||||
assert_eq(camera.limit_bottom, 688)
|
||||
|
||||
game.submit_test_action(Vector2i.DOWN)
|
||||
|
||||
assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cypvomhwmn2qt
|
||||
@@ -0,0 +1,64 @@
|
||||
extends GutTest
|
||||
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
|
||||
func make_state() -> GameState:
|
||||
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
|
||||
var player := ActorState.new(&"player", Vector2i(3, 3), 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
|
||||
return GameState.new(map, player, {&"goblin": goblin})
|
||||
|
||||
func test_try_interact_opens_the_first_closed_door_in_contract_neighbour_order() -> void:
|
||||
var state := make_state()
|
||||
var north := state.player.cell + Vector2i.UP
|
||||
var east := state.player.cell + Vector2i.RIGHT
|
||||
state.map.set_cell(north, GridMapState.CellKind.CLOSED_DOOR)
|
||||
state.map.set_cell(east, GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
|
||||
assert_eq(results.size(), 2)
|
||||
assert_eq(results[0].kind, &"door_opened")
|
||||
assert_eq(results[0].from_cell, state.player.cell)
|
||||
assert_eq(results[0].to_cell, north)
|
||||
assert_eq(state.map.get_cell(north), GridMapState.CellKind.FLOOR)
|
||||
assert_eq(state.map.get_cell(east), GridMapState.CellKind.CLOSED_DOOR)
|
||||
assert_eq(state.player.cell, Vector2i(3, 3))
|
||||
|
||||
func test_try_interact_without_a_target_only_reports_nothing_and_does_not_take_a_turn() -> void:
|
||||
var state := make_state()
|
||||
state.enemies[&"goblin"].cell = Vector2i(4, 3)
|
||||
var player_cell := state.player.cell
|
||||
var player_hp := state.player.hit_points
|
||||
var enemy_cell := state.enemies[&"goblin"].cell
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
|
||||
assert_eq(results.size(), 1)
|
||||
assert_eq(results[0].kind, &"nothing_to_interact")
|
||||
assert_eq(state.player.cell, player_cell)
|
||||
assert_eq(state.player.hit_points, player_hp)
|
||||
assert_eq(state.enemies[&"goblin"].cell, enemy_cell)
|
||||
|
||||
func test_opening_a_door_recalculates_fov_and_triggers_exactly_one_enemy_response() -> void:
|
||||
var map := GridMapState.new(Vector2i(7, 5), GridMapState.CellKind.FLOOR)
|
||||
var door := Vector2i(2, 2)
|
||||
var revealed_cell := Vector2i(3, 2)
|
||||
map.set_cell(door, GridMapState.CellKind.CLOSED_DOOR)
|
||||
var player := ActorState.new(&"player", Vector2i(1, 2), 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(5, 2), 6, 2)
|
||||
var state := GameState.new(map, player, {&"goblin": goblin})
|
||||
assert_false(state.visible_cells.has(revealed_cell))
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
var enemy_result_count := 0
|
||||
for result in results:
|
||||
if String(result.kind).begins_with("enemy_"):
|
||||
enemy_result_count += 1
|
||||
|
||||
assert_eq(results[0].kind, &"door_opened")
|
||||
assert_eq(state.map.get_cell(door), GridMapState.CellKind.FLOOR)
|
||||
assert_true(state.visible_cells.has(revealed_cell))
|
||||
assert_eq(enemy_result_count, 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://fbwhwqumcr76
|
||||
@@ -0,0 +1,19 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_hud_shows_exact_chest_prompt_only_while_the_chest_is_a_context_target() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(4, 8)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir le coffre")
|
||||
|
||||
state.player.cell = Vector2i(4, 10)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
@@ -0,0 +1 @@
|
||||
uid://bibs6suuqqgne
|
||||
@@ -0,0 +1,50 @@
|
||||
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_help_band_displays_the_exact_control_labels() -> void:
|
||||
var help_label := game.get_node_or_null("HUD/HelpLabel") as Label
|
||||
|
||||
assert_not_null(help_label)
|
||||
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
|
||||
assert_string_contains(help_label.text, "Interagir : Espace ou E")
|
||||
|
||||
func test_hud_uses_viewport_anchored_panels_with_distinct_stats_and_log_zones() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
||||
var stats_panel := hud.get_node_or_null("ResponsiveLayout/StatsPanel") as PanelContainer
|
||||
var log_panel := hud.get_node_or_null("ResponsiveLayout/LogPanel") as PanelContainer
|
||||
var player_health := hud.get_node("PlayerHealthLabel") as Label
|
||||
var enemy_health := hud.get_node("EnemyHealthLabel") as Label
|
||||
var event_log := hud.get_node("EventLog") as RichTextLabel
|
||||
|
||||
assert_not_null(layout)
|
||||
assert_eq(layout.anchor_right, 1.0)
|
||||
assert_eq(layout.anchor_bottom, 1.0)
|
||||
assert_not_null(stats_panel)
|
||||
assert_not_null(log_panel)
|
||||
assert_true(stats_panel.get_global_rect().encloses(player_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_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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dwanrbia4j6kf
|
||||
@@ -0,0 +1,38 @@
|
||||
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_context_prompt_describes_an_adjacent_closed_door_without_mutating_the_map() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
var door_cell := Vector2i(4, 11)
|
||||
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
|
||||
assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
func test_context_prompt_describes_stairs_under_player_and_nothing_else() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
|
||||
state.map.set_cell(state.player.cell, GridMapState.CellKind.FLOOR)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
|
||||
func test_context_prompt_describes_a_reached_exit() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
|
||||
state.exit_reached = true
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
@@ -0,0 +1 @@
|
||||
uid://t7qoojk6djxm
|
||||
@@ -10,13 +10,18 @@ func before_each() -> void:
|
||||
|
||||
func test_game_synchronizes_renderer_visibility_states_after_movement() -> void:
|
||||
var renderer := game.get_node("World/MapRenderer") as MapRenderer
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(2, 2)), &"visible")
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(1, 12)), &"visible")
|
||||
|
||||
game.submit_test_action(Vector2i.DOWN)
|
||||
game.submit_test_interact()
|
||||
game.submit_test_action(Vector2i.UP)
|
||||
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(8, 2)), &"explored")
|
||||
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_render_color(Vector2i(8, 2)), renderer.EXPLORED_DIM_COLOR)
|
||||
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_visibility_state(Vector2i(1, 12)), &"explored")
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(4, 17)), &"visible")
|
||||
assert_eq(renderer.get_cell_visibility_state(Vector2i(29, 19)), &"unknown")
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(1, 12)), renderer.EXPLORED_DIM_COLOR)
|
||||
assert_gte(renderer.EXPLORED_DIM_COLOR.get_luminance(), 0.55)
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(4, 17)), Color.WHITE)
|
||||
assert_eq(renderer.get_cell_render_color(Vector2i(29, 19)), 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)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
extends GutTest
|
||||
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_interacting_on_stairs_reaches_the_exit_emits_stairs_used_and_keeps_the_map_and_player() -> void:
|
||||
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
|
||||
var stairs := Vector2i(3, 3)
|
||||
map.set_cell(stairs, GridMapState.CellKind.STAIRS)
|
||||
var player := ActorState.new(&"player", stairs, 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
|
||||
var state := GameState.new(map, player, {&"goblin": goblin})
|
||||
var player_cell := state.player.cell
|
||||
var map_size := state.map.size
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(results[0].kind, &"stairs_used")
|
||||
assert_eq(results[0].from_cell, stairs)
|
||||
assert_eq(results[0].to_cell, stairs)
|
||||
assert_eq(results[0].message, "You descend the stairs.")
|
||||
assert_eq(state.player.cell, player_cell)
|
||||
assert_same(state.map, map)
|
||||
assert_eq(state.map.size, map_size)
|
||||
assert_eq(state.map.get_cell(stairs), GridMapState.CellKind.STAIRS)
|
||||
|
||||
func test_stairs_usage_triggers_exactly_one_enemy_response_without_transitioning_the_level() -> void:
|
||||
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
|
||||
var stairs := Vector2i(3, 3)
|
||||
map.set_cell(stairs, GridMapState.CellKind.STAIRS)
|
||||
var player := ActorState.new(&"player", stairs, 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
|
||||
var state := GameState.new(map, player, {&"goblin": goblin})
|
||||
var enemy_response_count := 0
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
for result in results:
|
||||
if String(result.kind).begins_with("enemy_"):
|
||||
enemy_response_count += 1
|
||||
|
||||
assert_eq(results.size(), 2)
|
||||
assert_eq(results[0].kind, &"stairs_used")
|
||||
assert_eq(enemy_response_count, 1)
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(state.player.cell, stairs)
|
||||
assert_same(state.map, map)
|
||||
|
||||
func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
|
||||
var results := game.submit_test_interact()
|
||||
|
||||
assert_eq(results[0].kind, &"stairs_used")
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
@@ -0,0 +1 @@
|
||||
uid://2h0jb4bg7qfi
|
||||
Reference in New Issue
Block a user