feat: port crafting

This commit is contained in:
goose
2026-10-03 15:04:38 -04:00
parent c1e5b9fa9c
commit a160063b05
14 changed files with 467 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
# Task D5 — Crafting recipes and alchemy
## Scope
Implemented D5 only in the Godot port worktree:
- `CraftingEngine` reads `data/ascii/recipes.json`, reports recipe availability, enforces `min_floor`, identifies every missing material, consumes input quantities, and adds the declared output item quantity.
- Crafting consumes inputs before adding the output so fully consumed ingredient slots can be reused by the result; validated availability prevents a failed attempt from consuming materials.
- Added modal `CraftingPanel` and a dedicated **B** (`crafting`) action. It lists all recipes, shows availability/requirements, supports arrow selection, Enter/Space crafting, and B/Escape dismissal.
- Integrated crafting journal events (`crafting_opened`, `craft_completed`, `craft_refused`, `crafting_closed`) and refreshes an already-open inventory after crafting.
- Added strict TDD coverage for JSON inputs, missing-material details, minimum floor, output quantity, capacity-slot reuse, and real keyboard panel-to-inventory E2E flow.
No D6 content-import or performance work was included.
## Root-cause report
There was no previous crafting domain or UI path: `recipes.json` existed but was neither loaded by the generic content catalog nor reachable from `Game`. Consequently, its `inputs`, `min_floor`, and `output` contract could not affect inventory state. The focused red test first failed because `crafting_engine.gd` was absent. A subsequent capacity regression test exposed a transactional ordering issue in the initial green implementation: it tried to add output before consuming ingredients, incorrectly rejecting an otherwise valid craft when ingredient stacks occupied all slots. The final engine validates all prerequisites first, consumes recipe inputs, then adds output, with input restoration as a defensive fallback if output insertion is unexpectedly rejected.
A first panel E2E attempt also exposed that **C** is already bound to diagonal movement (`move_southeast`). The crafting action was moved to **B**, avoiding the existing input-map collision rather than changing unrelated movement controls.
## TDD evidence
1. Red: `tests/unit/test_crafting.gd` failed before implementation because `res://scripts/domain/items/crafting_engine.gd` did not exist (`/tmp/d5-red-unit.log`).
2. Green: focused unit suite passed: 4 tests, 25 assertions (`/tmp/d5-green-unit-final.log`).
3. Red capacity regression: the added capacity-slot reuse test failed with the initial output-before-consume ordering (`/tmp/d5-red-capacity.log`).
4. Green panel E2E passed: 1 test, 11 assertions (`/tmp/d5-green-e2e-final.log`).
## Full verification
Executed `scripts/verify.sh` successfully:
- Unit: **139/139** tests, **1070** assertions.
- Integration: **7/7** tests, **9255** assertions.
- E2E (including `test_crafting_e2e.gd`): **36/36** tests, **372** assertions.
- Visual capture/check passed. Generated ignored artifacts:
- `artifacts/visual-check.png`
- `artifacts/visual-check-exit.png`
Godot/GUT emitted pre-existing resource/UID warnings and shutdown resource-leak diagnostics, but no test or parse failures; `verify` ended with `unit, integration, E2E, and visual checks passed`.
## Delivery
Local commit only; no push and no pull request.