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 #87
Sign in to join this conversation.
Split The code is public; the app answers only to the crew.
Make the buy menu tell the player why a button is dead, and lift it out of
main.tsinto a module that can be tested, because it is the panel every other buy-time issue has to edit.Today
renderBuy(src/client/main.ts:196-224) rebuilds the whole panel'sinnerHTMLon every purchase, re-attaches every listener, and hands back a row of buttons that are either clickable or greyed with no reason given: too poor, wrong side, already owned, already carrying a grenade, and "the freeze time ended two seconds ago" all look identical. There is no clock in the panel either, so a player buying is a player who has stopped watching the only timer that matters.main.tsis 529 lines and has no test file.Done looks like
src/client/buy.ts: pure, plain data in and out.buyMenu(world, player)returns the rows a panel needs —{ item, label, price, state, why }withstateone of"ok" | "owned" | "poor" | "side" | "closed"andwhya short phrase — plus the money and the seconds left to spend it. No DOM, nodocument, nothing frommain.ts.src/client/buy.test.tscovers, each failing without the change: a player who cannot afford a rifle getspoorand the price still shows; a CT sees no AK and a T sees no defuse kit (side); a player already holding an AK sees it asowned; a second grenade isowned; every row isclosedoncecanBuyis false; the price of armour reflects what they already wear (thepriceOfrule, not a constant).aria-describedbyor as part of its accessible name, so a screen reader hears why too.innerHTMLor re-adding listeners, and focus stays where the player left it. Keyboard: the digits 1-9 buy the row they number,B/Escape/Close still close, Tab order unchanged.main.tskeeps only the wiring: it reads the rows, paints them, and routes clicks tobuy(). The 44px minimum and the 360px layout still hold on a phone.buy,canBuy,canBuyItemandpriceOfinworld.ts/weapons.tskeep their current behaviour and their current tests.Files I expect to change
src/client/buy.ts, newsrc/client/buy.test.ts.src/client/main.ts(renderBuy/openBuyshrink to wiring),src/pages/game.ts(any style the reason text needs).Risks
buyMenurather than beside it — I have made #59 wait on this one.world.ts, and a second copy of the affordability rule is a bug waiting for the next price change.buybutton; check it there, not only with a keyboard.Who
scout — UI, a pure module and a test harness; no simulation or GL work in it.