step 5.3: done
This commit is contained in:
+16
-14
@@ -4,8 +4,8 @@
|
||||
> If this file disagrees with the code, trust the code and fix this file.
|
||||
|
||||
## 1. Where we are
|
||||
- **Last completed step:** 5.2 (inventory/equipment services + routes — list, equip, unequip)
|
||||
- **Next step:** 5.3 — stackable consumables: POST /api/inventory/use (health potion heals; energy tonic restores energy, capped)
|
||||
- **Last completed step:** 5.3 (stackable consumables: POST /api/inventory/use)
|
||||
- **Next step:** 5.4 — UI: inventory grid, equipment panel, tooltips with stats
|
||||
- **Updated:** 2026-10-20
|
||||
- **Was the last session cut off mid-task?** No
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|---|---|
|
||||
| `npm install` | succeeds |
|
||||
| `npm run migrate` | applies 001–004 and 006 / "nothing to do" |
|
||||
| `npm test` | **111 passing, 0 failing** (87 unit + 24 integration) |
|
||||
| `npm test` | **118 passing, 0 failing** (87 unit + 31 integration) |
|
||||
|
||||
## 3. What exists now (files that matter)
|
||||
- `src/game/stats.js` — `calcDerived()` is the ONLY derived-stat formula. Also re-exports xpToNext/checkLevelUp.
|
||||
@@ -23,21 +23,21 @@
|
||||
- `src/services/zoneService.js` — `listZones(characterLevel)` → zones with `unlocked` flag.
|
||||
- `src/services/combatLogService.js` — `getCombatLog(characterId, limit)` → recent fights.
|
||||
- `src/services/characterService.js` — `createCharacter`, `getCharacterProfile`, `getCharacterIdForUser`.
|
||||
- **NEW:** `src/services/inventoryService.js` — `listInventory`, `equipItem`, `unequipItem`. Uses WeakMap stmt cache. Derived stats recalculated on list.
|
||||
- **NEW:** `src/routes/inventory.js` — `GET /api/inventory`, `POST /api/inventory/equip`, `POST /api/inventory/unequip`. Zod-validated.
|
||||
- **NEW:** `src/services/inventoryService.js` — `listInventory`, `equipItem`, `unequipItem`, `useConsumable`. Uses WeakMap stmt cache. Derived stats recalculated on list. Consumables: heal (capped at maxHp) and energy (capped at ENERGY_MAX), qty decrement, row removal at 0.
|
||||
- **NEW:** `src/routes/inventory.js` — `GET /api/inventory`, `POST /api/inventory/equip`, `POST /api/inventory/unequip`, `POST /api/inventory/use`. Zod-validated.
|
||||
- `src/utils/time.js` — `now()/setNow()/resetNow()`; never call `Date.now()` in services.
|
||||
- `src/routes/zones.js` — `GET /api/zones`.
|
||||
- `src/routes/combatLog.js` — `GET /api/combat-log`.
|
||||
- `src/db/migrations/003_content.sql` — also SEEDS zones/monsters/items/loot (INSERT OR IGNORE).
|
||||
- `src/db/migrations/004_inventory.sql` — inventory table, FK constraints, partial unique index for equipped slots.
|
||||
- `tests/integration/inventory.test.js` — 13 integration tests for inventory service.
|
||||
- `tests/integration/inventory.test.js` — 20 integration tests (13 equip/unequip + 7 consumable).
|
||||
- `public/game.html` — dashboard with stats panel, zone list, combat log, result panel.
|
||||
- `public/js/game.js` — full hunt UI: load zones, hunt handler, result display, combat log replay, toast notifications, energy sync.
|
||||
- `public/css/main.css` — zone cards, combat log entries, result panel, toast styles.
|
||||
|
||||
## 4. Half-finished / fragile things
|
||||
- No consumable use endpoint yet (Phase 5 step 5.3).
|
||||
- No UI for inventory/equipment (Phase 5 step 5.4).
|
||||
- No consumable UI yet (Phase 5 step 5.4).
|
||||
- No inventory grid/equipment panel/tooltips in game.html.
|
||||
- HP never regenerates naturally; only level-up restores it.
|
||||
- No restart-persistence test for sessions.
|
||||
- `npm run seed` script in package.json points to nonexistent `scripts/seed.js`.
|
||||
@@ -47,6 +47,8 @@
|
||||
- D-004..D-007 in `docs/DECISIONS.md` (combat rounds, equipment counted once, session store, clock).
|
||||
- Zod query param parsing uses `zod.coerce.number()` because Express query params are strings.
|
||||
- Inventory response uses `itemId` (item.id) and `inventoryId` (inventory row id) to avoid confusion.
|
||||
- Consumable effect parsing: regex `^(heal|energy):(\d+)$` on items.effect field.
|
||||
- Qty decrement avoids CHECK constraint violation: delete directly when qty==1, decrement when qty>1.
|
||||
|
||||
## 6. Gotchas learned
|
||||
- `npm test` must be `node --test` with NO path/glob; files must be named `*.test.js`. A shell glob once skipped 17 tests.
|
||||
@@ -57,13 +59,13 @@
|
||||
- Express query params are strings, not numbers — use `zod.coerce.number()` for numeric query params.
|
||||
- SQL `SELECT id` from inventory returns the auto-increment row id; rename with `AS inventory_id` when you also need `item_id`.
|
||||
- `itemInSlot` query must alias `id AS inventory_id` so `existing.inventory_id` works in unequip logic.
|
||||
- Transaction callback args must match the call order exactly — passing `qty` as the second arg when the callback expects `etype` silently misapplies the effect.
|
||||
|
||||
## 7. Next-step briefing (5.3)
|
||||
- **Goal:** Stackable consumables: `POST /api/inventory/use` — health potion heals HP (capped at maxHp); energy tonic restores energy (capped at ENERGY_MAX). Only consumable type items can be used. Consumable is consumed (quantity -1, removed when 0).
|
||||
- **Docs:** DATABASE.md (§004_inventory), GAME_DESIGN.md §Items, BALANCE.md (effect format: 'heal:50', 'energy:25').
|
||||
- **Files to create/modify:** extend `inventoryService.js` with `useConsumable(characterId, itemId)`, extend `inventory.js` route.
|
||||
- **Key rules:** parse `effect` field from items table ('heal:N' or 'energy:N'); validate character has the item in inventory (quantity >= 1); apply effect; decrement quantity; remove row when quantity reaches 0; return updated inventory listing.
|
||||
- **Tests:** happy-path heal, happy-path energy, use on non-consumable rejected, insufficient quantity, effect capped at maxHp/energyMax.
|
||||
## 7. Next-step briefing (5.4)
|
||||
- **Goal:** UI for inventory — grid display of items (equipment + consumables), equipment panel showing current gear with stats, tooltips with stat bonuses.
|
||||
- **Docs:** GAME_DESIGN.md §Items, UI_GUIDE.md, API.md.
|
||||
- **Files to modify:** `public/game.html` (add inventory/equipment panels), `public/js/game.js` (load inventory, render grid, equip/unequip/use handlers, tooltips), `public/css/main.css` (inventory grid, tooltips, equipment panel styles).
|
||||
- **Key rules:** Use `GET /api/inventory` for data; render equipment slots + consumable list; show stat bonuses on hover; click to equip/unequip; click consumable to use.
|
||||
|
||||
## 8. Open Known Issues
|
||||
STATUS.md issues 1–6 (balance, dangling `seed` script, restart test, equipment-in-combat, HP regen, zone min_level balance).
|
||||
|
||||
Reference in New Issue
Block a user