lesen/geld.py (Spec tests/geld_spec.py), reine Funktionen: - buyin_hoehe: Vorgabe Max, wählbar min oder BB-Zahl, begrenzt auf Min/Max und Guthaben - nachkaufen: unter 60 BB zurück auf die Obergrenze - tischzahl: je Kauf höchstens ein Fünftel des verbleibenden Guthabens, höchstens 12 - ist_stopfaellig: unter 20 BB; was_tun: nachkaufen, aufstehen oder weiter Klon: Guthaben (--konto) sinkt mit Buy-in und Nachkauf und ist sichtbar. Der Dialog hat Guthaben, Min, 60/80 BB, Max. Der eigene Platz zeigt "+ Chips" statt +. Neu sind /api/nachkauf und der Prüfhebel /api/stack. stelleVon() nennt Klickstellen als Anteil des Fensterrahmens. Tests: test_geld (headless) und der Kettentest prüfen Max beim Buy-in, den Nachkauf nach sinkendem Stack und die Tischzahl nach Guthaben. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
353 lines
17 KiB
HTML
353 lines
17 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>{{TITEL}}</title>
|
||
<!-- Nachbildung des gemalten Unity-Tisches. Alle Stellen sind Anteile des FENSTERRAHMENS
|
||
(mock/vorlage/README.md), nicht der Seite - so rechnet auch hand/click.py. -->
|
||
<style>
|
||
html, body { margin: 0; height: 100%; overflow: hidden; }
|
||
body { background: #11131b; color: #eee; font: 15px/1.2 Roboto, Arial, sans-serif; position: relative; }
|
||
.filz { position: absolute; left: 7%; right: 7%; top: 21%; bottom: 20%; border-radius: 50%;
|
||
background: radial-gradient(#1d7a55, #0f4d37); border: 14px solid #232634; }
|
||
.stelle { position: absolute; transform: translate(-50%, -50%); }
|
||
.platz { text-align: center; }
|
||
.platz .name { background: #1b1e29; border-radius: 8px; padding: 6px 14px; min-width: 110px; }
|
||
.platz .chips { color: #f5c542; font-weight: 700; }
|
||
.platz.held .name { outline: 2px solid #4fc3f7; }
|
||
.platz.dran .name { outline: 2px solid #f5c542; }
|
||
.platz .aktion { color: #9ab; font-size: 12px; min-height: 14px; }
|
||
.platz.gefoldet { opacity: .45; }
|
||
.einsatz { background: #0d0f15; color: #f5c542; border-radius: 10px; padding: 2px 10px; font-size: 13px; }
|
||
.uhr { background: #f5c542; color: #111; font-weight: 700; border-radius: 10px; padding: 2px 8px; font-size: 13px; }
|
||
.uhr.knapp { background: #d4202c; color: #fff; }
|
||
.uhr[hidden] { display: none; }
|
||
.handnr { position: absolute; left: 12px; top: 10px; color: #778; font-size: 12px; }
|
||
.platz-frei { width: 80px; height: 80px; border-radius: 50%; border: 3px solid #2a2d3a;
|
||
background: #1a1c25; color: #ccc; font-size: 44px; line-height: 1; cursor: pointer; padding: 0; }
|
||
.mitte { text-align: center; }
|
||
.pot { background: #1b1e29; color: #fff; border-radius: 12px; padding: 4px 14px; display: inline-block; }
|
||
.pot[hidden] { display: none; }
|
||
.pot b { color: #4fc3f7; }
|
||
.karten { display: flex; gap: 6px; justify-content: center; margin-top: 10px; }
|
||
.karte { background: #fff; color: #111; border-radius: 6px; width: 42px; height: 58px; font-size: 20px;
|
||
font-weight: 700; display: flex; align-items: center; justify-content: center; }
|
||
.karte.rot { color: #d4202c; }
|
||
.aktionsleiste button { position: absolute; transform: translate(-50%, -50%); border: 0; border-radius: 8px;
|
||
background: #262a36; color: #fff; font: 600 16px Roboto, Arial, sans-serif; cursor: pointer;
|
||
white-space: nowrap; }
|
||
.aktionsleiste .gross { width: 12.5vw; height: 7vh; min-width: 90px; }
|
||
.aktionsleiste .klein { width: 5.2vw; height: 4.6vh; min-width: 40px; font-size: 13px; background: #1e2130; }
|
||
.aktionsleiste .fold { background: #8c2b2b; }
|
||
.aktionsleiste .call { background: #2b6b3f; }
|
||
.aktionsleiste .raise { background: #a5791d; }
|
||
.aktionsleiste .an { outline: 2px solid #4caf50; }
|
||
.betrag { position: absolute; transform: translate(-50%, -50%); width: 9vw; height: 4.4vh; text-align: center;
|
||
background: #0d0f15; color: #fff; border: 1px solid #333; border-radius: 6px; }
|
||
.dialog-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: none; }
|
||
.sfs-buy-in-modal { position: absolute; width: 380px; box-sizing: border-box;
|
||
background: #1b1e29; border-radius: 12px; padding: 18px; display: none; }
|
||
.sfs-buy-in-header { display: flex; justify-content: space-between; align-items: center; }
|
||
.sfs-buy-in-heading { font-size: 20px; font-weight: 700; margin: 0; }
|
||
.sfs-buy-in-header-game-info { color: #99a; margin: 6px 0 14px; }
|
||
.sfs-buy-in-balance-container { display: flex; justify-content: space-between; margin-bottom: 12px; }
|
||
.sfs-buy-in-user-balance { color: #f5c542; font-weight: 700; }
|
||
.sfs-slider-range-value { width: 100%; box-sizing: border-box; padding: 8px; font-size: 18px; text-align: center;
|
||
background: #0d0f15; color: #fff; border: 1px solid #333; border-radius: 6px; }
|
||
.sfs-buy-in-body-range-buttons { display: flex; justify-content: space-between; margin: 10px 0 16px; }
|
||
.sfs-buy-in-body-range-buttons button, .sfs-buy-in-modal-button {
|
||
background: #2b3045; color: #fff; border: 0; border-radius: 6px; padding: 6px 16px; cursor: pointer;
|
||
font: inherit; }
|
||
.sfs-buy-in-modal-button-container { padding: 6px 40px; }
|
||
.sfs-buy-in-modal-button { background: #1fae64; font-weight: 700; padding: 10px; width: 100%; }
|
||
.sfs-buy-in-body-error { color: #ff6b6b; min-height: 1em; font-size: 12px; }
|
||
.common-dialog-cross-icon { cursor: pointer; font-size: 22px; }
|
||
.sfs-buy-in-body-range-buttons .sfs-buy-in-body-mid-range { background: #1e2130; font-size: 12px; }
|
||
.sfs-buy-in-body-container-text { color: #99a; font-size: 13px; margin-bottom: 10px; }
|
||
.nachkauf { border: 0; border-radius: 10px; background: #1f6fae; color: #fff; font: 600 12px Roboto, Arial;
|
||
padding: 4px 10px; cursor: pointer; }
|
||
.nachkauf:disabled { background: #2a2d3a; color: #778; cursor: default; }
|
||
.guthaben { position: absolute; right: 14px; top: 10px; color: #99a; font-size: 13px; }
|
||
.guthaben b { color: #f5c542; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="filz"></div>
|
||
<div class="handnr" id="handnr"></div>
|
||
<div class="guthaben">Balance <b id="guthaben"></b></div>
|
||
<div id="plaetze"></div>
|
||
<div id="einsaetze"></div>
|
||
<div class="stelle uhr" id="uhr" hidden></div>
|
||
<div class="stelle mitte" data-fx="0.5" data-fy="0.5">
|
||
<div class="pot" hidden><b>Pot</b> <span id="pot"></span></div>
|
||
<div class="karten" id="board"></div>
|
||
</div>
|
||
<div class="stelle" id="eigene" data-fx="0.5" data-fy="0.73"><div class="karten"></div></div>
|
||
<div class="aktionsleiste" id="leiste"></div>
|
||
|
||
<div class="dialog-backdrop"></div>
|
||
<div class="sfs-buy-in-modal">
|
||
<div class="sfs-buy-in-header">
|
||
<h2 class="sfs-buy-in-heading">Buy-In</h2>
|
||
<div class="common-dialog-cross-icon" role="button" aria-label="close">×</div>
|
||
</div>
|
||
<div class="sfs-buy-in-header-game-info">{{TITEL}}</div>
|
||
<div class="sfs-buy-in-balance-container">
|
||
<div class="sfs-buy-in-balance-label">Balance</div>
|
||
<div class="sfs-buy-in-user-balance"></div>
|
||
</div>
|
||
<div class="sfs-buy-in-body">
|
||
<div class="sfs-buy-in-body-container-text" hidden></div>
|
||
<input class="sfs-slider-range-value" inputmode="numeric">
|
||
<div class="sfs-buy-in-body-range-buttons">
|
||
<button class="sfs-buy-in-body-min-range">Min</button>
|
||
<button class="sfs-buy-in-body-mid-range" data-bb="60">60 BB</button>
|
||
<button class="sfs-buy-in-body-mid-range" data-bb="80">80 BB</button>
|
||
<button class="sfs-buy-in-body-max-range">Max</button>
|
||
</div>
|
||
<div class="sfs-buy-in-body-error"></div>
|
||
</div>
|
||
<div class="sfs-buy-in-modal-button-container">
|
||
<button class="sfs-buy-in-modal-button">Buy-In</button>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const RAUM = "{{RAUM}}";
|
||
// Platz -> Anteil des Fensterrahmens. Platz 1 ist das + aus der README (0.14 / 0.24).
|
||
const BUYIN = [0.50, 0.62]; // Stelle des Buy-In-Knopfs - das Bild des Dialogs fehlt in der Vorlage
|
||
const PLATZ = {1: [0.14, 0.24], 2: [0.50, 0.20], 3: [0.86, 0.27],
|
||
4: [0.88, 0.66], 5: [0.50, 0.84], 6: [0.12, 0.64]};
|
||
// Die drei Zustände der Aktionsleiste (README; "vorab" wie in bild-tisch-im-spiel.png)
|
||
const LEISTE = {
|
||
zug: z => [["Fold", 0.66, 0.94, "gross fold", "fold"],
|
||
[z.call ? "Call " + z.call : "Check", 0.80, 0.94, "gross call", "call"],
|
||
["Raise" + (z.raise ? " " + z.raise : ""), 0.93, 0.94, "gross raise", "raise"],
|
||
["33%", 0.616, 0.86, "klein", "v33"], ["50%", 0.677, 0.86, "klein", "v50"],
|
||
["75%", 0.735, 0.86, "klein", "v75"], ["Max", 0.784, 0.86, "klein", "vmax"]],
|
||
vorab: () => [["✓ Call Any", 0.79, 0.876, "gross", "callany"],
|
||
["✓ X/F", 0.66, 0.95, "gross", "xf"],
|
||
["✓ Call", 0.80, 0.95, "gross", "vcall"]],
|
||
voll: () => [["Find Seat", 0.66, 0.94, "gross", "findseat"],
|
||
["Join Wait List", 0.80, 0.94, "gross", "waitlist"]],
|
||
keine: () => [],
|
||
};
|
||
const FARBE = {HEARTS: "♥", DIAMONDS: "♦", CLUBS: "♣", SPADES: "♠"};
|
||
const WERT = {TWO: "2", THREE: "3", FOUR: "4", FIVE: "5", SIX: "6", SEVEN: "7", EIGHT: "8",
|
||
NINE: "9", TEN: "10", JACK: "J", QUEEN: "Q", KING: "K", ACE: "A"};
|
||
|
||
let zustand = null, leisteSchluessel = "", vorab = new Set();
|
||
|
||
function rahmen() {
|
||
const w = outerWidth || innerWidth, h = outerHeight || innerHeight;
|
||
const rand = Math.max(0, (w - innerWidth) / 2); // links, rechts und unten gleich
|
||
return {w, h, rand, oben: Math.max(0, h - innerHeight - rand)};
|
||
}
|
||
function setzeStelle(el, fx, fy) {
|
||
const r = rahmen();
|
||
el.style.left = (fx * r.w - r.rand) + "px";
|
||
el.style.top = (fy * r.h - r.oben) + "px";
|
||
}
|
||
function anordnen() {
|
||
for (const el of document.querySelectorAll("[data-fx]")) setzeStelle(el, +el.dataset.fx, +el.dataset.fy);
|
||
}
|
||
function karte(k) {
|
||
const d = document.createElement("div");
|
||
d.className = "karte" + (k.suit === "HEARTS" || k.suit === "DIAMONDS" ? " rot" : "");
|
||
d.textContent = (WERT[k.value] || "?") + (FARBE[k.suit] || "?");
|
||
return d;
|
||
}
|
||
async function senden(pfad, daten) {
|
||
const r = await fetch(pfad, {method: "POST", body: JSON.stringify(Object.assign({room: RAUM}, daten))});
|
||
return r.json();
|
||
}
|
||
|
||
function plaetzeZeichnen() {
|
||
const box = document.getElementById("plaetze"), einsaetze = document.getElementById("einsaetze");
|
||
box.textContent = ""; einsaetze.textContent = "";
|
||
for (const s of zustand.sitze) {
|
||
let el;
|
||
if (s.name) {
|
||
el = document.createElement("div");
|
||
el.className = "stelle platz" + (s.nr === zustand.held_sitz ? " held" : "")
|
||
+ (zustand.uhr && zustand.uhr.sitz === s.nr ? " dran" : "")
|
||
+ (s.aktion === "Fold" ? " gefoldet" : "");
|
||
el.innerHTML = '<div class="name"><div></div><div class="chips"></div></div><div class="aktion"></div>';
|
||
el.querySelector(".name div").textContent = s.name;
|
||
el.querySelector(".chips").textContent = s.chips ?? "";
|
||
el.querySelector(".aktion").textContent = s.aktion || "";
|
||
if (s.einsatz) { // Einsatz liegt zwischen Platz und Mitte
|
||
const e = document.createElement("div");
|
||
e.className = "stelle einsatz"; e.textContent = s.einsatz;
|
||
e.dataset.fx = PLATZ[s.nr][0] + (0.5 - PLATZ[s.nr][0]) * 0.4;
|
||
e.dataset.fy = PLATZ[s.nr][1] + (0.5 - PLATZ[s.nr][1]) * 0.4;
|
||
einsaetze.appendChild(e);
|
||
}
|
||
if (s.nr === zustand.held_sitz) { // eigener Platz: Nachkauf statt +
|
||
const n = document.createElement("button");
|
||
n.className = "stelle nachkauf"; n.textContent = "+ Chips";
|
||
n.disabled = !(zustand.buyin.nachkauf_max > 0);
|
||
n.dataset.fx = PLATZ[s.nr][0]; n.dataset.fy = PLATZ[s.nr][1] + 0.075;
|
||
n.addEventListener("click", nachkaufOeffnen);
|
||
box.appendChild(n);
|
||
}
|
||
} else if (zustand.held_sitz === null) {
|
||
el = document.createElement("button"); // ohne Hülle: der Text gehört dem Knopf
|
||
el.className = "stelle platz-frei"; el.textContent = "+";
|
||
el.addEventListener("click", () => buyinOeffnen(s.nr));
|
||
} else continue;
|
||
el.dataset.fx = PLATZ[s.nr][0]; el.dataset.fy = PLATZ[s.nr][1];
|
||
box.appendChild(el);
|
||
}
|
||
}
|
||
|
||
function leisteZeichnen() {
|
||
const box = document.getElementById("leiste");
|
||
const knoepfe = LEISTE[zustand.leiste](zustand);
|
||
const schluessel = zustand.leiste + JSON.stringify(knoepfe.map(k => k[0]));
|
||
if (schluessel === leisteSchluessel) return;
|
||
leisteSchluessel = schluessel;
|
||
box.textContent = "";
|
||
for (const [text, fx, fy, art, name] of knoepfe) {
|
||
const b = document.createElement("button");
|
||
b.textContent = text; b.className = art; b.dataset.fx = fx; b.dataset.fy = fy;
|
||
if (vorab.has(name)) b.classList.add("an");
|
||
b.addEventListener("click", () => klick(name, b));
|
||
box.appendChild(b);
|
||
}
|
||
if (zustand.leiste === "zug") {
|
||
const f = document.createElement("input");
|
||
f.className = "betrag"; f.dataset.fx = 0.873; f.dataset.fy = 0.855; f.value = zustand.raise || "";
|
||
box.appendChild(f);
|
||
}
|
||
}
|
||
|
||
function klick(name, knopf) {
|
||
if (["fold", "call", "raise"].includes(name)) { senden("/api/aktion", {aktion: name}); return; }
|
||
if (name.startsWith("v") && zustand.leiste === "zug") {
|
||
const f = document.querySelector(".betrag");
|
||
if (f) f.value = name === "vmax" ? "Max" : name.slice(1) + "%";
|
||
return;
|
||
}
|
||
if (zustand.leiste === "vorab") { // Vorauswahl: nur Haken umschalten, wie im Client
|
||
vorab.has(name) ? vorab.delete(name) : vorab.add(name);
|
||
knopf.classList.toggle("an");
|
||
}
|
||
}
|
||
|
||
function zeichnen() {
|
||
plaetzeZeichnen();
|
||
leisteZeichnen();
|
||
const board = document.getElementById("board");
|
||
board.textContent = "";
|
||
for (const k of zustand.board) board.appendChild(karte(k));
|
||
const eigene = document.querySelector("#eigene .karten");
|
||
eigene.textContent = "";
|
||
for (const k of zustand.karten) eigene.appendChild(karte(k));
|
||
document.querySelector(".pot").hidden = zustand.pot === null;
|
||
document.getElementById("pot").textContent = zustand.pot ?? "";
|
||
document.getElementById("handnr").textContent = zustand.hand ? "Hand #" + zustand.hand : "";
|
||
document.getElementById("guthaben").textContent = zahl(zustand.buyin.konto);
|
||
const uhr = document.getElementById("uhr");
|
||
uhr.hidden = !(zustand.uhr && zustand.uhr.sitz);
|
||
if (!uhr.hidden) { // über dem Namen dessen, der dran ist
|
||
uhr.dataset.fx = PLATZ[zustand.uhr.sitz][0]; uhr.dataset.fy = PLATZ[zustand.uhr.sitz][1] - 0.075;
|
||
}
|
||
uhrTicken();
|
||
anordnen();
|
||
}
|
||
|
||
function uhrTicken() { // die Uhr läuft zwischen zwei Abfragen weiter
|
||
const u = zustand && zustand.uhr, el = document.getElementById("uhr");
|
||
if (!u || el.hidden) return;
|
||
const rest = Math.max(0, Math.ceil(u.frist - (Date.now() / 1000 - u.start) * u.faktor));
|
||
el.textContent = "⏱ " + rest;
|
||
el.classList.toggle("knapp", rest <= 5);
|
||
}
|
||
|
||
async function laden() {
|
||
try {
|
||
const neu = await (await fetch("/api/zustand?room=" + encodeURIComponent(RAUM))).json();
|
||
if (JSON.stringify(neu) !== JSON.stringify(zustand)) { zustand = neu; zeichnen(); }
|
||
} catch (e) { /* Server weg */ }
|
||
}
|
||
|
||
// --- Buy-in ---------------------------------------------------------------
|
||
const modal = document.querySelector(".sfs-buy-in-modal");
|
||
const feld = document.querySelector(".sfs-slider-range-value");
|
||
const fehler = document.querySelector(".sfs-buy-in-body-error");
|
||
let gewaehlt = null, modus = "sitzen";
|
||
const zahl = n => Number(n).toLocaleString("en-US");
|
||
const stackInfo = document.querySelector(".sfs-buy-in-body-container-text");
|
||
// Grenzen des Dialogs: beim Hinsetzen Min/Max des Tischs, beim Nachkauf bis zur Obergrenze
|
||
function grenzen() {
|
||
const b = zustand.buyin;
|
||
if (modus === "sitzen") return {min: b.min, max: Math.min(b.max, b.konto)};
|
||
const max = Math.min(b.nachkauf_max, b.konto);
|
||
return {min: Math.min(b.bb, max), max};
|
||
}
|
||
// Für Werkzeuge, die per Bildschirm klicken: Mitte eines Elements als Anteil des Fensterrahmens
|
||
window.stelleVon = sel => {
|
||
const el = document.querySelector(sel), r = rahmen();
|
||
if (!el || !el.offsetParent) return null;
|
||
const k = el.getBoundingClientRect();
|
||
return [(k.left + k.width / 2 + r.rand) / r.w, (k.top + k.height / 2 + r.oben) / r.h];
|
||
};
|
||
|
||
function buyinOeffnen(nr) {
|
||
gewaehlt = nr; modus = "sitzen";
|
||
dialogOeffnen("Buy-In");
|
||
}
|
||
function nachkaufOeffnen() {
|
||
modus = "nachkauf";
|
||
dialogOeffnen("Add Chips");
|
||
}
|
||
function dialogOeffnen(titel) {
|
||
const b = zustand.buyin;
|
||
document.querySelector(".sfs-buy-in-heading").textContent = titel;
|
||
document.querySelector(".sfs-buy-in-user-balance").textContent = zahl(b.konto);
|
||
stackInfo.hidden = modus !== "nachkauf";
|
||
stackInfo.textContent = "Stack " + zahl(b.stack ?? 0) + " · bis " + zahl(b.max);
|
||
feld.value = zahl(grenzen().min);
|
||
fehler.textContent = "";
|
||
modal.style.display = "block";
|
||
document.querySelector(".dialog-backdrop").style.display = "block";
|
||
buyinAusrichten();
|
||
}
|
||
function buyinAusrichten() {
|
||
if (modal.style.display !== "block") return;
|
||
const r = rahmen(), knopf = document.querySelector(".sfs-buy-in-modal-button");
|
||
modal.style.left = "0px"; modal.style.top = "0px";
|
||
const k = knopf.getBoundingClientRect();
|
||
modal.style.left = (BUYIN[0] * r.w - r.rand - (k.left + k.width / 2)) + "px";
|
||
modal.style.top = (BUYIN[1] * r.h - r.oben - (k.top + k.height / 2)) + "px";
|
||
}
|
||
function buyinSchliessen() {
|
||
modal.style.display = "none";
|
||
document.querySelector(".dialog-backdrop").style.display = "none";
|
||
}
|
||
document.querySelector(".sfs-buy-in-body-min-range").addEventListener("click", () => feld.value = zahl(grenzen().min));
|
||
document.querySelector(".sfs-buy-in-body-max-range").addEventListener("click", () => feld.value = zahl(grenzen().max));
|
||
for (const v of document.querySelectorAll(".sfs-buy-in-body-mid-range")) {
|
||
v.addEventListener("click", () => { // Voreinstellung: Stack nach dem Kauf in BB
|
||
const g = grenzen(), ziel = v.dataset.bb * zustand.buyin.bb;
|
||
const betrag = modus === "sitzen" ? ziel : ziel - (zustand.buyin.stack || 0);
|
||
feld.value = zahl(Math.min(Math.max(betrag, g.min), g.max));
|
||
});
|
||
}
|
||
document.querySelector(".common-dialog-cross-icon").addEventListener("click", buyinSchliessen);
|
||
document.querySelector(".sfs-buy-in-modal-button").addEventListener("click", async () => {
|
||
const betrag = Number(feld.value.replace(/[^0-9.]/g, ""));
|
||
const r = modus === "sitzen" ? await senden("/api/sitzen", {sitz: gewaehlt, betrag})
|
||
: await senden("/api/nachkauf", {betrag});
|
||
if (r.ok) { buyinSchliessen(); laden(); } else fehler.textContent = r.fehler || "Platz nicht frei";
|
||
});
|
||
|
||
addEventListener("resize", () => { anordnen(); buyinAusrichten(); });
|
||
laden();
|
||
setInterval(laden, 250);
|
||
setInterval(uhrTicken, 100);
|
||
</script>
|
||
</body>
|
||
</html>
|