feat: gadget backpack system — save circuits as items

Add Pokemon-style inventory where players save crafted circuits as
"gadgets" in a backpack. Gadgets can be used on puzzle doors to solve
them by testing their truth table against required outputs.

New files:
- js/world/inventory.js: gadget data model, backpack UI (list with
  scroll, action menu, detail panel), keyboard navigation

Changes:
- Workshop gets "Save as Gadget" button (pink, top-right)
- I key opens backpack overlay in world mode
- Puzzle doors open backpack to select a gadget to try
- HUD shows gadget count instead of old component count
- worldState gains gadgets[] array

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jose Luis
2026-03-20 17:30:30 +01:00
parent f8aa4e2eab
commit b999fe855a
6 changed files with 633 additions and 18 deletions

View File

@@ -2,6 +2,7 @@
import { worldState, advanceDialog, startDialog } from './worldState.js';
import { getMap, getInteraction, getNPC, getExit, isWalkable } from './maps.js';
import { toggleDebug } from './worldRenderer.js';
import { isBackpackOpen, openBackpack, handleBackpackInput } from './inventory.js';
const keysDown = new Set();
let interactionHandler = null;
@@ -25,6 +26,13 @@ function onKeyDown(e) {
const key = e.key;
keysDown.add(key);
// Backpack open — route all input there
if (isBackpackOpen()) {
e.preventDefault();
handleBackpackInput(key);
return;
}
// During dialog: advance on action keys
if (worldState.dialog) {
if (key === 'Enter' || key === ' ' || key === 'e' || key === 'E') {
@@ -43,6 +51,13 @@ function onKeyDown(e) {
return;
}
// Backpack toggle (I)
if (key === 'i' || key === 'I') {
e.preventDefault();
openBackpack(null);
return;
}
// Workshop shortcut (TAB)
if (key === 'Tab') {
e.preventDefault();