feat(server): web replay viewer (HTML/CSS + WASM bindings)
Wires the WASM module from the previous commit into a minimal web
viewer served at <server>/replays/<id>. Two new server routes:
- `GET /replays/:id` — returns the same embedded HTML page for any
id; the page itself reads the path from window.location in JS and
fetches the replay JSON via /api/replays/:id.
- `/web/*` — ServeDir for the static assets (replay.css, replay.js,
and the wasm-bindgen-generated pkg/).
Web layer:
- index.html — header, board, controls, status. Module script.
- replay.css — midnight-purple palette matching the desktop client,
dark felt board, CSS-grid pile layout, tableau fan via per-card
inline `top` offset.
- replay.js — fetches the replay, instantiates the wasm
ReplayPlayer, drives state(), step(). Controls: Restart, Play/Pause
toggle, Step. Auto-tick at 600 ms.
- pkg/ — generated by wasm-bindgen (committed so deployers don't
have to install wasm-bindgen-cli + the wasm32 target).
`tower-http = "0.6"` added to solitaire_server with the `fs` feature
for ServeDir.
To regenerate pkg/ after a solitaire_wasm change:
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \
cargo build -p solitaire_wasm \
--target wasm32-unknown-unknown --release
wasm-bindgen --target web \
--out-dir solitaire_server/web/pkg --no-typescript \
target/wasm32-unknown-unknown/release/solitaire_wasm.wasm
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
/* Solitaire Quest replay viewer — palette mirrors the desktop client's
|
||||
midnight-purple Balatro tone (BG_BASE = #1A0F2E) and the dark felt
|
||||
from the engine's TABLE_COLOUR. */
|
||||
|
||||
:root {
|
||||
--bg: #0f0a1f;
|
||||
--felt: #0f4c30;
|
||||
--panel: #1a0f2e;
|
||||
--panel-hi: #2d1b69;
|
||||
--text: #f5f0ff;
|
||||
--text-muted: #b5a8d5;
|
||||
--accent: #ffd23f;
|
||||
--red: #cc3344;
|
||||
--black: #1a0f2e;
|
||||
--card-bg: #ffffff;
|
||||
--card-border: #ccc;
|
||||
--card-w: 80px;
|
||||
--card-h: 112px;
|
||||
--gap: 12px;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
header {
|
||||
padding: 16px 24px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.muted { color: var(--text-muted); }
|
||||
|
||||
main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 24px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#board {
|
||||
background: var(--felt);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
width: min(100%, calc(7 * var(--card-w) + 8 * var(--gap)));
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, var(--card-w));
|
||||
grid-template-rows: var(--card-h) auto;
|
||||
gap: var(--gap);
|
||||
column-gap: var(--gap);
|
||||
row-gap: 32px;
|
||||
}
|
||||
|
||||
/* Top row: stock, waste, [skip], 4 foundations. */
|
||||
.pile-stock { grid-column: 1; grid-row: 1; }
|
||||
.pile-waste { grid-column: 2; grid-row: 1; }
|
||||
.pile-foundation-0 { grid-column: 4; grid-row: 1; }
|
||||
.pile-foundation-1 { grid-column: 5; grid-row: 1; }
|
||||
.pile-foundation-2 { grid-column: 6; grid-row: 1; }
|
||||
.pile-foundation-3 { grid-column: 7; grid-row: 1; }
|
||||
.pile-tableau-0 { grid-column: 1; grid-row: 2; }
|
||||
.pile-tableau-1 { grid-column: 2; grid-row: 2; }
|
||||
.pile-tableau-2 { grid-column: 3; grid-row: 2; }
|
||||
.pile-tableau-3 { grid-column: 4; grid-row: 2; }
|
||||
.pile-tableau-4 { grid-column: 5; grid-row: 2; }
|
||||
.pile-tableau-5 { grid-column: 6; grid-row: 2; }
|
||||
.pile-tableau-6 { grid-column: 7; grid-row: 2; }
|
||||
|
||||
.pile {
|
||||
position: relative;
|
||||
width: var(--card-w);
|
||||
/* Tableau columns let cards stack downward. */
|
||||
}
|
||||
|
||||
.pile-empty {
|
||||
width: var(--card-w);
|
||||
height: var(--card-h);
|
||||
border: 2px dashed rgba(255, 255, 255, 0.15);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.card {
|
||||
position: absolute;
|
||||
width: var(--card-w);
|
||||
height: var(--card-h);
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
padding: 4px 6px;
|
||||
font-family: "Helvetica Neue", Arial, sans-serif;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
user-select: none;
|
||||
transition: top 180ms ease, opacity 180ms ease;
|
||||
}
|
||||
|
||||
/* Tableau fan: cards beneath the top one peek through ~28 px down. */
|
||||
.pile-tableau-0 .card,
|
||||
.pile-tableau-1 .card,
|
||||
.pile-tableau-2 .card,
|
||||
.pile-tableau-3 .card,
|
||||
.pile-tableau-4 .card,
|
||||
.pile-tableau-5 .card,
|
||||
.pile-tableau-6 .card {
|
||||
/* Per-card top set inline by JS (offset = idx * 28 px). */
|
||||
}
|
||||
|
||||
.card.face-down {
|
||||
background:
|
||||
repeating-linear-gradient(
|
||||
45deg,
|
||||
#482f97 0,
|
||||
#482f97 6px,
|
||||
#2d1b69 6px,
|
||||
#2d1b69 12px
|
||||
);
|
||||
color: transparent;
|
||||
border-color: #4a3a8a;
|
||||
}
|
||||
|
||||
.card .corner {
|
||||
position: absolute;
|
||||
font-size: 14px;
|
||||
line-height: 1.1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card .corner.top { top: 4px; left: 6px; }
|
||||
.card .corner.bottom { bottom: 4px; right: 6px; transform: rotate(180deg); }
|
||||
|
||||
.card.red { color: var(--red); }
|
||||
.card.black { color: var(--black); }
|
||||
|
||||
.card .center {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#controls button {
|
||||
background: var(--panel-hi);
|
||||
color: var(--text);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
#controls button:hover:not(:disabled) {
|
||||
background: var(--accent);
|
||||
color: var(--black);
|
||||
}
|
||||
|
||||
#controls button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#status {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#status #result.win {
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
Reference in New Issue
Block a user