summaryrefslogtreecommitdiffstats
path: root/web/play/src/roulette.ts
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-08 03:32:24 +0100
committersalmonik <salmonik@tuta.io>2026-11-08 03:32:24 +0100
commitfda24c47a8262388ada92722850a362da65aaa6e (patch)
tree13363fa1461ae4e10087acba562a527b8bde4228 /web/play/src/roulette.ts
parentv5.0.0: protocol v5 and the browser frontend (diff)
downloadzagan-bet-fda24c47a8262388ada92722850a362da65aaa6e.tar.gz
zagan-bet-fda24c47a8262388ada92722850a362da65aaa6e.zip
web: accept the serialized reels array and stop game loops on navigation
The Rust SlotsView serializes reels as an array of chars, so the browser joins it instead of String(array). The crash chart, reel animation and roulette observer now stop when another screen takes over, and a returning crash screen rebuilds its detached canvas. Action buttons ignore a double click before the server view arrives. Also tightens the gateway session registry with a generation token, caps WebSocket messages at 64 KiB, uses the __Host- cookie prefix on HTTPS, and ships the systemd unit.
Diffstat (limited to '')
-rw-r--r--web/play/src/roulette.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/web/play/src/roulette.ts b/web/play/src/roulette.ts
index cbb7c6e..a42686a 100644
--- a/web/play/src/roulette.ts
+++ b/web/play/src/roulette.ts
@@ -20,6 +20,9 @@ type Hotspot = {
20 rank: number; 20 rank: number;
21}; 21};
22 22
23let observer: ResizeObserver | null = null;
24let lastSpin = 0;
25
23type Layout = { 26type Layout = {
24 width: number; 27 width: number;
25 height: number; 28 height: number;
@@ -413,9 +416,11 @@ export function renderRoulette(
413 const zone = hit(event.clientX, event.clientY); 416 const zone = hit(event.clientX, event.clientY);
414 canvas.style.cursor = zone && !spinning ? "pointer" : "default"; 417 canvas.style.cursor = zone && !spinning ? "pointer" : "default";
415 }); 418 });
416 new ResizeObserver(() => { 419 observer?.disconnect();
420 observer = new ResizeObserver(() => {
417 current = draw(canvas, view); 421 current = draw(canvas, view);
418 }).observe(canvas); 422 });
423 observer.observe(canvas);
419 424
420 // Sidebar 425 // Sidebar
421 side.append(node("div", "label", "Roulette")); 426 side.append(node("div", "label", "Roulette"));
@@ -459,7 +464,11 @@ export function renderRoulette(
459 const actions = node("div", "actions"); 464 const actions = node("div", "actions");
460 const spin = node("button", "btn primary wide big", spinning ? "SPINNING…" : "SPIN WHEEL"); 465 const spin = node("button", "btn primary wide big", spinning ? "SPINNING…" : "SPIN WHEEL");
461 spin.disabled = spinning || total === 0; 466 spin.disabled = spinning || total === 0;
462 spin.addEventListener("click", () => send("Spin")); 467 spin.addEventListener("click", () => {
468 if (Date.now() - lastSpin < 600) return;
469 lastSpin = Date.now();
470 send("Spin");
471 });
463 const clearBets = node("button", "btn wide", "Clear bets"); 472 const clearBets = node("button", "btn wide", "Clear bets");
464 clearBets.disabled = spinning || total === 0; 473 clearBets.disabled = spinning || total === 0;
465 clearBets.addEventListener("click", () => send("ClearBets")); 474 clearBets.addEventListener("click", () => send("ClearBets"));