const CACHE = 'forge-reactor-build-0009';
const ASSETS = [
  './', './index.html', './manifest.webmanifest?v=0009',
  './css/main.css?v=0009', './css/game.css?v=0009',
  './js/app.js?v=0009', './js/config.js', './js/ui/info-modal.js', './js/lang/language.js',
  './js/core/game.js', './js/core/input.js', './js/core/loop.js', './js/core/state.js',
  './js/gameplay/objects.js', './js/gameplay/effects.js',
  './js/systems/storage.js', './js/systems/audio.js', './js/ui/hud.js', './js/ui/screens.js',
  './assets/images/reactor-background.jpg', './assets/images/brandsborg-splash.jpg'
];
self.addEventListener('install', event => event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(ASSETS)).then(() => self.skipWaiting())));
self.addEventListener('activate', event => event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())));
self.addEventListener('fetch', event => {
  if (event.request.method !== 'GET') return;
  if (event.request.mode === 'navigate') {
    event.respondWith(fetch(event.request, { cache:'no-store' }).then(response => { const copy=response.clone(); caches.open(CACHE).then(cache=>cache.put('./index.html',copy)); return response; }).catch(()=>caches.match('./index.html')));
    return;
  }
  event.respondWith(fetch(event.request, { cache:'no-store' }).then(response => { if(response.ok){ const copy=response.clone(); caches.open(CACHE).then(cache=>cache.put(event.request,copy)); } return response; }).catch(()=>caches.match(event.request)));
});
