diff options
Diffstat (limited to '')
| -rw-r--r-- | web/play/src/crash.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/web/play/src/crash.ts b/web/play/src/crash.ts index 6f3c8dd..a683dcd 100644 --- a/web/play/src/crash.ts +++ b/web/play/src/crash.ts | |||
| @@ -31,6 +31,7 @@ let sendCommand: ((command: unknown) => void) | null = null; | |||
| 31 | let frameHandle: number | undefined; | 31 | let frameHandle: number | undefined; |
| 32 | let verifyToken = 0; | 32 | let verifyToken = 0; |
| 33 | let lastStatus = ""; | 33 | let lastStatus = ""; |
| 34 | let lastAction = 0; | ||
| 34 | 35 | ||
| 35 | function build( | 36 | function build( |
| 36 | board: HTMLElement, | 37 | board: HTMLElement, |
| @@ -88,6 +89,8 @@ function build( | |||
| 88 | const primary = node("button", "btn primary wide big", "START") as HTMLButtonElement; | 89 | const primary = node("button", "btn primary wide big", "START") as HTMLButtonElement; |
| 89 | const leave = node("button", "btn ghost wide", "Leave table") as HTMLButtonElement; | 90 | const leave = node("button", "btn ghost wide", "Leave table") as HTMLButtonElement; |
| 90 | primary.addEventListener("click", () => { | 91 | primary.addEventListener("click", () => { |
| 92 | if (Date.now() - lastAction < 500) return; | ||
| 93 | lastAction = Date.now(); | ||
| 91 | if (current?.status === "running") sendCommand?.("CashOut"); | 94 | if (current?.status === "running") sendCommand?.("CashOut"); |
| 92 | else sendCommand?.("Start"); | 95 | else sendCommand?.("Start"); |
| 93 | }); | 96 | }); |
| @@ -118,6 +121,15 @@ function build( | |||
| 118 | }; | 121 | }; |
| 119 | } | 122 | } |
| 120 | 123 | ||
| 124 | /// Stop the chart loop when another screen takes over. | ||
| 125 | export function stopCrashAnimation(): void { | ||
| 126 | if (frameHandle !== undefined) { | ||
| 127 | cancelAnimationFrame(frameHandle); | ||
| 128 | frameHandle = undefined; | ||
| 129 | } | ||
| 130 | current = null; | ||
| 131 | } | ||
| 132 | |||
| 121 | export function renderCrash( | 133 | export function renderCrash( |
| 122 | board: HTMLElement, | 134 | board: HTMLElement, |
| 123 | side: HTMLElement, | 135 | side: HTMLElement, |
| @@ -125,7 +137,7 @@ export function renderCrash( | |||
| 125 | send: (command: unknown) => void, | 137 | send: (command: unknown) => void, |
| 126 | now: Clock, | 138 | now: Clock, |
| 127 | ): void { | 139 | ): void { |
| 128 | if (!parts || parts.board !== board) { | 140 | if (!parts || parts.board !== board || !parts.canvas.isConnected) { |
| 129 | parts = build(board, side, send, now); | 141 | parts = build(board, side, send, now); |
| 130 | lastStatus = ""; | 142 | lastStatus = ""; |
| 131 | } | 143 | } |
