commit 84faf5fdb71e2a0167b09644d52f4d1f3b970f35
parent cb3d7e168bd37d37355e057a3fd97ed4836a4fbd
Author: anon <anon@example.com>
Date: Sun, 18 Oct 2026 05:59:49 +0000
Add player display menu with Retina resolution switching
Diffstat:
2 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
@@ -28,6 +28,10 @@ required. New visitors start in run mode with character tips disabled.
Click the game or press a key to enable sound.
Two-finger scrolling (or a mouse wheel) rotates the browser camera. Right-button
drag and Ctrl-drag also work; the game canvas suppresses the browser context menu.
+Press Ctrl+Alt+M (Control+Option+M on Mac) for the player display menu. Switch
+between CSS pixels and Retina pixels while playing; the choice is remembered.
+Retina uses the screen's pixel density, making the original interface smaller
+and sharper as well as increasing rendering resolution.
The first server run verifies and unpacks the bundled data.
[Server controls](http://127.0.0.1:8080/control)
provide character editing, teleporting and time controls.
diff --git a/src/browser/index.html b/src/browser/index.html
@@ -8,12 +8,34 @@
canvas { display: block; width: 100%; height: 100%; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
#loading[hidden] { display: none; }
+ dialog { width: min(320px, calc(100vw - 64px)); padding: 24px; border: 1px solid #777; border-radius: 8px; background: #202428; color: #eee; box-shadow: 0 8px 40px #0008; }
+ dialog::backdrop { background: #0006; }
+ dialog h1 { margin: 0 0 20px; font-size: 20px; }
+ dialog select { display: block; width: 100%; margin: 8px 0; padding: 8px; }
+ dialog p { color: #bbb; line-height: 1.5; }
+ dialog button { padding: 8px 16px; cursor: pointer; }
</style>
<canvas id="canvas" width="1024" height="768" tabindex="0"></canvas>
<div id="loading" role="status">Loading...</div>
+<dialog id="player-menu" aria-labelledby="menu-title">
+ <h1 id="menu-title">Display</h1>
+ <label for="pixel-mode">Resolution</label>
+ <select id="pixel-mode">
+ <option value="css">CSS pixels</option>
+ <option value="retina">Retina pixels</option>
+ </select>
+ <output id="render-size"></output>
+ <p>Retina makes the scene sharper and the game interface smaller. It may reduce frame rate.</p>
+ <form method="dialog"><button>Back to game</button></form>
+ <p>Ctrl+Alt+M to open or close. Escape to close.</p>
+</dialog>
<script>
const status = document.querySelector('#loading');
const canvas = document.querySelector('#canvas');
+ const playerMenu = document.querySelector('#player-menu');
+ const pixelMode = document.querySelector('#pixel-mode');
+ pixelMode.value = localStorage.getItem('ao-pixel-mode') === 'retina' ? 'retina' : 'css';
+ let runtimeReady = false;
let recording = null, reportURL = null;
function log(message) {
console.log(message);
@@ -31,8 +53,10 @@
onFirstFrame: () => { status.hidden = true; },
onRuntimeInitialized: () => {
console.log('Client running');
- new ResizeObserver(() => Module._browser_request_resize(canvas.clientWidth, canvas.clientHeight)).observe(canvas);
- canvas.focus();
+ runtimeReady = true;
+ new ResizeObserver(updateResolution).observe(canvas);
+ updateResolution();
+ if (!playerMenu.open) canvas.focus();
},
instantiateWasm: (imports, receive) => {
instantiateClient(imports, receive).catch(error => Module.onAbort(error.message));
@@ -40,6 +64,43 @@
}
};
+ // Keep CSS layout fixed while the render worker changes its backing pixels.
+ function renderSize() {
+ const scale = pixelMode.value === 'retina' ? devicePixelRatio : 1;
+ return [Math.round(canvas.clientWidth * scale), Math.round(canvas.clientHeight * scale)];
+ }
+ function updateResolution() {
+ const [width, height] = renderSize();
+ document.querySelector('#render-size').textContent = `${width} x ${height} pixels`;
+ if (runtimeReady) Module._browser_request_resize(width, height);
+ }
+ pixelMode.onchange = () => {
+ localStorage.setItem('ao-pixel-mode', pixelMode.value);
+ updateResolution();
+ };
+ window.addEventListener('resize', updateResolution);
+ window.addEventListener('keydown', event => {
+ if (event.ctrlKey && event.altKey && event.code === 'KeyM') {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ if (event.repeat) return;
+ if (playerMenu.open) playerMenu.close();
+ else {
+ // Release held game inputs before the dialog takes keyboard focus.
+ window.dispatchEvent(new Event('blur'));
+ playerMenu.showModal();
+ updateResolution();
+ }
+ } else if (playerMenu.open) event.stopImmediatePropagation();
+ }, true);
+ window.addEventListener('keypress', event => {
+ if (playerMenu.open) event.stopImmediatePropagation();
+ }, true);
+ playerMenu.addEventListener('close', () => {
+ window.dispatchEvent(new Event('focus'));
+ canvas.focus();
+ });
+
// Count compressed bytes and preserve streaming compilation while decoding.
async function instantiateClient(imports, receive) {
const response = await fetch('/wasm/game.wasm.gz');
@@ -137,9 +198,8 @@ show();
const response = await fetch('/browser-launch', {method: 'POST'});
if (!response.ok) { status.textContent = await response.text(); return; }
Module.arguments = (await response.text()).trim().split(' ').slice(1);
- // Match CSS pixels; the render worker owns the backing canvas after startup.
- canvas.width = canvas.clientWidth;
- canvas.height = canvas.clientHeight;
+ // The render worker owns the backing canvas after startup.
+ [canvas.width, canvas.height] = renderSize();
const script = document.createElement('script');
script.src = '/wasm/game.js';
script.onerror = () => { status.textContent = 'Could not load the client'; };