- Procedural island maps, RCI zoning, demand-driven growth - City-wide power grid with brownouts; wind coastal bonus - Land value, upgrades, services, pollution, fires & fire spread - Budget/taxes, happiness, milestones, quest onboarding - Traffic agents, day/night cycle, adaptive render scale - Saves: autosave + 3 slots + JSON export/import - PWA (offline), GitHub Pages/Netlify deploy configs - Tests: 40-assertion engine suite + headless E2E
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
/* PolyCity service worker — offline-first app shell */
|
|
const CACHE = 'polycity-v1';
|
|
const PRECACHE = ['./', './index.html', './manifest.webmanifest', './icon.svg', './icon-maskable.svg'];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
e.waitUntil(
|
|
caches.open(CACHE).then((c) => c.addAll(PRECACHE)).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())
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
const url = new URL(e.request.url);
|
|
if (e.request.method !== 'GET' || url.origin !== location.origin) return;
|
|
// cache-first for hashed assets, network-first for navigations
|
|
if (url.pathname.includes('/assets/')) {
|
|
e.respondWith(
|
|
caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => {
|
|
const copy = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(e.request, copy));
|
|
return res;
|
|
}))
|
|
);
|
|
} else if (e.request.mode === 'navigate') {
|
|
e.respondWith(
|
|
fetch(e.request)
|
|
.then((res) => { caches.open(CACHE).then((c) => c.put('./index.html', res.clone())); return res; })
|
|
.catch(() => caches.match('./index.html'))
|
|
);
|
|
}
|
|
});
|