Files
JoshHeaps.Net/tests/holdem/load.js
T
jheapsandClaude Opus 5 9af65a7b82 Sort a seat's eleven actions by when, not draw them all the same
The long-press menu had grown to eleven actions and drew every one of them as
the same full-width bar. On the fullest menu the tool can build — a live seat
that isn't the dealer, blinds still the only money in, an override already set
— that came to 796px and took 85% of the screen on all four viewports measured.
It scrolled on all four, and Cancel was off the bottom of the screen on all
four: 79px past it on a 390px phone, 252px on a 360px one, 448px in landscape.
Apple puts the comfortable number for an action sheet at three to five and says
not to let one scroll at all.

Nothing is cut. Every one of the eleven is the only route to something, and
"Blinds follow the button again" is the only route in the whole tool to
clearing a blind override. They are sorted by *when* instead: a seat action is
either something you do with cards in the air or housekeeping between hands,
and those two want different targets. The hand keeps the full-width bars —
Fold, All-in, Un-fold, and seating the next player off the rail, because a
chair opens between two hands with people watching it. Everything else goes to
a two-column grid of quieter 44px tiles underneath.

The captions are not decoration. A half-width tile reading "Small blind" is a
label, and the puck already wears one of those; under "Give this seat" it is a
verb again. That is what lets three of the longest labels here lose ten
characters each and still fit a half tile on one line, which is the height the
caption pays back. The override reset spans the grid rather than sitting in it
as a fourth position to give, dashed and unfilled — the felt's own word for
"nothing set by hand here" — so it doesn't read as the Cancel below it either.

Same fullest menu afterwards: 650px, 77%, no scroll on a phone or a desktop.
What a dealer actually sees mid-hand is eight actions and 546px, 65%. The move
picker, which was eleven more full-width bars, now fits all eleven chairs of a
twelve-handed table on a 360px phone without scrolling.

Two things the height was hiding, fixed with it:

The header is stuck to the top of the sheet's scrollport and carries a real
close button. NN/g is explicit that a grab handle is not a close affordance,
and this is the sheet that can still outgrow a landscape phone — so the way
out, and whose menu this is, are now in the part that cannot scroll away.

That close button is also the first control in the markup, which is what Modal
focuses. It used to focus Fold. The APG says to keep a dialog's initial focus
off the destructive choice; a close button at the top puts it there without a
special case. Escape finds that one rather than the button at the foot, so
Escape closes the sheet while the foot steps back — and it now has somewhere to
step back to: opening the move picker used to replace the sheet and leave only
a control that threw the whole menu away.

1068 tests pass; the 418-audit sweep is clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015bnp7xKUPFFSpwkYNFaPgb
2026-09-11 16:31:57 -06:00

112 lines
4.0 KiB
JavaScript

// Loads the dealer's browser modules into Node so they can be tested directly.
//
// The modules are plain script-tag files: each one declares a `const` namespace and
// ends with a `module.exports` guard. In the browser they find each other as globals,
// so the same names have to exist on `globalThis` here or `Betting` can't reach
// `HoldemState`. Load order matches the <script> order in TexasHoldem.cshtml.
const path = require("path");
const SRC = path.join(__dirname, "..", "..", "JoshHeaps.Net", "wwwroot", "js", "casino", "holdem");
function load(name) {
const mod = require(path.join(SRC, `${name}.js`));
globalThis[name.charAt(0).toUpperCase() + name.slice(1)] = mod;
return mod;
}
const Money = load("money");
const HandRank = load("handRank");
const PotCalculator = load("potCalculator");
const SplitCalculator = load("splitCalculator");
const Betting = load("betting");
const SettleUp = load("settleUp");
const HandHistoryExport = load("handHistoryExport");
// render.js exports { Render } rather than the namespace directly.
const Render = require(path.join(SRC, "render.js")).Render;
globalThis.Render = Render;
// state.js exports `HoldemState`, which doesn't match its filename.
const HoldemState = require(path.join(SRC, "state.js"));
globalThis.HoldemState = HoldemState;
// actionBar.js after state, since its own module-level code reaches for neither but
// its methods reach for both. Loaded last so nothing it touches is still undefined.
const ActionBar = load("actionBar");
// The picker's slot bookkeeping — which slots it is filling, what is already dealt —
// is plain state work and testable here. Only render() and open() touch the DOM.
const CardPicker = load("cardPicker");
// The wake lock's rule about when a table needs the screen is plain state work too.
// Its acquire/release bookkeeping is testable here as well, against a stand-in for
// navigator.wakeLock — see wakeLock.test.js.
const WakeLock = load("wakeLock");
// The seat menu's list — which actions a seat is offered and which group each one
// lands in — is decided before anything is drawn, so actionsFor() answers here. Only
// render() and open() touch the DOM.
const SeatMenu = load("seatMenu");
// ---- Table builders ----------------------------------------------------------
// A table with `seatCount` chairs where `seated` (a list of seat indexes) are dealt
// in with `stack` chips each. Everything else is the app's own defaults, so a test
// that forgets to set a field gets whatever a real dealer would get.
function makeTable({ seatCount = 6, seated = null, stack = 100, smallBlind = 1, bigBlind = 2, dealerSeatIndex = 0 } = {}) {
const state = HoldemState.createDefault();
HoldemState.resizeSeats(state, seatCount);
state.smallBlind = smallBlind;
state.bigBlind = bigBlind;
state.dealerSeatIndex = dealerSeatIndex;
const sitting = seated || state.seats.map((_, i) => i);
state.seats.forEach((player, index) => {
player.inHand = sitting.includes(index);
player.stack = sitting.includes(index) ? stack : null;
player.name = `P${index + 1}`;
});
return state;
}
// Total chips the table is accountable for: what's in front of everyone, plus what
// they've pushed in this street, plus what's already banked into the pot.
function chipsOnTable(state) {
return Money.round(
state.seats.reduce(
(sum, p) => sum + (Number(p.stack) || 0) + (Number(p.committed) || 0) + (Number(p.amountOverride) || 0),
0
)
);
}
// Contributions in the shape PotCalculator wants them.
function contributions(state) {
return state.seats
.filter(p => p.inHand)
.map(p => ({
id: p.id,
contribution: Betting.handTotal(p),
folded: p.folded,
}));
}
module.exports = {
Money,
HandRank,
Render,
HandHistoryExport,
PotCalculator,
SplitCalculator,
SettleUp,
Betting,
HoldemState,
ActionBar,
CardPicker,
WakeLock,
SeatMenu,
makeTable,
chipsOnTable,
contributions,
};