diff options
Diffstat (limited to '')
| -rw-r--r-- | web/play/src/crash.ts | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/web/play/src/crash.ts b/web/play/src/crash.ts index a683dcd..0f18bd2 100644 --- a/web/play/src/crash.ts +++ b/web/play/src/crash.ts | |||
| @@ -44,26 +44,22 @@ function build( | |||
| 44 | sendCommand = send; | 44 | sendCommand = send; |
| 45 | clock = now; | 45 | clock = now; |
| 46 | 46 | ||
| 47 | board.append(node("h2", undefined, "Crash")); | ||
| 48 | board.append( | ||
| 49 | node("p", "note", "The multiplier rises from 1.00×. Cash out before it crashes."), | ||
| 50 | ); | ||
| 51 | |||
| 52 | const wrap = node("div", "crash-wrap"); | 47 | const wrap = node("div", "crash-wrap"); |
| 53 | const number = node("div", "crash-number", "1.00×"); | 48 | const number = node("div", "crash-number", "1.00×"); |
| 49 | const phase = node("div", "label", "READY"); | ||
| 54 | const meta = node("div", "crash-meta"); | 50 | const meta = node("div", "crash-meta"); |
| 55 | const canvas = node("canvas", "crash-canvas") as HTMLCanvasElement; | 51 | const canvas = node("canvas", "crash-canvas") as HTMLCanvasElement; |
| 56 | const verify = node("div", "verify", "Waiting for a round commitment."); | 52 | const verify = node("div", "verify", "Waiting for a round commitment."); |
| 57 | wrap.append(number, meta, canvas, verify); | 53 | wrap.append(number, phase, meta, canvas, verify); |
| 58 | board.append(wrap); | 54 | board.append(wrap); |
| 59 | 55 | ||
| 60 | side.append(node("div", "label", "Crash")); | 56 | side.append(node("h2", undefined, "Crash")); |
| 61 | side.append(node("p", "note", "The server commits to a seed before the round. The seed is revealed when it ends.")); | 57 | side.append(node("p", "note", "Cash out before the multiplier crashes.")); |
| 62 | 58 | ||
| 63 | const betRow = node("div", "row"); | 59 | const betRow = node("div", "row"); |
| 64 | const minus = node("button", "btn small", "−10") as HTMLButtonElement; | 60 | const minus = node("button", "btn small", "−") as HTMLButtonElement; |
| 65 | const bet = node("strong", "mono", "—"); | 61 | const bet = node("strong", "mono", "—"); |
| 66 | const plus = node("button", "btn small", "+10") as HTMLButtonElement; | 62 | const plus = node("button", "btn small", "+") as HTMLButtonElement; |
| 67 | minus.addEventListener("click", () => sendCommand?.({ AdjustBet: -10 })); | 63 | minus.addEventListener("click", () => sendCommand?.({ AdjustBet: -10 })); |
| 68 | plus.addEventListener("click", () => sendCommand?.({ AdjustBet: 10 })); | 64 | plus.addEventListener("click", () => sendCommand?.({ AdjustBet: 10 })); |
| 69 | betRow.append(minus, bet, plus); | 65 | betRow.append(minus, bet, plus); |
| @@ -80,7 +76,7 @@ function build( | |||
| 80 | side.append(row); | 76 | side.append(row); |
| 81 | } | 77 | } |
| 82 | 78 | ||
| 83 | const status = node("p", "note", "Ready."); | 79 | const status = node("p", "note", "Press START to play."); |
| 84 | const lastCrash = node("p", "note", ""); | 80 | const lastCrash = node("p", "note", ""); |
| 85 | const error = node("p", "error-text"); | 81 | const error = node("p", "error-text"); |
| 86 | side.append(status, lastCrash, error); | 82 | side.append(status, lastCrash, error); |
| @@ -188,7 +184,7 @@ export function renderCrash( | |||
| 188 | p.status.textContent = "Round forfeited."; | 184 | p.status.textContent = "Round forfeited."; |
| 189 | p.status.className = "note error-text"; | 185 | p.status.className = "note error-text"; |
| 190 | } else { | 186 | } else { |
| 191 | p.status.textContent = "Ready. Start a round when you want."; | 187 | p.status.textContent = "Press START to play."; |
| 192 | p.status.className = "note"; | 188 | p.status.className = "note"; |
| 193 | } | 189 | } |
| 194 | 190 | ||
| @@ -197,7 +193,9 @@ export function renderCrash( | |||
| 197 | } | 193 | } |
| 198 | 194 | ||
| 199 | const commit = view.commit ? String(view.commit) : ""; | 195 | const commit = view.commit ? String(view.commit) : ""; |
| 200 | p.meta.textContent = commit ? `commit ${shortHash(commit, 12)}` : "no commitment yet"; | 196 | p.meta.textContent = commit ? `commit ${shortHash(commit, 12)}` : ""; |
| 197 | p.meta.style.display = commit ? "" : "none"; | ||
| 198 | p.verify.style.display = commit ? "" : "none"; | ||
| 201 | 199 | ||
| 202 | if (view.seed && commit) { | 200 | if (view.seed && commit) { |
| 203 | const token = ++verifyToken; | 201 | const token = ++verifyToken; |
| @@ -249,6 +247,19 @@ function currentMultiplier(view: View, now: Clock): number { | |||
| 249 | function update(p: Parts, view: View, now: Clock): void { | 247 | function update(p: Parts, view: View, now: Clock): void { |
| 250 | const multiplier = currentMultiplier(view, now); | 248 | const multiplier = currentMultiplier(view, now); |
| 251 | p.number.textContent = `${multiplier.toFixed(2)}×`; | 249 | p.number.textContent = `${multiplier.toFixed(2)}×`; |
| 250 | const phase = p.number.nextElementSibling as HTMLElement | null; | ||
| 251 | if (phase) { | ||
| 252 | phase.textContent = | ||
| 253 | view.status === "running" | ||
| 254 | ? "RUNNING" | ||
| 255 | : view.status === "cashed" | ||
| 256 | ? "CASHED OUT" | ||
| 257 | : view.status === "crashed" | ||
| 258 | ? "CRASHED" | ||
| 259 | : view.status === "starting" | ||
| 260 | ? "STARTING" | ||
| 261 | : "READY"; | ||
| 262 | } | ||
| 252 | p.number.className = `crash-number ${ | 263 | p.number.className = `crash-number ${ |
| 253 | view.status === "running" | 264 | view.status === "running" |
| 254 | ? "running" | 265 | ? "running" |
| @@ -296,6 +307,8 @@ function drawChart(canvas: HTMLCanvasElement, view: View, multiplier: number, no | |||
| 296 | ctx.strokeStyle = "#242e38"; | 307 | ctx.strokeStyle = "#242e38"; |
| 297 | ctx.fillStyle = "#8a98a6"; | 308 | ctx.fillStyle = "#8a98a6"; |
| 298 | ctx.font = "11px ui-monospace, monospace"; | 309 | ctx.font = "11px ui-monospace, monospace"; |
| 310 | ctx.textAlign = "left"; | ||
| 311 | ctx.textBaseline = "middle"; | ||
| 299 | ctx.lineWidth = 1; | 312 | ctx.lineWidth = 1; |
| 300 | for (let step = 0; step <= 4; step += 1) { | 313 | for (let step = 0; step <= 4; step += 1) { |
| 301 | const value = 1 + ((yMax - 1) * step) / 4; | 314 | const value = 1 + ((yMax - 1) * step) / 4; |
| @@ -304,7 +317,7 @@ function drawChart(canvas: HTMLCanvasElement, view: View, multiplier: number, no | |||
| 304 | ctx.moveTo(padL, py); | 317 | ctx.moveTo(padL, py); |
| 305 | ctx.lineTo(width - padR, py); | 318 | ctx.lineTo(width - padR, py); |
| 306 | ctx.stroke(); | 319 | ctx.stroke(); |
| 307 | ctx.fillText(`${value.toFixed(1)}×`, 6, py + 4); | 320 | ctx.fillText(`${value.toFixed(1)}×`, 10, py); |
| 308 | } | 321 | } |
| 309 | for (let step = 0; step <= 4; step += 1) { | 322 | for (let step = 0; step <= 4; step += 1) { |
| 310 | const seconds = (xMax * step) / 4; | 323 | const seconds = (xMax * step) / 4; |
| @@ -315,7 +328,20 @@ function drawChart(canvas: HTMLCanvasElement, view: View, multiplier: number, no | |||
| 315 | ctx.strokeStyle = "#1b232c"; | 328 | ctx.strokeStyle = "#1b232c"; |
| 316 | ctx.stroke(); | 329 | ctx.stroke(); |
| 317 | ctx.fillStyle = "#5b6773"; | 330 | ctx.fillStyle = "#5b6773"; |
| 318 | ctx.fillText(`${seconds.toFixed(0)}s`, px - 10, height - 12); | 331 | ctx.textAlign = "center"; |
| 332 | ctx.textBaseline = "alphabetic"; | ||
| 333 | ctx.fillText(`${seconds.toFixed(0)}s`, px, height - 12); | ||
| 334 | ctx.textAlign = "left"; | ||
| 335 | ctx.textBaseline = "middle"; | ||
| 336 | } | ||
| 337 | |||
| 338 | if (!["running", "cashed", "crashed"].includes(String(view.status))) { | ||
| 339 | ctx.fillStyle = "#5b6773"; | ||
| 340 | ctx.textAlign = "center"; | ||
| 341 | ctx.textBaseline = "middle"; | ||
| 342 | ctx.font = '13px "Open Sans", sans-serif'; | ||
| 343 | ctx.fillText("Press START to play", padL + plotW / 2, padT + plotH / 2); | ||
| 344 | return; | ||
| 319 | } | 345 | } |
| 320 | 346 | ||
| 321 | const line = | 347 | const line = |
