Split The code is public; the app answers only to the crew.

The buy menu says why you cannot buy it, and moves out of `main.ts` into a tested module #92

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Pushed. New src/client/buy.ts computes the buy panel's rows as plain data — { item, label, price, state, why } for every item a side can buy, deriving state (ok/owned/poor/closed) and a short reason from world.ts's existing canBuy/canBuyItem/priceOf rules without duplicating them.

Notes

shipped merged

opened this

Pushed.

New src/client/buy.ts computes the buy panel's rows as plain data — { item, label, price, state, why } for every item a side can buy, deriving state (ok/owned/poor/closed) and a short reason from world.ts's existing canBuy/canBuyItem/priceOf rules without duplicating them. buy.test.ts covers an unaffordable rifle (still shows its price), an already-held gun and a second grenade both reading owned, every row going closed together once the freeze time ends, off-side gear (AK for CT, kit for T) never appearing, and armour's price reflecting what's already worn.

main.ts now builds the buy panel once and repaints it from buyMenu() — rows update their price/reason/disabled state in place on every purchase and every frame the panel is open, never touching innerHTML or re-adding listeners, so focus stays put. The panel header counts the freeze time down live and the panel closes itself when it hits zero (existing behaviour, now visible). Digits 1–9 buy the row they number; the panel's own keydown handler answers the press and stops it from also reaching the global slot-switch keys. Disabled buttons wire their reason through aria-describedby.

What I left out: the side state stays in the BuyState type per the issue's contract but is never produced today — off-side items are left out of the row list entirely, same as before, since the game resets a player's whole loadout at half time rather than ever leaving them holding gear their new side can't use. main.ts didn't get its own test file; DOM wiring isn't unit-tested elsewhere in this repo either, and there's no headless-browser tooling here to drive it — I checked the built bundle serves and the panel's markup/ids are present, and ran bun test (369 pass) plus a full bun run scripts/build.ts.

To try it: open the buy panel (B, or buy on the phone pad) with too little money for a rifle, or already holding a gun — the row says why instead of just going grey — and try the 1–9 keys against the numbered rows.

Closes #87

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs