feat: save-on-pause via visibilitychange and beforeunload (#57)
Auto-save game state when the browser tab is hidden (visibilitychange) or closed/navigated away (beforeunload). Prevents data loss on mobile where tab switching can kill the page without a save interval firing. Part of epic #57 Night of Polish — Task 6: Mobile Polish.
This commit is contained in:
10
js/main.js
10
js/main.js
@@ -99,3 +99,13 @@ window.addEventListener('keydown', function (e) {
|
||||
saveGame();
|
||||
}
|
||||
});
|
||||
|
||||
// Save-on-pause: auto-save when tab is hidden or closed (#57 Mobile Polish)
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (document.hidden) {
|
||||
saveGame();
|
||||
}
|
||||
});
|
||||
window.addEventListener('beforeunload', function () {
|
||||
saveGame();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user