Ask before leaving the page while a world is open (Ctrl+W closed the game)

Ctrl (replace) + W (fly) hits the browser's close-tab shortcut, which a page
cannot block. A beforeunload prompt now catches it. Autosave on hiding the
tab no longer depends on the audio context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 19:47:27 -04:00
co-authored by Claude Opus 5.5
parent f9012384fc
commit 0679878e69
3 changed files with 24 additions and 1 deletions
+4
View File
@@ -27,6 +27,10 @@ with sync_playwright() as p:
ev = pg.evaluate
look = sys.argv[2] if len(sys.argv) > 2 else 'pixel'
check('a new game starts fully zoomed in', ev('SET.zoom') == 12, ev('SET.zoom'))
# Ctrl+W (Ctrl to replace, W to fly) closes the tab; with a world open the browser must ask first
leave = "(() => { const e = new Event('beforeunload', { cancelable: true }); dispatchEvent(e); return e.defaultPrevented; })()"
check('leaving the page with a world open asks to confirm', ev(leave))
check('but not on the title screen', not ev(f'(() => {{ GAME.running = false; const r = {leave}; GAME.running = true; return r; }})()'))
ev("SET.zoom = 4; resizeRender(); R.snapNext = true;") # the rest of this play-through was laid out at zoom 4
ev(f"SET.look = '{look}'"); pg.wait_for_timeout(200)
check(f'the {look} look is drawing', ev('R.smoothOn') == (look == 'smooth'), ev('[SET.look, R.smoothOn, SM.ok]'))