Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f72dda6fa |
@@ -183,10 +183,38 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById("seatCountInput").addEventListener("change", e => {
|
// A seat that has anything of a player in it — a name, chips, cash in, or a hand
|
||||||
HoldemState.resizeSeats(state, Number(e.target.value));
|
// in progress. Shrinking the table throws these away permanently, and it also
|
||||||
hooks.save(state);
|
// orphans them in the session standings, where they keep their winnings but lose
|
||||||
Render.renderAll();
|
// 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 => {
|
document.getElementById("directionSelect").addEventListener("change", e => {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ const PotWizard = {
|
|||||||
this.playerLabelById = new Map(
|
this.playerLabelById = new Map(
|
||||||
players.map(p => [p.id, this.labelFor(p, state.seats.indexOf(p))])
|
players.map(p => [p.id, this.labelFor(p, state.seats.indexOf(p))])
|
||||||
);
|
);
|
||||||
this.seatIndexById = new Map(players.map(p => [p.id, state.seats.indexOf(p)]));
|
|
||||||
const contributions = players.map(p => ({
|
const contributions = players.map(p => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
contribution: HoldemState.computeContribution(p, state.chipLegend, state.basePotAmount),
|
contribution: HoldemState.computeContribution(p, state.chipLegend, state.basePotAmount),
|
||||||
@@ -50,20 +49,6 @@ const PotWizard = {
|
|||||||
this.totals.set(id, (this.totals.get(id) || 0) + amount);
|
this.totals.set(id, (this.totals.get(id) || 0) + amount);
|
||||||
},
|
},
|
||||||
|
|
||||||
// A chopped pot rarely divides exactly, and the odd chip goes to the first player
|
|
||||||
// left of the button — not to whoever the dealer happened to tick first. The
|
|
||||||
// calculator hands leftovers out in the order it's given the winners, so ordering
|
|
||||||
// them here is what makes the payout match the rule.
|
|
||||||
orderFromButton(ids) {
|
|
||||||
const distance = new Map();
|
|
||||||
for (let step = 1; step <= this.state.seatCount; step++) {
|
|
||||||
distance.set(HoldemState.nextSeatIndex(this.state, this.state.dealerSeatIndex, step), step);
|
|
||||||
}
|
|
||||||
return [...ids].sort((a, b) =>
|
|
||||||
(distance.get(this.seatIndexById.get(a)) ?? 0) - (distance.get(this.seatIndexById.get(b)) ?? 0)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderStep() {
|
renderStep() {
|
||||||
// Auto-resolve any round where only one player is left standing — nothing to ask.
|
// Auto-resolve any round where only one player is left standing — nothing to ask.
|
||||||
let contenders = PotCalculator.getContenders(this.entries);
|
let contenders = PotCalculator.getContenders(this.entries);
|
||||||
@@ -142,7 +127,7 @@ const PotWizard = {
|
|||||||
confirmBtn.addEventListener("click", () => {
|
confirmBtn.addEventListener("click", () => {
|
||||||
const selected = Array.from(choices.querySelectorAll("input:checked")).map(i => i.value);
|
const selected = Array.from(choices.querySelectorAll("input:checked")).map(i => i.value);
|
||||||
if (selected.length === 0) return;
|
if (selected.length === 0) return;
|
||||||
const result = PotCalculator.resolveRound(this.entries, this.orderFromButton(selected));
|
const result = PotCalculator.resolveRound(this.entries, selected);
|
||||||
this.recordRound(result);
|
this.recordRound(result);
|
||||||
this.entries = result.updatedEntries;
|
this.entries = result.updatedEntries;
|
||||||
this.renderStep();
|
this.renderStep();
|
||||||
|
|||||||
Reference in New Issue
Block a user