Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
/* Mineflappy offline cache.
|
2026-10-23 18:10:09 +00:00
|
|
|
|
|
|
|
|
The app shell (index.html) is fetched NETWORK-FIRST so a new deploy
|
|
|
|
|
reaches the player immediately; if the network is down it falls back to
|
|
|
|
|
the cached copy. The icons and manifest are cache-first because they
|
|
|
|
|
only change with a version bump. */
|
|
|
|
|
const CACHE = 'mineflappy-v2';
|
Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
const ASSETS = [
|
|
|
|
|
'./',
|
|
|
|
|
'./index.html',
|
|
|
|
|
'./manifest.webmanifest',
|
|
|
|
|
'./icon-192.png',
|
|
|
|
|
'./icon-512.png',
|
|
|
|
|
'./apple-touch-icon.png',
|
|
|
|
|
'./favicon-32.png'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', e => {
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
caches.open(CACHE)
|
|
|
|
|
.then(c => c.addAll(ASSETS))
|
|
|
|
|
.then(() => self.skipWaiting())
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', e => {
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
caches.keys()
|
|
|
|
|
.then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))))
|
|
|
|
|
.then(() => self.clients.claim())
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-23 18:10:09 +00:00
|
|
|
function isAppShell(url) {
|
|
|
|
|
return url.pathname.endsWith('/') ||
|
|
|
|
|
url.pathname.endsWith('/index.html') ||
|
|
|
|
|
url.pathname.endsWith('/sw.js');
|
|
|
|
|
}
|
|
|
|
|
|
Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
self.addEventListener('fetch', e => {
|
|
|
|
|
const req = e.request;
|
2026-10-23 18:10:09 +00:00
|
|
|
if (req.method !== 'GET') return;
|
|
|
|
|
const url = new URL(req.url);
|
|
|
|
|
if (url.origin !== location.origin) return;
|
|
|
|
|
|
|
|
|
|
if (isAppShell(url)) {
|
|
|
|
|
/* network first - a redeploy shows up straight away */
|
|
|
|
|
e.respondWith(
|
|
|
|
|
fetch(req).then(res => {
|
|
|
|
|
if (res && res.status === 200) {
|
|
|
|
|
const copy = res.clone();
|
|
|
|
|
caches.open(CACHE).then(c => c.put(req, copy));
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}).catch(() => caches.match(req).then(hit => hit || caches.match('./index.html')))
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
|
2026-10-23 18:10:09 +00:00
|
|
|
/* everything else: cache first, refresh in the background */
|
Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
e.respondWith(
|
|
|
|
|
caches.match(req).then(hit => {
|
|
|
|
|
const network = fetch(req).then(res => {
|
|
|
|
|
if (res && res.status === 200 && res.type === 'basic') {
|
|
|
|
|
const copy = res.clone();
|
|
|
|
|
caches.open(CACHE).then(c => c.put(req, copy));
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2026-10-23 18:10:09 +00:00
|
|
|
}).catch(() => hit);
|
Fullscreen PWA: no border, installs as an app, works offline
- canvas fills the entire screen on any device; the 480x640 world is
scaled to fit and bottom-aligned so the ground always sits on the
bottom edge, with the sky painted full-bleed behind it
- the canvas buffer now always matches its laid-out size, so the drawing
can never drift out of step with the screen
- HUD (score, badge, buffs, toasts, biome banner) moved to screen space
so it stays pinned to the real screen edges
- sun and stars drawn in screen space so the sky above the play area is
not empty
- PWA: manifest, service worker (offline), generated app icons and an
in-game INSTALL APP button
- overlays now dim the whole screen, not just the game strip
2026-10-23 17:52:18 +00:00
|
|
|
return hit || network;
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|