perf: support full ASCII generated content catalog

This commit is contained in:
goose
2026-10-03 15:22:50 -04:00
parent c87fbce01a
commit 3853e99a97
16 changed files with 387 additions and 22 deletions
+30 -21
View File
@@ -1,34 +1,43 @@
# D3 — Equipment, identification, consumable use, and inventory UI
# D6 — Large generated-content catalog performance
## Scope
D3 adds persistent equipment and item-identification state to the run, supports equipping and swapping gear, consumable use, ally-target handoff, dropping stack units, and a keyboard-driven inventory presentation. D4 economy/shops/paid rest and D5 crafting remain out of scope.
## Design and implementation
- `EquipmentState` owns the declared equipment slots, moves instances between inventory and equipment, rejects unsupported slots without mutation, swaps displaced equipment back into inventory, and recomputes `PlayerState` attribute/skill modifiers.
- `ItemIdentification` masks names, descriptions, and combat modifiers for unidentified instances. Equipping and consuming reveal the relevant instance.
- `InventoryState` now provides instance lookup/removal, stack-aware dropping, and data-backed `heal`, `heal_pct`, `cure_status`, and `apply_status` effects. It supports both the domain `PlayerState.max_hp()` contract and the live combat `ActorState.max_hit_points` contract.
- `InventoryPanel` presents selection, item details, equipment comparison, equipped summary, and keyboard actions (`E` equip, `U` use, `D` drop, arrows select, `I`/Escape close). The game records accepted/refused equip, use, and drop events and keeps ranged main-hand equipment synchronized with the existing combat actor.
- Ally-target consumables expose `submit_inventory_ally_target()` as a UI-neutral seam for a future party selector; D3 does not introduce a party UI.
D6 imports and exposes the full generated item, spell, and achievement catalog, adds a search-and-page catalog browser to the main menu, proves source integrity/taxonomy, and measures the loading/opening path. Dialogue and E1 were not changed.
## Root cause and fix
The D3 keyboard integration initially exercised live `ActorState` healing while `InventoryState.use_item()` only assumed the `PlayerState.max_hp()` method. The resulting runtime failure was an invalid `max_hp` call on `ActorState`. The fix centralizes maximum-health resolution in `InventoryState`: use `max_hp()` for `PlayerState`, otherwise use the supported `max_hit_points` property, and reject invalid recipients before applying effects or consuming an item. A unit regression test covers the `ActorState` path; the end-to-end test covers the live keyboard flow.
The ASCII loader only registered the earlier gameplay catalogs: `achievements.json` was copied under `data/ascii/` but silently ignored. Consequently there was no `achievement` catalog getter, and existing inventory/spell presentation lists were run-state/learned-spell lists that would eagerly format every entry if used as a full catalog viewer. That was both incomplete and unsuitable for 15,058 generated items.
## Verification
`ContentLoader` now recognizes `achievements.json`; `ContentCatalog` stores it under `achievement` and exposes `get_achievement()`. The main menu now has a Content Catalog entry/key (`C`) with one shared browser for items, spells, and achievements. It filters ids/names and pages results at 24 rows; only the active page is formatted/rendered. Tab cycles types, Page Up/Down changes page, and Escape returns to the menu.
The new bulk integration test reads the authoritative JSON source and verifies every generated id occurs exactly once in the catalog: 15,058 items, 5,009 spells, and 5,031 achievements. It also validates item category/rarity/equipment slots, spell schools, and achievement categories. The E2E test opens the real menu, moves to the second 24-row item page, searches the rusted sword, and visits spell and achievement pages.
## Performance measurement
The documented Linux release-like headless benchmark (`scripts/measure_catalog_performance.gd`) uses the actual `MainMenu` and Catalog button after import. On Godot 4.5.0, three warm-import runs measured:
```text
menu ready: 13–16 ms
catalog open: 293–306 ms
end-to-end process wall time: 0.99–1.05 s
rendered rows: 24 of 15,058 items
```
Acceptance budgets are cold catalog import ≤5,000 ms (enforced in the integration test) and menu opening ≤1,000 ms. A true Linux release export was unavailable: the repository does not contain `export_presets.cfg`, so Godot cannot select an export preset. README records this limitation and the reproducible release-like command rather than claiming an unavailable export measurement.
## TDD and verification
The initial red integration test failed as expected because `achievement` had zero catalog entries (expected 5,031). After loading support was added, the integration suite passed. The initial E2E failure exposed the test harness requirement to emit `LineEdit.text_changed` after assigning text programmatically; the production connected signal worked normally. The test was corrected to model that signal and then passed.
Executed with Godot 4.5.0 (`/snap/bin/godot4`):
```text
GODOT_BIN=/snap/bin/godot4 ./scripts/test-unit.sh PASS — 129/129 tests, 998 assertions
GODOT_BIN=/snap/bin/godot4 ./scripts/test-integration.sh PASS — 7/7 tests, 9,255 assertions
GODOT_BIN=/snap/bin/godot4 ./scripts/test-e2e.sh PASS — 31/31 tests, 326 assertions
git diff --check PASS
GODOT_BIN=/snap/bin/godot4 ./scripts/test-integration.sh PASS — 8/8 tests, 59,453 assertions
GODOT_BIN=/snap/bin/godot4 ./scripts/test-e2e.sh PASS — 37/37 tests, 383 assertions
GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh PASS — 139/139 unit tests, 1,080 assertions; 8/8 integration tests, 59,453 assertions; 37/37 E2E tests, 383 assertions; visual capture passed
/snap/bin/godot4 --headless --path . -s res://scripts/measure_catalog_performance.gd
PASS — 24 rendered rows; metrics above
git diff --check PASS
```
The test runners emitted pre-existing GUT invalid-UID and resource-cleanup warnings, but no `SCRIPT ERROR` or parse error. No push or PR was performed.
## Files
Production changes are limited to the game scene, domain actor/player/inventory/run state, equipment and identification domain services, game integration, and inventory presentation. New unit and E2E coverage is included for D3 behavior.
GUT continues to emit pre-existing invalid-UID/resource cleanup warnings. No test emitted a `SCRIPT ERROR` or parse error. No push or PR was performed.