Spaces:
Running on Zero
Running on Zero
play: autosize the terminal so the full board always fits (cards were clipping)
Browse files- space/static/app.css +2 -2
- space/static/play.html +23 -4
space/static/app.css
CHANGED
|
@@ -213,8 +213,8 @@ html, body {
|
|
| 213 |
.term-frame {
|
| 214 |
position: relative;
|
| 215 |
z-index: 10;
|
| 216 |
-
width: min(
|
| 217 |
-
height: min(
|
| 218 |
background: var(--bg);
|
| 219 |
border: 1px solid var(--ink);
|
| 220 |
border-radius: 6px;
|
|
|
|
| 213 |
.term-frame {
|
| 214 |
position: relative;
|
| 215 |
z-index: 10;
|
| 216 |
+
width: min(1280px, 96vw);
|
| 217 |
+
height: min(1100px, 94vh);
|
| 218 |
background: var(--bg);
|
| 219 |
border: 1px solid var(--ink);
|
| 220 |
border-radius: 6px;
|
space/static/play.html
CHANGED
|
@@ -36,10 +36,16 @@ const JADE = {
|
|
| 36 |
brightCyan: "#8cd3cb", brightWhite: "#f6f5dd",
|
| 37 |
};
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
const term = new Terminal({
|
| 40 |
theme: JADE,
|
| 41 |
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
| 42 |
-
fontSize:
|
| 43 |
lineHeight: 1.05,
|
| 44 |
cursorBlink: true,
|
| 45 |
cursorStyle: "block",
|
|
@@ -61,7 +67,20 @@ try {
|
|
| 61 |
webgl.onContextLoss(() => webgl.dispose());
|
| 62 |
term.loadAddon(webgl);
|
| 63 |
} catch (e) { /* DOM renderer: playable, just softer card frames */ }
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
const status = document.getElementById("status");
|
| 67 |
function setStatus(html, dead = false) {
|
|
@@ -95,8 +114,8 @@ term.onData((data) => {
|
|
| 95 |
if (ws.readyState === WebSocket.OPEN) ws.send(new TextEncoder().encode(data));
|
| 96 |
});
|
| 97 |
|
| 98 |
-
window.addEventListener("resize", () => {
|
| 99 |
-
const ro = new ResizeObserver(() => {
|
| 100 |
ro.observe(document.getElementById("terminal"));
|
| 101 |
</script>
|
| 102 |
</body>
|
|
|
|
| 36 |
brightCyan: "#8cd3cb", brightWhite: "#f6f5dd",
|
| 37 |
};
|
| 38 |
|
| 39 |
+
// The board needs this much terminal real estate; below it, cards clip.
|
| 40 |
+
const MIN_ROWS = 44;
|
| 41 |
+
const MIN_COLS = 110;
|
| 42 |
+
const MAX_FONT = 15;
|
| 43 |
+
const MIN_FONT = 10;
|
| 44 |
+
|
| 45 |
const term = new Terminal({
|
| 46 |
theme: JADE,
|
| 47 |
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
| 48 |
+
fontSize: MAX_FONT,
|
| 49 |
lineHeight: 1.05,
|
| 50 |
cursorBlink: true,
|
| 51 |
cursorStyle: "block",
|
|
|
|
| 67 |
webgl.onContextLoss(() => webgl.dispose());
|
| 68 |
term.loadAddon(webgl);
|
| 69 |
} catch (e) { /* DOM renderer: playable, just softer card frames */ }
|
| 70 |
+
|
| 71 |
+
// Fit the whole board, not just the window: start at the comfy font size and
|
| 72 |
+
// step down until the grid clears MIN_ROWS x MIN_COLS (or we hit the floor).
|
| 73 |
+
function fitGame() {
|
| 74 |
+
let size = MAX_FONT;
|
| 75 |
+
term.options.fontSize = size;
|
| 76 |
+
fit.fit();
|
| 77 |
+
while ((term.rows < MIN_ROWS || term.cols < MIN_COLS) && size > MIN_FONT) {
|
| 78 |
+
size -= 1;
|
| 79 |
+
term.options.fontSize = size;
|
| 80 |
+
fit.fit();
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
fitGame();
|
| 84 |
|
| 85 |
const status = document.getElementById("status");
|
| 86 |
function setStatus(html, dead = false) {
|
|
|
|
| 114 |
if (ws.readyState === WebSocket.OPEN) ws.send(new TextEncoder().encode(data));
|
| 115 |
});
|
| 116 |
|
| 117 |
+
window.addEventListener("resize", () => { fitGame(); sendResize(); });
|
| 118 |
+
const ro = new ResizeObserver(() => { fitGame(); sendResize(); });
|
| 119 |
ro.observe(document.getElementById("terminal"));
|
| 120 |
</script>
|
| 121 |
</body>
|