clone

a takuzu puzzle field for agents to explore tile by tile, with a referee and a replayable spectator view

viewer: a ?zoom= deep link for the initial view (used for screenshots and links)

dami committed 2df8a9e
commit
2df8a9e82d668242294c91f1a6ed1af2bfc439fd
parent
d7f3c1c435bd6bc9804c142133cec3a0781f37a1
author
dami <gazey55@gmail.com>
3 files changed, +27 -4
Msite/islands/Viewer.tsx20+++++++++++++++++---
Msite/routes/day/[date].tsx9++++++++-
Msite/routes/index.tsx2++
M site/islands/Viewer.tsx +17 -3
@@ -1084,7 +1084,7 @@ const STYLE = `
10841084 .pane{flex:1;min-height:0;overflow:auto;font-size:12.5px}10851085 .moves{display:grid;grid-template-columns:auto 14px minmax(0,1fr);column-gap:8px;padding:6px 14px;align-items:baseline}10861086 .moves .n{color:var(--muted);text-align:right}1087-.moves .who{color:var(--text-dim)}1087+.moves .who{color:var(--text-dim);margin-right:5px}10881088 .moves .what{color:var(--text)}10891089 .moves .note{grid-column:1 / span 3;font-style:italic;color:var(--text-dim);padding:3px 0}10901090 .moves .note.danger{color:var(--danger)}
@@ -1135,6 +1135,8 @@ export default function Viewer(
11351135 live?: string | null;11361136 /** the day this game is (for the head and the result card) */11371137 day?: string | null;1138+ /** an initial zoom in pixels per cell, centred on the cluster (deep links) */1139+ zoom?: number | null;11381140 },11391141 ) {11401142 const canvasRef = useRef<HTMLCanvasElement>(null);
@@ -1282,11 +1284,23 @@ export default function Viewer(
12821284 cache.current.clear();12831285 }, [theme, hues]);12841286 1285- // initial fit1287+ // initial fit (or a deep-linked zoom about the cluster's centre)12861288 useEffect(() => {12871289 const c = canvasRef.current;12881290 if (!c || !state.manifest || view) return;1289- setView(fitView(final, c.clientWidth, c.clientHeight));1291+ const fit = fitView(final, c.clientWidth, c.clientHeight);1292+ if (props.zoom && props.zoom > 0) {1293+ const W = c.clientWidth, H = c.clientHeight;1294+ const cx = (W / 2 - fit.ox) / fit.scale,1295+ cy = (H / 2 - fit.oy) / fit.scale;1296+ setView({1297+ scale: props.zoom,1298+ ox: W / 2 - cx * props.zoom,1299+ oy: H / 2 - cy * props.zoom,1300+ });1301+ return;1302+ }1303+ setView(fit);12901304 }, [state.manifest, view]);12911305 12921306 // the placement snap: when the revision changes, the newest stones grow
M site/routes/day/[date].tsx +8 -1
M site/routes/index.tsx +2 -0