diff --git a/JoshHeaps.Net/wwwroot/js/casino/holdem/main.js b/JoshHeaps.Net/wwwroot/js/casino/holdem/main.js index f6915ae..30137cc 100644 --- a/JoshHeaps.Net/wwwroot/js/casino/holdem/main.js +++ b/JoshHeaps.Net/wwwroot/js/casino/holdem/main.js @@ -183,10 +183,38 @@ document.addEventListener("DOMContentLoaded", () => { }); }; - document.getElementById("seatCountInput").addEventListener("change", e => { - HoldemState.resizeSeats(state, Number(e.target.value)); - hooks.save(state); - Render.renderAll(); + // A seat that has anything of a player in it — a name, chips, cash in, or a hand + // in progress. Shrinking the table throws these away permanently, and it also + // orphans them in the session standings, where they keep their winnings but lose + // the stack and buy-in the settle-up is worked out from. + const seatHasSomeoneIn = player => + !!(player.name && player.name.trim()) || + player.inHand || + (Number(player.stack) || 0) > 0 || + (Number(player.buyIns) || 0) > 0 || + (Number(player.amountOverride) || 0) > 0; + + document.getElementById("seatCountInput").addEventListener("change", async e => { + const requested = Math.max(2, Math.min(24, Math.floor(Number(e.target.value)) || state.seatCount)); + const losing = state.seats.slice(requested).filter(seatHasSomeoneIn); + + if (losing.length > 0) { + const who = losing + .map((p, i) => HoldemState.displayName(p, requested + state.seats.slice(requested).indexOf(p))) + .join(", "); + const ok = await Dialog.confirm({ + title: `Remove ${losing.length} ${losing.length === 1 ? "player" : "players"}?`, + message: `Going down to ${requested} seats takes ${who} off the table along with their chips and buy-ins, and their session totals stop adding up.`, + confirmLabel: "Remove them", + danger: true, + }); + if (!ok) { + e.target.value = state.seatCount; + return; + } + } + + runUndoable(`Table set to ${requested} seats.`, () => HoldemState.resizeSeats(state, requested)); }); document.getElementById("directionSelect").addEventListener("change", e => {